using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 骑士飞行棋
{
class Program
{
static string[] name=new string[2];
static int[] map = new int[100];
static int[] ab = {0,0}; //存玩家的下标
static bool[] isstop = { false, false };//A、B轮流掷骰子的标志
static void Main(string[] args)
{
ShowUI();
Console.WriteLine("请输入玩家A的姓名");
name[0] = Console.ReadLine();
name[0]=IsNull(name[0]);
Console.WriteLine("请输入玩家B的姓名");
name[1] = Console.ReadLine();
name[1] = IsNull(name[1]);
while(name[1] == name[0])
{
Console.WriteLine("用户名被占用,请重新输入");
name[1] = Console.ReadLine();
name[1] = IsNull(name[1]);
}
Console.Clear();
ShowUI();
Console.WriteLine("决战开始......");
Console.WriteLine("玩家{0}的士兵用A来表示",name[0]);
Console.WriteLine("玩家{0}的士兵用B来表示", name[1]);
Console.WriteLine("如果AB在同一位置用<>来表示");
Console.WriteLine("图例:☆是地雷(倒退6步)、卍是时空隧道(前进10步)、▲是暂停一次、◎是幸运轮盘");
InitializeMap();
DrawMap();
Console.WriteLine("开始游戏......");
while (ab[0] < 99 && ab[1] < 99)
{
if (isstop[0] == false)
{
action(0);
}
else{ isstop[0] =false; }
if (isstop[1] == false)
{
action(1);
}
else { isstop[1] = false; }
for (int i=0; i < 2; i++)
{
if(ab[i]>=99)
{
break;
}
}
}
Console.Clear();
if (ab[0] >= 99)
{
Console.WriteLine("{0}胜利了!!!!!!,大神出现了!!!!!!", name[0]);
Console.WriteLine();
Console.WriteLine("失败者{0}获得新称号:李阳家的笨猫", name[1]);
}
else
{
Console.WriteLine("{0}胜利了!!!!!!,大神出现了", name[1]);
Console.WriteLine();
Console.WriteLine("失败者{0}获得新称号:李阳家的笨猫", name[0]);
}
Console.ReadKey();
}
/// <summary>
/// 页面设计
/// </summary>
static void ShowUI()
{
Console.WriteLine("*****************************************************");
Console.WriteLine("** **");
Console.WriteLine("** 骑 士 飞 行 棋 **");
Console.WriteLine("** **");
Console.WriteLine("*****************************************************");
}
/// <summary>
/// 验证用户输入是否为空
/// </summary>
/// <param name="temp"></param>
static string IsNull(string temp)
{
while (temp == "")
{
Console.WriteLine("您输入有误,不能为空值!");
temp = Console.ReadLine();
}
return temp;
}
/// <summary>
/// 初始化地图
/// </summary>
static void InitializeMap()
{
int[] dilei = { 5,13,17,33,38,50,64,80,94 }; //地雷
int[] suidao = { 20,25,45,63,72,88,90}; //隧道
int[] zanting = { 9,27,60,93 }; //暂停
int[] lunpan = { 6, 23, 40, 55, 69, 83 }; //轮盘
for (int i = 0; i < dilei.Length; i++)
{
map[dilei[i]] = 1;
}
for (int i = 0; i < suidao.Length; i++)
{
map[suidao[i]] = 2;
}
for (int i = 0; i < zanting.Length; i++)
{
map[zanting[i]] = 3;
}
for (int i = 0; i < lunpan.Length; i++)
{
map[lunpan[i]] = 4;
}
}
/// <summary>
/// 绘制地图的形状 1是地雷、2是隧道、3是暂停、4是轮盘
/// </summary>
/// <returns></returns>
static string getmap(int temp)
{
string result="";
if (ab[0] == temp && ab[1] == temp)
{
Console.ForegroundColor = ConsoleColor.Yellow;
result="<>";
}else if(ab[0] == temp)
{
Console.ForegroundColor = ConsoleColor.Yellow;
result="A";
}
else if (ab[1] == temp)
{
Console.ForegroundColor = ConsoleColor.Yellow;
result = "B";
}
else
{
switch (map[temp])
{
case 0:
Console.ForegroundColor = ConsoleColor.White;
result = "□";
break;
case 1:
Console.ForegroundColor = ConsoleColor.Green;
result = "☆";
break;
case 2:
Console.ForegroundColor = ConsoleColor.Red;
result = "卍";
break;
case 3:
Console.ForegroundColor = ConsoleColor.Blue;
result = "▲";
break;
case 4:
Console.ForegroundColor = ConsoleColor.Magenta;
result = "◎";
break;
}
}
return result;
}
/// <summary>
/// 绘制地图的样式
/// </summary>
static void DrawMap()
{
for (int i = 0; i < 30; i++)
{
Console.Write(getmap(i));
}
Console.WriteLine();
for (int i = 30; i < 35; i++)
{
for (int j = 0; j < 29; j++)
{
Console.Write(" ");
}
Console.WriteLine(getmap(i));
}
for (int i =64; i>=35; i--)
{
Console.Write(getmap(i));
}
Console.WriteLine();
for (int i = 65; i < 70; i++)
{
Console.WriteLine(getmap(i));
}
for (int i = 70; i < 100; i++)
{
Console.Write(getmap(i));
}
Console.WriteLine();
Console.ResetColor();
}
|
|