using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Pachee

{

class Program

{

#region 静态字段

// 关卡数量

public static int[] Maps = new int[100];

// 玩家坐标

public static int[] PlayerPos = new int[2];

// 玩家名称

public static string[] PlayerNames = new string[2];

// 判断玩家是否暂停

public static bool[] Flags = new bool[2];

#endregion

///

/// 输出游戏头

///

public static void ShowGame()

{

Console.ForegroundColor = ConsoleColor.Green;

Console.WriteLine("****************************");

Console.ForegroundColor = ConsoleColor.Blue;

Console.WriteLine("****************************");

Console.ForegroundColor = ConsoleColor.White;

Console.WriteLine("***C#基础练习:飞行棋项目***");

Console.ForegroundColor = ConsoleColor.Yellow;

Console.WriteLine("****************************");

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine("****************************");

}

///

/// 接受用户输入的游戏名称,判断是否合法

///

/// 游戏名称

public static string[] InputPlayerNames()

{

PlayerNames[0] = "";

PlayerNames[1] = "";

Console.ForegroundColor = ConsoleColor.White;

while (PlayerNames[0] == "")

{

Console.Write("Please enter the name of game A player: ");

PlayerNames[0] = Console.ReadLine().Trim();

if (PlayerNames[0] == "")

{

Console.WriteLine("A player name cannot be empty, please enter again.");

continue;

}

break;

}

while (PlayerNames[1] == "" || PlayerNames[0] == PlayerNames[1])

{

Console.Write("Please enter the name of game B player: ");

PlayerNames[1] = Console.ReadLine().Trim();

if (PlayerNames[1] == "")

{

Console.WriteLine("B player name cannot be empty, please enter again.");

continue;

}

else if (PlayerNames[1] == PlayerNames[0])

{

Console.WriteLine("The player name cannot be the same as the player A B, please enter again.");

continue;

}

break;

}

return PlayerNames;

}

///

/// 初始化地图,改变默认的地图坐标类型

/// 0:方块

/// 1:轮盘

/// 2:地雷

/// 3:暂停

/// 4:隧道

///

public static void InitailMap()

{

#region 轮盘

int[] luckTrun = { 6, 23, 40, 55, 69, 83 };

for (int i = 0; i < luckTrun.Length; i++)

{

Maps[luckTrun[i]] = 1;

}

#endregion

#region 地雷

int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };

for (int i = 0; i < landMine.Length; i++)

{

Maps[landMine[i]] = 2;

}

#endregion

#region 暂停

int[] pause = { 9, 27, 60, 93 };

for (int i = 0; i < pause.Length; i++)

{

Maps[pause[i]] = 3;

}

#endregion

#region 隧道

int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };

for (int i = 0; i < timeTunnel.Length; i++)

{

Maps[timeTunnel[i]] = 4;

}

#endregion

}

///

/// 设定当前坐标的类型

///

/// 坐标

/// 坐标类型

public static string DrawStringMap(int i)

{

string str = null;

if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i)

{

str = "<>";

}

else if (PlayerPos[0] == i)

{

str = "A";

}

else if (PlayerPos[1] == i)

{

str = "B";

}

else

{

switch (Maps[i])

{

case 0:

Console.ForegroundColor = ConsoleColor.Yellow;

str = "□";

break;

case 1:

Console.ForegroundColor = ConsoleColor.Blue;

str = "◎";

break;

case 2:

Console.ForegroundColor = ConsoleColor.Green;

str = "☆";

break;

case 3:

Console.ForegroundColor = ConsoleColor.Red;

str = "▲";

break;

case 4:

Console.ForegroundColor = ConsoleColor.Cyan;

str = "卐";

break;

}

}

return str;

}

///

/// 生成所有坐标

///

public static void DrawMap()

{

Console.WriteLine("Legend: LuckTrun landMine Pause timeTunnel");

#region 第一橫行

for (int i = 0; i < 30; i++)

{

Console.Write(DrawStringMap(i));

}

Console.WriteLine();

#endregion

#region 第一竖行

for (int i = 30; i < 35; i++)

{

for (int j = 0; j <= 28; j++)

{

Console.Write(" ");

}

Console.Write(DrawStringMap(i));

Console.WriteLine();

}

#endregion

#region 第二橫行

for (int i = 64; i >= 35; i--)

{

Console.Write(DrawStringMap(i));

}

Console.WriteLine();

#endregion

#region 第二竖行

for (int i = 65; i < 70; i++)

{

Console.WriteLine(DrawStringMap(i));

}

#endregion

#region 第三橫行

for (int i = 70; i <= 99; i++)

{

Console.Write(DrawStringMap(i));

}

Console.WriteLine();

#endregion

}

///

/// 判断坐标是否超出范围

///

public static void ChangePos()

