using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _骑士飞行棋
{
class Program
{
public static int[] Map = new int[100];//声明一个长度为100的数组用来画地图
public static int[] PlayerPos = new int[2] { 0, 0 };//声明一个数组用来存玩家A和玩家B
public static string[] PlayerNames = new string[2];
public static bool[] flag = new bool[] { false,false};
static void Main(string[] args)
{
ShowUI();//游戏头
InitMap();//初始化地图
#region 玩家A和玩家B输入姓名
Console.WriteLine("请输入玩家A的姓名");
PlayerNames[0] = Console.ReadLine();
while (PlayerNames[0]=="")
{
Console.WriteLine("玩家A的姓名不能为空,请重新输入");
PlayerNames[0] = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的姓名");
PlayerNames[1] = Console.ReadLine();
while (PlayerNames[1] == PlayerNames[0] || PlayerNames[1] == "")
{
if (PlayerNames[1] == PlayerNames[0])
{
Console.WriteLine("玩家B的姓名和玩家A的姓名[{0}]不能相同相同",PlayerNames[0]);
}
else
{
Console.WriteLine("玩家B的姓名为空,请重新输入");
}
PlayerNames[1] = Console.ReadLine();
}
#endregion
Console.Clear();
ShowUI();//游戏头
Console.WriteLine("对战开始......");
Console.WriteLine("{0}的士兵用A表示......",PlayerNames[0]);
Console.WriteLine("{0}的士兵用B表示......", PlayerNames[1]);
DrawMap();//画地图
#region 玩家A掷骰子
if (flag[0]==false)
{
RowTouZi(0);
}
else
{
flag[0] = false;
}
#endregion
if (PlayerPos[0]==99)
{
Console.WriteLine("恭喜玩家A胜利了");
break;
}
#region 玩家B掷骰子
if (flag[1]==false)
{
RowTouZi(1);
}
else
{
flag[1] = false;
}
#endregion
if (PlayerPos[1]==99)
{
Console.WriteLine("恭喜玩家B胜利了");
break;
}
Console.WriteLine("行动完毕...");
}
Win();
Console.ReadKey();
//画图
//如何行走-----逻辑判断
}
/// <summary>
/// 显示游戏头
/// </summary>
public static void ShowUI()
{
Console.WriteLine("************************************");
Console.WriteLine("* *");
Console.WriteLine("* 终极骑士飞行棋 10.18 *");
Console.WriteLine("* *");
Console.WriteLine("************************************");
}
/// <summary>
/// 初始化地图
/// </summary>
public static void InitMap()
{
//初始化地图
//我用0表示普通,显示给用户就是 □
//....1...幸运,显示组用户就 ◎
//....2...地雷,显示给用户就是 ☆
//....3...暂停,显示给用户就是 ▲
//....4...时空隧道,显示组用户就 卐
int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运◎
int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷☆
int[] pause = { 9, 27, 60, 93 };//暂停▲
int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道卐
//把数组中下标为6, 23, 40, 55, 69, 83的地方的值改为1
for (int i = 0; i < luckyturn.Length; i++)
{
//int temp = luckyturn[i];
Map[luckyturn[i]] = 1;
}
for (int i = 0; i < landMine.Length; i++)
{
Map[landMine[i]] = 2;
}
for (int i = 0; i < pause.Length; i++)
{
Map[pause[i]] = 3;
}
for (int i = 0; i < timeTunnel.Length; i++)
{
Map[timeTunnel[i]] = 4;
}
}
/// <summary>
/// 画地图的
/// </summary>
public static void DrawMap()
{
//图例:幸运:◎ 地雷:☆ 暂停:▲ 时空隧道:卐
Console.WriteLine("图例:幸运:◎ 地雷:☆ 暂停:▲ 时空隧道:卐");
#region 画地图第一行
DrawMapLeftToRight(0, 29);
#endregion
Console.WriteLine();
#region 画地图第一竖行
for (int i = 30; i <= 34; i++)
{
for (int j = 0; j <= 28; j++)
{
Console.Write(" ");
}
//Console.Write();
Console.WriteLine(DrawStringMap(i));
}
#endregion
#region 画第二横行
for (int i = 64; i >= 35; i--)
{
Console.Write(DrawStringMap(i));
}
#endregion
Console.WriteLine();
#region 画第二竖行
for (int i = 65; i <= 69; i++)
{
Console.WriteLine(DrawStringMap(i));
}
#endregion
#region 画第三横行
DrawMapLeftToRight(70, 99);
#endregion
Console.WriteLine();
}
/// <summary>
/// 画地图的逻辑
/// </summary>
/// <param name="pos">传过来的坐标</param>
/// <returns></returns>
public static string DrawStringMap(int pos)
{
string temp = "";
#region 画第一行的逻辑
//如果玩家A和玩家B在一起并且在地图上就画<>
if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == pos)
{
Console.ForegroundColor = ConsoleColor.Yellow;
temp = "<>";
}
else if (PlayerPos[0] == pos)//如果玩家A在地图上就画A
{
Console.ForegroundColor = ConsoleColor.Yellow;
temp = "A";
}
else if (PlayerPos[1] == pos)//如果玩家B在地图上就画B
{
Console.ForegroundColor = ConsoleColor.Yellow;
temp = "B";
}
else
{
switch (Map[pos])//如果玩家A和玩家B不在一起也不在这个坐标上就画该显示的地图图标
{
case 0: Console.ForegroundColor = ConsoleColor.Gray;
temp = "□";
break;
case 1:
Console.ForegroundColor = ConsoleColor.Red;
temp = "◎";
break;
case 2:
Console.ForegroundColor = ConsoleColor.Blue;
temp = "☆";
break;
case 3:
Console.ForegroundColor = ConsoleColor.Green;
temp = "▲";
break;
case 4:
Console.ForegroundColor = ConsoleColor.Magenta;
temp = "卐";
break;
}//end switch
}//end else
return temp;
#endregion
}
/// <summary>
/// 从某个坐标到另一个坐标画地图
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
public static void DrawMapLeftToRight(int left, int right)
{
for (int i = left; i <= right; i++)
{
Console.Write(DrawStringMap(i));
}
}
/// <summary>
/// 根据传过来的数字,返回一个数字
/// </summary>
/// <param name="msg"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
public static int ReadInt(string msg, int min, int max)
{
while (true)
{
try
{
Console.WriteLine(msg);
int number = Convert.ToInt32(Console.ReadLine());
if (number >= min && number <= max)
{
return number;
}
else
{
Console.WriteLine("你的输入不合法!只能输入{0}到{1}之间的数字!", min, max);
continue;
}
}
catch
{
Console.WriteLine("输入有误,请重新输入!");
}
}
//程序绝对走不到这里
}
public static void RowTouZi(int playerPos)
{
Random r = new Random();
int num = r.Next(1,7);
string msg = "";
Console.WriteLine("{0}按任意键开始掷骰子", PlayerNames[playerPos]);
ConsoleKeyInfo coninfo = Console.ReadKey(true);
if (coninfo.Key == ConsoleKey.Q)
{
coninfo = Console.ReadKey(true);
if (coninfo.Key == ConsoleKey.A)
{
coninfo = Console.ReadKey(true);
if (coninfo.Key == ConsoleKey.Z)
{
num = 50;
}
}
}
Console.WriteLine("{0}掷出了{1}", PlayerNames[playerPos], num);
Console.WriteLine("{0}按任意键开始行动.....", PlayerNames[playerPos]);
Console.ReadKey(true);
PlayerPos[playerPos] += num;
CheckPos();
if (PlayerPos[playerPos] == PlayerPos[1 - playerPos])
{
msg=string.Format("玩家{0}踩到了玩家{1},玩家{2}退6格", PlayerNames[playerPos], PlayerNames[1 - playerPos], PlayerNames[1 - playerPos]);
PlayerPos[1 - playerPos] -= 6;
CheckPos();
}
else
{
switch (Map[PlayerPos[playerPos]])
{
case 0: msg="行动完了"; break;
case 1:
msg = string.Format("{0}走到了幸运,请选择 1----交换位置,2----轰炸对方", PlayerNames[playerPos]);
int number = ReadInt(msg, 1, 2);
if (number == 1)
{
int temp = 0;
temp = PlayerPos[playerPos];
PlayerPos[playerPos] = PlayerPos[1 - playerPos];
PlayerPos[1 - playerPos] = temp;
msg=string.Format("玩家{0}选择了与玩家{1}交换位置", PlayerNames[playerPos], PlayerNames[1 - playerPos]);
}
else
{
PlayerPos[1 - playerPos] = 0;
msg=string.Format("玩家{0}选择轰炸玩家{1}", PlayerNames[playerPos], PlayerNames[1 - playerPos]);
}
break;
case 2:
//踩到地雷了
msg="恭喜你,能踩到地雷,百年不遇,退6格";
PlayerPos[playerPos] -= 6;
CheckPos();
break;
case 3:
msg="踩到暂停了";
flag[playerPos] = true;
break;
case 4:
msg="恭喜你,这个猥琐家伙竟然穿越了10步";
PlayerPos[playerPos] += 10;
CheckPos();
break;
}
}
Console.Clear();
DrawMap();
Console.WriteLine(msg);
}
public static void CheckPos()
{
if (PlayerPos[0]>99)
{
PlayerPos[0] = 99;
}
if (PlayerPos[1]>99)
{
PlayerPos[1] = 99;
}
if (PlayerPos[0]<0)
{
PlayerPos[0] = 0;
}
if (PlayerPos[1]<0)
{
PlayerPos[1] = 0;
}
}
public static void Win()
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" ◆ ");
Console.WriteLine(" ■ ◆ ■ ■");
Console.WriteLine(" ■■■■ ■ ■ ◆■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ■ ◆ ■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■■■■■■ ■■■■■■■ ■ ■ ■");
Console.WriteLine(" ■■■■ ■ ■ ●■● ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ● ■ ● ■ ■ ■");
Console.WriteLine(" ■ ■ ■■■■■■ ● ■ ● ■ ■ ■");
Console.WriteLine(" ■■■■ ■ ● ■ ■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ■ ■ ■ ■ ■");
Console.WriteLine(" ■ ■ ■ ■ ■ ■ ");