SOGO論壇
標題:
圈圈叉叉 成是錯誤 需高手修改
[列印本頁]
作者:
q87963
時間:
2010-6-17 20:19:28
標題:
圈圈叉叉 成是錯誤 需高手修改
import java.io.*;
public class ooxx {
/**
* @param args
*/
static int a[][]=new int [3][3];
public static void main(String[] args)throws Exception {
// TODO 自動產生方法 Stub
int who=-1;
boolean f=true;
int x=0,y=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(f){
x=Integer.parseInt(br.readLine());
if(x<1||x>3){
System.out.println("lose");
}
else{
y=Integer.parseInt(br.readLine());
a [x-1][y-1]=who;
display();
if(check()){
System.out.println("win");
f=false;
}
who*=-1;
}
}
}
public static void display(){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
switch(a
[j]){
case(-1):System.out.print("O "); break;
case(0):System.out.print("_ "); break;
case(1):System.out.print("X "); break;
}
}
System.out.println("");
}
}
public static boolean check(){
if(Math.abs(a[0][0]+a[0][1]+a[0][2])==3){return true;}
if(Math.abs(a[1][0]+a[1][1]+a[1][2])==3){return true;}
if(Math.abs(a[2][0]+a[2][1]+a[2][2])==3){return true;}
if(Math.abs(a[0][0]+a[1][0]+a[2][0])==3){return true;}
if(Math.abs(a[0][1]+a[1][1]+a[2][1])==3){return true;}
if(Math.abs(a[0][2]+a[1][2]+a[2][2])==3){return true;}
if(Math.abs(a[0][0]+a[1][1]+a[2][2])==3){return true;}
if(Math.abs(a[0][2]+a[1][1]+a[2][0])==3){return true;}
return false;
}
}
------------分隔線-------------------------------------------------
結果:
O _ _
_ O _
_ _ O
希望可以改到9個格子都可以有圈叉
答案:
X O O
O X O
O O X
希望可以有高手修改到這樣
作者:
09380938
時間:
2010-6-18 00:54:18
我不太懂你的問題耶
因為我再測試你的程式
除了
public static void display(){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
switch(a[j]
[
i
]
){ <-----這裡的 [
i
]沒加
case(-1):System.out.print("O "); break;
case(0):System.out.print("_ "); break;
case(1):System.out.print("X "); break;
}
}
大致上沒問題
還有以OOXX來說
O--
-O-
--O
因該不可能發生吧
因為不是輪流的嗎?
所以要
XOO
OXO
OOX
也不可能阿
還有你這沒有判斷"平手"
也沒有判斷 "防覆蓋" 同樣位置
《 本帖最後由
09380938
於 2010-6-18 01:11 編輯 》
歡迎光臨 SOGO論壇 (https://oursogo.com/)
Powered by OURSOGO.COM