当前位置:网站首页>Console C # flying chess small project
Console C # flying chess small project
2022-07-21 05:22:00 【hjl011006】
Code display
Catalog
using System;
namespace Aircraft project
{
class Program
{
// Simulate global variables with static fields
public static int[] Maps = new int[100];
// Declare a static array to store players A And players B Coordinates of
public static int[] PlayerPos = new int[2];
// Declare an array for storing player names
static string[] PlayerNames = new string[2];
// Judge whether the player stepped on the pause round
public static bool[] Flags = new bool[2];// The default is false
static void Main(string[] args)
{
Program.GameShow();
Console.WriteLine(" Please enter the player A The name of ");
PlayerNames[0] = Console.ReadLine();
while (PlayerNames[0] == "")
{
Console.WriteLine(" Player name cannot be empty , Please re-enter ");
PlayerNames[0] = Console.ReadLine();
}
Console.WriteLine(" Please enter the player B The name of ");
PlayerNames[1] = Console.ReadLine();
while (true)
{
if (PlayerNames[1] == "")
{
Console.WriteLine(" Player name cannot be empty , Please re-enter ");
PlayerNames[1] = Console.ReadLine();
}
else if (PlayerNames[1] == PlayerNames[0])
{
Console.WriteLine(" The player B With players A Your name cannot be the same , Please re-enter ");
PlayerNames[1] = Console.ReadLine();
}
else
{
break;
}
}
// After entering the name, clear
Console.Clear();
Program.GameShow();
Console.WriteLine("{0} It's used by our soldiers A Express \n{1} It's used by our soldiers B Express ", PlayerNames[0], PlayerNames[1]);
Program.IntailMap();
Program.ShowMap();
// When a player A And players B Don't stop playing at the end
while (PlayerPos[0] < 99 && PlayerPos[1] < 99)
{
if (Flags[0] == false)
{
PlayGame(0);
}
else
{
Flags[0] = false;
}
if (PlayerPos[0] >= 99)
{
Console.WriteLine("{0} The player won {1} The player , Congratulations !!!", PlayerNames[0], PlayerNames[1]);
break;
}
if (Flags[1] == false)
{
PlayGame(1);
}
else
{
Flags[1] = false;
}
if (PlayerPos[1] >= 99)
{
Console.WriteLine("{0} The player won {1} The player , Congratulations !!!", PlayerNames[1], PlayerNames[0]);
break;
}
}//while
}
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("****** Flying chess project ******");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("**********************");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("**********************");
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("**********************");
Console.ForegroundColor = ConsoleColor.DarkGreen;
}
public static void IntailMap()
{
int[] luckturn = { 6, 23, 40, 55, 69, 83 };// Wheel disc
for (int i = 0; i < luckturn.Length; i++)
{
Maps[luckturn[i]] = 1;
}
int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };// mine
for (int i = 0; i < landMine.Length; i++)
{
Maps[landMine[i]] = 2;
}
int[] pause = { 9, 27, 60, 93 };// Pause
for (int i = 0; i < pause.Length; i++)
{
Maps[pause[i]] = 3;
}
int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };// Time and space tunnel
for (int i = 0; i < timeTunnel.Length; i++)
{
Maps[timeTunnel[i]] = 4;
}
}
public static void ShowMap()
{
Console.WriteLine(" legend :\n The roulette of fortune :◎\t mine :*\t Pause :▲\t Time and space tunnel : On the wall ");
// The first is horizontal
for (int i = 0; i < 30; i++)
{
DrawstringMap(i);
}
Console.WriteLine();
// The first vertical line
for (int i = 30; i < 35; i++)
{
for (int j = 0; j < 29; j++)
{
Console.ForegroundColor = ConsoleColor.Black;
Console.Write("**");
}
DrawstringMap(i);
Console.WriteLine();
}
// Second, horizontal
for (int i = 64; i >= 35; i--)
{
DrawstringMap(i);
}
Console.WriteLine();
// Second vertical line
for (int i = 65; i < 70; i++)
{
DrawstringMap(i);
Console.WriteLine();
}
// Third, horizontal
for (int i = 70; i < 100; i++)
{
DrawstringMap(i);
}
Console.WriteLine();
static void DrawstringMap(int i)
{
// If the player A and B The coordinates are the same , draw <>
if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write("<>");
}
else if (PlayerPos[0] == i)
{
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.Write("A");
}
else if (PlayerPos[1] == i)
{
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.Write("B");
}
else
{
switch (Maps[i])
{
case 0:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("□");
break;
case 1:
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("◎");
break;
case 2:
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("*");
break;
case 3:
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("▲");
break;
case 4:
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(" On the wall ");
break;
}
}
}
}
public static void PlayGame(int playerNumber)
{
Random r = new Random();
int rnumber = r.Next(1, 7);
Console.WriteLine("{0} Press any key to roll the dice ", PlayerNames[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("{0} Throw out {1}", PlayerNames[playerNumber], rnumber);
PlayerPos[playerNumber] += rnumber;
ChangePos();
Console.ReadKey(true);
Console.WriteLine("{0} Press any key to start ", PlayerNames[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("{0} End of action ", PlayerNames[playerNumber]);
Console.ReadKey(true);
if (PlayerPos[playerNumber] == PlayerPos[1 - playerNumber])
{
Console.WriteLine(" The player {0} Step on the player {1}, The player {1} refund 6 grid ", PlayerNames[playerNumber], PlayerNames[1 - playerNumber]);
PlayerPos[1 - playerNumber] -= 6;
ChangePos();
Console.ReadKey(true);
}
else
{
switch (Maps[PlayerPos[playerNumber]])
{
case 0:
Console.WriteLine("{0} Step on the square , Nothing happened ", PlayerNames[playerNumber]);
Console.ReadKey(true);
break;
case 1:
Console.WriteLine("{0} Stepping on the wheel of fortune ", PlayerNames[playerNumber]);
Console.WriteLine(" Please select 1--- Swap places ,2--- Bomb each other ");
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
Console.WriteLine("{0} Choice and {1} Swap places ", PlayerNames[playerNumber], PlayerNames[1 - playerNumber]);
Console.ReadKey(true);
int temp = PlayerPos[playerNumber];
PlayerPos[playerNumber] = PlayerPos[1 - playerNumber];
PlayerPos[1 - playerNumber] = temp;
ChangePos();
Console.WriteLine(" Exchange complete !!! Please press any key to continue !!!");
Console.ReadKey(true);
break;
}
else if (input == "2")
{
Console.WriteLine(" The player {0} Choose bombing players {1}, The player {1} refund 6 grid !!!", PlayerNames[playerNumber], PlayerNames[1 - playerNumber]);
Console.ReadKey(true);
PlayerPos[1 - playerNumber] -= 6;
ChangePos();
Console.WriteLine(" The player {0} retired 6 grid ", PlayerNames[1 - playerNumber]);
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine(" Input only 1 perhaps 2,1--- Swap places ,2--- Bomb each other !!!");
input = Console.ReadLine();
}
}
break;
case 2:
Console.WriteLine(" The player {0} Stepped on a mine , Need to return 6 grid ", PlayerNames[playerNumber]);
Console.ReadKey(true);
PlayerPos[playerNumber] -= 6;
ChangePos();
Console.WriteLine(" The player {0} retired 6 grid ", PlayerNames[playerNumber]);
break;
case 3:
Console.WriteLine(" The player {0} Stepped on the pause , Pause a round ", PlayerNames[playerNumber]);
Flags[playerNumber] = true;
Console.ReadKey(true);
break;
case 4:
Console.WriteLine(" The player {0} Stepped on the space-time tunnel , Forward 10 grid ", PlayerNames[playerNumber]);
PlayerPos[playerNumber] += 10;
ChangePos();
Console.ReadKey(true);
break;
}// switch
}// else
ChangePos();
Console.Clear();
Program.ShowMap();
}
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;
}
}
}
}
边栏推荐
猜你喜欢
The difference between copy and copy in XMIND
Topological sorting-
Don't use the line segment tree to solve all my schedule problems with one idea
Leetcode force deduction solution - 30 Concatenate substrings of all words
微服务入门
AutoJs學習-投幣小遊戲
IO(1)-IO的分层
go runtime 包
Mandatory element of JMeter interface
两种常见的Vlan间通信的方式
随机推荐
两种常见的Vlan间通信的方式
The solution of MySQL inserting Chinese errors
OpenMV接收stm32单片机数据
Okaleido或杀出NFT重围,你看好它吗?
openresty访问redis和mysql
AutoJs学习-实现透明状态栏
MySQL表的增删改查(初阶)
小程序毕设作品之微信运动场地预约小程序毕业设计(6)开题答辩PPT
使用基于SSIM的CNN进行环路滤波
Flink 的学习笔记
Program yuan sent an article lamenting unemployment, which attracted program apes from various industries to comfort, laughing in the comment area
extern 、static 作为全局变量的使用与差异
go 多路复用
Fluent print widget level list
领域驱动模型(DDD)
go GMP模型
[Verilog digital system design (Xia Yuwen) -- basic knowledge of Verilog 1]
【Verilog数字系统设计(夏宇闻)----Verilog的基础知识1】
Addition, deletion, query and modification of MySQL [advanced]
VRRP中的上层回的路由