c # console to play flight chess game

using System;

Game namespace
{
class Program
{
// static field simulation using a global variable
int [] Maps = new new int [100] public static;
// declare an array to store the players A and B
public static int [] = PlayerPos new new int [2] ;
// store player name
public static String [] = PlayNames new new String [2];
// two players to mark
static bool [] Flags = new bool [2]; // default is false
static void Main (String [] args)
{
Gameshow ();
#region input player name
Console.WriteLine ( "Please enter the name of the player a");
PlayNames [0] = Console.ReadLine ();
the while (PlayNames [0] == "")
{
Console .WriteLine ( "can not be empty, please re-enter");
PlayNames [0] = Console.ReadLine ();
}
Console.WriteLine ( "Please enter the name of the player B");
PlayNames [. 1] = Console.ReadLine ();
the while (PlayNames [. 1] == PlayNames [0] || PlayNames [. 1] == "")
{
IF (PlayNames [. 1] == "")
{
Console.WriteLine ( "can not be empty, please re-enter");
PlayNames [. 1] = Console.ReadLine ();
}
the else
{
Console.WriteLine ( "a player can not be the same as the name, please re-enter");
PlayNames [. 1] = Console.ReadLine ();
}
}
#endregion
Console.Clear ();
Gameshow ();
Console.WriteLine ( "{0} represented by a soldier", PlayNames [0]);
Console.WriteLine ( "{0} of soldier with A ", PlayNames [1]);
InitailMap ();
drawmap ();
// AB at the same time allowing the player to start playing the game and ends
while (PlayerPos [0] <99 && PlayerPos [1] <99)
{
if (Flags[0]== false)
{
The PlayGame (0);
}
the else
{
the Flags [0] = to false;
}
IF (PlayerPos [0]> = 99)
{
Console.WriteLine ( "player win {0} players {1}", PlayNames [0 ] , PlayNames [. 1]); BREAK;
}
IF (the Flags [. 1] == to false)
{
the PlayGame (. 1);
}
the else
{
the Flags [. 1] = to false;
}
IF (PlayerPos [. 1]> = 99)
{
Console. WriteLine ( "player win {0}}. 1 players {", PlayNames [. 1], PlayNames [0]); BREAK;
}
}
win ();
the Console.ReadKey ();
}
/// <Summary>
// / game header
/// </ Summary>
public static void Gameshow ()
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("**********************");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("**********************");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("*****飞行棋***********");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("**********************");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("**********************");
}

/// <summary>
/// 初始化地图
/// </summary>
public static void InitailMap()
{
int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘◎
for (int i = 0; i < luckyturn.Length; i++)
{
Maps[luckyturn[i]] = 1;
}
int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷☆
for (int i = 0; i < landMine.Length; i++)
{
Maps[landMine[i]] = 2;
}
int[] pause = { 9, 27, 60, 93,4,2,3,7,8 };//暂停▲
for (int i = 0; i < pause.Length; i++)
{
Maps[pause[i]] = 3;
}
int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道卐
for (int i = 0; i < timeTunnel.Length; i++)
{
Maps[timeTunnel[i]] = 4;
}
}

static void drawmap public ()
{
Console.WriteLine ( "Legend: wheel of fortune: ◎ mines: ☆ Pause: ▲ time tunnel: swastika");
#region a first transverse
for (int i = 0; i <30; i ++)
{
// If player a player B with the same coordinates, and in this map, a draw angle bracket
Console.Write (DrawStringMap (I));
}
#endregion
// next line drawn vertically
Console.WriteLine ();
The first vertical row #region
for (int I = 30; I <35; I ++)
{
for (int J = 0; J <= 28; J ++)
{
Console.Write ( "");
}
Console.Write (DrawStringMap ( I));
Console.WriteLine ();
}
#endregion

a second transverse #region
for (int I = 64; I> = 35; i--)
{
Console.Write (DrawStringMap (I));
}
#endregion
// next line drawn vertically
Console.WriteLine ();
#region The second vertical row
for (int I = 65; I <= 69; I ++)
{
Console.WriteLine (DrawStringMap (I));
}
#endregion

#region 第三横行
for (int i = 70; i <= 99; i++)
{
Console.Write(DrawStringMap(i));
}

#endregion
Console.WriteLine ();
}
/// <Summary>
a /// method drawing abstract extracted
/// </ Summary>
/// <param name = "I"> </ param>
// / <Returns> </ Returns>
public static String DrawStringMap (I int)
{
String STR = "";
// if player a player B with the coordinates of the same, and in this map, a draw angle brackets
if (PlayerPos [ 0] == PlayerPos [. 1] && PlayerPos [0] == I)
{
STR = "<>";
}
the else IF (PlayerPos [0] == I)
{
STR = "A";
}
the else IF (PlayerPos [ . 1] == I)
{
STR = "B";
}
the else
{
Switch (Maps [I])
{
case 0: Console.ForegroundColor = ConsoleColor.Green; str = "□"; break;
case 1: Console.ForegroundColor = ConsoleColor.Blue; str = "◎"; break;
case 2: Console.ForegroundColor = ConsoleColor.Yellow; str = "☆"; break;
case 3: Console.ForegroundColor = ConsoleColor.Magenta; str = "▲"; break;
case 4: Console.ForegroundColor = ConsoleColor.Green; str = "卐"; break;
}
}
return str;
}
/// <summary>
/// 玩游戏
/// </summary>
/// <param name="playNumber"></param>
public static void PlayGame(int playNumber)
{
Random r = new Random();
int rNumber = r.Next(1, 7);
Console.WriteLine ( "{0} Press any key to start dice", PlayNames [playNumber]);
The Console.ReadKey (to true);
Console.WriteLine ( "{0}}. 1 threw {", PlayNames [playNumber], rnumber);
PlayerPos [playNumber] + = rnumber;
the Console.ReadKey (to true);
Console.WriteLine ( "{0} press any key to start operation", PlayNames [playNumber]);
the Console.ReadKey (to true);
Console.WriteLine ( "{0} action over", PlayNames [playNumber]);
the Console.ReadKey (to true);
/ / player a and player B is possible to block the stepped wheel of fortune mines pause time tunnel
IF (PlayerPos [playNumber] == PlayerPos [1 - playNumber])
{
Console.WriteLine ( "stepped {0} and {1} {1 } grid 6 back ", PlayNames [playNumber], PlayNames [. 1 - playNumber], PlayNames [. 1 - playNumber]);
PlayerPos [playNumber] - = 6;
the Console.ReadKey (to true);
}
else
{
switch (Maps[PlayerPos[playNumber]])
{
case 0: Console.WriteLine ( "{0 } stepped block game is continued", PlayNames [playNumber]); the Console.ReadKey (to true); BREAK;
Case. 1:
Console.WriteLine ( "{0} stepped wheel of fortune, select 1-- 2-- bombing other switching position ", PlayNames [playNumber]);
String INPUT = Console.ReadLine ();
the while (to true)
{
IF (INPUT ==". 1 ")
{
Console.WriteLine (" { 0} and {1} exchanging position ", PlayNames [playNumber], PlayNames [1 - playNumber]);
the Console.ReadKey (to true);
int PlayerPos TEMP = [playNumber];
PlayerPos [playNumber] PlayerPos = [1 - playNumber];
PlayerPos [. 1 - playNumber] = TEMP;
Console.WriteLine ( "press any key exchange is completed continue the game!!");
the Console.ReadKey (to true);
BREAK;
}
the else IF (INPUT == "2")
{
Console.WriteLine("{0}轰炸{1} 使{2}退6格", PlayNames[playNumber], PlayNames[1 - playNumber],PlayNames[1-playNumber]);

The Console.ReadKey (to true);
PlayerPos [-playNumber. 1] - = 6;
ChangePos ();
Console.WriteLine ( "{0} grid 6 back", PlayNames [playNumber]);
the Console.ReadKey (to true);
BREAK;
}
the else
{
Console.WriteLine ( "input 1 can exchange position 2-- 21-- or other bombing");
iNPUT = Console.ReadLine ();
}

}
BREAK;
Case 2: Console.WriteLine ( "{0} 6 cells stepped back mines", PlayNames [playNumber]); the Console.ReadKey (to true); PlayerPos [playNumber] - = 6; ChangePos (); BREAK;
Case 3: Console.WriteLine ( "{0} a round stepped pause", PlayNames [playNumber]); the Flags [playNumber] = to true; the Console.ReadKey (to true); BREAK;
Case. 4: Console.WriteLine ( "{0 } stepped forward time tunnel grid 10 ", PlayNames [playNumber]); PlayerPos [playNumber] + = 10; the Console.ReadKey (to true); ChangePos (); BREAK;
}
}
ChangePos ();
Console.Clear ();
drawmap ; ()
}
used to prevent the outer array AB ran mobile transmission coordinate //
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 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();
}
}
}

Guess you like

Origin www.cnblogs.com/Angdybo/p/11901426.html