实例介绍
【实例简介】
【实例截图】【核心代码】
static int[] Map = new int[100];
static int [] lukyTurn={6,26,47,69,94};
static int [] boom={12,36,52,78,99};
static int [] pause={17,44,61,84};
static int [] fly={2,32,62,82};
static Person[] player = new Person[2];
static void Main(string[] args)
{
ShowUI();
initial();
#region 玩家A B名字输入
Console.WriteLine("请输入玩家A的名字:");
player[0].name = InPutName();
Console.WriteLine("请输入玩家B的名字:");
player[1].name = InPutName();
while (player[0].name == player[1].name)
{
Console.WriteLine("不能与玩家A名字相同");
player[1].name = InPutName();
}
#endregion
Rult();
Console.WriteLine();
Console.WriteLine("请按任意键继续!");
Console.ReadKey();
Console.Clear();
player[0].roll = 2;
player[1].roll = 1;
PrintUI();
do
{
PrintUI();
Console.WriteLine();
RollB();
RollA();
Console.ReadKey();
} while (player[0].pos<100&&player[1].pos<100);
if (player[0].pos>player[1].pos)
{
Console.Clear();
Console.WriteLine("玩家A胜利,他就是:{0}",player[0].name);
}
else
{
Console.Clear();
Console.WriteLine("玩家B胜利,他就是:{0}",player[1].name);
}
Console.ReadKey();
}
static void ShowUI()
{
Console.WriteLine("*****************************************");
Console.WriteLine("* *");
Console.WriteLine("* 骑 士 行 棋 *");
Console.WriteLine("* *");
Console.WriteLine("*****************************************");
}//显示界面
static string InPutName()//输入名字
{
string name;
name = Console.ReadLine();
while (name == "")
{
Console.WriteLine("名字不能为空,请重新输入");
name = Console.ReadLine();
};
return name;
}
static void initial()//初始化
{
for (int i = 0; i < lukyTurn.Length; i )//幸运轮盘 为1
{
Map[lukyTurn[i]]=1;
}
for (int i = 0; i < boom.Length; i )//炸弹 为2
{
Map[boom[i]]=2;
}
for (int i = 0; i < pause.Length; i )//暂停 为2
{
Map[pause[i]]=3;
}
for (int i = 0; i < fly.Length; i )//传送 为4
{
Map[fly[i]]=4;
}
}
static string GameUI(int pos)//把Map所存放的数字转化为字符串
{
string result="□";
//返回字符串
#region 返回对应字符串
if (player[0].pos==pos && player[1].pos==pos)
{
result = "<>";
}
else if (player[0].pos==pos)
{
result = "A";
}
else if (player[1].pos == pos)
{
result = "B";
}
else
{
switch (Map[pos])
{
case 0:
result= "□";
break;
case 1:
result = "◎";
break;
case 2:
result = "★";
break;
case 3:
result = "▲";
break;
case 4:
result = "卐";
break;
}
}
return result;
#endregion
}
static void PrintUI()//绘制游戏地图
{
Console.Clear();
Console.WriteLine("A代表玩家{0},B代表玩家{1}", player[0].name, player[1].name);
int x = 64;
for (int i = 0; i < Map.Length; i )
{
#region 第一行
if (i < 30)
{
Console.Write(GameUI(i));
}
else if (i == 30)
{
Console.WriteLine(GameUI(i));
}
#endregion
#region 第二列
else if (i < 34)
{
for (int j = 0; j < 30; j )
{
Console.Write(" ");
}
Console.WriteLine(GameUI(i));
}
#endregion
#region 第三行
else if (i <= 64)
{
Console.Write(GameUI(x));
x--;
}
else if (x == 34)
{
Console.Write(GameUI(x));
}
#endregion
#region 第四列
else if (i <= 69)
{
Console.WriteLine();
Console.Write(GameUI(i));
}
#endregion
#region 第五行
else
{
Console.Write(GameUI(i));
}
#endregion
}
}
static void Rult() //游戏规则
{
Console.Clear();
Console.WriteLine(" 游戏说明");
Console.WriteLine("<>表示AB玩家均在一起。");
Console.WriteLine("{0}使用A代表,{1}使用B代表", player[0].name, player[1].name);
Console.WriteLine("地图中□代表普通位置");
Console.WriteLine("◎幸运轮盘,可以选择与对手交换位置,或者让对方倒退10步");
Console.WriteLine("★代表炸弹,踩中后倒退6步");
Console.WriteLine("▲表示暂停,踩中后停止扔骰子一回合");
Console.WriteLine("卐时空隧道,向前20步");
PrintUI();
}
static void RollA()//投掷骰子
{
int num=0;
Random shaizi = new Random();
for (int i = 0; i < player[0].roll; i )
{
if (player[0].pause == 0)
{
Console.WriteLine("请玩家A按任意键扔骰子");
Console.ReadKey();
num = shaizi.Next(1, 7);
Console.WriteLine("玩家A投出的数字是“{0}”", num);
Console.ReadKey();
player[0].pos = player[0].pos num;
LukyTurn();
Boom();
Pause();
PrintUI();
}
}
}
static void RollB()//B玩家投掷骰子
{
int num = 0;
Random shaizi = new Random();
for (int i = 0; i < player[0].roll; i )
{
if (player[1].pause == 0)
{
Console.WriteLine();
Console.WriteLine("请玩家B按任意键扔骰子");
Console.ReadKey();
num = shaizi.Next(1, 7);
Console.WriteLine("玩家B投出的数字是“{0}”", num);
Console.ReadKey();
player[1].pos = player[1].pos num;
LukyTurn();
Boom();
Pause();
} PrintUI();
}
player[0].roll = 1;
}
static void LukyTurn()//幸运轮盘事件
{
for (int i = 0; i < lukyTurn.Length; i )
{
if (player[0].pos==lukyTurn[i])
{
Console.WriteLine("请选择其中一项:按“1”或“2”");
Console.WriteLine("1.与B玩家交换位置;2.前进10步");
if(Console.ReadKey().Key == ConsoleKey.D1)
{
int temp = player[0].pos;
player[0].pos = player[1].pos;
player[1].pos = temp;
}
else if (Console.ReadKey().Key == ConsoleKey.D2)
{
player[0].pos = player[0].pos 10;
}
}
if (player[1].pos == lukyTurn[i])
{
Console.WriteLine("请选择其中一项:按“1”或“2”");
Console.WriteLine("1.与A玩家交换位置;2.前进10步");
if (Console.ReadKey().Key == ConsoleKey.D1)
{
int temp = player[0].pos;
player[0].pos = player[1].pos;
player[1].pos = temp;
}
else if (Console.ReadKey().Key == ConsoleKey.D2)
{
player[1].pos = player[1].pos 10;
}
}
}
}
static void Boom()//炸弹事件
{
for (int i = 0; i < boom.Length; i )
{
if (player[0].pos == boom[i])
{
Console.WriteLine("玩家A踩到炸弹倒退6步");
Console.ReadKey();
player[0].pos -= 6;
}
if (player[1].pos == boom[i])
{
Console.WriteLine("玩家B踩到炸弹倒退6步");
Console.ReadKey();
player[1].pos -= 6;
}
}
}
static void Pause()//暂停事件
{
for (int i = 0; i < pause.Length; i )
{
if (player[0].pos == pause[i])
{
Console.WriteLine("玩家A暂停一回合");
Console.ReadKey();
player[1].roll = 2;
}
if (player[1].pos == pause[i])
{
Console.WriteLine("玩家B暂停一回合");
Console.ReadKey();
player[0].roll = 2;
}
}
}
static void Fly()//幸运轮盘事件
{
for (int i = 0; i < fly.Length; i )
{
if (player[0].pos == fly[i])
{
Console.WriteLine("太幸运了,玩家A好像飞了起来");
player[0].pos = 20;
}
if (player[1].pos == fly[i])
{
Console.WriteLine("太幸运了,玩家B好像飞了起来");
player[1].pos = 20;
}
}
}
标签: 面向过程飞行棋
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论