1、打印游戏头
![这里写图片描述](https://img-blog.csdn.net/20171027165737257?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTQ2MzY0Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
using System
using System.Collections.Generic
using System.Linq
using System.Text
using System.Threading.Tasks
namespace ChuangzhiConsel
{
class Program
{
static void Main(string[] args)
{
GameShow()
Console.ReadKey()
}
public static void GameShow()
{
Console.ForegroundColor = ConsoleColor.DarkRed
Console.WriteLine("************************")
Console.ForegroundColor = ConsoleColor.DarkGreen
Console.WriteLine("************************")
Console.ForegroundColor = ConsoleColor.Cyan
Console.WriteLine("************************")
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine("*********飞行棋*********")
Console.ForegroundColor = ConsoleColor.Blue
Console.WriteLine("************************")
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("************************")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("************************")
}
}
}
2、初始化飞行棋地图
public static void InitialMap()
{
int[] luckTurn = { 6, 23, 40, 55, 69, 83 };
for (int i = 0; i < luckTurn.Length; i++)
{
Map[luckTurn[i]] = 1;
}
int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };
for (int i = 0; i < landMine.Length; i++)
{
Map[landMine[i]] = 2;
}
int[] pause = { 9, 27, 60, 93 };
for (int i = 0; i < pause.Length; i++)
{
Map[pause[i]] = 3;
}
int[] timeTunnel = { 20, 23, 63, 72, 88, 90 };
for (int i = 0; i < timeTunnel.Length; i++)
{
Map[timeTunnel[i]] = 4;
}
}
![这里写图片描述](https://img-blog.csdn.net/20171027221921337?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTQ2MzY0Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
public static void DrawMap()
{
#region #第一个横行
for (int i = 0; i < 30; i++)
{
Console.Write(DrawPos(i));
}
#endregion
#region#第一个竖行
Console.WriteLine();
for (int i = 30; i < 35; i++)
{
for (int j = 0; j < 29; j++)
{
Console.Write(" ");
}
Console.Write(DrawPos(i));
Console.WriteLine();
}
#endregion
#region #第二个横行
for (int i = 64; i > 34; i--)
{
Console.Write(DrawPos(i));
}
#endregion
#region #第二个竖行
Console.WriteLine();
for (int i = 65; i < 70; i++)
{
Console.WriteLine(DrawPos(i));
}
#endregion
#region #最后的横行
for (int i = 70; i < Map.Length; i++)
{
Console.Write(DrawPos(i));
}
#endregion
}
![这里写图片描述](https://img-blog.csdn.net/20171027221955040?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTQ2MzY0Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
3、输入AB玩家信息
#region #输入玩家姓名
Console.WriteLine("请输入玩家A的昵称:")
PlayerName[0] = Console.ReadLine()
while (PlayerName[0] == "")
{
Console.WriteLine("玩家A的昵称不能为空!!!请重新输入:")
PlayerName[0] = Console.ReadLine()
}
Console.WriteLine("请输入玩家B的昵称:")
PlayerName[1] = Console.ReadLine()
while (PlayerName[1] == ""||PlayerName[1]==PlayerName[0])
{
if (PlayerName[0] == PlayerName[1])
{
Console.WriteLine("B玩家不能与A玩家重名,请重新输入:")
PlayerName[1] = Console.ReadLine()
}
else
{
Console.WriteLine("B玩家不能为空,请重新输入:")
PlayerName[1] = Console.ReadLine()
}
}
#endregion
![这里写图片描述](https://img-blog.csdn.net/20171028153548379?/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTQ2MzY0Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
4、开始玩游戏
![这里写图片描述](https://img-blog.csdn.net/20171028224513502?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTQ2MzY0Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
public static void PlayGames(int playerNumber)
{
Random r = new Random();
int step = r.Next(1, 7);
Console.WriteLine("玩家【{0}】按任意键,掷骰子:", PlayerName[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("【{0}】投掷出了:{1}", PlayerName[playerNumber], step);
PlayerPos[playerNumber] += step;
Console.ReadKey(true);
OutofMap(playerNumber);
OutofMap(1 - playerNumber);
if (PlayerPos[0] == PlayerPos[1])
{
Console.WriteLine("【{0}】踩到了【{1}】,玩家【{2}】退六格...", PlayerName[playerNumber], PlayerName[1 - playerNumber], PlayerName[1 - playerNumber]);
PlayerPos[1 - playerNumber] -= 6;
Console.ReadKey(true);
}
else
{
switch (Map[PlayerPos[playerNumber]])
{
case 0: Console.WriteLine("踩到了方块。"); Console.ReadKey(true); break;
case 1: Console.WriteLine("踩到了幸运轮盘,选择:1、交换位置;2、轰炸,使对方退六格。");
#region #case1
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
int temp = PlayerPos[0];
PlayerPos[0] = PlayerPos[1];
PlayerPos[1] = temp;
break;
}
else if (input == "2")
{
PlayerPos[1 - playerNumber] -= 6;
if (PlayerPos[0] == PlayerPos[1])
{
PlayerPos[playerNumber] -= 6;
Console.WriteLine("踩到对方,对方退六格...");
Console.ReadKey(true);
}
break;
}
else
{
Console.WriteLine("请重新输入数字!选择:1、交换位置;2、轰炸,使对方退六格。");
input = Console.ReadLine();
}
}
break;
#endregion
case 2: Console.WriteLine("踩到了地雷,退六格。");
Console.ReadKey(true); PlayerPos[playerNumber] -= 6;
if (PlayerPos[0] == PlayerPos[1])
{
PlayerPos[1 - playerNumber] -= 6;
Console.WriteLine("踩到对方,对方退六格...");
Console.ReadKey(true);
}
break;
case 3: Console.WriteLine("踩到了暂停,暂停一回合。");
Pause_Falgs[playerNumber] = true;
Console.ReadKey(true);
break;
case 4: Console.WriteLine("踩到了时空隧道,前进6格。"); Console.ReadKey(true); PlayerPos[playerNumber] += 6;
if (PlayerPos[0] == PlayerPos[1])
{
PlayerPos[1 - playerNumber] -= 6;
Console.WriteLine("踩到对方,对方退六格...");
Console.ReadKey(true);
}
break;
}
}
Console.Clear();
OutofMap(playerNumber);
OutofMap(1 - playerNumber);
DrawMap();
}
5、代码下载
点击下载完整代码的地址连接
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ChuangzhiConsel
{
class Program
{
public static int[] Map = new int[100];
public static int[] PlayerPos = new int[2];
public static string[] PlayerName = new string[2];
public static bool[] Pause_Falgs = new bool[2];
static void Main(string[] args)
{
GameShow();
#region #输入玩家姓名
Console.WriteLine("请输入玩家A的昵称:");
PlayerName[0] = Console.ReadLine();
while (PlayerName[0] == "")
{
Console.WriteLine("玩家A的昵称不能为空!!!请重新输入:");
PlayerName[0] = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的昵称:");
PlayerName[1] = Console.ReadLine();
while (PlayerName[1] == "" || PlayerName[1] == PlayerName[0])
{
if (PlayerName[0] == PlayerName[1])
{
Console.WriteLine("B玩家不能与A玩家重名,请重新输入:");
PlayerName[1] = Console.ReadLine();
}
else
{
Console.WriteLine("B玩家不能为空,请重新输入:");
PlayerName[1] = Console.ReadLine();
}
}
#endregion
Console.Clear();
GameShow();
Console.WriteLine("{0}的玩家用A表示,{1}的玩家用B表示。", PlayerName[0], PlayerName[1]);
InitialMap();
DrawMap();
#region #游戏开始
while (PlayerPos[0] < (Map.Length - 1) && PlayerPos[1] < (Map.Length - 1))
{
if (Pause_Falgs[0] == false)
{
PlayGames(0);
}
else
{
Pause_Falgs[0] = false;
}
if (PlayerPos[0] >= 99)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("恭喜玩家【{0}】赢得了比赛!!!", PlayerName[0]);
Console.ReadKey(true);
break;
}
if (Pause_Falgs[1] == false)
{
PlayGames(1);
}
else
{
Pause_Falgs[1] = false;
}
if (PlayerPos[1] >= 99)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("恭喜玩家【{0}】赢得了比赛!!!", PlayerName[1]);
Console.ReadKey(true);
break;
}
}
#endregion
Win();
Console.ReadKey();
}
public static void GameShow()
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("************************");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("************************");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("************************");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("*********飞行棋*********");
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("************************");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("************************");
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("************************");
}
public static void InitialMap()
{
int[] luckTurn = { 4, 23, 40, 55, 68, 83 };
for (int i = 0; i < luckTurn.Length; i++)
{
Map[luckTurn[i]] = 1;
}
int[] landMine = { 2, 13, 17, 33, 38, 50, 64, 80, 94 };
for (int i = 0; i < landMine.Length; i++)
{
Map[landMine[i]] = 2;
}
int[] pause = {7, 9, 27, 35,42,60, 93 };
for (int i = 0; i < pause.Length; i++)
{
Map[pause[i]] = 3;
}
int[] timeTunnel = { 20, 23, 63, 72, 88, 90 };
for (int i = 0; i < timeTunnel.Length; i++)
{
Map[timeTunnel[i]] = 4;
}
}
public static void DrawMap()
{
Console.ForegroundColor = ConsoleColor.Gray; Console.Write("图例:");
Console.ForegroundColor = ConsoleColor.White; Console.Write("正常:□ ");
Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("幸运轮盘:◎ ");
Console.ForegroundColor = ConsoleColor.Red; Console.Write("地雷:★ ");
Console.ForegroundColor = ConsoleColor.Blue; Console.Write("暂停:▲ ");
Console.ForegroundColor = ConsoleColor.Green; Console.Write("时空隧道:◆");
Console.WriteLine();
#region #第一个横行
for (int i = 0; i < 30; i++)
{
Console.Write(DrawPos(i));
}
#endregion
#region#第一个竖行
Console.WriteLine();
for (int i = 30; i < 35; i++)
{
for (int j = 0; j < 29; j++)
{
Console.Write(" ");
}
Console.Write(DrawPos(i));
Console.WriteLine();
}
#endregion
#region #第二个横行
for (int i = 64; i > 34; i--)
{
Console.Write(DrawPos(i));
}
#endregion
#region #第二个竖行
Console.WriteLine();
for (int i = 65; i < 70; i++)
{
Console.WriteLine(DrawPos(i));
}
#endregion
#region #最后的横行
for (int i = 70; i < Map.Length; i++)
{
Console.Write(DrawPos(i));
}
Console.WriteLine();
#endregion
}
public static string DrawPos(int i)
{
string str = "";
#region//AB坐标相同时,且在地图范围内
if (PlayerPos[0] == PlayerPos[1] && PlayerPos[1] == i)
{
Console.ForegroundColor = ConsoleColor.Magenta;
str = ">>";
}
else if (PlayerPos[0] == i)
{
Console.ForegroundColor = ConsoleColor.Magenta;
str = "A";
}
else if (PlayerPos[1] == i)
{
Console.ForegroundColor = ConsoleColor.Magenta;
str = "B";
}
else
{
switch (Map[i])
{
case 0: Console.ForegroundColor = ConsoleColor.White; str = "□"; break;
case 1: Console.ForegroundColor = ConsoleColor.Yellow; str = "◎"; break;
case 2: Console.ForegroundColor = ConsoleColor.Red; str = "★"; break;
case 3: Console.ForegroundColor = ConsoleColor.Blue; str = "▲"; break;
case 4: Console.ForegroundColor = ConsoleColor.Green; str = "◆"; break;
}
}
return str;
#endregion
}
public static void PlayGames(int playerNumber)
{
Random r = new Random();
int step = r.Next(1, 7);
Console.WriteLine("玩家【{0}】按任意键,掷骰子:", PlayerName[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("【{0}】投掷出了:{1}", PlayerName[playerNumber], step);
PlayerPos[playerNumber] += step;
Console.ReadKey(true);
OutofMap(playerNumber);
OutofMap(1 - playerNumber);
if (PlayerPos[0] == PlayerPos[1])
{
Console.WriteLine("【{0}】踩到了【{1}】,玩家【{2}】退六格...", PlayerName[playerNumber], PlayerName[1 - playerNumber], PlayerName[1 - playerNumber]);
PlayerPos[1 - playerNumber] -= 6;
Console.ReadKey(true);
}
else
{
switch (Map[PlayerPos[playerNumber]])
{
case 0: Console.WriteLine("踩到了方块。"); Console.ReadKey(true); break;
case 1: Console.WriteLine("踩到了幸运轮盘,选择:1、交换位置;2、轰炸,使对方退六格。");
#region #case1
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
int temp = PlayerPos[0];
PlayerPos[0] = PlayerPos[1];
PlayerPos[1] = temp;
break;
}
else if (input == "2")
{
PlayerPos[1 - playerNumber] -= 6;
if (PlayerPos[0] == PlayerPos[1])
{
PlayerPos[playerNumber] -= 6;
Console.WriteLine("踩到对方,对方退六格...");
Console.ReadKey(true);
}
break;
}
else
{
Console.WriteLine("请重新输入数字!选择:1、交换位置;2、轰炸,使对方退六格。");
input = Console.ReadLine();
}
}
break;
#endregion
case 2: Console.WriteLine("踩到了地雷,退六格。");
Console.ReadKey(true); PlayerPos[playerNumber] -= 6;
if (PlayerPos[0] == PlayerPos[1])
{
PlayerPos[1 - playerNumber] -= 6;
Console.WriteLine("踩到对方,对方退六格...");
Console.ReadKey(true);
}
break;
case 3: Console.WriteLine("踩到了暂停,暂停一回合。");
Pause_Falgs[playerNumber] = true;
Console.ReadKey(true);
break;
case 4: Console.WriteLine("踩到了时空隧道,前进6格。"); Console.ReadKey(true); PlayerPos[playerNumber] += 6;
if (PlayerPos[0] == PlayerPos[1])
{
PlayerPos[1 - playerNumber] -= 6;
Console.WriteLine("踩到对方,对方退六格...");
Console.ReadKey(true);
}
break;
}
}
Console.Clear();
OutofMap(playerNumber);
OutofMap(1 - playerNumber);
DrawMap();
}
public static void OutofMap(int playerNumber)
{
if (PlayerPos[playerNumber] < 0)
{
PlayerPos[playerNumber] = 0;
}
else if (PlayerPos[playerNumber] >= 99)
{
PlayerPos[playerNumber] = 99;
}
}
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(" ■ ■ ■ ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■ ■ ● ■ ");
Console.WriteLine(" ■ ■■ ■■■■■■ ■ ● ●");
Console.ResetColor();
}
}
}