> 动作冒险 > 7723手游免费手机游戏手机游戏下载游戏盒子下载(java小游戏合集)

7723手游免费手机游戏手机游戏下载游戏盒子下载(java小游戏合集)

来源:www.buanju.cn 时间:2023-06-25 16:20:10 作者:青山花争色

本文向给大家分享java小游戏合集相关知识,同时小编也会对java老版手机怀旧游戏大全进行解释,如果能解决您在java小游戏合集方面面临的问题,请收藏关注本站,现在开始吧!

小游戏集合app,一个汇集多种热门小游戏的合集作品,现在抖音上很多人
 

package day17.gobang;

import java.util.Arrays;

public class GoBangGame {
public static final char BLANK='*';
public static final char BLACK='@';
public static final char WHITE='O';

public static final int MAX = 16;
private static final int COUNT = 5;
//棋盘
private char[][] board;

public GoBangGame() {

}
//开始游戏
public void start() {
board = new char[MAX][MAX];
//把二维数组都填充‘*’
for(char[] ary: board){
Arrays.fill(ary, BLANK);
}
}
public char[][] getChessBoard(){
return board;
}
public void addBlack(int x, int y) throws ChessExistException{
//@
//char blank = '*';
//System.out.println( x +"," + y + ":" + board[y][x] + "," + BLANK);
if(board[y][x] == BLANK){// x, y 位置上必须是空的才可以添棋子
board[y][x] = BLACK;
return;
}
throw new ChessExistException("已经有棋子了!");
}
public void addWhite(int x, int y)
throws ChessExistException{
if(board[y][x] == BLANK){// x, y 位置上必须是空的才可以添棋子
board[y][x] = WHITE;
return;
}
throw new ChessExistException("已经有棋子了!");
}
//chess 棋子:'@'/'O'
public boolean winOnY(char chess, int x, int y){
//先找到y方向第一个不是 blank的棋子
int top = y;
while(true){
if(y==0 || board[y-1][x]!=chess){
//如果y已经是棋盘的边缘, 或者的前一个不是chess
//就不再继续查找了
break;
}
y--;
top = y;
}
//向回统计所有chess的个数,如果是COUNT个就赢了
int count = 0;
y = top;
while(true){
if(y==MAX || board[y][x]!=chess){
//如果找到头 或者 下一个子不是chess 就不再继续统计了
break;
}
count++;
y++;
}
return count==COUNT;
}
//chess 棋子:'@'/'O'
public boolean winOnX(char chess, int x, int y){
//先找到x方向第一个不是 blank的棋子
int top = x;
while(true){
if(x==0 || board[y][x-1]!=chess){
//如果x已经是棋盘的边缘, 或者的前一个不是chess
//就不再继续查找了
break;
}
x--;
top = x;
}
//向回统计所有chess的个数,如果是COUNT个就赢了
int count = 0;
x = top;
while(true){
if(x==MAX || board[y][x]!=chess){
//如果找到头 或者 下一个子不是chess 就不再继续统计了
break;
}
count++;
x++;
}
return count==COUNT;
}

//chess 棋子:'@'/'O'
public boolean winOnXY(char chess, int x, int y){
//先找MAX向第一个不是 blank的棋子
int top = y;
int left = x;
while(true){
if(x==0 || y==0 || board[y-1][x-1]!=chess){
//如果x已经是棋盘的边缘, 或者的前一个不是chess
//就不再继续查找了
break;
}
x--;
y--;
top = y;
left=x;
}
//向回统计所有chess的个数,如果是COUNT个就赢了
int count = 0;
x = left;
y = top;
while(true){
if(x==MAX || y==MAX || board[y][x]!=chess){
//如果找到头 或者 下一个子不是chess 就不再继续统计了
break;
}
count++;
x++;
y++;
}
return count==COUNT;
}
//chess 棋子:'@'/'O'
public boolean winOnYX(char chess, int x, int y){
//先找到x方向第一个不是 blank的棋子
int top = y;
int left = x;
while(true){
if(x==MAX-1 || y==0 || board[y-1][x+1]!=chess){
//如果x已经是棋盘的边缘, 或者的前一个不是chess
//就不再继续查找了
break;
}
x++;
y--;
top = y;
left=x;
}
//向回统计所有chess的个数,如果是COUNT个就赢了
int count = 0;
x = left;
y = top;
while(true){
if(x==0 || y==MAX || board[y][x]!=chess){
//如果找到头 或者 下一个子不是chess 就不再继续统计了
break;
}
count++;
x--;
y++;
}
return count==COUNT;
}

public boolean whiteIsWin(int x, int y) {
//在任何一个方向上赢了,都算赢
return winOnY(WHITE, x, y) ||
winOnX(WHITE, x, y) ||
winOnXY(WHITE, x, y) ||
winOnYX(WHITE, x, y);
}
public boolean blackIsWin(int x, int y) {
return winOnY(BLACK, x, y) ||
winOnX(BLACK, x, y) ||
winOnXY(BLACK, x, y) ||
winOnYX(BLACK, x, y);
}

}

以上就是与java小游戏合集以及java老版手机怀旧游戏大全的相关内容,看完java小游戏合集一文后,希望这对大家有所帮助!

上一篇:玩java游戏合集玩java游戏APP下载手机乐园(java手机游戏乐园)

下一篇:经典java手机游戏(手机java游戏大全)

声明:《7723手游免费手机游戏手机游戏下载游戏盒子下载(java小游戏合集)》一文由卜安居(www.buanju.cn)注册用户青山花争色自主发布上传,不代表本站观点,版权归原作者本人所有,转载请注明出处,如有侵权、虚假信息、错误信息或任何问题,可发邮件到81156344@qq.com处理!

最近更新