2008年8月23日
摘要:
1import java.util.Scanner;
2
3public class StuManager {
4
5 /** *//**
6 *&...
阅读全文
写了一半 现在只能下棋 还不能判断
package day04;
import java.util.Scanner;
public class FiveChess {
public static void main(String[] args) {
char[][] state=new char[14][14];
for(int i=0;i<state.length;i++){
for(int j=0;j<state[i].length;j++){
state[i][j]='*';
}
}
boolean isBlack=true;//当前是黑方下子
Scanner sca=new Scanner(System.in);
printState(state);
while(true){
System.out.println("请"+(isBlack?"黑":"白")+"方下子:");
String input=sca.next();
if(input.equals("exit")){
break;
}
int x=input.charAt(0)-'a';
int y=input.charAt(1)-'a';
if(state[x][y]=='@' || state[x][y]=='O'){//该位置已经有棋子了
System.out.println("该位置已经有棋子,请重新指定坐标!");
continue;
}
state[x][y]=(isBlack?'@':'O');
printState(state);
if(isWin(state,isBlack,x,y)){
System.out.println((isBlack?"黑":"白")+"方获胜!");
break;
}
isBlack=!isBlack;
}
}
public static void printState(char[][] state){
for(int i=0;i<state.length;i++){//输出每一行的内容
System.out.print((char)('a'+i)+" ");//输出行坐标(左边的字母)
for(int j=0;j<state[i].length;j++){//输出该行的内容
System.out.print(state[i][j]+" ");
}
System.out.print("\n");//输出换行符
}
System.out.print(" ");//输出第一行开头的空格
for(int i=0;i<state[0].length;i++){//输出第一行的所有字母
System.out.print((char)('a'+i)+" ");
}
System.out.print("\n");//输出换行符
}
public static boolean isWin(char[][] state,boolean isBlack,int x,int y){
//char c=isBlack?'@':'O';
return isShuipingWin(state,isBlack,x,y) || isChuizhiWin(state,isBlack,x,y) ||
isZuoXieWin(state,isBlack,x,y) || isYouXieWin(state,isBlack,x,y);
}
public static boolean isShuipingWin(char[][] state,boolean isBlack,int x,int y){
//?????
return false;
}
public static boolean isChuizhiWin(char[][] state,boolean isBlack,int x,int y){
//?????
return false;
}
public static boolean isZuoXieWin(char[][] state,boolean isBlack,int x,int y){
//??????
return false;
}
public static boolean isYouXieWin(char[][] state,boolean isBlack,int x,int y){
//??????
return false;
}
}