当前位置: 首页 > news >正文

高密做网站哪家好珠海营销营网站建设公司

高密做网站哪家好,珠海营销营网站建设公司,如何在网站上做404页面,如何用公司名称搜到公司网站以前做过一个C语言版五子棋:C语言+二维数组+非递归实现五子棋游戏 现在做一个Java语言版五子棋,规则如下: 1、白子为O; 2、黑子为; 3、白子先手;…

以前做过一个C语言版五子棋:C语言+二维数组+非递归实现五子棋游戏

现在做一个Java语言版五子棋,规则如下:

1、白子为O;

2、黑子为@;

3、白子先手;

4、格子占满时为平局;

5、四个方向上有连续五个子为胜利;

6、如果选择0 3表示选的第1行与第4列;

废话不多说,直接上代码:

import java.util.Scanner;/*** 命令行版五子棋* 规则:* 1、白子为O;* 2、黑子为@;* 3、白子先手;* 4、格子占满时为平局;* 5、四个方向上有连续五个子为胜利;* 6、如果选择0 3表示选的第1行与第4列;*/
public class WuZiQi {public static final int N = 16;public static void main(String[] args) {Scanner sc = new Scanner(System.in);char[][] GAME = new char[N][N];int count = 0;    //轮换落子计算int m, n; //白家int x, y; //黑家int res = 0;wzq_init(GAME);wzq_show(GAME);while (true) {//当棋盘格子被下满了时if (N * N == count) {System.out.println("棋盘已经下满了,平局!");sc.close();return;}if (0 == count % 2) {System.out.print("请白家落子(例如0 3或1 3):");m = sc.nextInt();n = sc.nextInt();while (m < 0 || m > N - 1 || n < 0 || n > N - 1) {System.out.print("输入的坐标超出范围,请重新输入:");m = sc.nextInt();n = sc.nextInt();}while ('+' != GAME[m][n]) {System.out.print("此处已经落过子,请重新落子:");m = sc.nextInt();n = sc.nextInt();}GAME[m][n] = 'O';res = wzq_play(m, n, GAME);if (1 == res) {wzq_show(GAME);System.out.println("程序结束");sc.close();return;}} else {System.out.print("请黑家落子(例如0 3或1 3):");x = sc.nextInt();y = sc.nextInt();while (x < 0 || x > N - 1 || y < 0 || y > N - 1) {System.out.print("输入的坐标超出范围,请重新输入:");x = sc.nextInt();y = sc.nextInt();}while ('+' != GAME[x][y]) {System.out.print("此处已经落过子,请重新落子:");x = sc.nextInt();y = sc.nextInt();}GAME[x][y] = '@';res = wzq_play(x, y, GAME);if (1 == res) {wzq_show(GAME);System.out.println("程序结束");sc.close();return;}}count++;wzq_show(GAME);}}//显示五子棋棋盘public static void wzq_show(char[][] GAME) {System.out.println("五子棋棋盘如下:");for (int i = 0; i < N; i++) {for (int j = 0; j < N; j++) {System.out.print(GAME[i][j]);}System.out.println();}}//初始化五子棋棋盘public static void wzq_init(char[][] GAME) {for (int i = 0; i < N; i++) {for (int j = 0; j < N; j++) {GAME[i][j] = '+';}}}//游戏是否胜利的运算,一旦有人胜利则返回1public static int wzq_play(int a, int b, char[][] GAME) {int i = 0, j = 0, k = 0;//方向-上的for (j = b - 4; j < b + 4; j++) {if (j < 0 || j > N - 1) {continue;}for (i = 0; i < 5; i++) {if (j + i < 0 || j + i > N - 1) {break;}if ('@' == GAME[a][j + i] || '+' == GAME[a][j + i]) {break;}if ('O' == GAME[a][j + i] && 4 == i) {System.out.println("\n恭喜你,白家-方向上获胜!");return 1;}}for (i = 0; i < 5; i++) {if (j + i < 0 || j + i > N - 1) {break;}if ('O' == GAME[a][j + i] || '+' == GAME[a][j + i]) {break;}if ('@' == GAME[a][j + i] && 4 == i) {System.out.println("\n恭喜你,黑家-方向上获胜!");return 1;}}}//方向|上的for (i = a - 4; i < a + 4; i++) {if (i < 0 || i > N - 1) {continue;}for (j = 0; j < 5; j++) {if (i + j < 0 || i + j > N - 1) {break;}if ('@' == GAME[i + j][b] || '+' == GAME[i + j][b]) {break;}if ('O' == GAME[i + j][b] && 4 == j) {System.out.println("\n恭喜你,白家|方向上获胜!");return 1;}}for (j = 0; j < 5; j++) {if (i + j < 0 || i + j > N - 1) {break;}if ('O' == GAME[i + j][b] || '+' == GAME[i + j][b]) {break;}if ('@' == GAME[i + j][b] && 4 == j) {System.out.println("\n恭喜你,黑家|方向上获胜!");return 1;}}}//方向\上的for (i = a - 4, j = b - 4; i < a + 4 && j < b + 4; i++, j++) {if (i < 0 || i > N - 1 || j < 0 || j > N - 1) {continue;}for (k = 0; k < 5; k++) {if (i + k < 0 || i + k > N - 1 || j + k < 0 || j + k > N - 1) {break;}if ('@' == GAME[i + k][j + k] || '+' == GAME[i + k][j + k]) {break;}if ('O' == GAME[i + k][j + k] && 4 == k) {System.out.println("\n恭喜你,白家\方向上获胜!");return 1;}}for (k = 0; k < 5; k++) {if (i + k < 0 || i + k > N - 1 || j + k < 0 || j + k > N - 1) {break;}if ('O' == GAME[i + k][j + k] || '+' == GAME[i + k][j + k]) {break;}if ('@' == GAME[i + k][j + k] && 4 == k) {System.out.println("\n恭喜你,黑家\方向上获胜!");return 1;}}}//方向/上的for (i = a + 4, j = b - 4; i > a - 4 && j < b + 4; i--, j++) {if (i < 0 || i > N - 1 || j < 0 || j > N - 1) {continue;}for (k = 0; k < 5; k++) {if (i - k < 0 || i - k > N - 1 || j + k < 0 || j + k > N - 1) {break;}if ('@' == GAME[i - k][j + k] || '+' == GAME[i - k][j + k]) {break;}if ('O' == GAME[i - k][j + k] && 4 == k) {System.out.println("\n恭喜你,白家/方向上获胜!");return 1;}}for (k = 0; k < 5; k++) {if (i - k < 0 || i - k > N - 1 || j + k < 0 || j + k > N - 1) {break;}if ('O' == GAME[i - k][j + k] || '+' == GAME[i - k][j + k]) {break;}if ('@' == GAME[i - k][j + k] && 4 == k) {System.out.println("\n恭喜你,黑家/方向上获胜!");return 1;}}}return 0;}
}

idea里面测试可以正常运行,游戏结果正常,运行环境:jdk1.8+win11。

http://www.yayakq.cn/news/843244/

相关文章:

