12345组成三个不重复数java,求大神帮忙!五子棋!只能识别按顺序识别!例如 12345 不能...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

import java.util.Arrays;

import java.util.Scanner;

public class Gobang {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

boolean finish = false;// 有戏是否结束

int flagNum = 1;// 当前下棋者标记

char flagch;// 当前下棋者的棋子

int x = 0;

int y = 0;

// 棋盘初始化

char checkboard[][] = new char[10][10];

for (int i = 0; i < checkboard.length; i++) {

Arrays.fill(checkboard[i], '+');

}

game: while (!finish) {

/* 打印棋盘 */

System.out.println("---------------------");

System.out.println(" 1 2 3 4 6 7 8 9 10");

for (int i = 0; i < checkboard.length; i++) {

System.out.print((char) (i + 65) + " ");

for (int j = 0; j < checkboard[i].length; j++) {

System.out.print(checkboard[i][j] + " ");

}

System.out.println();

}

System.out.println("---------------------");

/* 判断当前下棋者 */

if (flagNum == 1) {

flagch = '*';

System.out.println("请*输入棋子坐标:");

} else {

flagch = 'o';

System.out.println("请o输入棋子坐标:");

}

/* 输入棋子坐标 */

String str = sc.nextLine();

char ch = str.toUpperCase().charAt(0);

x = ch - 65;

y = Integer.parseInt(str.substring(1)) - 1;

/* 判断坐标是否在棋盘内 */

if (x < 0 || x > 9 || y < 0 || y > 9) {

System.out.println("您输入的坐标有误,请重新输入!");

continue;

}

/* 判断坐标上是否有棋子 */

if (checkboard[x][y] == '+') {

checkboard[x][y] = flagch;

} else {

System.out.println("您输入的位置已经有其他棋子,请重新输入!");

continue;

}

/* 判断棋子左侧 */

if (y - 4 >= 0) {

if (checkboard[x][y - 1] == flagch && checkboard[x][y - 2] == flagch && checkboard[x][y - 3] == flagch

&& checkboard[x][y - 4] == flagch) {

finish = true;

break game;

}

}

/* 判断棋子右侧 */

if (y + 4 <= 9) {

if (checkboard[x][y + 1] == flagch && checkboard[x][y + 2] == flagch && checkboard[x][y + 3] == flagch

&& checkboard[x][y + 4] == flagch) {

finish = true;

break game;

}

}

/* 判断棋子上方 */

if (x - 4 >= 0) {

if (checkboard[x - 1][y] == flagch && checkboard[x - 2][y] == flagch && checkboard[x - 3][y] == flagch

&& checkboard[x - 4][y] == flagch) {

finish = true;

break game;

}

}

/* 判断棋子下方 */

if (x + 4 <= 9) {

if (checkboard[x + 1][y] == flagch && checkboard[x + 2][y] == flagch && checkboard[x + 3][y] == flagch

&& checkboard[x + 4][y] == flagch) {

finish = true;

break game;

}

}

/* 判断棋子西北 */

if (x - 4 >= 0 && y - 4 >= 0) {

if (checkboard[x - 1][y - 1] == flagch && checkboard[x - 2][y - 2] == flagch

&& checkboard[x - 3][y - 3] == flagch && checkboard[x - 4][y - 4] == flagch) {

finish = true;

break game;

}

}

/* 判断棋子西南 */

if (x + 4 <= 9 && y - 4 >= 0) {

if (checkboard[x + 1][y - 1] == flagch && checkboard[x + 2][y - 2] == flagch

&& checkboard[x + 3][y - 3] == flagch && checkboard[x + 4][y - 4] == flagch) {

finish = true;

break game;

}

}

/* 判断棋子东北 */

if (x - 4 >= 0 && y + 4 <= 9) {

if (checkboard[x - 1][y + 1] == flagch && checkboard[x - 2][y + 2] == flagch

&& checkboard[x - 3][y + 3] == flagch && checkboard[x - 4][y + 4] == flagch) {

finish = true;

break game;

}

}

/* 判断棋子东南 */

if (x + 4 <= 9 && y + 4 <= 9) {

if (checkboard[x + 1][y + 1] == flagch && checkboard[x + 2][y + 2] == flagch

&& checkboard[x + 3][y + 3] == flagch && checkboard[x + 4][y + 4] == flagch) {

finish = true;

break game;

}

}

flagNum *= -1;

}

System.out.println("---------------------");

System.out.println(" 1 2 3 4 6 7 8 9 10");

for (int i = 0; i < checkboard.length; i++) {

System.out.print((char) (i + 65) + " ");

for (int j = 0; j < checkboard[i].length; j++) {

System.out.print(checkboard[i][j] + " ");

}

System.out.println();

}

System.out.println("---------------------");

if(flagNum==1){

System.out.println("*棋胜利");

}else{

System.out.println("o棋胜利");

}

}

}

