chess類
public
class
chess
public
intgetxpos()
public
void
setxpos
(int xpos)
public
intgetypos()
public
void
setypos
(int ypos)
public string getchesstype()
public
void
setchesstype
(string chesstype)
}
fivestone類
public
class
fivestone
system.out.
println()
;}}private string gamechoicechess()
else
return choice;
}private
boolean
isseachsuccess
(string chess,
int i,
int j)
x=i;y=j;
while
(x-1
>=
0&&board[x-1]
[y].
getchesstype()
.equals
(chess))if
(count>=connection)}if
(j+1
[j+1].
getchesstype()
.equals
(chess)
//橫方向
||j-
1>=
0&&board[i]
[j-1].
getchesstype()
.equals
(chess)
) x=i;y=j;
while
(y-1
>=
0&&board[x]
[y-1].
getchesstype()
.equals
(chess))if
(count>=connection)}if
(j-1
>=
0&&i-
1>=
0&&board[i-1]
[j-1].
getchesstype()
.equals
(chess)
//斜方向
||i+
11[j+1].
getchesstype()
.equals
(chess)
) x=i;y=j;
while
(y+1
1[y+1].
getchesstype()
.equals
(chess))if
(count>=connection)}if
(j-1
>=
0&&i+
1[j-1].
getchesstype()
.equals
(chess)
//反斜方向
||i-
1>=
0&&j+
1[j+1].
getchesstype()
.equals
(chess)
) x=i;y=j;
while
(y+1
1>
0&&board[x-1]
[y+1].
getchesstype()
.equals
(chess))if
(count>=connection)
}return
false;}
public
void
start()
else
else
}//白棋黑棋交替下
for(
int i =
0; i < board.length; i++
) system.out.
println()
;}if(beginchess.
equals
("⭕"))
else}}
}}
testdemo
public
class
testdemo
}
難點在於對每個下的棋子方向的判斷,四個方向是否連成五個子贏得遊戲。 五子棋的小遊戲
感想 終於寫出人生中第乙個小遊戲來了 include include include include using namespace std const int x 21 棋盤行數 const int y 21 棋盤列數 char p x y 定義棋盤 int m 0 定義臨時點,儲存輸入座標 in...
python五子棋小遊戲
話不多說,直接上 全部工程檔案,在github 五子棋 效果預覽 判斷上下左右左上右上左下右下8個方向 i x 1 while i 0 if darray i y 1 num1 1 i 1 else break i x 1 while i 19 if darray i y 1 num1 1 i 1 ...
c 小遊戲 五子棋
include include includeusing namespace std const int x 21 棋盤行數 const int y 21 棋盤列數 char p x y 定義棋盤 int m 0 定義臨時點,儲存輸入座標 int n 0 void display 輸出棋盤 else...