/// <summary>
/// 初始化游戏地图
/// </summary>
static void InitialMap()
{
for (int i=0;i<Map.Length;i++)
{
Map[i] =0;
}
//用于存储关卡位置
int[] luckyTurn = { 6, 23, 40, 55, 69, 83,98 };//幸运转盘 1
int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷 2
int[] pause = { 9, 27, 60, 93 };//暂停 3
int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90};//时空隧道 4
for (int i=0;i<luckyTurn.Length;i++)
{
int pos = luckyTurn[i];
Map[pos] = 1;
}
for (int i=0;i<landMine.Length;i++)
{
Map[landMine[i]] = 2;
}
for (int i=0;i<pause.Length;i++)
{
int pos = pause[i];
Map[pos] = 3;
}
for(int i=0;i<timeTunnel.Length;i++)
{
int pos = timeTunnel[i];
Map[pos] =4;
}
}
/// <summary>
/// 获得要绘制的坐标
/// </summary>
/// <param name="i"> 要绘制的坐标</param>
/// <returns></returns>
static string GetMapString(int i)
{
string Result="";//用于返回 给一个坐标相应的图案
if (playerPos[0] == i && playerPos[1] == i)//判断是否是对战双方所在此处
{
Console.ForegroundColor = ConsoleColor.Yellow;//设置图案的前景色为黄色
Result = "<>";//得到两人均在图案
}
else if (playerPos[0] == i)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Result = "A";//得到A均在图案
}
else if (playerPos[1] == i)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Result = "B";//得到B均在图案
}
else
{
switch (Map[i])
{
case 0:
Console.ForegroundColor = ConsoleColor.White;
Result = "□";//得到普通均在图案
break;
case 1:
Console.ForegroundColor = ConsoleColor.Red;
Result = "○";//得转盘图案
break;
case 2:
Console.ForegroundColor = ConsoleColor.Blue;
Result = "☆";
break;
case 3:
Console.ForegroundColor = ConsoleColor.Green;
Result = "▲";
break;
case 4:
Console.ForegroundColor = ConsoleColor.DarkBlue;
Result = "卍";
break;
}
}
return Result; //返回图案
}
/// <summary>
/// 绘制游戏地图
/// </summary>
static void DrownMap()
{
Console.WriteLine("图例:幸运转盘 ○ 地雷 ☆ 暂停 ▲ 时空隧道 卍");
//画第一行 下标0-29 的地图
for(int i=0;i<30;i++)//循环坐标得到 第一行每个点的图案
{
Console.Write(GetMapString(i)); //调用函数得到每个坐标的图案
}
Console.Write("\n");
Console.ResetColor();//重置前景色
}
/// <summary>
/// 检查坐标是否越界
/// </summary>
static void CheckPos()
{
for (int i = 0; i <= 1; i++)
{
if (playerPos[i] > 99)
{
playerPos[i] = 99;
}
if (playerPos[i] < 0)
{
playerPos[i] = 0;
}
}
}
static int ReadInt(int min,int max)
{
while (true)
{
try
{
int number = Convert.ToInt32(Console.ReadLine());
if(number<min||number>max)
{
Console.WriteLine("只能输入{0}-{1}之间的数字,请重新输入!", min, max);
continue;
}
return number;
}
catch
{
Console.WriteLine("只能输入数字,请重新输入!");
}
}
}
//这个循环中 玩家轮流掷骰子,当任何一人坐标>=99时,游戏结束
while(playerPos[0]<99&&playerPos[1]<99)
{
Random r = new Random();//产生随机数
int Step;//存放产生的随机数;
if (isStop[0] == false)
{
#region//玩家A掷骰子
Console.WriteLine("{0}按任意键掷骰子....", names[0]);
ConsoleKeyInfo rec = Console.ReadKey(true);
if (rec.Key == ConsoleKey.Tab)
{
Step = 6;
}
else
{
Step = r.Next(1, 7);
}
Console.WriteLine("{0}掷出了{1}", names[0], Step);
Console.WriteLine("{0}按任意键行动...", names[0]);
Console.ReadKey(true);//不显示 按下按下的按键的值
playerPos[0] = playerPos[0] + Step;//更改坐标<一旦坐标发生改变,判断是否大于99或 小于0>
CheckPos();
if (playerPos[0] == playerPos[1])//玩家A踩到玩家B
{
playerPos[1] = 0;
msg = string.Format("{0}踩到了{1},退回原点", names[0], names[1]);//Format函数用于拼接字符段
}
#region
else //没踩到,判断此位置是否有其他关卡
{
switch (Map[playerPos[0]])
{
case 0:
//普通位置,无效果
msg = "";
break;
case 1:
//幸运转盘
Console.Clear();
DrownMap();
Console.WriteLine("{0}走到了幸运转盘,请选择运气?", names[0]);
Console.WriteLine("1:交换位置 2: 轰炸 ");
int userSelect = ReadInt(1, 2);
if (userSelect == 1)
{
int temp;
temp = playerPos[0];
playerPos[0] = playerPos[1];
playerPos[1] = temp;
msg = string.Format("{0}选择了与{1}交换位置,哈哈,一夜回到解放前啊", names[0], names[1]);
}
else
{
playerPos[1] = playerPos[1] - 6;
CheckPos();
msg = string.Format("{0}选择了与让 {1}后退6步,自求多福吧", names[0], names[1]);
}
break;
case 2:
//地雷
playerPos[0] = playerPos[0] - 6;
CheckPos();
msg = string.Format("{0}踩到了地雷,后退6步,阿弥陀佛", names[0]);
break;
case 3:
//暂停
isStop[0] = true;
msg = string.Format("{0}暂停一次!", names[0]);
break;
case 4:
//时空隧道
playerPos[0] = playerPos[0] + 6;
CheckPos();
msg = string.Format("{0}进入了时空隧道 ,前进吧!", names[0]);
break;
}
}
#endregion
Console.WriteLine("按任意键开始行动...");
Console.ReadKey(true);
Console.Clear();
DrownMap();
if (msg != "")
{
Console.WriteLine(msg);
}
Console.WriteLine("{0}掷出了{1},行动完成!", names[0], Step);
Console.WriteLine("*******w玩家A和玩家B的位置如下***********");
Console.WriteLine(" 玩家{0}的位置为{1}", names[0], playerPos[0] + 1);
Console.WriteLine(" 玩家{0}的位置为{1}", names[1], playerPos[1] + 1);
#endregion
}
else
{
//说明A暂停一次
isStop[0] = false;
}
if(playerPos[0]>=99)
{
break;
}
#region 玩家B掷骰子
#endregion
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有