最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#控制臺實現(xiàn)簡單飛行棋游戲

 更新時間:2021年07月21日 12:55:43   作者:梳碧湖-砍柴人  
這篇文章主要為大家詳細介紹了C#控制臺實現(xiàn)簡單飛行棋游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C#控制臺實現(xiàn)簡單飛行棋游戲的具體代碼,供大家參考,具體內(nèi)容如下

需求分析

1.制作游戲頭部:游戲頭部介紹
2.繪制地圖

使用一維數(shù)組裝整個地圖的路線
如果這個位置是0,繪制普通格子□
如果這個位置是1,繪制幸運輪盤◎
如果這個位置是2,繪制地雷★
如果這個位置是3,繪制暫?!?br /> 如果這個位置是4,繪制時空隧道卍
規(guī)劃幸運輪盤位置

int[] luckyturn = { 6, 23, 40, 55, 69, 83 };

規(guī)劃地雷的位置

int[] landMine = { 5,13,17,33,38,50,64,80,94};

規(guī)劃暫停位置

int[] pause = {9,27,60,93 };

規(guī)劃時空隧道的位置

int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };

3.設(shè)置特殊關(guān)卡

代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01飛行棋
{
    class Program
    {
        /// <summary>
        /// 整個地圖數(shù)組
        /// </summary>
        static int[] Maps = new int[100];
        /// <summary>
        /// 存儲玩家的數(shù)組
        /// </summary>
        static int[] PlayerPos = new int[2];
        /// <summary>
        /// 玩家名稱的數(shù)組
        /// </summary>
        static string[] PlayerName = new string[2];

        static bool[] PlayerFlage = new bool[2];
        static void Main(string[] args)
        {
            //繪制游戲標題
            ShowTitle();
            //輸入玩家名稱
            Console.WriteLine("請輸入玩家A的姓名:");
            PlayerName[0] = Console.ReadLine();
            while (PlayerName[0] == "")
            {
                Console.WriteLine("玩家A的姓名不能為空,請重新輸入!");
                PlayerName[0]=Console.ReadLine();
            }
            Console.WriteLine("請輸入玩家B的姓名:");
            PlayerName[1] = Console.ReadLine();
            while (PlayerName[1]==""||PlayerName[1]==PlayerName[0])
            {
                if (PlayerName[1]=="")
                {
                    Console.WriteLine("玩家B的姓名不能為空,請重新輸入!");
                    PlayerName[1]= Console.ReadLine();
                }
                if (PlayerName[1]==PlayerName[0])
                {
                    Console.WriteLine("玩家B的姓名和A重復,請重新輸入!");
                    PlayerName[1] = Console.ReadLine();
                }
            }
            //輸入完姓名,清空屏幕
            Console.Clear();
            ShowTitle();
            //初始化地圖關(guān)卡
            InitialMap();
            //繪制地圖
            DrawMap();
            Console.ReadLine();
            while (PlayerPos[0]<99&&PlayerPos[1]<99)
            {
                if (PlayerFlage[0]==false)
                {
                    PlayGame(0);
                }
                else
                {
                    PlayerFlage[0] = false;
                }
                if(PlayerFlage[1]==false)
                {
                    PlayGame(1);
                }
                else
                {
                    PlayerFlage[1] = false;
                }
                if (PlayerPos[0] == 99)
                {
                    Console.WriteLine("恭喜玩家[{0}]獲勝", PlayerName[0]);
                }
                if (PlayerPos[1] == 99)
                {
                    Console.WriteLine("恭喜玩家[{0}]獲勝", PlayerName[1]);
                }
            }
        }
        /// <summary>
        /// 設(shè)置游戲標題
        /// </summary>
        static void ShowTitle()
        {
        //設(shè)置顏色
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("************************************");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("************************************");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("************************************");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("***************飛行棋***************");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("************************************");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("************************************");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("************************************");
        }
        /// <summary>
        /// 初始化地圖關(guān)卡
        /// </summary>
        static void InitialMap()
        {
            //確定幸運輪盤的位置◎==1
            int[] luckyturn = { 6, 23, 40, 55, 69, 83 };
            for (int i=0;i<luckyturn.Length;i++)
            {
                Maps[luckyturn[i]] = 1;
            }
            //確定地雷的位置★==2
            int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };
            for (int i=0;i<landMine.Length;i++)
            {
                Maps[landMine[i]] = 2;
            }
            //確定暫停的位置▲==3
            int[] pause = { 9, 27, 60, 93 };
            for (int i=0;i<pause.Length;i++)
            {
                Maps[pause[i]] = 3;
            }
            //確定時空隧道的位置卍==4
            int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };
            for (int i=0;i<timeTunnel.Length;i++)
            {
                Maps[timeTunnel[i]] = 4;
            }
        }
        /// <summary>
        /// 繪制地圖
        /// </summary>
        static void DrawMap()
        {
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("玩家[{0}]使用A表示", PlayerName[0]);
            Console.WriteLine("玩家[{0}]使用B表示", PlayerName[1]);
            Console.WriteLine("游戲規(guī)則:");
            Console.WriteLine("1.兩名玩家輪流擲骰子,規(guī)定A玩家先擲.");
            Console.WriteLine("2.踩到□格子安全,沒有獎懲!");
            Console.WriteLine("3.踩到◎幸運輪盤,可以進行兩種選擇:a.置換與對方玩家的位置;b.進行轟炸對方,使對方倒退6步");
            Console.WriteLine("4.踩到★地雷,倒退6步!");
            Console.WriteLine("5.踩到▲暫停,下個回合將暫停操作!");
            Console.WriteLine("6.踩到卍時空隧道,直接前進10步!");
            Console.WriteLine("7.如果踩到對方,則對方直接退6步!");
            ///第一橫行
            for (int i=0;i<30;i++)
            {
                //判斷兩個玩家的位置一樣,確定兩個玩家還都在地圖中
                Console.Write(DrawString(i));
            }
            Console.WriteLine();
            ///第一豎列
            for (int i=30;i<35;i++)
            {
                for (int j=0;j<29;j++)
                {
                    Console.Write(" ");
                }
                Console.WriteLine(DrawString(i));
            }
            ///第二橫行
            for (int i=64;i>34;i--)
            {
                Console.Write(DrawString(i));
            }
            Console.WriteLine();
            ///第二豎列
            for (int i=65;i<70;i++)
            {
                Console.WriteLine(DrawString(i));
            }
            ///第三橫行
            for (int i=70;i<100;i++)
            {
                Console.Write(DrawString(i));
            }
            Console.WriteLine();
        }
        /// <summary>
        /// 判斷繪制地圖的方法
        /// </summary>
        /// <param name="pos"></param>
        private static string DrawString(int pos)
        {
            string str = "";
            if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == pos)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                str ="<>";
            }
            else if (PlayerPos[0] == pos)
            {
                Console.ForegroundColor = ConsoleColor.Magenta;
               str="A";
            }
            else if (PlayerPos[1] == pos)
            {
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                str ="B";
            }
            else
            {
                switch (Maps[pos])
                {
                    case 0:
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        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.Yellow;
                        str ="卍";
                        break;
                    default:
                        break;
                }
            }
            return str;
        }
        //游戲環(huán)節(jié)
        static void PlayGame(int playerNum)
        {
            Random r = new Random();
            Console.WriteLine("玩家[{0}]按下任意鍵擲骰子.",PlayerName[playerNum]);
            Console.ReadKey(true);
            int number = r.Next(1, 7);
            Console.WriteLine("玩家[{0}]擲出<{1}>點.",PlayerName[playerNum],number);
            Console.WriteLine("玩家[{0}]按下任意鍵進行移動.",PlayerName[playerNum]);
            Console.ReadKey(true);
            PlayerPos[playerNum] += number;
            Console.WriteLine("玩家[{0}]移動完成!",PlayerName[playerNum]);
            //玩家踩到對方
            ChangedCheck();
            if (PlayerPos[playerNum]==PlayerPos[1-playerNum])
            {
                Console.WriteLine("玩家[{0}]踩到玩家[{1}],玩家[{1}]退6步", PlayerName[playerNum], PlayerName[1 - playerNum]);
                PlayerPos[1 - playerNum] -= 6;
            }
            else
            {
                switch (Maps[PlayerPos[playerNum]])
                {
                    //踩到普通地板,安全沒有獎懲
                    case 0:
                        Console.WriteLine("玩家[{0}]踩到安全地帶,沒有獎懲!按下任意鍵繼續(xù)游戲", PlayerName[playerNum]);
                        Console.ReadKey(true);
                        break;
                    //踩到1幸運輪盤,選擇獎勵
                    case 1:
                        Console.WriteLine("玩家[{0}]踩到幸運輪盤,請選擇:a--交換位置  b--轟炸對方.", PlayerName[playerNum]);
                        string input = Console.ReadLine();
                        while (true)
                        {
                            if (input =="a")
                            {
                                Console.WriteLine("玩家[{0}]選擇與玩家[{1}]交換位置.",PlayerName[playerNum],PlayerName[1-playerNum]);
                                int temp = PlayerPos[playerNum];
                                PlayerPos[playerNum] = PlayerPos[1 - playerNum];
                                PlayerPos[1 - playerNum] = temp;
                                Console.WriteLine("玩家[{0}]與玩家[{1}]交換位置完成!按下任意鍵繼續(xù)游戲", PlayerName[playerNum], PlayerName[1 - playerNum]);
                                Console.ReadKey(true);
                                break;
                            }
                            else if (input == "b")
                            {
                                Console.WriteLine("玩家[{0}]選擇轟炸玩家[{1}]", PlayerName[playerNum], PlayerName[1 - playerNum]);
                                PlayerPos[1 - playerNum] -= 6;
                                Console.WriteLine("玩家[{0}]被轟炸倒退6步!按下任意鍵繼續(xù)游戲",PlayerName[1-playerNum]);
                                Console.ReadKey(true);
                                break;
                            }
                            else
                            {
                                input = Console.ReadLine();
                            }
                        }
                        break;
                    //踩到2地雷,直接倒退6格
                    case 2:
                        Console.WriteLine("玩家[{0}]踩到地雷,退6格! 按下任意鍵繼續(xù)游戲", PlayerName[playerNum]);
                        PlayerPos[playerNum] -= 6;
                        Console.ReadKey(true);
                        break;
                    //踩到3暫停,下個回合暫停
                    case 3:
                        Console.WriteLine("玩家[{0}]踩到暫停,下個回合暫停操作!按下任意鍵繼續(xù)游戲", PlayerName[playerNum]);
                        PlayerFlage[playerNum] = true;
                        Console.ReadKey(true);
                        break;
                    //踩到4時空隧道,直接前進10步
                    case 4:
                        Console.WriteLine("玩家[{0}]踩到時空隧道,前進10步!按下任意鍵繼續(xù)游戲", PlayerName[playerNum]);
                        PlayerPos[playerNum] += 10;
                        Console.ReadKey(true);
                        break;
                }
            }
            ChangedCheck();
            Console.Clear();
            ShowTitle();
            DrawMap();
           
        }
        static void ChangedCheck()
        {
            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;
            }
        }
    }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C# 獲取系統(tǒng)進程的用戶名

    C# 獲取系統(tǒng)進程的用戶名

    這也是應(yīng)一位網(wǎng)友的要求寫的,寫的比較倉促,湊合吧
    2009-06-06
  • WebService 的簡單封裝接口調(diào)用方法

    WebService 的簡單封裝接口調(diào)用方法

    這篇文章主要介紹了WebService 的簡單封裝接口調(diào)用方法,主要是通過簡單的sql語句來查詢數(shù)據(jù)庫,從而返回dataset,十分簡單實用,有需要的小伙伴可以參考下。
    2015-06-06
  • c#中object、var和dynamic的區(qū)別小結(jié)

    c#中object、var和dynamic的區(qū)別小結(jié)

    這篇文章主要給大家介紹了關(guān)于c#中object、var和dynamic的區(qū)別,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-09-09
  • C# Winform 分頁功能的實現(xiàn)

    C# Winform 分頁功能的實現(xiàn)

    本文主要介紹了C# Winform 分頁功能的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-06-06
  • Unity3D實現(xiàn)射線使物體移動

    Unity3D實現(xiàn)射線使物體移動

    這篇文章主要為大家詳細介紹了Unity3D實現(xiàn)射線使物體移動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • WinForm實現(xiàn)關(guān)閉按鈕不可用或隱藏的方法

    WinForm實現(xiàn)關(guān)閉按鈕不可用或隱藏的方法

    這篇文章主要介紹了WinForm實現(xiàn)關(guān)閉按鈕不可用或隱藏的方法,很實用的功能,需要的朋友可以參考下
    2014-08-08
  • C#清理非托管對象實例分析

    C#清理非托管對象實例分析

    這篇文章主要介紹了C#清理非托管對象的方法,結(jié)合實例形式詳細分析了C#清理非托管對象釋放資源的相關(guān)原理與實現(xiàn)技巧,需要的朋友可以參考下
    2016-02-02
  • gridview的buttonfield獲取該行的索引值(實例講解)

    gridview的buttonfield獲取該行的索引值(實例講解)

    本篇文章主要介紹了gridview的buttonfield獲取該行的索引值(實例講解)需要的朋友可以過來參考下,希望對大家有所幫助
    2014-01-01
  • C#驗證用戶輸入信息是否包含危險字符串的方法

    C#驗證用戶輸入信息是否包含危險字符串的方法

    這篇文章主要介紹了C#驗證用戶輸入信息是否包含危險字符串的方法,可針對and、or、exec、insert、select等SQL操作技巧進行過濾操作,非常具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • String.Format大全(C# Java)

    String.Format大全(C# Java)

    String.format無論是在C#中還是在java中應(yīng)用都非常廣泛,今天小編抽個時間把有關(guān)string.format知識總結(jié)分享給大家,需要的朋友可以參考下
    2015-09-09

最新評論

晋中市| 余姚市| 荆州市| 塔城市| 仁寿县| 新巴尔虎右旗| 赤峰市| 昌吉市| 彭州市| 高平市| 德兴市| 洪江市| 内乡县| 疏勒县| 昭通市| 金华市| 苏州市| 龙川县| 涡阳县| 绥棱县| 兴宁市| 望江县| 铜鼓县| 甘洛县| 涿鹿县| 海宁市| 韶关市| 微博| 金秀| 丘北县| 长白| 平南县| 织金县| 城口县| 廉江市| 兴宁市| 贵南县| 鄂托克前旗| 新竹县| 綦江县| 抚州市|