using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 飞行棋Ver1._0
{
class Program
{
//如果元素的值是0 代表这是1个普通
//1 幸运轮盘 ◎
//2 暂停 ▲
//3 地雷 ●
//4. 时光隧道 卍
static int[] map = new int[];
static int[] pos = new int[];//第一个元素代表的是玩家A的位置 第2个元素代表的是玩家B的位置
static bool[] isStop = {false,false };
static string[] names = new string[];//用于保存玩家AB的姓名
static void Main(string[] args)
{
ShowUI();//显示LOGO
Console.WriteLine("请输入玩家A的名字:");
while (true)//进入循环 接受用户输入玩家A的名字 退出条件是 玩家A输入的不是空的字符串
{
names[] = Console.ReadLine();
if (names[] == "")
{
Console.WriteLine("玩家的名字不能为空,请重新输入!");
}
else
{
break;//跳出循环
}
}
Console.WriteLine("请输入玩家B的名字:");
names[] = Console.ReadLine();//接收用户的输入 并把用户的输入赋值给names数组的第1个元素
while (names[] == "" || names[] == names[])//循环接收用户的输入
{
if (names[] == "")
{
Console.WriteLine("玩家的名字不能为空,请重新输入!");
}
else if (names[] == names[])
{
Console.WriteLine("玩家B的名字不能与玩家A的名字一样,请重新输入");
}
names[] = Console.ReadLine();
}
//到这里为止 我们已经接收了用户输入的玩家A和玩家B的姓名
Console.Clear();//将当前控制台上的所有的信息 清空
ShowUI();
Console.WriteLine(names[] + "," + names[] + "欢迎你们来到飞行棋乐园。。。。。。。");
Console.WriteLine(names[] + "用A表示\n" + names[] + "用B表示\n" + "如果两个在一起用<>表示\n现在对战开始!");
InitMap();
DrawMap();
Random r = new Random();
//开始轮流掷骰子
while (pos[] < && pos[] < )
{
if (isStop[] == false)
{
#region 玩家A掷骰子
Play();
#endregion
}
else
{
isStop[] = false;
}
if (pos[] >= )
{
break;
}
if (isStop[] == false)
{
#region 玩家B掷骰子
Play();
#endregion
}
else
{
isStop[] = false;
}
//如果是普通的 则什么效果都木有
//如果玩家A踩到玩家B 玩家B的位置到0
//如果是幸运轮盘 1可以和对方互换位置 2.可以轰炸对方(让对方退6格)
//如果是时空隧道 就让玩家A前进10格
//如果是地雷 就退6格
//如果是暂停 那么就让玩家A暂停一次
}
if (pos[] >= )
{
Console.WriteLine("恭喜你" + names[] + "玩家胜利!");
}
else
{
Console.WriteLine("恭喜你" + names[] + "玩家胜利!");
}
Console.ReadKey();
}
/// /// 是接收用户从控制台输入指定范围的整数
/// /// 最小值
/// 最大值
///
static int ReadInt(int min, int max)
{
while (true)
{
string str = Console.ReadLine();//接收用户从控制台输入的字符串 并将字符串赋值给str变量
int i;//声明1个iint类型的变量叫做i
if (int.TryParse(str, out i))//int.TryParse()这个方法将指定的字符串转换成int类型的
//如果转换成功.那么返回true 并且将转换成功的整数赋值给这个方法的第2个out参数
//如果转换失败,那么这个方法就返回false
{
if (i < min || i > max)
{
Console.WriteLine("输入的数字只能在{0}-{1}之间,请重新输入", min, max);
continue;
}
else
{
return i;
}
}
else
{
Console.WriteLine("只能输入整数数字。。。。请重新输入....");
continue;
}
}
}
static void Play(int playerNumer)//传递0就是表示的是第玩家A调用 1代表的是玩家B在调用
{
string AorB = playerNumer == ? "A" : "B";
Random r = new Random();
Console.WriteLine("玩家{1}:{0}按任意键开始掷骰子....", names[playerNumer], AorB);
ConsoleKeyInfo info = Console.ReadKey(true);//接收用户任意键的输入
int step = r.Next(, );//返回1个1-6的随机数
if (info.Key == ConsoleKey.Tab)
{
step = ;
}
Console.WriteLine("玩家{2}:{0}掷的数字是:{1}", names[playerNumer], step, AorB);
pos[playerNumer] += step;
CheckPos();
string msg = "";
//判断玩家A是否踩到了玩家B
if (pos[] == pos[])
{
if (playerNumer == )
pos[] = ;
else
pos[] = ;
}
else
{
switch (map[pos[playerNumer]])
{
case ://普通的 没有效果
break;
case ://幸运轮盘
//如果是幸运轮盘 1可以和对方互换位置 2.可以轰炸对方(让对方退6格)
Console.WriteLine("恭喜你,踩到了幸运轮盘,请选择你的运气: 1.和对方互换位置 2.轰炸对方");
int userSelect = ReadInt(, );
if (userSelect == )//和对方互换位置
{
int temp = pos[];//交换变量的值
pos[] = pos[];
pos[] = temp;
msg = "你选择了和对方互换位置........";
}
else //轰炸对方 让对方退6格
{
if (playerNumer == )
pos[] -= ;
else pos[] -= ;
CheckPos();
msg = string.Format("你轰炸了对方,{0}退6格", names[]);
}
break;
case ://暂停
isStop[playerNumer] = true;
msg = "倒霉,暂停一次!";
break;
case ://地雷
pos[playerNumer] -= ;
CheckPos();
msg = "真倒霉,你踩到地雷了,后退6格";
break;
case ://时光隧道
pos[playerNumer] += ;
CheckPos();
msg = "真爽, 你穿越了, 前进10格";
break;
}
}
if (msg != "")
{
Console.WriteLine(msg);
}
Console.WriteLine("按任意键开始移动。。。");
Console.ReadKey(true);
Console.Clear();
ShowUI();
DrawMap();
Console.WriteLine("**********************位置信息**********************");
Console.WriteLine("玩家A的位置:" + pos[]);
Console.WriteLine("玩家B的位置:" + pos[]);
}
/// /// 检测玩家A和玩家B的位置是否越界
/// static void CheckPos()
{
for (int i = ; i < pos.Length; i++)
{
if (pos[i] > )
{
pos[i] = ;
}
if (pos[i] < )
{
pos[i] = ;
}
}
}
static string GetMapString(int p)
{
//1 幸运轮盘 ◎
//2 暂停 ▲
//3 地雷 ●
//4. 时光隧道 卍
string res = "";
if (pos[] == p && pos[] == p)
{
Console.ForegroundColor = ConsoleColor.Red;
res = ("<>");
}
else if (pos[] == p)
{
Console.ForegroundColor = ConsoleColor.Red;
res = ("A");
}
else if (pos[] == p)
{
Console.ForegroundColor = ConsoleColor.Red;
res = ("B");
}
else
{
switch (map[p])
{
case :
Console.ForegroundColor = ConsoleColor.White;//是设置控制台的前景色
res = "□";
break;
case :
Console.ForegroundColor = ConsoleColor.Green;
res = "◎";
break;
case :
Console.ForegroundColor = ConsoleColor.Yellow;
res = "▲";
break;
case :
Console.ForegroundColor = ConsoleColor.DarkRed;
res = "●";
break;
case :
Console.ForegroundColor = ConsoleColor.Blue;
res = "卍";
break;
}
}
return res;
}
static void InitMap()
{
int[] luckTurn = { , , , , , , };//幸运轮盘
int[] landMine = { , , , , , , , , };//地雷
int[] pause = { , , , };//暂停
int[] timeTunnel = { , , , , , , };//时空隧道
//1 幸运轮盘 ◎
//2 暂停 ▲
//3 地雷 ●
//4. 时光隧道 卍
for (int i = ; i < luckTurn.Length; i++)
{
map[luckTurn[i]] = ;
}
for (int i = ; i < landMine.Length; i++)
{
map[landMine[i]] = ;
}
for (int i = ; i < pause.Length; i++)
{
map[pause[i]] = ;
}
for (int i = ; i < timeTunnel.Length; i++)
{
map[timeTunnel[i]] = ;
}
}
static void DrawMap()
{
for (int i = ; i <= ; i++)
{
Console.Write(GetMapString(i));
}
Console.WriteLine();
for (int i = ; i <= ; i++)
{
for (int j = ; j < ; j++)
{
Console.Write(" ");
}
Console.Write(GetMapString(i));
Console.WriteLine();
}
//打印第
for (int i = ; i >= ; i--)
{
Console.Write(GetMapString(i));
}
Console.WriteLine();
for (int i = ; i <= ; i++)
{
Console.WriteLine(GetMapString(i));
}
for (int i = ; i <= ; i++)
{
Console.Write(GetMapString(i));
}
Console.WriteLine();
}
static void ShowUI()
{
Console.WriteLine("***************************");
Console.WriteLine("* *");
Console.WriteLine("* 棋 士 飞 行 棋 *");
Console.WriteLine("* *");
Console.WriteLine("***************************");
}
}
}

