飛行棋小游戲

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é)果
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末灰殴,一起剝皮案震驚了整個(gè)濱河市敬特,隨后出現(xiàn)的幾起案子掰邢,更是在濱河造成了極大的恐慌,老刑警劉巖伟阔,帶你破解...
    沈念sama閱讀 219,427評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件辣之,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡皱炉,警方通過(guò)查閱死者的電腦和手機(jī)怀估,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)合搅,“玉大人多搀,你說(shuō)我怎么就攤上這事≡植浚” “怎么了康铭?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,747評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)赌髓。 經(jīng)常有香客問(wèn)我从藤,道長(zhǎng),這世上最難降的妖魔是什么锁蠕? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,939評(píng)論 1 295
  • 正文 為了忘掉前任夷野,我火速辦了婚禮,結(jié)果婚禮上匿沛,老公的妹妹穿的比我還像新娘扫责。我一直安慰自己,他們只是感情好逃呼,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布鳖孤。 她就那樣靜靜地躺著,像睡著了一般抡笼。 火紅的嫁衣襯著肌膚如雪苏揣。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,737評(píng)論 1 305
  • 那天推姻,我揣著相機(jī)與錄音平匈,去河邊找鬼。 笑死藏古,一個(gè)胖子當(dāng)著我的面吹牛增炭,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播拧晕,決...
    沈念sama閱讀 40,448評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼隙姿,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了厂捞?” 一聲冷哼從身側(cè)響起输玷,我...
    開(kāi)封第一講書(shū)人閱讀 39,352評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤队丝,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后欲鹏,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體机久,經(jīng)...
    沈念sama閱讀 45,834評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評(píng)論 3 338
  • 正文 我和宋清朗相戀三年赔嚎,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了膘盖。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,133評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡尽狠,死狀恐怖衔憨,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情袄膏,我是刑警寧澤践图,帶...
    沈念sama閱讀 35,815評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站沉馆,受9級(jí)特大地震影響码党,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜斥黑,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評(píng)論 3 331
  • 文/蒙蒙 一揖盘、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧锌奴,春花似錦兽狭、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,022評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至茴恰,卻和暖如春颠焦,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背往枣。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,147評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工伐庭, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人分冈。 一個(gè)月前我還...
    沈念sama閱讀 48,398評(píng)論 3 373
  • 正文 我出身青樓圾另,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親雕沉。 傳聞我的和親對(duì)象是個(gè)殘疾皇子盯捌,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 本實(shí)例基于 React + ES6 + Webpack + Node 實(shí)現(xiàn)一個(gè)井字棋的小游戲,來(lái)進(jìn)一步深刻理解 R...
    sylvia_yue閱讀 1,423評(píng)論 0 1
  • C語(yǔ)言是面向過(guò)程的,而C++是面向?qū)ο蟮某ι和C++的區(qū)別: C是一個(gè)結(jié)構(gòu)化語(yǔ)言幼衰,它的重點(diǎn)在于算法和數(shù)據(jù)結(jié)構(gòu)。C程...
    小辰帶你看世界閱讀 942評(píng)論 0 1
  • 你在北國(guó)漫舞 我追你 將你捧在掌心 你卻化成淚滴 落進(jìn)我眼里 我將你盛裝在心中 生怕灑落 你卻如煙缀雳,如霧 不辭而別...
    山上人家123閱讀 188評(píng)論 6 19
  • 很多人都覺(jué)得頂頭上司領(lǐng)導(dǎo)稀里糊涂是傻比渡嚣,實(shí)際上領(lǐng)導(dǎo)心里比誰(shuí)都明白。沒(méi)有什么人能比一個(gè)長(zhǎng)時(shí)間近距離觀察你們的人更了解...
    Rainyopus閱讀 875評(píng)論 0 0
  • 做好自己要做該做的肥印!為自己定下的目標(biāo)努力识椰!不為未來(lái)到來(lái)時(shí)留有遺憾!
    清心小閱讀 217評(píng)論 0 1