sing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _01复习
{
class Program
{
static void Main(string[] args)
{
//飞行棋 游戏头
//标题
GameShow();
#region 输入玩家姓名
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("请输入玩家A的姓名:");
PlayerNames[0] = Console.ReadLine().Replace(" ", "");
while (PlayerNames[0] == "")
{
Console.Write("玩家A的姓名不能为空,请重新输入:");
PlayerNames[0] = Console.ReadLine().Replace(" ", "");
}
Console.Write("请输入玩家B的姓名:");
PlayerNames[1] = Console.ReadLine().Replace(" ", ""); ;
while (PlayerNames[1] == "" || PlayerNames[0] == PlayerNames[1])
{
if (PlayerNames[1] == "")
{
Console.Write("玩家B的姓名不能为空,请重新输入:");
PlayerNames[1] = Console.ReadLine().Replace(" ", "");
}
else
{
Console.Write("玩家B的姓名不能跟玩家A相同,请重新输入:");
PlayerNames[1] = Console.ReadLine().Replace(" ", ""); ;
}
}
#endregion
//玩家输入完姓名 首先应该清屏
Console.Clear(); //清屏
GameShow();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("{0}的士兵用A表示.", PlayerNames[0]);
Console.WriteLine("{0}的士兵用B表示", PlayerNames[1]);
//初始化
InitialMap();
//画地图
DrawMap();
//当玩家A跟玩家B没有一个在终点的时候 两个玩家不停的玩
while (PlayerPos[0] < 99 && PlayerPos[1] < 99)
{
if (PlayerFlag[0] == false)
{
PlayGame(0);
}
else
{
PlayerFlag[0] = false;
}
if (PlayerPos[0] >= 99)
{
Console.WriteLine("玩家{0}赢了玩家{1}",PlayerNames[0],PlayerNames[1]);
break;
}
if (!PlayerFlag[1])
{
PlayGame(1);
}
else
{
PlayerFlag[1] = false;
}
if (PlayerPos[1] >= 99)
{
Console.WriteLine("玩家{0}赢了玩家{1}",PlayerNames[1],PlayerNames[0]);
break;
}
}
Win();
Console.ReadKey();
}
//两个玩家的标记
public static bool[] PlayerFlag = new bool[2];
//声明一个静态数组来存储A和B的坐标
public static int[] PlayerPos = new int[2];
//静态字段模拟全局变量
public static int[] maps = new int[100];
//存储两个玩家的姓名
public static string[] PlayerNames = new string[2];
public static void Win()
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("◤ ↑ ◥");
Console.WriteLine("← 胜利 →");
Console.WriteLine("◣ ↓ ◢");
Console.ResetColor();
Console.ReadKey(true);
}
/// <summary>
/// 当玩家坐标发生改变调用
/// </summary>
public static void ChangePos()
{
if (PlayerPos[0] < 0)
{
PlayerPos[0] = 0;
}
if (PlayerPos[0] > 99)
{
PlayerPos[0] = 99;
}
if (PlayerPos[1] < 0)
{
PlayerPos[1] = 0;
}
if (PlayerPos[1] > 99)
{
PlayerPos[1] = 99;
}
}
/// <summary>
///玩游戏
/// </summary>
public static void PlayGame(int playerNumber)
{
//获取一个随机数
Random r = new Random();
int rNumber = r.Next(1, 7);
Console.WriteLine("{0}按任意键掷骰子", PlayerNames[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}掷出了{1}", PlayerNames[playerNumber], rNumber);
PlayerPos[playerNumber] += rNumber;
ChangePos();
Console.ReadKey(true);
Console.WriteLine("{0}按任意键开始行动", PlayerNames[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}行动完了", PlayerNames[playerNumber]);
Console.ReadKey();
if (PlayerPos[playerNumber] == PlayerPos[1 - playerNumber])
{
Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退6格!", PlayerNames[playerNumber], PlayerNames[1 - playerNumber], PlayerNames[1 - playerNumber]);
PlayerPos[1 - playerNumber] -= 6;
ChangePos();
Console.ReadKey(true);
}
else//踩到了关卡
{
//玩家坐标
switch (maps[PlayerPos[playerNumber]])
{
case 0:
Console.WriteLine("玩家{0}踩到了方块,安全!", PlayerNames[playerNumber]);
Console.ReadKey(true);
break;
case 1:
Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择1--交换位置 2--轰炸对方", PlayerNames[playerNumber]);
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
Console.WriteLine("玩家{0}选择和玩家{1}交换位置", PlayerNames[playerNumber], PlayerNames[1 - playerNumber]);
Console.ReadKey(true);
int temp = PlayerPos[playerNumber];
PlayerPos[playerNumber] = PlayerPos[1 - playerNumber];
PlayerPos[1 - playerNumber] = temp;
Console.WriteLine("交换成功!!!按任意键进行游戏!");
break;
}
else if (input == "2")
{
Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}退6格", PlayerNames[playerNumber], PlayerNames[1 - playerNumber], PlayerNames[1 - playerNumber]);
Console.ReadKey(true);
PlayerPos[1 - playerNumber] -= 6;
ChangePos();
Console.WriteLine("玩家{0}退了6格", PlayerNames[1 - playerNumber]);
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("只能输入1或者2 1--交换位置 2--轰炸对方");
input = Console.ReadLine();
}
}
break;
case 2:
Console.WriteLine("玩家{0}踩到了地雷,退6格", PlayerNames[playerNumber]);
Console.ReadKey(true);
PlayerPos[playerNumber] -= 6;
ChangePos();
break;
case 3:
Console.WriteLine("玩家{0}c踩到了暂停,暂停一回合", PlayerNames[playerNumber]);
PlayerFlag[playerNumber] = true;
Console.ReadKey(true);
break;
case 4:
Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", PlayerNames[playerNumber]);
PlayerPos[playerNumber] += 10;
ChangePos();
Console.ReadKey(true);
break;
}
}
ChangePos();
//清屏,重新绘制,更新玩家地图
Console.Clear();
DrawMap();
}
/// <summary>
/// 画地图
/// </summary>
public static void DrawMap()
{
Console.WriteLine("图例:幸运轮盘:¤ 地雷:☆ 暂停:△ 时空隧道:▓▓ ");
#region 第一横行
for (int i = 0; i < 30; i++)
{
string draw = DrawStringMap(i);
Console.Write(draw);
}
Console.WriteLine();
#endregion
#region 第一竖行
for (int i = 30; i < 35; i++)
{
for (int j = 0; j < 29; j++)
{
Console.Write(" ");
}
string draw = DrawStringMap(i);
Console.Write(draw);
Console.WriteLine();
}
#endregion
#region 第二个横行
for (int i = 64; i >= 35; i--)
{
string map = DrawStringMap(i);
Console.Write(map);
}
//画完换行
Console.WriteLine();
#endregion
#region 二哥竖行
for (int i = 65; i < 70; i++)
{
string map = DrawStringMap(i);
Console.WriteLine(map);
}
#endregion
#region 第三横行
for (int i = 70; i < 100; i++)
{
string map = DrawStringMap(i);
Console.Write(map);
}
#endregion
//画完最后一行 换行
Console.WriteLine();
}
/// <summary>
/// 从画地图的方法中抽象出的一个方法
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static string DrawStringMap(int i)
{
string str = "";
#region 画图
//如果玩家A和玩家B的坐标相同,则画一个尖括号
if (PlayerPos[0] == PlayerPos[1] && PlayerPos[1] == i)
{
str = "<>";
}
else if (PlayerPos[0] == i)
{
str = "A";
}
else if (PlayerPos[1] == i)
{
str = "B";
}
else
{
switch (maps[i])
{
case 0:
Console.ForegroundColor = ConsoleColor.Yellow;
str = "□";
break;
case 1:
Console.ForegroundColor = ConsoleColor.Green;
str = "¤";
break;
case 2:
Console.ForegroundColor = ConsoleColor.Red;
str = "☆";
break;
case 3:
Console.ForegroundColor = ConsoleColor.Blue;
str = "△";
break;
case 4:
Console.ForegroundColor = ConsoleColor.DarkCyan;
str = "▓▓";
break;
}
}
return str;
#endregion
}
/// <summary>
/// 初始化地图
/// </summary>
public static void InitialMap()
{
//幸运轮盘
int[] luckyturn = { 6, 23, 40, 55, 69, 83 };
for (int i = 0; i < luckyturn.Length; i++)
{
int index = luckyturn[i];
maps[index] = 1;
}
//地雷
int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };
for (int i = 0; i < landMine.Length; i++)
{
int index = landMine[i];
maps[index] = 2;
}
//暂停
int[] pause = { 9, 27, 60, 93 };
for (int i = 0; i < pause.Length; i++)
{
int index = pause[i];
maps[index] = 3;
}
//时空隧道
int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };
for (int i = 0; i < timeTunnel.Length; i++)
{
int index = timeTunnel[i];
maps[index] = 4;
}
}
/// <summary>
/// 游戏头
/// </summary>
public static void GameShow()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("███████████████████████████████████████████████████████");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("███████████████████████████████████████████████████████");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("███████████████████████████████████████████████████████");
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("████████████████████飞行棋的小游戏█████████████████████");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("███████████████████████████████████████████████████████");
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("███████████████████████████████████████████████████████");
}
08-20
03-25
1064
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交