日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

从0开始 Java实习 黑白棋

發布時間:2023/12/2 java 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 从0开始 Java实习 黑白棋 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

黑白棋的設計

代碼如下:

import java.util.*; public class Chess{char[][] chess = new char[16][16];public static void main(String args[]){ Scanner in = new Scanner(System.in);Chess ch = new Chess();ch.init(); ch.output();int tag = 0;int nn = 0;while(nn < 225){System.out.println("please enter your place to put the chess");int x = in.nextInt();int y = in.nextInt();if(ch.set(x,y,nn) == false)continue;if(ch.judgeColumn(x,y)==true){System.out.println(ch.chess[x][y] + "win");tag = 1;break;}else if(ch.judgeRow(x,y)==true){System.out.println(ch.chess[x][y] + "win");tag = 1;break;}else if(ch.judgeLUtoRD(x,y)==true){System.out.println(ch.chess[x][y] + "win");tag = 1;break;}else if(ch.judgeRUtoLD(x,y)==true){System.out.println(ch.chess[x][y] + "win");tag = 1;break;}elsenn++; }if(tag == 0)System.out.println("平局");in.close();}boolean set(int ii, int jj,int nn){if(ii <1 || jj > 15 || ii > 15 || jj <1)return false;else{if(chess[ii][jj] == '+'){if(nn%2 == 1){chess[ii][jj] = '●';}else{chess[ii][jj] = '○';}output();return true;}else{System.out.println("you can't put your chess on this place");return false;} } }void init(){System.out.println("this is a 15*15 chess ");for(int i = 1; i <= 15; i++){for(int j = 1 ; j <= 15; j++){chess[i][j] = '+';}}}void output(){for(int i = 1 ; i <= 15; i++){for(int j = 1 ; j <= 15; j++){System.out.print(chess[i][j] + " ");}System.out.println();}System.out.println();}//judge columnboolean judgeColumn(int ii,int jj){int i = 1;int j = 1; while(ii-i >= 1 && chess[ii-i][jj] == chess[ii][jj]){i += 1;}while(ii+j <= 15 && chess[ii+j][jj] == chess[ii][jj]){j += 1;}if(i+j-1>=5)return true;elsereturn false;}//judge rowboolean judgeRow(int pi, int pj){int i = 1;int j = 1;while(pj-i>=1&&chess[pi][pj-i]==chess[pi][pj])i+=1;while(pj+j<=15&&chess[pi][pj+j]==chess[pi][pj])j+=1;if(i+j-1 >= 5)return true;elsereturn false;}//judge from left up to right downboolean judgeLUtoRD(int pi, int pj){int i = 1;int j = 1;while(pi+i<=15 && pj-i>=0 && chess[pi+i][pj-i] == chess[pi][pj])i+=1;while(pi-j>=0 && pj+j <= 15 && chess[pi-j][pj+j] == chess[pi][pj])j++;if(i+j-1>=5)return true;elsereturn false; }//jduge from right up to left downboolean judgeRUtoLD(int pi,int pj){int i = 1;int j = 1;while(pi+i <= 15 && pj+i <= 15 && chess[pi+i][pj+i] == chess[pi][pj])i+=1;while(pi-j >= 0 && pj-j >= 0 && chess[pi-j][pj-j] == chess[pi][pj])j+=1;if(i+j-1>=5)return true;elsereturn false;} }

轉載于:https://www.cnblogs.com/pprp/p/7856927.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的从0开始 Java实习 黑白棋的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。