import java.util.Hashtable;
import java.util.Vector;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class GameCanvas extends Canvas implements CommandListener
{
private MyMidlet game;
private boolean dinfo = true;
private Image LRCardImage = null;
private Image UPCardImage = null;
private Image backImage = null;
private Image backGround = null;
private Image messageBak = null;
private Image messageImage = null;
private Image showButtond;
private Image tempButtonImg = null;
private Image panel;
private Image scoreImage;
private Image scoreGround;
private Image infoImage;
private Image[] playerImg = new Image[2];
private Graphics bufferg;
private Graphics messageBuffer;
private Graphics scoreBuffer;
private final int NUM = 4;
private final int cardWidth;
private final int cardHeight;
private Vector cardsRound;
private int roundNum;// 局数
private int roundKey;
private final int WIDTH = getWidth();
private final int HEIGHT = getHeight();
private int messageWidth;
private int messageHeight;
private int selectIndex = -1;
private int cardCount = 13;// 牌数
private int LCount = 13;// 左面玩家的牌数
private int RCount = 13;// 右面玩家的牌数
private int UCount = 13;// 对面玩家的牌数
private boolean myTurn = false;// 是不是到我出牌
private Card[] myCard = new Card[cardCount];
private Card[][] scores = new Card[NUM][14];
private String[] playerName = new String[NUM];
private Hashtable scoreAmount = new Hashtable();
private int desknum = -1; // 桌子序号
private int seatPos = -1; // 座位序号
private boolean banker = false;// 判断自己是不是庄
private Client client;
protected Command exitCmd, start;
private boolean keyPress = true;
private boolean gameOver = false;
public void init()
{
banker = false;
myTurn = false;
this.addCommand(start);
}
public void reset()
{
cardCount = 13;
scoreAmount.clear();
cardsRound.removeAllElements();
roundKey = 0;
roundNum = 0;
cls();
scoreCls();
for (int i = 0; i < NUM; i++)
for (int j = 0; j < 14; j++)
scores[i][j] = new Card(-1);
keyPress = true;
gameOver = false;
banker = false;
myTurn = false;
}
public GameCanvas(MyMidlet game, Client client)// 构造函数
{
try
{
infoImage = Image.createImage("/message/bg_playerinfo.png");
playerImg[0] = Image.createImage("/message/nan.png");
playerImg[1] = Image.createImage("/message/nv.png");
LRCardImage = Image.createImage("/cards/h.png");
UPCardImage = Image.createImage("/cards/0.png");
messageImage = Image.createImage("/message.png");
showButtond = Image.createImage("/button/show.png");
if (WIDTH <= 180)
{
scoreGround = Image.createImage("/score180.png");
backGround = Image.createImage("/back.png");
}
else if (WIDTH >= 240)
{
scoreGround = Image.createImage("/score240.png");
backGround = Image.createImage("/bigBack.png");
}
}
catch (Exception e)
{
System.out.println("error image...");
e.printStackTrace();
}
if (messageImage != null)
{
messageWidth = messageImage.getWidth();
messageHeight = messageImage.getHeight();
}
else
{
messageWidth = -1;
messageHeight = -1;
}
cardWidth = UPCardImage.getWidth();
cardHeight = UPCardImage.getHeight();
panel = Image.createImage(WIDTH, HEIGHT);
messageBak = Image.createImage(messageWidth, messageHeight);
scoreImage = Image.createImage(scoreGround.getWidth(), scoreGround
.getHeight());
scoreBuffer = scoreImage.getGraphics();
scoreCls();
messageBuffer = messageBak.getGraphics();
bufferg = panel.getGraphics();
cls();
cardsRound = new Vector();
roundKey = 0;
roundNum = 0;
for (int i = 0; i < NUM; i++)
{
playerName[i] = "P" + i;
for (int j = 0; j < 14; j++)
scores[i][j] = new Card(-1);
}
this.game = game;
this.client = client;
exitCmd = new Command("退出", Command.EXIT, 0);
start = new Command("开始", Command.OK, 1);
addCommand(start);
addCommand(exitCmd);
setCommandListener(this);
}
public int getDeskIndex()
{
return desknum;
}
public void setDeskIndex(int i)
{
desknum = i;
}
public void setSeatPos(int i)
{
seatPos = i;
}
public int getSeatPos()
{
return seatPos;
}
private void scoreCls()
{
scoreBuffer.drawImage(scoreGround, 0, 0, Graphics.LEFT | Graphics.TOP);
}
private void cls()
{
bufferg.drawImage(backGround, WIDTH / 2, HEIGHT / 2, Graphics.HCENTER
| Graphics.VCENTER);
}
protected void paint(Graphics g)
{
drawPlayer(gameOver);
g.drawImage(panel, 0, 0, Graphics.LEFT | Graphics.TOP);
if (dinfo)
drawInfo(g);
}
public void commandAction(Command c, Displayable d)
{
if (c == exitCmd)
{
client.sendMessage("exit");
seatPos = -1;
desknum = -1;
MyMidlet.display.setCurrent(game.getPlayerList());
}
else if (c == start)
{
banker = false;
reset();
this.removeCommand(start);
client.sendMessage("start");
}
}
private void drawPlayer(boolean show)
{
if (!gameOver)
{
for (int i = 0; i < NUM; i++)
{
char[] playerChar = playerName[i].toCharArray();
int wid = Font.getDefaultFont().charsWidth(playerChar, 0,
playerChar.length - 1);
if (i == seatPos)
{
bufferg.drawString(playerName[i], (WIDTH - wid) / 2, HEIGHT
- Font.getDefaultFont().getHeight() - cardHeight
- 10, Graphics.LEFT | Graphics.TOP);
}
else if (i == (seatPos + 1) % NUM)
{
bufferg.drawString(playerName[i], WIDTH - wid - 25,
HEIGHT / 2 - 10, Graphics.LEFT | Graphics.TOP);
}
else if (i == (seatPos + 2) % NUM)
{
bufferg.drawString(playerName[i], (WIDTH - wid) / 2, 10,
Graphics.LEFT | Graphics.TOP);
}
else if (i == (seatPos + 3) % NUM)
{
bufferg.drawString(playerName[i], 25, HEIGHT / 2 - 10,
Graphics.LEFT | Graphics.TOP);
}
}
}
}
private void drawUBackCard()
{
int px = WIDTH / 2 - 13 * 10 / 2;
int x = WIDTH / 2 - cardCount * 10 / 2;
int y = 5;
int oldx = bufferg.getClipX();
int oldy = bufferg.getClipY();
int oldw = bufferg
没有合适的资源?快使用搜索试试~ 我知道了~
java手机字牌游戏
共245个文件
png:198个
class:17个
java:10个
3星 · 超过75%的资源 需积分: 9 286 下载量 52 浏览量
2008-04-12
21:42:54
上传
评论 2
收藏 924KB RAR 举报
温馨提示
java手机字牌游戏
资源推荐
资源详情
资源评论
收起资源包目录
java手机字牌游戏 (245个子文件)
GameCanvas.class 19KB
GameCanvas.class 17KB
Desk.class 7KB
Server.class 6KB
MyMidlet.class 6KB
MyMidlet.class 5KB
Client.class 4KB
Client.class 4KB
Score.class 2KB
Player.class 2KB
Card.class 1KB
Card.class 1KB
Queue.class 1KB
GameCanvas$1.class 1KB
GameCanvas$1.class 1KB
Card.class 628B
Queue$EmptyQueueException.class 431B
.classpath 332B
.classpath 250B
Thumbs.db 94KB
Thumbs.db 94KB
Thumbs.db 94KB
.eclipseme 214B
PigClient.jad 268B
PigClient.jad 243B
PigClient.jar 241KB
GameCanvas.java 27KB
Desk.java 9KB
Server.java 7KB
MyMidlet.java 6KB
Client.java 5KB
Score.java 3KB
Queue.java 1KB
Player.java 1KB
Card.java 859B
Card.java 382B
backimg.jpg 9KB
backimg.jpg 9KB
backimg.jpg 9KB
MANIFEST.MF 39B
.mymetadata 308B
bigBack.png 63KB
bigBack.png 63KB
bigBack.png 63KB
back.png 35KB
back.png 35KB
back.png 35KB
score240.png 19KB
score240.png 19KB
score240.png 19KB
score180.png 15KB
score180.png 15KB
score180.png 15KB
message.png 9KB
message.png 9KB
message.png 9KB
nan.png 7KB
nan.png 7KB
nan.png 7KB
nv.png 7KB
nv.png 7KB
nv.png 7KB
bg_playerinfo.png 6KB
bg_playerinfo.png 6KB
bg_playerinfo.png 6KB
show.png 5KB
show.png 5KB
show.png 5KB
0.png 412B
0.png 412B
0.png 412B
icon.png 380B
icon.png 380B
icon.png 380B
icon.png 380B
icon.png 380B
icon.png 380B
4.png 366B
4.png 366B
4.png 366B
1.png 365B
1.png 365B
1.png 365B
13.png 362B
15.png 362B
2.png 362B
2.png 362B
13.png 362B
15.png 362B
2.png 362B
15.png 362B
13.png 362B
17.png 361B
3.png 361B
3.png 361B
12.png 361B
12.png 361B
17.png 361B
3.png 361B
17.png 361B
共 245 条
- 1
- 2
- 3
资源评论
- sen_yang2012-07-19纯粹的标题党,是JAVA程序,但是不是字牌源码,是扑克。
- guiziwen2012-06-26纯粹的标题党,是JAVA程序,但是不会字牌源码,是扑克。
quchengbo
- 粉丝: 5
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功