国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C#/.net學習-7-飛行棋代碼

2019-11-10 18:28:41
字體:
來源:轉載
供稿:網友
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _04飛行棋游戲{    class PRogram    {        //我們用靜態字段來模擬全局變量        static int[] Maps = new int[100];        //聲明一個靜態數組用來存儲玩家A跟玩家B的坐標        static int[] PlayerPos = new int[2];        //存儲兩個玩家的姓名        static string[] PlayerNames = new string[2];        //兩個玩家的標記        static bool[] Flags = new bool[2];//Flags[0]默認是false  Flags[1]默認也是false        static void Main(string[] args)        {            GameShow();            #region 輸入玩家姓名            Console.WriteLine("請輸入玩家A的姓名");            PlayerNames[0] = Console.ReadLine();            while (PlayerNames[0] == "")            {                Console.WriteLine("玩家A的姓名不能為空,請重新輸入");                PlayerNames[0] = Console.ReadLine();            }            Console.WriteLine("請輸入玩家B的姓名");            PlayerNames[1] = Console.ReadLine();            while (PlayerNames[1]==""||PlayerNames[1]==PlayerNames[0])            {                if (PlayerNames[1] == "")                {                    Console.WriteLine("玩家B的姓名不能為空,請重新輸入");                    PlayerNames[1] = Console.ReadLine();                }                else                {                    Console.WriteLine("玩家B的姓名不能玩家A的形同,請重新輸入");                    PlayerNames[1] = Console.ReadLine();                }            }            #endregion            //玩家姓名輸入OK之后 我們首先應該清屏             Console.Clear();//清屏            GameShow();            Console.WriteLine("{0}的士兵用A表示",PlayerNames[0]);            Console.WriteLine("{0}的士兵用B表示",PlayerNames[1]);            //在畫地圖之前 首先應該初始化地圖            InitailMap();            DrawMap();            //當玩家A跟玩家B沒有一個人在終點的時候 兩個玩家不停的去玩游戲            while (PlayerPos[0] < 99 && PlayerPos[1] < 99)            {                if (Flags[0] == false)                {                    PlayGame(0);//Flags[0]=true;                }                else                {                    Flags[0] = false;                }                if (PlayerPos[0] >= 99)                {                    Console.WriteLine("玩家{0}無恥的贏了玩家{1}",PlayerNames[0],PlayerNames[1]);                    break;                }                if (Flags[1] == false)                {                    PlayGame(1);                }                else                {                    Flags[1] = false;                }                if (PlayerPos[1] >= 99)                {                    Console.WriteLine("玩家{0}無恥的贏了玩家{1}",PlayerNames[1],PlayerNames[0]);                    break;                }            }//while            Win();            Console.ReadKey();        }        /// <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();        }        /// <summary>        /// 畫游戲頭        /// </summary>        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("***0505.Net基礎班飛行棋***");            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++)            {                //int index = luckyturn[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,2,3,4,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;            }        }        public static void DrawMap()        {            Console.WriteLine("圖例:幸運輪盤:◎   地雷:☆   暫停:▲   時空隧道:卐");            #region  第一橫行            for (int i = 0; i < 30; i++)            {                Console.Write(DrawStringMap(i));            }//for            #endregion            //畫完第一橫行后 應該換行            Console.WriteLine();            #region 第一豎行            for (int i = 30; i < 35; i++)            {                for (int j = 0; j <= 28; j++)                {                    Console.Write("  ");                }                Console.Write(DrawStringMap(i));                Console.WriteLine();            }            #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 <= 99; i++)            {                Console.Write(DrawStringMap(i));            }            #endregion            //畫完最后一行  應該換行            Console.WriteLine();        }//DrawMap方法的結尾        /// <summary>        /// 從畫地圖的方法中抽象出來的一個方法        /// </summary>        /// <param name="i"></param>        /// <returns></returns>        public static string DrawStringMap(int i)        {            string str = "";            #region 畫圖            //如果玩家A跟玩家B的坐標相同,并且都在這個地圖上,畫一個尖括號            if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i)            {                str = "<>";            }            else if (PlayerPos[0] == i)            {                //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;                }//switch            }//else            return str;            #endregion        }        /// <summary>        /// 玩游戲        /// </summary>        public static void PlayGame(int playerNumber)        {            Random r = new Random();            int rNumber = r.Next(1, 7);            Console.WriteLine("{0}按任意鍵開始擲骰子", PlayerNames[playerNumber]);            Console.ReadKey(true);            Console.WriteLine("{0}擲出了{1}", PlayerNames[playerNumber],rNumber);            PlayerPos[playerNumber] += rNumber;            ChangePos();            Console.ReadKey(true);            Console.WriteLine("{0}按任意鍵開始行動", PlayerNames[playerNumber]);            Console.ReadKey(true);            Console.WriteLine("{0}行動完了", PlayerNames[playerNumber]);            Console.ReadKey(true);            //玩家A有可能踩到了玩家B 方塊 幸運輪盤 地雷 暫停 時空隧道            if (PlayerPos[playerNumber] == PlayerPos[1 - playerNumber])            {                Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退6格", PlayerNames[playerNumber], PlayerNames[1 - playerNumber], PlayerNames[1 - playerNumber]);                PlayerPos[1 - playerNumber] -= 6;                ChangePos();                Console.ReadKey(true);            }            else//踩到了關卡            {                //玩家的坐標                switch (Maps[PlayerPos[playerNumber]])// 0 1 2 3 4                {                    case 0: Console.WriteLine("玩家{0}踩到了方塊,安全。", PlayerNames[playerNumber]);                        Console.ReadKey(true);                        break;                    case 1: Console.WriteLine("玩家{0}踩到了幸運輪盤,請選擇 1--交換位置 2--轟炸對方", PlayerNames[playerNumber]);                        string input = Console.ReadLine();                        while (true)                        {                            if (input == "1")                            {                                Console.WriteLine("玩家{0}選擇跟玩家{1}交換位置", PlayerNames[playerNumber], PlayerNames[1 - playerNumber]);                                Console.ReadKey(true);                                int temp = PlayerPos[playerNumber];                                PlayerPos[playerNumber] = PlayerPos[1 - playerNumber];                                PlayerPos[1 - playerNumber] = temp;                                Console.WriteLine("交換完成!!!按任意鍵繼續游戲!!!");                                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;                                ChangePos();                                Console.WriteLine("玩家{0}退了6格", PlayerNames[1 - playerNumber]);                                Console.ReadKey(true);                                break;                            }                            else                            {                                Console.WriteLine("只能輸入1或者2  1--交換位置 2--轟炸對方");                                input = Console.ReadLine();                            }                        }                        break;                    case 2: Console.WriteLine("玩家{0}踩到了地雷,退6格", PlayerNames[playerNumber]);                        Console.ReadKey(true);                        PlayerPos[playerNumber] -= 6;                        ChangePos();                        break;                    case 3: Console.WriteLine("玩家{0}踩到了暫停,暫停一回合", PlayerNames[playerNumber]);                        Flags[playerNumber] = true;                        Console.ReadKey(true);                        break;                    case 4: Console.WriteLine("玩家{0}踩到了時空隧道,前進10格", PlayerNames[playerNumber]);                        PlayerPos[playerNumber] += 10;                        ChangePos();                        Console.ReadKey(true);                        break;                }//switch            }//else            ChangePos();//perfect            Console.Clear();            DrawMap();        }        /// <summary>        /// 當玩家坐標發生改變的時候調用        /// </summary>        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;            }        }    }}
上一篇:mybatis 批量insert , update

下一篇:poj1573

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁陵县| 顺平县| 崇明县| 从化市| 承德县| 巴马| 镇康县| 炎陵县| 莱阳市| 楚雄市| 肇东市| 永福县| 余江县| 沈丘县| 清徐县| 会东县| 通化市| 马龙县| 岳普湖县| 行唐县| 武山县| 潞西市| 泗阳县| 札达县| 讷河市| 岑巩县| 昭苏县| 漯河市| 名山县| 沁阳市| 绩溪县| 滨州市| 治县。| 房产| 科技| 鄂州市| 饶阳县| 横峰县| 普格县| 镶黄旗| 娄底市|