import java.util.Scanner;
public class FiveChessGame {
private int temp;
private String[][] String1;//注意在这里不能定义为char型不然打印的数字
////////////////////////////
public FiveChessGame(){
System.out.println("please input the line number");
Scanner sc=new Scanner(System.in);
this.temp=sc.nextInt();
String1=new String[temp][temp];
for(int i=0;i<temp;i ){
for(int j=0;j<temp;j ){
String1[i][j]="*";//注意在这里不能定义为char型不然打印的数字
}
}
System.out.print('t');
for(int i=0;i<temp;i ){
System.out.print(i);
System.out.print('t');
}
System.out.println();
for(int i=0;i<temp;i ){
System.out.print(i);//注意在这里的格式不能写成System.out.print(i 't');不然从9打印
System.out.print('t');
for(int j=0;j<temp;j ){
System.out.print(String1[i][j] 't');
}
System.out.println();
}
}
////////////////////
public int getline(){
return this.temp;
}
///////////////////////
public String[][] getString(){
return this.String1;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.util.*;
public class FiveChessPlayers {
private String name;
public static FiveChessGame fcg=new FiveChessGame();
//////////////////////
public FiveChessPlayers(){//玩多少行的游戏
System.out.println("please input player's name");
Scanner sc=new Scanner(System.in);
this.name=sc.next();
}
///////////////////
public String getName(){
return this.name;
}
////////////////////////////////
public void play(String str2){//the player could play the chess
Scanner sc=new Scanner(System.in);
int x,y;
while(true){
System.out.println("please input your chess");
x=sc.nextInt();
y=sc.nextInt();
if(x>=fcg.getline()||y>=fcg.getline()) {
System.out.println("your input is error");
continue;
}
if(fcg.getString()[x][y]=="*"){
fcg.getString()[x][y]=str2;
break;
}else{
System.out.println("you coudl'n put your chess here");
continue;
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
import java.util.*;
public class TestChess {
private FiveChessPlayers f2;
private FiveChessPlayers f3;
public TestChess(){
f2=new FiveChessPlayers();
f3=new FiveChessPlayers();
}
///////////////////////////////////////////////////////////////////////////
public void display(){
System.out.print('t');
for(int i=0;i<FiveChessPlayers.fcg.getline();i ){
System.out.print(i);
System.out.print('t');
}
System.out.println();
for(int i=0;i<FiveChessPlayers.fcg.getline();i ){
System.out.print(i);//注意在这里的格式不能写成System.out.print(i 't');不然从9打印
System.out.print('t');
for(int j=0;j<FiveChessPlayers.fcg.getline();j ){
System.out.print(FiveChessPlayers.fcg.getString()[i][j] 't');
}
System.out.println();
}
}
//////////////////////////////////////////////////////////////////////////////
public void putChess(String tem1){
if(tem1.equals("@"))
{
f2.play("@");
}
if(tem1.equals("#"))
{
f3.play("#");
}
}
/////////////////////////////////////////////////////////
public void victory(){
String str1=new String();
String str2="@@@@@";
////////////////////////////////////
int X=0,Y=0;//用来记录每次查找到的“@”字符的数组下标,从两个for循环里导出来
int k=0;int j=-1;//注意首次的控制条件的建立,j为-1可以使第二个for检测首次从下标0开始.
///////////////////////////////////
while(true)
{
LABEL:for(;k<FiveChessPlayers.fcg.getline();k ){//添加标签,要注意标签的用法
for(j=(j 1)%FiveChessPlayers.fcg.getline();j<FiveChessPlayers.fcg.getline();j ){
//注意在这里的这个表达式的写法,可以在一次寻找不满足时下一次从数组的下一个位置开始.
if(FiveChessPlayers.fcg.getString()[k][j].equals("@")){
X=k;
Y=j;
break LABEL;//每找到一个相同字符则跳出;
}else{
System.out.println(k "行");
System.out.println(j "列");
// continue;//多余
}
}
}
// System.exit(0);//调试语句,退出虚拟机
if(k<FiveChessPlayers.fcg.getline()&j<FiveChessPlayers.fcg.getline())
{
for(int i=0;i<5;i ){
if(X<FiveChessPlayers.fcg.getline()&Y<(FiveChessPlayers.fcg.getline()-4)){//遍历列
str1 =FiveChessPlayers.fcg.getString()[X][Y i];
if(i!=4)
continue;
if(i==4){
System.out.println("安列取" str1);
if(str1.equals(str2)){
System.out.println(f2.getName() " is the winner");
System.exit(0);//结束退出虚拟机
}else{
str1="";
}
}
}
}
for(int i=0;i<5;i ){
if((X 4)<FiveChessPlayers.fcg.getline()&(Y 4)<FiveChessPlayers.fcg.getline()){//四十五度遍历
str1 =FiveChessPlayers.fcg.getString()[X i][Y i];
if(i!=4)
continue;
if(i==4){
System.out.println("四十五度向前取" str1);
if(str1.equals(str2)){
System.out.println(f2.getName() " is the winner");
System.exit(0);//胜利结束游戏
}else{
str1="";
}
}
}
}
for(int i=0;i<5;i ){
if((X 4)<FiveChessPlayers.fcg.getline()&Y<FiveChessPlayers.fcg.getline()){//行遍历
str1 =FiveChessPlayers.fcg.getString()[X i][Y];
if(i!=4)
continue;
if(i==4){
System.out.println("安行取" str1);
if(str1.equals(str2)){
System.out.println(f2.getName() " is the winner");
System.exit(0);//如上
}else{
str1="";
}
}
}
}
for(int i=0;i<5;i ){
if((X 4)<FiveChessPlayers.fcg.getline()&(Y-4)>=0){
str1 =FiveChessPlayers.fcg.getString()[X i][Y-i];
if(i!=4)
continue;
if(i==4){
System.out.println("四十五度向后取" str1);
if(str1.equals(str2)){
System.out.println(f2.getName() " is the winner");
System.exit(0);//如上
}else{
str1="";
}
}
// str1 =f1.String1[X i][Y i];//注意对比写法
// continue;
// str1="" f1.String1[X i][Y i];//注意错误的写法;不然每次覆盖前一次的串累加值;
// continue;
}
}
}
//////////////////////////////////////////////////////////////////////////////
if(str1==""&k<FiveChessPlayers.fcg.getline()&j<FiveChessPlayers.fcg.getline()){
j ;
continue ;
}else{
break;
}
}
}
////////////////////////////////////////////////////////////////////
public void victory1(){
String str4=new String();
String str3="#####";
////////////////////////////////////
int X=0,Y=0;
int k=0;int j=0;
while(true)
{
LABEL:for(;k<FiveChessPlayers.fcg.getline();k ){//添加标签,要注意标签的用法
for(j=(j 1)%FiveChessPlayers.fcg.getline();j<FiveChessPlayers.fcg.getline();j ){
if(FiveChessPlayers.fcg.getString()[k][j].equals("#")){
X=k;
Y=j; System.out.println(FiveChessPlayers.fcg.getString()[k][j]);
break LABEL;
}else{
System.out.println(k "******");
System.out.println(j);
}
}
}
///////////////////////////////////////////////
for(int i=0;i<5;i ){
if(X<FiveChessPlayers.fcg.getline()&Y<(FiveChessPlayers.fcg.getline()-4)){//遍历列
str4 =FiveChessPlayers.fcg.getString()[X][Y i];
if(i!=4)
continue;
if(i==4){
System.out.println(str4);
System.out.println(1);
if(str4.equals(str3)){
System.out.println(f3.getName() " is the winner");
System.exit(0);//结束
}else{
str4="";
}
}
}
}
for(int i=0;i<5;i ){
if((X 4)<FiveChessPlayers.fcg.getline()&(Y 4)<FiveChessPlayers.fcg.getline()){//四十五度遍历
str4 =FiveChessPlayers.fcg.getString()[X i][Y i];
if(i!=4)
continue;
if(i==4){
System.out.println(str4);
System.out.println(2);
if(str4.equals(str3)){
System.out.println(f3.getName() " is the winner");
System.exit(0);//结束
}else{
str4="";
}
}
}
}
for(int i=0;i<5;i ){
if((X 4)<FiveChessPlayers.fcg.getline()&Y<FiveChessPlayers.fcg.getline()){//行遍历
str4 =FiveChessPlayers.fcg.getString()[X i][Y];
if(i!=4)
continue;
if(i==4){
System.out.println(str4);
System.out.println(3);
if(str4.equals(str3)){
System.out.println(f3.getName() " is the winner");
System.exit(0);//结束
}else{
str4="";
}
}
}
}
for(int i=0;i<5;i ){
if((X 4)<FiveChessPlayers.fcg.getline()&(Y-4)>=0){
str4 =FiveChessPlayers.fcg.getString()[X i][Y-i];
if(i!=4)
continue;
if(i==4){
System.out.println(str4);
System.out.println(4);
if(str4.equals(str3)){
System.out.println(f3.getName() " is the winner");
System.exit(0);//结束
}else{
str4="";
}
}
// str1 =f1.String1[X i][Y i];
// continue;
// str1="" f1.String1[X i][Y i];//注意错误的写法;不然每次覆盖前一次的串累加值;
// continue;
}
}
//////////////////////////////////////////////////////////////////////////////
if(str4==""&k<FiveChessPlayers.fcg.getline()&j<FiveChessPlayers.fcg.getline()){
j ;
continue ;
}else{
break;
}
}
}
////////////////////////////////////////
public static void main(String[] args) {
TestChess tc=new TestChess();
boolean b1=true;
while(b1){
tc.putChess("@");
tc.victory();
tc.display();
tc.putChess("#");
tc.display();
tc.victory1();
Scanner sc=new Scanner(System.in);
System.out.println("if you like to continue input true or exit input false");
b1=sc.nextBoolean();
if(!b1){
System.out.println("welcome to use ! ");
break;
}
}
}
}