只能识别按顺序识别!例如 12345 不能先1235 再4! 求大佬帮忙解决!在线等,急!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540912.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[转]Visual Studio 各版本下载

原文地址&#xff1a;[置顶] Visual Studio 各版本下载 文件名称文件大小百度网盘下载微软官方下载Visual Studio 2015 Enterprise - 企业版 - 简体中文3.89GBhttp://pan.baidu.com/s/1bnAY68Bvs2015.ent_chs.isoVisual Studio 2015 Professional - 专业版 - 简体中文3.84GBht…

JavaScript中的“ this”关键字

JavaScriptthis关键字 (JavaScript this keyword) The this keyword is widely used in JavaScript. It has many use cases and is also one of the most intimidating features of JavaScript. In most of the programming languages, this is used to refer to the current …

oracle 列级外键,Oracle外键列上是否需要索引?

外键列上缺少索引会带来两个问题&#xff0c;限制并发性、影响性能。而这两个问题中的任意一个都可能会造成严重性能问题。 无论是Or外键列上缺少索引会带来两个问题&#xff0c;限制并发性、影响性能。而这两个问题中的任意一个都可能会造成严重性能问题。无论是Oracle的官方文…

python 改变词典顺序_按词典顺序排列的功率集

python 改变词典顺序Description: 描述&#xff1a; This is a standard interview problem to find out the power sets in lexicographic order of a given set of numbers using backtracking. 这是一个标准的面试问题&#xff0c;它使用回溯来按给定数字集的字典顺序查找能…

oracle创建用户名了,oracle创建用户名

创建用户//创建用户名create user username identified by password‘’//赋权限Grant Connect,Resource,DBA to UserName;plsql developer配置下载地址http://ah1.down.chinaz.com/201011/plsql8.04cn.zip右击"我的电脑" - "属性" - "高级" - &…

webpack学习笔记1

webpack学习笔记1&#xff1a;基本概念 前言&#xff1a; 现在在日常的开发中&#xff0c;webpack已经是必不可少的东西了&#xff0c;现在的需求基本都是用webpack对资源进行打包整合&#xff0c;所以打算写一点关于webpack的东西&#xff0c;这是第一篇&#xff0c;主要是介绍…

ruby 嵌套函数_Ruby嵌套有示例的循环

ruby 嵌套函数嵌套循环 (Nested for loop) Nesting of for loop means one for loop is available inside another for loop. It means that there are two loops, then the first one is an outer loop and the second one is the inner loop. Execution will take place in t…

oracle10数据库链接失败,Oracle10g出现Enterprise Manager 无法连接到数据库实例解决办法...

刚装好 10g 时&#xff0c;把的监听端口是1521&#xff0e;后来把端口改成了1568了&#xff0c;登上em发现Enterprise Manager 无法连接到数据库实例 &#xff0c;连接字符串的端口仍是1521&#xff0c;如何解决这个问题。登陆&#xff1a;出现下面错误&#xff1a;Enterprise …

springJdbc in 查询,Spring namedParameterJdbcTemplate in查询

springJdbc in 查询&#xff0c;Spring namedParameterJdbcTemplate in查询&#xff0c; SpringJdbc命名参数in查询&#xff0c;namedParameterJdbcTemplate in查询 >>>>>>>>>>>>>>>>>>>>>>>>>>…

