黑马程序员技术交流社区
标题:
骑士飞行棋的源码分享--2
[打印本页]
作者:
wanghuailin1030
时间:
2013-6-18 22:40
标题:
骑士飞行棋的源码分享--2
接上一贴
/// <summary>
/// 判断是否越界
/// </summary>
static void line()
{
for (int i = 0; i < 2; i++)
{
if (ab[i] > 99)
{
ab[i] = 99;
}
if (ab[i] < 0)
{
ab[i] = 0;
}
}
}
/// <summary>
/// 判断输入数字是否在范围内
/// </summary>
/// <returns></returns>
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("只能输入数字,请重新输入");
}
}
}
/// <summary>
/// 掷骰子 1是地雷、2是隧道、3是暂停、4是轮盘
/// </summary>
/// <param name="playerNumber">A掷骰子传0过来,B掷骰子传1过来</param>
static void action(int playerNumber)
{
int step = 0;
Random ran = new Random();
Console.WriteLine("玩家{0}按任意键开始掷骰子", name[playerNumber]);
Console.ReadKey(true);
step = ran.Next(1, 7);
Console.WriteLine("玩家{0}掷出了{1}", name[playerNumber], step);
Console.WriteLine("按任意键开始行动");
Console.ReadKey(true);
ab[playerNumber] = ab[playerNumber] + step;
line();
string msg = ""; //用于接收被清屏的值,存储关卡的提示语言
if (ab[0] == ab[1])
{
msg = string.Format("玩家{0}踩到了玩家{1},玩家{1}退到起点", name[playerNumber], name[1 - playerNumber]);
ab[1 - playerNumber] = 0;
}
else
{
switch (map[ab[playerNumber]])
{
case 1:
msg = string.Format("{0}踩到了地雷,退六步", name[playerNumber]);
ab[playerNumber] = ab[playerNumber] - 6;
line();
break;
case 2:
msg = string.Format("{0}进入时空隧道,爽歪歪,前进10步", name[playerNumber]);
ab[playerNumber] = ab[playerNumber] + 10;
line();
break;
case 3:
msg = string.Format("{0}撞到了暂停陷阱,暂停一次掷骰子", name[playerNumber]);
isstop[playerNumber] = true;
break;
case 4:
Console.Clear();
DrawMap();
Console.WriteLine("{0}走到了幸运轮盘,请选择你的运气", name[playerNumber]);
Console.WriteLine("1---互换位置 2---轰炸对方");
int i = ReadInt(1, 2);
if (i == 1)
{
int temp = 0;
temp = ab[0];
ab[0] = ab[1];
ab[1] = temp;
msg = string.Format("{0}选择与{1}交换位置", name[playerNumber], name[1 - playerNumber]);
}
else
{
ab[1 - playerNumber] = ab[1 - playerNumber] - 6;
line();
msg = string.Format("{0}轰炸了{1},{1}退6步", name[playerNumber], name[1 - playerNumber]);
}
break;
}
}
Console.Clear();
ShowUI();
Console.WriteLine();
Console.WriteLine("图例:☆是地雷(倒退6步)、卍是时空隧道(前进10步)、▲是暂停一次、◎是幸运轮盘");
Console.WriteLine();
DrawMap();
Console.WriteLine(msg);
Console.WriteLine("玩家{0}掷出了{1},行动完成", name[playerNumber], step);
Console.WriteLine("*********玩家A与B的位置如下***************");
Console.WriteLine("玩家{0}的位置:{1}", name[0],ab[0] + 1);
Console.WriteLine("玩家{0}的位置:{1}", name[1],ab[1] + 1);
}
}
}
作者:
许庭洲
时间:
2013-6-19 06:53
值得学习ing!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2