import java.util.Vector;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class GameCanvas extends Canvas implements CommandListener {
protected Game game;
String color = "";
protected int empty;// 屏幕右侧留的空间
protected int x;// 棋盘输出的坐标
private boolean myTurn = false;
protected int cellWidth;// 每个棋格的边长
protected int mapWidth, canvasW;// 棋盘的宽度和画布的宽度
protected int a, b, c, d;// 这是画炮下面的那几个折线,没什么用
protected int chessR;// 棋子的半径
private int desknum = -1; // 桌子序号
private int seatPos = -1; // 座位序号
private boolean banker = false;
protected int selectedX, selectedY;// 选择框在棋盘格局上的x,y位置
protected static int i, j;
protected int m, n, p;// 记住开始的selectedX,selectedY和point[selectedX][selectedY]
protected String q;// 记住word[selectedX][selectedY]
protected int guard, guard1, guard2, g, g1;// 标记FIRE被按了多少次,g是用来判断走直线时前后的棋子,中间是否有其他棋子的累加器
protected static int g2, isRedWin, isWhiteWin;// g2表示该谁走了,后面那俩顾名思义了
private Client client;
protected Command exitCmd, start, ok;
private int point[][];
protected String[][] word;
public GameCanvas() {
};
public void init() {
// desknum = -1;
// seatPos = -1;
addCommand(start);
addCommand(exitCmd);
initWord();
banker = false;
myTurn = false;
}
public void reset() {
initWord();
addCommand(start);
addCommand(exitCmd);
banker = false;
myTurn = false;
}
public GameCanvas(Game game, Client client)// 构造函数
{
this.game = game;
this.client = client;
empty = getWidth() / 6;
x = empty * 1 / 3;
canvasW = getWidth() - empty;
mapWidth = canvasW - canvasW % 8;
cellWidth = mapWidth / 8;
a = cellWidth * 2 / 5;
b = cellWidth / 8;
c = cellWidth - a;
d = cellWidth - b;
chessR = cellWidth * 2 / 5;
selectedX = 4;
selectedY = 7;
guard = 0;
guard1 = selectedX;
guard2 = selectedY;
m = guard1;
n = guard2;
word = new String[10][9];
g2 = 1;
initWord();
exitCmd = new Command("退出", Command.EXIT, 0);
start = new Command("开始", Command.OK, 1);
addCommand(start);
addCommand(exitCmd);
setCommandListener(this);
}
public void initWord() {
point = new int[][] { { 1, 2, 3, 4, 5, 6, 7, 8, 9 },// 初始化INT数组
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 10, 0, 0, 0, 0, 0, 11, 0 },
{ 12, 0, 13, 0, 14, 0, 15, 0, 16 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 28, 0, 29, 0, 30, 0, 31, 0, 32 },
{ 0, 26, 0, 0, 0, 0, 0, 27, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 17, 18, 19, 20, 21, 22, 23, 24, 25 } };
for (i = 0; i < 10; i++)// 初始化字符数组
{
for (j = 0; j < 9; j++) {
if (i == 0) {
if (j == 0) {
word[i][j] = "车";
}
if (j == 1) {
word[i][j] = "马";
}
if (j == 2) {
word[i][j] = "相";
}
if (j == 3) {
word[i][j] = "士";
}
if (j == 4) {
word[i][j] = "帅";
}
if (j == 8) {
word[i][j] = "车";
}
if (j == 7) {
word[i][j] = "马";
}
if (j == 6) {
word[i][j] = "相";
}
if (j == 5) {
word[i][j] = "士";
}
}
if (i == 1) {
word[i][j] = "空";
}
if (i == 2) {
if ((j != 1) & (j != 7)) {
word[i][j] = "空";
}
if (j == 1) {
word[i][j] = "炮";
}
if (j == 7) {
word[i][j] = "炮";
}
}
if (i == 3) {
if (j % 2 == 0) {
word[i][j] = "卒";
}
if (j % 2 == 1) {
word[i][j] = "空";
}
}
if (i == 4) {
word[i][j] = "空";
}
if (i == 5) {
word[i][j] = "空";
}
if (i == 6) {
if (j % 2 == 0) {
word[i][j] = "卒";
}
if (j % 2 == 1) {
word[i][j] = "空";
}
}
if (i == 7) {
if ((j != 1) & (j != 7)) {
word[i][j] = "空";
}
if (j == 1) {
word[i][j] = "炮";
}
if (j == 7) {
word[i][j] = "炮";
}
}
if (i == 8) {
word[i][j] = "空";
}
if (i == 9) {
if (j == 0) {
word[i][j] = "车";
}
if (j == 1) {
word[i][j] = "马";
}
if (j == 2) {
word[i][j] = "相";
}
if (j == 3) {
word[i][j] = "士";
}
if (j == 4) {
word[i][j] = "帅";
}
if (j == 8) {
word[i][j] = "车";
}
if (j == 7) {
word[i][j] = "马";
}
if (j == 6) {
word[i][j] = "相";
}
if (j == 5) {
word[i][j] = "士";
}
}
}
}
}
public int getDeskIndex() {
return desknum;
}
public void setDeskIndex(int i) {
desknum = i;
}
public void setSeatPos(int i) {
seatPos = i;
}
public int getSeatPos() {
return seatPos;
}
protected void paintMapa(Graphics g)// 画河的上半部分的棋盘
{
for (int q = 0; q < 4; q++) {
for (int w = 0; w < 8; w++) {
g.setColor(128, 128, 128);
g.drawRect(x + w * cellWidth, x + q * cellWidth, cellWidth,
cellWidth);
}
}
g.setColor(128, 128, 128);
g.drawLine(x + 3 * cellWidth, x, x + 5 * cellWidth, x + 2 * cellWidth);
g.drawLine(x + 5 * cellWidth, x, x + 3 * cellWidth, x + 2 * cellWidth);
// 画左上方的炮
g.drawLine(x + d, x + cellWidth + c, x + d, x + cellWidth + d);// 左上竖
g.drawLine(x + c, x + cellWidth + d, x + d, x + cellWidth + d);// 左上横
g.drawLine(x + d + 2 * b, x + cellWidth + c, x + d + 2 * b, x
+ cellWidth + d);// 右上竖
g.drawLine(x + cellWidth + b, x + cellWidth + d, x + cellWidth + a, x
+ cellWidth + d);// 右上横
g.drawLine(x + d, x + 2 * cellWidth + b, x + d, x + 2 * cellWidth + a);// 左下竖
g.drawLine(x + c, x + cellWidth + d + 2 * b, x + d, x + cellWidth + d
+ 2 * b);// 左下横
g.drawLine(x + d + 2 * b, x + 2 * cellWidth + b, x + d + 2 * b, x + 2
* cellWidth + a);// 右下竖
g.drawLine(x + cellWidth + b, x + cellWidth + d + 2 * b, x + cellWidth
+ a, x + cellWidth + d + 2 * b);// 右下横
// 画右上方的炮
g.drawLine(x + d + 6 * cellWidth, x + cellWidth + c, x + d + 6
* cellWidth, x + cellWidth + d);
g.drawLine(x + c + 6 * cellWidth, x + cellWidth + d, x + d + 6
* cellWidth, x + cellWidth + d);
g.drawLine(x + d + 2 * b + 6 * cellWidth, x + cellWidth + c, x + d + 2
* b + 6 * cellWidth, x + cellWidth + 13 + 9);
g.drawLine(x + cellWidth + b + 6 * cellWidth, x + cellWidth + d, x
+ cellWidth + a + 6 * cellWidth, x + cellWidth + d);
g.drawLine(x + d + 6 * cellWidth, x + 2 * cellWidth + b, x + d + 6
* cellWidth, x + 2 * cellWidth + a);
g.drawLine(x + c + 6 * cellWidth, x + cellWidth + d + 2 * b, x + d + 6
* cellWidth, x + cellWidth + d + 2 * b);
g.drawLine(x + d + 2 * b + 6 * cellWidth, x + 2 * cellWidth + b, x + d
+ 2 * b + 6 * cellWidth, x + 2 * cellWidth + a);
g.drawLine(x + cellWidth + b + 6 * cellWidth,
x + cellWidth + d + 2 * b, x + cellWidth + a + 6 * cellWidth, x
+ cellWidth + d + 2 * b);
}
protected void paintMapb(Graphics g)// 画那条河--楚河,哈哈
{
g.setColor(128, 128, 128);
g.drawRect(x, x + 4 * cellWidth, mapWidth, cellWidth);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
Font.SIZE_LARGE));
g.drawString("楚河 汉界", getWidth() / 2, x + 4 * cellWidth
+ cellWidth * 3 / 4, Graphics.HCENTER | Graphics.BASELINE);
}
protected void paintMapc(Graphics g)// 画河的下半部分的棋盘
{
for (int q = 0; q < 4; q++) {
for (int w = 0; w < 8; w++) {
g.setColor(128, 128, 128);
g.drawRect(x + w * cellWidth, x + (q + 5) * cellWidth,
cellWidth, cellWidth);
}
}
g.setColor(128, 128, 128);
g.drawLine(x + 3 * cellWidth, x + 7 * cellWidth, x + 5 * cellWidth, x
+ 9 * cel
没有合适的资源?快使用搜索试试~ 我知道了~
java小游戏编程源代码象棋游戏网络对战版
共43个文件
java:14个
class:10个
jad:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 186 浏览量
2023-09-13
01:44:30
上传
评论 3
收藏 532KB ZIP 举报
温馨提示
java小游戏编程源代码象棋游戏网络对战版 java小游戏编程源代码、象棋游戏、网络对战版、java象棋游戏代码、国际象棋java 发布与运行 1.服务器端配置 (1)将光盘\TM\10\XiangQiServer文件夹拷贝到Eclipse的工作空间中。 (2)启动Eclipse。 (3)选择“文件”/“导入”菜单项,展开“常规”节点,选择“现有项目到工作空间中”子节点,如图1.1所示。 (4)单击【下一步】按钮,单击【浏览】按钮,选择程序所在目录,然后勾选“将项目复制到工作空间中”复选框,如图1.2所示。 (5)单击【完成】按钮。 (7)参照第7章文档中的7.3.5节中的第5小节,为MyEclipse配置Tomcat服务器。 (8)单击工具栏的“”按钮,将弹出如图1.3所示的对话框。这个对话框是项目发布对话框,在对话框的“Project”下拉选择框中选择本系统的项目名称“XiangQiServer”,单击Add按钮进行项目发布的设置。
资源推荐
资源详情
资源评论
收起资源包目录
java小游戏编程源代码象棋游戏网络对战版.zip (43个子文件)
xiangqi
.classpath 242B
.settings
org.eclipse.jdt.core.prefs 208B
org.eclipse.core.resources.prefs 354B
src
com
lzw
Client.java 3KB
GameCanvas.java 27KB
Game.java 4KB
false.gif 4KB
win.gif 4KB
deployed
xiangqi.jar 24KB
xiangqi.jad 301B
.eclipseme 242B
res
xiangqi.jad 277B
.eclipseme.tmp
emulation
xiangqi.jar 24KB
xiangqi.jad 301B
verified
classes
com
lzw
Game.class 5KB
GameCanvas$1.class 656B
Client.class 4KB
GameCanvas.class 25KB
libs
.models 95B
.project 709B
.processed
src
Client.java 3KB
GameCanvas.java 30KB
Game.java 4KB
com
lzw
Client.java 3KB
GameCanvas.java 27KB
Game.java 4KB
readme.doc 446KB
XiangQiServer
.classpath 340B
.mymetadata 312B
src
com
lzw
Queue.java 1KB
Desk.java 4KB
Umpire.java 2KB
Server.java 5KB
Player.java 1KB
WebRoot
WEB-INF
classes
Server.class 6KB
Desk.class 5KB
Player.class 2KB
Queue$EmptyQueueException.class 413B
Queue.class 1KB
Umpire.class 2KB
lib
web.xml 501B
META-INF
MANIFEST.MF 39B
.project 1KB
.myeclipse
共 43 条
- 1
资源评论
- liuxiaoxiao00022024-05-01资源和描述一致,质量不错,解决了我的问题,感谢资源主。
心兰相随引导者
- 粉丝: 1104
- 资源: 5639
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功