{

#region Player A

if (PlayerPos[0] < 0)

{

PlayerPos[0] = 0;

}

if (PlayerPos[0] > 99)

{

PlayerPos[0] = 99;

}

#endregion

#region Player B

if (PlayerPos[1] < 0)

{

PlayerPos[1] = 0;

}

if (PlayerPos[1] > 99)

{

PlayerPos[1] = 99;

}

#endregion

}

///

/// 踩到轮盘时,选择功能

///

/// 玩家的选择

/// 玩家标示

public static void PlayerSelect(string input, int player)

{

while (true)

{

if (input == "1")

{

Console.WriteLine("Player {0} select and {1} swap places.", PlayerNames[player], PlayerNames[1 - player]);

int temp = PlayerPos[player];

PlayerPos[player] = PlayerPos[1 - player];

PlayerPos[1 - player] = temp;

Console.WriteLine("Swap complete, press any key continue.");

Console.ReadKey(true);

break;

}

else if (input == "2")

{

Console.WriteLine("Player {0} select bombing {1}, Player {2} back to 6.", PlayerNames[player], PlayerNames[1 - player], PlayerNames[1 - player]);

PlayerPos[1 - player] -= 6;

Console.ReadKey(true);

break;

}

else

{

Console.WriteLine("Can only select: 1--Swap places 2--bombing: ");

input = Console.ReadLine();

}

}

}

///

/// 进行游戏

///

/// 玩家标示位

public static void PlayGame(int player)

{

Random r = new Random();

int next = r.Next(1, 7);

Console.WriteLine("{0} press any key to start rolling the dice.", PlayerNames[player]);

Console.ReadKey(true);

Console.WriteLine("{0} Throw out of {1}", PlayerNames[player], next);

PlayerPos[player] += next;

ChangePos();

Console.ReadKey(true);

Console.WriteLine("{0} press any key to start action.", PlayerNames[player]);

Console.ReadKey(true);

Console.WriteLine("{0} action complete.", PlayerNames[player]);

Console.ReadKey(true);

// Player A 有可能踩到: Player B、方块、轮盘、地雷、暂停、隧道

if (PlayerPos[player] == PlayerPos[1 - player])

{

Console.WriteLine("Player {0} step on {1}, {2} back to 6.", PlayerNames[player], PlayerNames[1 - player], PlayerNames[1 - player]);

PlayerPos[1 - player] -= 6;

Console.ReadKey(true);

}

else

{

switch (Maps[PlayerPos[player]])

{

case 0:

Console.WriteLine("Player {0} step on Square, safe.", PlayerNames[player]);

Console.ReadKey(true);

break;

case 1:

Console.WriteLine("Player {0} step on a LuckTrun, please select: 1--Swap places 2--bombing: ", PlayerNames[player]);

string input = Console.ReadLine().Trim();

PlayerSelect(input, player);

Console.ReadKey(true);

break;

case 2:

Console.WriteLine("Player {0} step on a LandMine, back to 6", PlayerNames[player]);

PlayerPos[player] -= 6;

Console.ReadKey(true);

break;

case 3:

Console.WriteLine("Player {0} step on a Pause, to suspend a round.", PlayerNames[player]);

Console.ReadKey(true);

Flags[player] = true;

break;

case 4:

Console.WriteLine("Player {0} step on a TimeTunnel, forward 10.", PlayerNames[player]);

PlayerPos[player] += 10;

Console.ReadKey();

break;

}

}

ChangePos();

Console.Clear();

DrawMap();

}

static void Main(string[] args)

{

ShowGame();

InputPlayerNames();

Console.WriteLine("Player {0} is A.", PlayerNames[0]);

Console.WriteLine("Player {0} is B.", PlayerNames[1]);

InitailMap();

DrawMap();

while (PlayerPos[0] < 99 && PlayerPos[1] < 99)

{

#region A

if (Flags[0] == false)

{

PlayGame(0);

}

else

{

Flags[0] = false;

}

#endregion

#region B

if (Flags[1] == false)

{

PlayGame(1);

}

else

{

Flags[1] = false;

}

#endregion

}

#region 判断玩家胜利

if (PlayerPos[0] == 99)

{

Console.Clear();

Console.WriteLine("Player {0} Win.", PlayerNames[0]);

}

if (PlayerPos[1] == 99)

{

Console.Clear();

Console.WriteLine("Player {0} Win.", PlayerNames[1]);

}

#endregion

Console.ReadKey();

}

}

}