最新文章

  1. C#中两个Form窗口之间的传值(父-&gt;子)(子-&gt;父)
  2. vm网络设置
  3. 基础篇之 Create Type
  4. hibernate 映射 多对一
  5. XMPP——Smack[6]离线消息和离线文件的实现
  6. 关于在WIN32调用一些Zw系列的文件操作函数
  7. Yii PHP 框架分析 (一)
  8. Objective-C:KVO
  9. 统计建模与R软件习题二答案
  10. Effective Java Item4:Enforce noninstantiability with a private constructor
  11. js html5 仿微信摇一摇
  12. C#用链式方法
  13. [leetcode-604-Design Compressed String Iterator]
  14. 开源网络监控管理系统:OpenNMS
  15. 介绍几款 Python 类型检查工具
  16. Docker的安装与使用介绍
  17. 为什么要使用mybaits
  18. python(十四)新式类和旧式类
  19. jquery.ajax请求aspx和ashx的异同 Jquery Ajax调用aspx页面方法
  20. 虚函数指针sizeof不为sizeof(void*)

热门文章

  1. Uva 1572 自组合
  2. Microsoft Azure 资料整理
  3. UVALive 6507 Passwords
  4. MySQL最优配置文件模板&#183;2016-11-28
  5. CentOS 7.1安装GNOME,开启VNC Server
  6. windows 下 iptables
  7. MVC Ajax.BeginForm重复提交解决方法
  8. 欧拉 路径&amp;&amp;回路
  9. POJ 1064_Cable master
  10. JDBC的异常