五子棋游戏项目报告(共2篇)
一、目的:
1、完成疯狂java讲义第四章作业
2、提升代码能力
3、熟悉java语言
二、环境:
Windows8.1系统、jdk1.8、记事本(需要把文件扩展名改成java)
三、遇到的问题:
1、错误需要为class、interface或enum的问题
这个问题,经调试发现是因为注释的时候使用了嵌套注释,即在跨行注释/* */里面添加了跨行注释
2、如何提取控制台输入的问题
这个问题,根据书上例子,采用bufferedreader解决,具体可以参见api文档.3、斜方向棋子的检测问题
这个问题,解决它所需要的算法,着实让我头疼了一下.因为我是以棋盘左边第一列为基准进行斜上方和斜下方的检测,以及以棋盘最后一列为基准进行斜上方和斜下方的检测.第一列的检测会好做很多,因为只需要两层嵌套for循环的i和j相加或相减就可以实现斜方向的递进.而以最后一列的,则需要让两层嵌套for循环i和j的初始值设定为棋盘大小,然后递减.这就导致无法直接用i和j相加或相减来实现递进.我的解决办法是引入额外的变量reduce(具体详见源码),从0开始递增,这样就可以用i和reduce的相加或相减来实现递进.四、所做的内容: 和大多数五子棋游戏代码一样,我也是采用一个二维数组board来作为棋盘.同时采用一个全局变量boardsize来指定这个二维数组的大小,类似于这样:board[boardsize][boardsize].然后使用水平、竖直、斜方向来检测游戏是否出现结果。
有棋盘初始化函数,对二维数组board[][]进行赋值.有棋盘打印函数实现棋盘的显示.一个棋子输入函数.一个胜负检测函数.一个信息输出函数.然后在main函数里面采用while循环实现游戏的流程.列举几个很有用的变量:
Board[][];//字符串型,作为棋盘的二维数组,是全局变量
Boardsize;//int型,控制棋盘大小,是全局变量
E_o_t;//布尔变量,用来判断main函数中的while循环是否结束.即实现游戏是否结束功能.W_steps,B_steps;//int型,用来记录白棋,黑棋连在一起的棋子的个数,它们中的任何一个值达到5,则代表相应的棋手赢了.Reduce;//int型,在胜负检测函数中斜方向的检测用到,前面用介绍.控制台用到的命令:
Javac;//用来编译记事本写的程序.Java;//用来执行编译过的程序
五、总结:
这次的作业,感觉对自己的代码能力有一定的提升,同时,对java编程有了更深的认识, 同时了解到在java编程中,几乎所有的全局变量和方法函数,需要被定义成static.也认识到java提供的一些方法函数功能十分强大,例如bufferedreader.六、源码:
importjava.io.InputStreamReader;importjava.io.BufferedReader;public class test2{ private static String[][] board;private static intboard_size=16;
private static boolean PLAYER=true;//棋手,默认白棋先下.false代表黑棋,true代表白棋 private static booleane_o_n=true;//作为循环(游戏)是否结束的依据,意思为end or not.public static void board_init(){ board=new String[board_size][board_size];for(inti=0;i for(int j=0;j board[i][j]=“+”; } } } public static void board_print(){ for(inti=0;i if(i==0){ for(intbou=0;bou if(bou==0) System.out.print(bou+“-------”); else if(bou>=1&&bou<=9) System.out.print(“0”+bou+“-”); else System.out.print(bou+“-”); } System.out.print(“n”); } for(int j=0;j if(j==0){ System.out.print(i+1+“t”+board[i][j]); } else System.out.print(“-”+board[i][j]); } } System.out.print(“n”);} for(intbou=0;bou if(bou==0) System.out.print(“--------”); else if(bou>=1&&bou<=9) System.out.print(“0”+bou+“-”); else System.out.print(bou+“-”); } System.out.print(“n”); //实现棋子输入并调换棋手 public static void qizi_input(inta,int b){ int x=a-1; int y=b-1; if(x>=0&&y if(true==PLAYER){ board[x][y]=“●”; PLAYER=false; } else{ } } else board[x][y]=“○”;PLAYER=true; System.out.println(“【棋子必须落在棋盘上且该位置没有已下的棋子!】”); } public static void WINNERis(){ //实现判断胜负方法并输出输赢信息 intB_steps=0;intW_steps=0;for(inti=0;i for(int j=0;j if(board[i][j]==“●”){ W_steps++; } else{ W_steps=0;} if(board[i][j]==“○”){ B_steps++;} else{ B_steps=0;} if(5==W_steps){ System.out.print(“【白棋赢了O(∩_∩)O!黑棋输了~(╯﹏╰)~】”);e_o_n=false;break;} if(5==B_steps){ System.out.print(“【黑棋赢了O(∩_∩)O!白棋输了~(╯﹏╰)~】”); e_o_n=false; break; } } W_steps=0;B_steps=0; } for(int j=0;j for(inti=0;i if(board[i][j]==“●”){ W_steps++;} else{ W_steps=0;} if(board[i][j]==“○”){ B_steps++;} else{ B_steps=0;} if(5==W_steps){ System.out.print(“【白棋赢了O(∩_∩)O!黑棋输了~(╯﹏╰)~】”);e_o_n=false;break;} “); ”); if(5==B_steps){ System.out.print(“【黑棋赢了O(∩_∩)O!白棋输了~(╯﹏╰)~】”); e_o_n=false; break; } } W_steps=0;B_steps=0; } for(inti=0;i for(int j=0;j if(i+j if(board[i+j][j]==“●”){ W_steps++;} else{ W_steps=0;} if(board[i+j][j]==“○”){ B_steps++;} else{ B_steps=0;} if(5==W_steps){ System.out.print(“【白棋赢了O(∩_∩)O!黑棋输了~(╯﹏╰)~】 e_o_n=false;break;} if(5==B_steps){ System.out.print(”【黑棋赢了O(∩_∩)O!白棋输了~(╯﹏╰)~】 e_o_n=false; break; } } else continue;} for(int j=0;j if(board[i-j][j]==“●”){ “); ”); W_steps++;} else{ W_steps=0;} if(board[i-j][j]==“○”){ B_steps++;} else{ B_steps=0;} if(5==W_steps){ System.out.print(“【白棋赢了O(∩_∩)O!黑棋输了~(╯﹏╰)~】 e_o_n=false;break;} if(5==B_steps){ System.out.print(”【黑棋赢了O(∩_∩)O!白棋输了~(╯﹏╰)~】 e_o_n=false; break; } } else continue;} W_steps=0;B_steps=0; } for(inti=board_size-2;i>0;i--){ //实现最右列的斜方向的判断 int reduce=0;for(int j=board_size-1;j>0;j--){ if(i-reduce>0){ if(board[i-reduce][j]==“●”){ W_steps++;} else{ W_steps=0;} if(board[i-reduce][j]==“○”){ B_steps++;} “); ”); “); ”); else{ B_steps=0;} if(5==W_steps){ System.out.print(“【白棋赢了O(∩_∩)O!黑棋输了~(╯﹏╰)~】 e_o_n=false;break;} if(5==B_steps){ System.out.print(”【黑棋赢了O(∩_∩)O!白棋输了~(╯﹏╰)~】 e_o_n=false; break; } reduce++;} else continue;} reduce=0;for(int j=board_size-1;j>0;j--){ if(board_size>i+reduce){ if(board[i+reduce][j]==“●”){ W_steps++; } else{ W_steps=0; } if(board[i+reduce][j]==“○”){ B_steps++; } else{ B_steps=0; } if(5==W_steps){ System.out.print(“【白棋赢了O(∩_∩)O!黑棋输了~(╯﹏╰)~】 e_o_n=false;break;} if(5==B_steps){ System.out.print(”【黑棋赢了O(∩_∩)O!白棋输了~(╯﹏╰)~】 e_o_n=false; break; } reduce++; } else continue; } W_steps=0; B_steps=0; } } public static void INFO_SHOW(){ //显示棋盘及必要信息:落子方重新开始退出游戏 System.out.println(“【输入格式为:‘1,1’或者‘88,99’】”); if(true==PLAYER) System.out.print(“【想重新开始吗?请输入暗号88,88】【想退出游戏吗?请输入暗号66,66】n【现在落子方是白棋:”); else System.out.print(“【想重新开始吗?请输入暗号88,88】【想退出游戏吗?请输入暗号66,66】n【现在落子方是黑棋:”);} public static void main(String[] args)throws java.io.IOException { /** **实现整个逻辑流程的实现,** **黑白两方的步数统计 **胜负信息输出*/ test2 WUZIQI= new test2();//创建对象 System.out.print(“【控制台五子棋,超高逼格版】n【默认白棋先下,你无法改变,这就是命!】n【请务必根据指示操作】n”); WUZIQI.board_init(); WUZIQI.board_print(); //实现电脑控制台的输入读取 BufferedReader P_INPUT= new BufferedReader(new InputStreamReader(System.in)); String str_input= null; //循环体实现游戏框架 while(e_o_n){ INFO_SHOW(); } } str_input=P_INPUT.readLine();String[] posStrArr=str_input.split(“,”);intxPos=Integer.parseInt(posStrArr[0]);intyPos=Integer.parseInt(posStrArr[1]);if(88==xPos&&88==yPos){ WUZIQI.board_init();continue;} if(66==xPos&&66==yPos){ e_o_n=false;continue;} qizi_input(xPos,yPos);WUZIQI.board_print();WINNERis();System.out.println(“n【游戏结束,再见哦,亲!】”); 课程设计报告 学 院: 信息科学技术学院 班 级: 软件技术2班 姓 名: 王更新 学 号: 1108900505 指导教师: 郭韶升 课设时间: 2014-03-17 至2014-03-26 二O一四 年 三月 二十六 日 目 录 一、设计要求…………………………………………....2 二、设计步骤…………………………………………....2 2.1程序流程图………………………….…………...2 2.2程序的功能分配……………………….………...3 三、设计正文…………………………………………....6 3.1创建棋盘类……………………………………….6 3.2判断输赢功能实现……………………………….9 3.3测试结果……………………………………….....9 四、心得体会…………………………………………...12 五、参考文献…………………………………………...12 附录(源代码)……………………………………….13 一、课程设计要求 设计一个15╳15围棋棋盘,由两玩家交替进行对战,并可以实现以下功能: 1.选择落子的先后顺序 2.重置棋盘 3.刷新重新开始 4.退出提示 并且规定退出者判为负,但退出过程中要有提示。以防不小心点错了。最后判断某一方是否为五子连珠。 实现一个简单的多用户五子棋的游戏程序,包括如下两个界面(1)选择对弈桌(执黑、执白)。 (2)在游戏界面,有开始,退出(游戏未结束、点退出自动判负); 二、设计步骤 2.1程序流程图 2.2 程序的功能分配 a.棋盘的绘制 public void draw_qipan(Graphics G)//画棋盘 15*15{ G.setColor(Color.lightGray); G.fill3DRect(10,10,300,300,true); G.setColor(Color.black); for(int i=1;i<16;i++){ G.drawLine(20,20*i,300,20*i); G.drawLine(20*i,20,20*i,300); } } b.添加按钮 Button b1=new Button(“开始”);Button b2=new Button(“重置游戏”);Label lblWin=new Label(“ ”);Checkbox ckbHB[]=new Checkbox[3];Button exist = new Button(“退出”);public void init(){ ckbHB[0]=new Checkbox(“执白”,ckgHB,false); ckbHB[1]=new Checkbox(“执黑”,ckgHB,false); ckbHB[2]=new Checkbox(“观看”,ckgHB, false);} c.鼠标棋子的触发事件 public void mouseClicked(MouseEvent e){ Graphics g=getGraphics(); int x1,y1; x1=e.getX(); y1=e.getY(); if(e.getX()<20 || e.getX()>300 || e.getY()<20 || e.getY()>300){ return; } if(x1%20>10){ x1+=10; } if(y1%20>10){ y1+=10; } x1=x1/20*20; y1=y1/20*20; set_Qizi(x1,y1); m*=(-1);} d.按钮的触发事件 public void actionPerformed(ActionEvent e){ Graphics g=getGraphics(); if(e.getSource()==b1){ Game_start(); } else{ Game_re(); } if(e.getSource()==exist){ Game_re(); lblWin.setText(Get_qizi_color(color_Qizi)+“输了!”); intGame_Start=0; } e.判断落子的位置及画出相应的黑白棋子 public void set_Qizi(int x,int y)//落子{ if(intGame_Start==0)//判断游戏未开始{ return; } if(intGame_Body[x/20][y/20]!=0){ return; } Graphics g=getGraphics(); if(color_Qizi==1)//判断黑子还是白子{ g.setColor(Color.black); color_Qizi=0; } else{ g.setColor(Color.white); color_Qizi=1; } g.fillOval(x-10,y-10,20,20); intGame_Body[x/20][y/20]=color_Qizi+1;} f.判断胜负 if(Game_win_1(x/20,y/20))//判断输赢1{ lblWin.setText(Get_qizi_color(color_Qizi)+“赢了!”); intGame_Start=0; } if(Game_win_2(x/20,y/20))//判断输赢2{ lblWin.setText(Get_qizi_color(color_Qizi)+“赢了!”); intGame_Start=0;} if(Game_win_3(x/20,y/20))//判断输赢3{ lblWin.setText(Get_qizi_color(color_Qizi)+“赢了!”);intGame_Start=0;} if(Game_win_4(x/20,y/20))//判断输赢4{ lblWin.setText(Get_qizi_color(color_Qizi)+“赢了!”); intGame_Start=0;} } 三、设计正文 3.1创建棋盘类 Public class WcyChess extends Applet ActionListener,MouseListener,MouseMotionListener,ItemListener{ int color_Qizi=0;//旗子的颜色标识 0:白子 1:黑子 int intGame_Start=0;//游戏开始标志 0未开始 1游戏中 int intGame_Body[][]=new int[16][16];//设置棋盘棋子状态 int m=-1;Button b1=new Button(“开始”);Button b2=new Button(“重置游戏”);Label lblWin=new Label(“ ”);Checkbox ckbHB[]=new Checkbox[3];Button exist = new Button(“退出”);CheckboxGroup ckgHB=new CheckboxGroup();NetchatClient chat=new NetchatClient();public void init(){ setLayout(null); addMouseListener(this); add(b1); b1.setBounds(330,50,80,30); b1.addActionListener(this); add(b2); b2.setBounds(330,90,80,30); b2.addActionListener(this); ckbHB[0]=new Checkbox(“执白”,ckgHB,false); ckbHB[0].setBounds(320,20,60,30); ckbHB[1]=new Checkbox(“执黑”,ckgHB,false); ckbHB[1].setBounds(380,20,60,30); ckbHB[2]=new Checkbox(“观看”,ckgHB, false); add(ckbHB[0]); add(ckbHB[1]); add(ckbHB[2]); ckbHB[0].addItemListener(this); ckbHB[1].addItemListener(this); add(lblWin); lblWin.setBounds(330,180,80,30); lblWin.setBackground(Color.red); lblWin.setText(“胜利者!”);//没有显示? ckbHB[2].setBounds(440, 20,60, 30); add(exist); exist.setBounds(330,130,80,30); implements // exist.addActionListener(this);add(chat);chat.setBounds(20, 500, 300, 300);chat.frame();chat.setVisible(true);Game_start_csh();setSize(500,600);setVisible(true);} public void itemStateChanged(ItemEvent e){ if(ckbHB[0].getState())//选择黑子还是白子{ color_Qizi=0;} else{ color_Qizi=1;} } public void mousePressed(MouseEvent e){} public void mouseClicked(MouseEvent e){ Graphics g=getGraphics();int x1,y1;x1=e.getX();y1=e.getY();if(e.getX()<20 || e.getX()>300 || e.getY()<20 || e.getY()>300){ return;} if(x1%20>10){ x1+=10;} if(y1%20>10){ y1+=10;} x1=x1/20*20;y1=y1/20*20;set_Qizi(x1,y1);m*=(-1);} public void actionPerformed(ActionEvent e){ Graphics g=getGraphics();if(e.getSource()==b1){ Game_start();} else { Game_re();} } if(e.getSource()==exist){ Game_re(); lblWin.setText(Get_qizi_color(color_Qizi)+“输了!”); intGame_Start=0;} } public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseDragged(MouseEvent e){} public void mouseMoved(MouseEvent e){} public void paint(Graphics g){ draw_qipan(g); 3.2判断输赢功能实现 if(Game_win_1(x/20,y/20)){ //判断输赢1 lblWin.setText(Get_qizi_color(color_Qizi)+“赢了!”); intGame_Start=0;} if(Game_win_2(x/20,y/20)){ //判断输赢2 lblWin.setText(Get_qizi_color(color_Qizi)+“赢了!”); intGame_Start=0;} if(Game_win_3(x/20,y/20))//判断输赢3{ lblWin.setText(Get_qizi_color(color_Qizi)+“赢了!”); intGame_Start=0;} if(Game_win_4(x/20,y/20))//判断输赢4{ lblWin.setText(Get_qizi_color(color_Qizi)+“赢了!”); intGame_Start=0;} 3.3 测试结果 a.进入游戏界面 游戏开始的界面有三个选择项,用户可以选择相应的角色,选择 完毕后点击开始进入游戏。 b.选择角色,开始下棋 首先达到五个棋子连在一块的赢了,并在红色区域显示谁赢了!c.下完后,重新开始 下完一盘后游戏停止,点击重新开始,界面回到初始界面,选择角色继续游戏.d.游戏中点退出,自动判输 在下棋的过程当中谁中途退出,即点击退出,系统自动判断谁输 四、课程设计心得体会 通过此次课程设计,将我本学期所学的JAVA知识得到巩固和应用,在设计的过程中我遇到了很到问题,不过在老师和同学们的帮助和自己的思考下还是很好的完成了。这此课程设计还让我懂得了写程序不能闭门造车,要努力拓宽知识面,开阔视野,拓展思维。它还让我学会了在网上查阅那些无限的资料。由于自己的分析设计和程序经验不足,该系统设计和实现过程中,还有许多没有完善的地方,比如用户界面设计不够美观,异常出错处理比较差等多方面问题,这些都有待进一步完善和提高。对于文中出现的不足和系统中出现的问题敬请老师指导。 五、参考文献 1.吴其庆编著.Java程序设计实例教程.北京:冶金工业出版社 2.柳西玲.许斌编著.Java语言应用开发基础.北京:清华大学出版社 3.丁振凡 Java 语言实用教程 :北京邮电大学出版社 附录(源代码) import java.net.*;import java.io.*;import java.applet.*;import java.awt.*;import java.awt.event.*;import java.applet.Applet;import java.awt.Color;Public class wuziqi extends Applet implements ActionListener,MouseListener,MouseMotionListener,ItemListener{ int color_Qizi=0;//旗子的颜色标识 0:白子 1:黑子 int intGame_Start=0;//游戏开始标志 0未开始 1游戏中 int intGame_Body[][]=new int[16][16];//设置棋盘棋子状态 int m=-1;Button b1=new Button(“开始”);Button b2=new Button(“重新开始”);Label lblWin=new Label(“ ”);Checkbox ckbHB[]=new Checkbox[3];Button exist = new Button(“退出”);CheckboxGroup ckgHB=new CheckboxGroup();public void init(){ setLayout(null); addMouseListener(this); add(b1); b1.setBounds(330,50,80,30); b1.addActionListener(this); add(b2); b2.setBounds(330,90,80,30); b2.addActionListener(this); ckbHB[0]=new Checkbox(“执白”,ckgHB,false); ckbHB[0].setBounds(320,20,60,30); ckbHB[1]=new Checkbox(“执黑”,ckgHB,false); ckbHB[1].setBounds(380,20,60,30); ckbHB[2]=new Checkbox(“观看”,ckgHB, false); add(ckbHB[0]); add(ckbHB[1]); add(ckbHB[2]); ckbHB[0].addItemListener(this); ckbHB[1].addItemListener(this); add(lblWin); lblWin.setBounds(330,180,80,30); lblWin.setBackground(Color.red); e.getY()<20 || e.getY()>300){ lblWin.setText(“胜利者!”);//没有显示? ckbHB[2].setBounds(440, 20,60, 30);add(exist); exist.setBounds(330,130,80,30);exist.addActionListener(this);Game_start_csh();setSize(500,600);setVisible(true);} public void itemStateChanged(ItemEvent e){ if(ckbHB[0].getState())//选择黑子还是白子 { color_Qizi=0;} else { color_Qizi=1;} } public void mousePressed(MouseEvent e){} public void mouseClicked(MouseEvent e){ Graphics g=getGraphics();int x1,y1;x1=e.getX();y1=e.getY(); if(e.getX()<20 || e.getX()>300 || return;} if(x1%20>10){ x1+=10;} if(y1%20>10){ y1+=10;} x1=x1/20*20;y1=y1/20*20;set_Qizi(x1,y1);m*=(-1)} public void actionPerformed(ActionEvent e){ Graphics g=getGraphics();if(e.getSource()==b1){ Game_start(); } else{ // 输了!“); 赢了!”); Game_re();} if(e.getSource()==exist){ Game_re(); color_Qizi=m; lblWin.setText(Get_qizi_color(color_Qizi)+“ intGame_Start=0; } } public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseDragged(MouseEvent e){} public void mouseMoved(MouseEvent e){} public void paint(Graphics g){ draw_qipan(g);} public void set_Qizi(int x,int y){ //落子 if(intGame_Start==0){//判断游戏未开始 return;} if(intGame_Body[x/20][y/20]!=0){ return;} Graphics g=getGraphics(); if(color_Qizi==1){//判断黑子还是白子 g.setColor(Color.black); color_Qizi=0;} else{ g.setColor(Color.white); color_Qizi=1;} g.fillOval(x-10,y-10,20,20); intGame_Body[x/20][y/20]=color_Qizi+1;if(Game_win_1(x/20,y/20)){ //判断输赢1 lblWin.setText(Get_qizi_color(color_Qizi)+” intGame_Start=0; 了!“); 赢了!”); 赢了!“); 15*15 } if(Game_win_2(x/20,y/20)){ //判断输赢2{ lblWin.setText(Get_qizi_color(color_Qizi)+”赢 intGame_Start=0;} if(Game_win_3(x/20,y/20)){ //判断输赢3 lblWin.setText(Get_qizi_color(color_Qizi)+“ intGame_Start=0;} if(Game_win_4(x/20,y/20)){ //判断输赢4 lblWin.setText(Get_qizi_color(color_Qizi)+” intGame_Start=0;} } public String Get_qizi_color(int x){ if(x==0){ return “黑子”;} else { return “白子”;} } public void draw_qipan(Graphics G){ //画棋盘 G.setColor(Color.lightGray); G.fill3DRect(10,10,300,300,true);G.setColor(Color.black);for(int i=1;i<16;i++){ G.drawLine(20,20*i,300,20*i); G.drawLine(20*i,20,20*i,300);} } public void Game_start(){ //游戏开始 intGame_Start=1; Game_btn_enable(false); b2.setEnabled(true);} public void Game_start_csh(){//游戏开始初始化 intGame_Start=0; Game_btn_enable(true); b2.setEnabled(false); ckbHB[0].setState(true); for(int i=0;i<16;i++){ for(int j=0;j<16;j++){ intGame_Body[i][j]=0; } } lblWin.setText(“");} public void Game_re(){ //重新开始游戏 repaint(); Game_start_csh();} public void Game_btn_enable(boolean e){ //设置组件状态 b1.setEnabled(e); b2.setEnabled(e); ckbHB[0].setEnabled(e); ckbHB[1].setEnabled(e);} public boolean Game_win_1(int x,int y){ //横向判断输赢 int x1,y1,t=1; x1=x; y1=y; for(int i=1;i<5;i++){ if(x1>15){ break; } if(intGame_Body[x1+i][y1]==intGame_Body[x][y]){ t+=1; } else{ break; } } for(int i=1;i<5;i++){ if(x1<1){){ t+=1; } else{ break; } } if(t>4){ return true; } else{ return false; } } public boolean Game_win_2(int x,int y){ //纵向判断输赢 int x1,y1,t=1; x1=x; y1=y; for(int i=1;i<5;i++){ if(x1>15){ break; } if(intGame_Body[x1][y1+i]==intGame_Body[x][y]){ t+=1; } else{ break; } } for(int i=1;i<5;i++){ if(x1<1){ break; } if(intGame_Body[x1][y1-i]==intGame_Body[x][y]){ t+=1; } break; } if(intGame_Body[x1-i][y1]==intGame_Body[x][y] else{ break; } } if(t>4){ return true; } else{ return false; } } public boolean Game_win_3(int x,int y){ //左斜判断输赢 int x1,y1,t=1; x1=x; y1=y; for(int i=1;i<5;i++){ if(x1>15){ break; } if(intGame_Body[x1+i][y1-i]==intGame_Body[x][y]){ t+=1; } else{ break; } } for(int i=1;i<5;i++){ if(x1<1){ break; } if(intGame_Body[x1-i][y1+i]==intGame_Body[x][y]){ t+=1; } else{ break; } } if(t>4){ return true; } else{ return false; } } public boolean Game_win_4(int x,int y){ //左斜判断输赢 int x1,y1,t=1; x1=x; y1=y; for(int i=1;i<5;i++){ if(x1>15){ break; } if(intGame_Body[x1+i][y1+i]==intGame_Body[x][y]){ t+=1; } else{ break; } } for(int i=1;i<5;i++){ if(x1<1){ break; } if(intGame_Body[x1-i][y1-i]==intGame_Body[x][y]){ t+=1; } else{ break; } } if(t>4){ return true; } else{ return false; } } }五子棋JAVA语言课程设计报告 篇2