android飞行棋小程序,C#飞行棋小程序设计代码相关推荐

  1. 飞鹅小票打印机嵌入生成指定小程序页面二维码的解决方案 | 扫普通链接二维码打开小程序示例 | 生成正方形小程序码

    部分朋友不需要打印机的业务,则 忽略有关打印机的部分 即可. 其他有关 微信小程序配置的介绍是通用的!通用的! 生成正方形小程序码,请看 标题一. 扫普通链接生成的二维码打开小程序,请看 标题二. 目 ...

  2. 微信小程序 - 使用 uni-app 开发小程序以及部分功能实现

    文章目录 一.uni-app 1.简介 2.开发工具 3.新建 uni-app项目 4.把项目运行到微信开发者工具 二.实现tabBar效果 1.创建tabBar页面 2.配置tabBar 三.配置网 ...

  3. 微信小程序详细图文教程-10分钟完成微信小程序开发部署发布 小程序趟过的坑,你遇到几个??

    很多朋友都认为微信小程序申请.部署.发布很难,需要很长时间. 实际上,微信和腾讯云同是腾讯产品,已经提供了10分钟(根据准备资源情况,已完成小程序申请认证)完成小程序开发.部署.发布的方式.当然,实现 ...

  4. 【腾讯连连 腾讯物联网入门学习 第3篇】安信可IoT微信小程序全面开源,小程序上实现一键配网+控制+绑定!(源码开放)

    文章目录 一.简介 二.开发指导 2.1 腾讯物联开发平台配置 2.2 微信小程序导入步骤 三.设备开发 3.1 AT直连对接 3.2 SDK二次开发 四.本人开源微信物联网控制 一览表 另外,不要把 ...

  5. 微信小程序开发学习笔记001--认识微信小程序,第一个微信小程序

    第一天,认识微信小程序,第一个微信小程序 1.什么是微信小程序? 是h5网页嘛?不是 微信张小龙说: 小程序是一种不需要下载安装即可使用的应用, 它实现了应用"触手可及"的梦想,用 ...

  6. [转]微信小程序之购物车 —— 微信小程序实战商城系列(5)

    本文转自:http://blog.csdn.net/michael_ouyang/article/details/70755892 续上一篇的文章:微信小程序之商品属性分类  -- 微信小程序实战商城 ...

  7. 微信小程序全选,微信小程序checkbox,微信小程序购物车

    微信小程序,这里实现微信小程序checkbox,有需要此功能的朋友可以参考下. 摘要: 加减商品数量,汇总价格,全选与全不选 设计思路: 一.从网络上传入以下Json数据格式的数组  1.标题titl ...

  8. python 自动化微信小程序_干货 | 微信小程序自动化测试最佳实践(附 Python 源码)...

    原标题:干货 | 微信小程序自动化测试最佳实践(附 Python 源码) 本文为霍格沃兹测试学院测试大咖公开课<微信小程序自动化测试>图文整理精华版. 随着微信小程序的功能和生态日益完善, ...

  9. 了解微信小程序、掌握微信小程序开发工具的使用、了解小程序的目录以及文件结构、掌握小程序中常用的组件、掌握WXML、WXSS、WXS的基本使用

    1 微信小程序介绍以及开发准备 1.1 了解微信小程序 百度百科: 微信小程序,简称小程序,英文名Mini Program,是一种不需要下载安装即可使用的应用,它实现了应用"触手可及&quo ...

  10. 微信小程序学习笔记一 + 小程序介绍 前置知识

    微信小程序学习笔记一 1. 什么是小程序? 2017年度百度百科十大热词之一 微信小程序, 简称小程序, 英文名 Mini Program, 是一种不需要下载安装即可使用的应用 ( 张小龙对其的定义是 ...

最新文章

  1. iphone退款申请教程_王者荣耀账号注销退钱吗?王者荣耀账号注销100%退款教程...
  2. win 7 新建文件夹 new folder Item Not Found 解决办法
  3. 多轮对话之对话管理:Dialog Management
  4. GridView实现数据编辑和删除(一)
  5. WPF Slider设置整数
  6. 【基础知识】Sticky Bit, SUID,SGID
  7. html跑马灯代码大全(图片文字移动代码)
  8. Google 另类技巧不完全手册
  9. 数商云钢材行业智慧供应商管理系统:降低企业运营成本,构建数字化供应商管理体系
  10. b java 之 serviceLoader详解 serviceLoader.load(XXX.class)
  11. html 发言样式,HTML样式
  12. 2022年智能家居生态系统状态报告
  13. 微信小程序联盟:官方文档+精品教程+demo集合(12月更新……)
  14. 记录一下学习嵌入式的方法和小窍门
  15. 如何实现vue表单验证cron表达式?【亲测有效】
  16. 微信小程序添加音效createInnerAudioContext
  17. 微信获取scheme码提示invalid weapp pagepath rid: 6397ef44-0f537d77-76155114
  18. 配置exchange2010邮箱和邮件大小限制
  19. 考中山大学计算机博士专业考什么,2020年中山大学博士考试的科目以及录取分数值...
  20. ULTRA EDIT -32 之传统正则表达式

热门文章

  1. 云服务上搭建halo博客
  2. android 程序白屏,Android冷启动白屏问题
  3. 28岁程序员的2016规划
  4. 关于汽油必须知道的11件事 可能是最全的油品全解
  5. 多多客id是什么意思_【多多情报学堂】拼多多id是什么?拼多多店铺id在哪里看?...
  6. Android UI个性style
  7. 防止恶意调用API接口
  8. NTFS删除及恢复分析
  9. MTK平台如何切换SIM卡槽
  10. C++软件开发岗位要求