oracle 11g r2版本号,Oracle 11g r2新增版本功能(二)

在11.2中&#xff0c;Oracle数据库引入的版本的概念&#xff0c;这为应用程序的升级提供了极大的方便。这篇简单描述版本的实现和查询方式。前一篇简单描述了版本&#xff0c;下面接着上面的例子看看Oracle是如何实现这个功能的&#xff1a;SQL> select synonym_name, table…

python 添加图例_Python | 在图例标签中添加Sigma

python 添加图例Sigma (&#x1d70e;) is very often used greek mathematical letters and has a higher repetition in probability. In this article, we are going to add &#x1d70e; using a command in matplotlib. Sigma(&#x1d70e;)是希腊数学字母中经常使用的字…

【51CTO学院】搜索V2.0——新的搜索,只为给你更好的

为了让你能快速、准确的找到自己心仪的内容&#xff0c;51CTO学院产品及研发用尽了洪荒之力研发近2个月终于将搜索进行了全面升级。 搜索看似简单&#xff0c;实则要做到精准和智能却不是件易事&#xff0c;为了让学员快速找到自己所需&#xff0c;节省找课时间&#xff0c;更高…

oracle扩容日志文件,ORACLE 加大日志文件

--新建临时日志文件alter database add logfile group 4 (‘/u01/app/oracle/oradata/orcl/redo04.log‘) size 10m;alter database add logfile group 5 (‘/u01/app/oracle/oradata/orcl/redo05.log‘) size 10m;alter database add logfile group 6 (‘/u01/app/oracle/orad…

java多线程总结(二)

线程一般有6个状态&#xff1a; 新建状态&#xff1a;NEW 可运行状态&#xff1a;RUNNABLE 休眠状态&#xff1a;TIMED_WAITING 等待状态&#xff1a;WAITING 阻塞状态:BLOCKED 终止状态“TERMINATED 当我们使用new创建线程之后&#xff0c;线程处于新建状态&#xff0c;当调用…

scandir函数_PHP scandir()函数与示例

scandir函数PHP scandir()函数 (PHP scandir() function) The full form of scandir is "Scan Directory", the function scandir() is used to get the list of the files and directories available in the specified directory. scandir的完整格式为“ Scan Direc…

韩顺平.2011最新版.玩转oracle视频教程笔记,韩顺平.2011最新版.玩转oracle视频教程(笔记)...

韩顺平.2011最新版.玩转oracle视频教程ORA-01045: user XIAOMING lacks CREATE SESSION privilege; logon denied 警告: 您不再连接到 ORACLE。 SQL> show user; USER 为 ""SQL> conn system/p; 已连接。SQL> grant connect to xiaoming; 授权成功。SQL>…

方幂序列 c+~+_C ++编程中的Trigraph序列

方幂序列 c&#xff5e;Trigraph Sequences in C are the set of three characters starting from double question marks (??). These set of the characters replaces by a single character specified in the below table, C 中的Trigraph序列是从双问号( ?? )开始的三个…

oracle sysauth,sysauth$基表的用户权限的一点分析

select privilege#,level from sysauth$ connect by grantee#prior privilege# and privilege#>0 start with grantee#:1 and privilege#>0如上的sql语句频繁执行&#xff0c;其实对于递归sql对于自己初始oracle才一年的菜鸟一般是略去不看的&#xff0c;eygle前辈们有时…

ansys 内聚力_内聚力 软件工程

ansys 内聚力凝聚 (Cohesion) In general terms, the word cohesion means the action or act of forming a united whole. According to the definition of Cambridge University, cohesion is defined as "the state of sticking together, or being in close agreement…

oracle认证都需要考哪几个方面,Oracle OCP认证要通过哪些考试

Oracle OCP认证要通过哪些考试Oracle OCP DBA认证是所有Oracle认证中最普及的一种认证&#xff0c;这一认证过程是专为那些想要从事Oracle管理的专业数据库管理人员设计的&#xff0c;适用于Oracle9I DBAs的OCP认证通过改进&#xff0c;删除了备份和恢复以及网络考试&#xff0…