【java】井字游戏
来源:互联网 发布:国民生产总值c语言 编辑:程序博客网 时间:2024/05/19 08:38
import java.util.Scanner;public class game {public static void main(String[] args){int p = 0;Scanner input = new Scanner(System.in);char [][]b = new char[3][3];for(int k = 0;k<3;k++){for(int u =0;u<3;u++){b[k][u] = 'V';}}while(isfull(b)==false){if(p%2==0){ System.out.println("Enter a row(1, 2 or 3)for player X: "); int k = input.nextInt(); System.out.println("Enter a column(1, 2 or 3)for player X: "); int j = input.nextInt(); b[k][j] = 'X'; p++;}else{System.out.println("Enter a row(1, 2 or 3)for player O: ");int k = input.nextInt();System.out.println("Enter a column(1, 2 or 3)for player O: ");int j = input.nextInt();b[k][j] = 'O'; p++;}for(int s = 0;s<3;s++){for(int t =0;t<3;t++){if(b[s][t]!='V') System.out.print(b[s][t]);elseSystem.out.print(" ");}System.out.print("\n");}}}public static boolean isfull(char [][]m){int a = m.length;boolean main = true;boolean subd = true;for(int k = 0;k<3;k++){boolean row = true;for(int u =0;u<3;u++){if(m[k][u]!=m[k][0])row = false;if(k==u){if(m[k][u]!=m[0][0])main = false;}if(k==a-1-u){if(m[k][u]!=m[0][a-1])subd = false;}}if(row==true&&m[k][0]!='V'){ System.out.println(m[k][0]+" player won"); return true;}if(main==true&&m[0][0]!='V'){System.out.println(m[0][0]+" player won");return true;}if(subd==true&&m[0][a-1]!='V'){System.out.println(m[0][a-1]+" player won"); return true; }}for(int s = 0;s<3;s++){boolean rank = true;for(int t =0;t<3;t++){if(m[t][s]!=m[0][s])rank = false;}if(rank==true&&m[0][s]!='V'){System.out.println(m[0][s]+" player won");return true; } }return false;}}
0 0
- 【java】井字游戏
- 井字游戏(java)
- java猜字游戏
- JAVA---猜字游戏
- 井字游戏!
- Python3 井字游戏
- Java小程序猜字游戏
- java小程序——简单井字游戏双人版
- 井字游戏 指针版
- 井字游戏(C++版)
- 是否赢得井字游戏
- C#编程 井字游戏
- qt 井字游戏编写
- 开发一个井字游戏
- SDL游戏教程第四课 井字游戏
- SDL游戏教程第四课 井字游戏
- [JAVA] 俄罗斯方块游戏
- [JAVA] 俄罗斯方块游戏
- 打包ios程序成ipa
- 删除的文件怎么还会恢复呢?
- IOS Button简要说明
- JSP内置对象---response
- UIColor,CGColor,CIColor三者的区别和联系
- 【java】井字游戏
- asm磁盘相关
- 百万级PHP网站架构工具箱
- table中的colspan和rowspan
- 网络连接错误代码大全及处理办法
- [笔记] Android Service 使用注意事项
- Linux shell少见用法和技巧
- 自由人——互联网实现了自由人的自由联合,这是一个天翻地覆的时代
- 产品设计原型制作工具【mark】