欢迎来到天天文库
浏览记录
ID:40585270
大小:17.50 KB
页数:3页
时间:2019-08-04
《五子棋java编程》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、packageday;\修改包名和类名importjava.util.Scanner;publicclassb{publicstaticchara[][]=newchar[17][17];publicstaticStrings="0123456789abcdef";publicstaticvoidmain(String[]args){inti,b,x,y;charz;Scannersca=newScanner(System.in);startChar();for(i=0;i<100;i++){if(i%2==0){System.out.println("白子下:");b=sca.nextIn
2、t();if(b<100){x=b%10;y=b/10;}else{x=b%100;y=b/100;}z='@';newChar(x,y,z);isWin(x+1,y+1);}else{System.out.println("黑子下:");b=sca.nextInt();if(b<100){x=b%10;y=b/10;}else{x=b%100;y=b/100;}z='O';newChar(x,y,z);isWin(x+1,y+1);}}}publicstaticvoidstartChar(){inti,j;for(i=0;i<17;i++)for(j=0;j<17;j++){if(i==0)
3、a[i][j]=s.charAt(j);elseif(j==0)a[i][j]=s.charAt(i);elsea[i][j]='*';}for(i=0;i<17;i++){for(j=0;j<17;j++)System.out.print(a[i][j]+"");System.out.println();}}publicstaticvoidnewChar(intb,intc,chard){inti,j;if(b>=0&&b<16&&c>=0&&c<=16){for(i=0;i<17;i++){for(j=0;j<17;j++){if(i==b&&j==c){a[i+1][j+1]=d;}Sy
4、stem.out.print(a[i][j]+"");}System.out.println();}}else{System.out.println("你输入的坐标有误,请重新输入:");}}publicstaticvoidisWin(intb,intc){inti=1,i1=1,i2=1,i3=1,j=1,j1=1,j2=1,j3=1;while(a[b][c+i]==a[b][c]){i++;}while(a[b][c-j]==a[b][c]){j++;}if(i+j==6){System.out.println("你赢了!");}while(a[b+i1][c]==a[b][c]){i1
5、++;}while(a[b-j1][c]==a[b][c]){j1++;}if(i1+j1==6){System.out.println("你赢了!");}while(a[b-i2][c-i2]==a[b][c]){i2++;}while(a[b+j2][c+j2]==a[b][c]){j2++;}if(i2+j2==6){System.out.println("你赢了!");}while(a[b+i3][c-i3]==a[b][c]){i3++;}while(a[b-j3][c+j3]==a[b][c]){j3++;}if(i3+j3==6){System.out.println("你赢了!
6、");}}}
此文档下载收益归作者所有