  • 怎么修改网站上的内容哈尔滨网站建设口碑好
  • html5网站模板 医院网站制作报价明细
  • 小程序如何做外部连接网站深圳装饰装修公司
  • 广州外贸公司网站建设微网站怎么做的好
  • 渭南专业做网站莘县网站建设价格
  • 无锡专业制作网站外链官网
  • 网站优化 福州网站开发要学哪些知识
  • 广东电白建设集团有限公司网站做网站有哪些程序
  • 生活门户网站开发方案东莞网站设计行情
  • 网友让你建网站做商城wordpress主题分类
  • 公司网站开发 中山手机网页微信
  • 大兴网站建设制作凡科建站登录官网
  • 海口建设局网站邵阳网站建设
  • 怎么用ps做网站首页字表白网站制作源代码
  • 荷城网站设计推广网app下载
  • 做卡贴的网站四平网站建设404页面对网站的好处及设置方法
  • 二级域名绑定网站可以在线制作网页的网站
  • 抓好门户网站建设免费域名注册方式
  • 网站主机设置方法广州哪里能买到武士刀
  • 天猫网站建设的目标是什么东莞网站建设如何做
  • 运城网站推广商务平台搭建
  • 网站网页优化下载公众号
  • 北京网站制作公司排名域名备案期间 网站访问
  • 站长之家网站建设制作做网站发现是传销
  • 网站页面优化怎么做做啥类型网站
  • 互联网软件门户网站合肥网页制作公司推荐
  • flash网站建设教程视频网站在哪做
  • sns社交网站注册房产管理局信息查询入口
  • 如何做网站百科西部数码官方网站
  • 网站内页301重定向怎么做h5自适应网站模板下载