文档库 最新最全的文档下载
当前位置:文档库 › 小游戏飞行棋 C#代码

小游戏飞行棋 C#代码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace _6._12飞行棋

{

class Program

{

static int[] PlaysPos = new int[2]; //玩家坐标

static bool[] flage = new bool[2];

static int[] MapsPos = new int[100]; //地图坐标0表示普通,显示给用户就是□

static void Main(string[] args)

{

GameTitle();

string[]strs= Action();

Console.Clear();

Console.WriteLine("玩家{0}用A表示",strs[0]);

Console.WriteLine("玩家{0}用B表示", strs[1]);

InitialMap();

Maps();

#region只要没有人赢,就让玩家继续玩

while (PlaysPos[0] <99 && PlaysPos[1] <99)

{

if (flage[0] != true)

{

PlayGame(strs, 0);

}

else

{

flage[0] = false;

}

if (flage[1] != true)

{

PlayGame(strs, 1);

}

else

{

flage[1] = false;

}

}

#endregion

if (PlaysPos[0] == 99)

{

Console.WriteLine("玩家{0}无耻的赢了玩家{1}", strs[0], strs[1]);

}

else if (PlaysPos[1] == 99)

{

Console.WriteLine("玩家{0}无耻的赢了玩家{1}", strs[1], strs[0]);

}

Win();

Console.ReadKey();

}

///

///画游戏头

///

public static void GameTitle()

{

Console.ForegroundColor = ConsoleColor.Blue;

Console.WriteLine("********************************");

Console.ForegroundColor = ConsoleColor.DarkYellow;

Console.WriteLine("********************************");

Console.ForegroundColor = ConsoleColor.Green;

Console.WriteLine("*******--001版飞行棋游戏--******");

Console.ForegroundColor = ConsoleColor.DarkRed;

Console.WriteLine("********************************");

Console.ForegroundColor = ConsoleColor.Yellow;

Console.WriteLine("********************************");

}

///

///初始化地图

///

public static void InitialMap()

{

int[] lukyturn = { 8, 13, 50, 62, 73, 87 };//幸运轮盘◎1

int[] landMine = { 4, 22, 56, 78, 82, 90 };//地雷☆2

int[] pause = { 18, 32, 55, 79 };//暂停▲ 3

int[] timeTunnel = { 28, 36, 71, 88, 97 };//时光隧道卐4

for (int i = 0; i < lukyturn.Length; i++)

{

MapsPos[lukyturn[i]] = 1;

}

for (int i = 0; i < landMine.Length; i++)

{

MapsPos[landMine[i]] = 2;

}

for (int i = 0; i < pause.Length; i++)

{

MapsPos[pause[i]] = 3;

}

for (int i = 0; i < timeTunnel.Length; i++)

{

MapsPos[timeTunnel[i]] = 4;

}

}

///

///画地图

///

public static void Maps()

{

Console.ForegroundColor = ConsoleColor.Green;

Console.WriteLine("图例:幸运轮盘◎地雷:☆暂停:▲ 时空隧道卐");

//画第一横行

for (int i = 0; i < 30; i++)

{

String str=JudgeType(i);

Console.Write(str);

} //for结尾

//第一横行结束后要换行

Console.WriteLine();

//画第一竖行

for (int i = 30; i < 35; i++)

{

String str = JudgeType(i);

Console.WriteLine("

" + str);

}

//画第二横行

for (int i = 64; i>=35; i--)

{

String str = JudgeType(i);

Console.Write(str);

}

Console.WriteLine();

//画第二竖行

for (int i = 65; i < 70;i++)

{

String str = JudgeType(i);

Console.WriteLine(str);

}

//画三横行

for (int i = 70; i<=99; i++)

{

String str = JudgeType(i);

Console.Write(str);

}

Console.WriteLine();

}

///

///判断属于哪个种类

///

///

///

public static string JudgeType(int i)

{

String str = "";

//玩家A,B坐标相同,并且都在第一横行上

if (PlaysPos[0] == PlaysPos[1] && PlaysPos[0] == i)

{

str = "<>";

}

else if (PlaysPos[0] == i)

{

str = "A";

}

else if (PlaysPos[1] == i)

{

str = "B";

}

else

{

int type = MapsPos[i];

switch (type)

{

case 0: str = "□";

break;

case 1: str = "◎";

break;

case 2: str = "☆";

break;

case 3: str = "▲";

break;

case 4: str = "卐";

break;

}

}

return str;

}

///

///用户输入玩家名称,准备开始游戏

///

public static string[] Action()

{

Console.WriteLine("请输入玩家A的姓名");

String str= Console.ReadLine();

while (str == "")

{

Console.WriteLine("玩家A的姓名不能为空,请输入名称");

str = Console.ReadLine();

}

Console.WriteLine("请输入玩家B的姓名");

String strB = Console.ReadLine();

while (strB == ""||strB==str)

{

if (strB == "")

{

Console.WriteLine("玩家B的姓名不能为空,请输入名称");

}

else

{

Console.WriteLine("玩家A与B不能够重名,请重新输入");

}

strB = Console.ReadLine();

}

String []strs={str,strB} ;

return strs;

}

///

///游戏的规则设置

///

///

///

public static void PlayGame(string[] strs,int playnumber)

{

Console.WriteLine("玩家{0}按任意键开始掷骰子",

strs[playnumber]);

Console.ReadKey(true);

Random ran = new Random();

int r= ran.Next(1,7);

Console.WriteLine("玩家{0}掷出了{1}", strs[playnumber], r);

Console.WriteLine("玩家{0}按任意键开始执行", strs[playnumber]);

Console.ReadKey(true);

PlaysPos[playnumber] += r;

#region判断游戏是否需要结束以及不能让玩家出界

if (PlaysPos[0] < 0)

{

PlaysPos[0] = 0;

}

if (PlaysPos[1] < 0)

{

PlaysPos[1] = 0;

}

if (PlaysPos[0] >= 99)

{

PlaysPos[0] = 99;

}

if (PlaysPos[1] >= 99)

{

PlaysPos[1] = 99;

}

#endregion

String results="";

#region判断踩到了什么

switch (MapsPos[PlaysPos[playnumber]])

{

case 0: results = "踩到了空格,没有任何事件发生";

break;

case 1:

Console.WriteLine("请输入1或2,1--与对方交换位置2---对方后退10格");

#region踩到幸运轮盘

String option = Console.ReadLine();

while (true)

{

if (option == "1")

{

int temp = PlaysPos[playnumber];

PlaysPos[playnumber] = PlaysPos[1 -playnumber];

PlaysPos[1 -playnumber] = temp;

break;

}

else if (option == "2")

{

PlaysPos[1 - playnumber] -= 10;

break;

}

else

{

Console.WriteLine("输入不正确,请输入1或2,1--与对方交换位置2---对方后退10格");

option = Console.ReadLine();

}

}

#endregion

break;

case 2: results = "踩到了地雷,后退6格";

PlaysPos[playnumber] -= 6;

break;

case 3: results = "踩到了暂停";

flage[playnumber] = true;

break;

case 4: results = "踩到了时光隧道,前进10格";

PlaysPos[playnumber] += 10;

break;

}

#endregion

Console.WriteLine(results);

Console.ReadKey(true);

Console.Clear();

Maps();

}

///

///游戏结束,一方胜利

///

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();

Console.ReadKey(true);

}

}

}

相关文档