using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace feixingqi
{
class Program
{
//靜態(tài)字段模仿全局變量 地圖
public static int[] Maps = new int[100];
//聲明數(shù)組存儲(chǔ)玩家的坐標(biāo)
public static int[] PlayerPos = new int[2];
//聲明玩家的姓名
public static string[] PlayerNames = new string[2];
//兩個(gè)為玩家的標(biāo)記
public static bool[] Flags = new bool[2];
//主方法
static void Main(string[] args)
{
//游戲標(biāo)題
GameShow();
//輸入玩家姓名
#region 輸入玩家姓名
Console.WriteLine("請(qǐng)輸入玩家A的姓名:");
PlayerNames[0] = Console.ReadLine();
while (PlayerNames[0] == "") {
Console.WriteLine("玩家A的姓名不能為空廓译,請(qǐng)重新輸入:");
PlayerNames[0] = Console.ReadLine();
}
Console.WriteLine("請(qǐng)輸入玩家B的姓名:");
PlayerNames[1] = Console.ReadLine();
while (PlayerNames[1] == ""||PlayerNames[1]==PlayerNames[0])
{
if (PlayerNames[1] == "")
{
Console.WriteLine("玩家B的姓名不能為空萝究,請(qǐng)重新輸入:");
PlayerNames[1] = Console.ReadLine();
}
else {
Console.WriteLine("玩家B的姓名不能與玩家A的相同廓八,請(qǐng)重新輸入:");
PlayerNames[1] = Console.ReadLine();
}
}
#endregion
//玩家姓名輸入完成后清屏
Console.Clear();
//重新顯示游戲頭部
GameShow();
Console.WriteLine("{0}的士兵為A",PlayerNames[0]);
Console.WriteLine("{0}的士兵為B", PlayerNames[1]);
//初始化地圖
InitailMap();
//畫(huà)地圖
DrawMap();
while (PlayerPos[0]<99&&PlayerPos[1]<99) {
if (Flags[0] == false)
{
PlayGame(0);
}
else {
Flags[0] = false;
}
if (PlayerPos[0] >= 99) {
Console.WriteLine("玩家{0}無(wú)恥的贏了玩家{1}",PlayerNames[0],PlayerNames[1]);
break;
}
if (Flags[1] == false)
{
PlayGame(1);
}
else {
Flags[1] = false;
}
if (PlayerPos[0] >= 99)
{
Console.WriteLine("玩家{0}無(wú)恥的贏了玩家{1}", PlayerNames[1], PlayerNames[1]);
break;
}
}
Win();
Console.ReadKey();
}
//游戲頭部
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.DarkBlue;
Console.WriteLine("***********豆豆飛行棋V1.0************");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.White;
}
//初始化地圖
public static void InitailMap() {
int[] luckyturn = { 6, 23, 40, 69, 83 };//幸運(yùn)輪盤◎
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 };//暫拖牒保▲
for (int i = 0; i < pause.Length; i++)
{
Maps[pause[i]] = 3;
}
int[] timeTunnel = { 20, 25, 45, 63, 72, 88 };//時(shí)空隧道卍
for (int i = 0; i < timeTunnel.Length; i++)
{
Maps[timeTunnel[i]] = 4;
}
}
//畫(huà)地圖
public static void DrawMap()
{
Console.WriteLine("圖例:幸運(yùn)輪盤:◎ 地雷:☆ 暫停:▲ 時(shí)空隧道:卍");
#region 第一行
for (int i=0;i<30;i++) {
Console.Write(DrawStringMap(i));
}
#endregion
//畫(huà)完第一行換行
Console.WriteLine();
#region 第一列
for (int i = 30; i < 35; i++) {
for (int j = 0; j < 29; j++) {
Console.Write(" ");
}
Console.WriteLine(DrawStringMap(i));
}
#endregion
#region 第二行
for (int i = 64; i >= 35; i--)
{
Console.Write(DrawStringMap(i));
}
#endregion
Console.WriteLine();
#region 第二列
for (int i = 65; i < 69; i++)
{
Console.WriteLine(DrawStringMap(i));
}
#endregion
#region 第三行
for (int i = 70; i < 100; i++)
{
Console.Write(DrawStringMap(i));
}
#endregion
Console.WriteLine();
}
//從畫(huà)地圖的方法里抽象出一個(gè)方法
public static string DrawStringMap(int i)
{
string str = "";
//如果玩家1的坐標(biāo)和萬(wàn)家2的坐標(biāo)相同都在地圖上就畫(huà)<>
if (PlayerPos[0] == PlayerPos[1] && PlayerPos[1] == i)
{
str="<>";
}
else if (PlayerPos[0] == i)
{
//全角符號(hào) shift+空格
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;
}
//玩游戲
public static void PlayGame(int playerNumber) {
//隨機(jī)數(shù)骰子
Random r = new Random();
int rNumber = r.Next(1, 7);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("玩家{0}按任意鍵開(kāi)始擲骰子", PlayerNames[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}骰子出了{(lán)1}", PlayerNames[playerNumber], rNumber);
PlayerPos[playerNumber] += rNumber;
ChangePos();
Console.WriteLine("玩家{0}開(kāi)始行動(dòng)", PlayerNames[playerNumber]);
//玩家A可能踩到玩家B狈醉,方塊,幸運(yùn)輪盤朦佩,地雷鹿寨,暫停,時(shí)空隧道
if (PlayerPos[playerNumber] == PlayerPos[1- playerNumber])
{
//玩家踩到玩家
Console.WriteLine("玩家{0}猜到了玩家{1}膘茎,玩家{2}退六格", PlayerNames[playerNumber], PlayerNames[1- playerNumber], PlayerNames[1- playerNumber]);
PlayerPos[1- playerNumber] -= 6;
Console.ReadKey(true);
}
else
{
//玩家踩到關(guān)卡
switch (Maps[PlayerPos[playerNumber]])
{
case 0:
Console.WriteLine("玩家{0}猜到了方塊桃纯,什么都不做", PlayerNames[playerNumber]);
Console.ReadKey(true);
break;
case 1:
Console.WriteLine("玩家{0}猜到了幸運(yùn)輪盤,請(qǐng)選擇:1-交換位置披坏,2-轟炸對(duì)方", PlayerNames[playerNumber]);
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
Console.WriteLine("玩家{0}選擇和玩家{1}交換位置", PlayerNames[playerNumber], PlayerNames[1- playerNumber]);
Console.ReadKey(true);
int tmp = PlayerPos[playerNumber];
PlayerPos[playerNumber] = PlayerPos[1- playerNumber];
PlayerPos[1- playerNumber] = tmp;
Console.WriteLine("交換完成L埂!刮萌!按任意鍵繼續(xù)M耘洹!着茸!");
Console.ReadKey(true);
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;
Console.WriteLine("玩家{0}退了6格", PlayerNames[1- playerNumber]);
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("只能輸入1或2,1-交換位置琐旁,2-轟炸對(duì)方");
input = Console.ReadLine();
break;
}
}
break;
case 2:
Console.WriteLine("玩家{0}踩到了地雷涮阔,退6格", PlayerNames[playerNumber]);
PlayerPos[playerNumber] -= 6;
break;
case 3:
Flags[playerNumber] = true;
break;
case 4:
Console.WriteLine("玩家{0}踩到了時(shí)空隧道,前進(jìn)10格", PlayerNames[playerNumber]);
PlayerPos[playerNumber] += 10;
Console.ReadKey(true);
break;
}
}
ChangePos();
Console.Clear();
DrawMap();
}
//做一個(gè)限定防止玩家跑出地圖 當(dāng)玩家坐標(biāo)發(fā)生改變的時(shí)候調(diào)用
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;
}
}
//勝利
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(" ■ ■■ ■■■■■■ ■ ● ● ");
}
}
}
運(yùn)行結(jié)果