欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c# 編寫(xiě)的簡(jiǎn)單飛行棋游戲

 更新時(shí)間:2021年06月22日 08:53:54   作者:靜態(tài)類  
這個(gè)簡(jiǎn)單的飛行棋游戲主要是講的方法怎么應(yīng)用,充分的去理解方法和方法的調(diào)用。整體收獲還是很大的。感興趣的朋友可以參考下

項(xiàng)目效果

實(shí)現(xiàn)代碼

using System;

namespace 飛行棋項(xiàng)目
{
    class Program
    {
        ///1、畫(huà)游戲頭
        ///2、初始化地圖
        ///把整數(shù)數(shù)組中數(shù)字編程控制臺(tái)中顯示的特殊字符顯示的過(guò)程,就是初始化地圖
        ///3、畫(huà)地圖
        ///4、玩游戲
        //我們用靜態(tài)數(shù)組用來(lái)模擬全局變量,這個(gè)數(shù)組代表地圖長(zhǎng)度以及地圖坐標(biāo)
        public static int[] Maps = new int[100];
        //聲明一個(gè)靜態(tài)數(shù)組用來(lái)存儲(chǔ)玩家A跟玩家B的坐標(biāo)
        public static int[] PlayerPos = new int[2];
        //存儲(chǔ)兩個(gè)玩家的姓名
        public static string[] PlayerName = new string[2];

        public static bool[] Flag = new bool[2];

        static void Main(string[] args)
        {

            TitleName();
            #region 輸入玩家姓名
            Console.WriteLine("請(qǐng)輸入玩家A的姓名");
            PlayerName[0] = Console.ReadLine();
            while (PlayerName[0] == "")
            {
                Console.WriteLine("玩家A的姓名不能為空,請(qǐng)重新輸入");
                PlayerName[0] = Console.ReadLine();
            }

            Console.WriteLine("請(qǐng)輸入玩家B的姓名");
            PlayerName[1] = Console.ReadLine();
            while (PlayerName[1] == "" || PlayerName[1] == PlayerName[0])
            {
                if (PlayerName[1] == "")
                {
                    Console.WriteLine("玩家B的姓名不能為空,請(qǐng)重新輸入");
                    PlayerName[1] = Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("玩家B的姓名不能和玩家A的相同,請(qǐng)重新輸入");
                    PlayerName[1] = Console.ReadLine();
                }
            }
            #endregion 
            //玩家姓名輸入正確之后
            Console.Clear();//清屏功能
            TitleName();
            Console.WriteLine("{0}玩家用A表示\n{1}玩家用B表示", PlayerName[0], PlayerName[1]);
            //在畫(huà)地圖之前首先要初始化地圖
            InitailMap();
            DrawMap();
            //當(dāng)玩家A跟玩家B沒(méi)有一個(gè)人在終點(diǎn)的時(shí)候,兩個(gè)玩家就不停的去玩游戲
            while (PlayerPos[0] < 99 && PlayerPos[1] < 99)
            {
                if (Flag[0] == false)
                {
                    PlayGame(0);
                }
                else
                {
                    Flag[0] = false;
                }
                if(PlayerPos [0]>=99)
                {
                    Console.WriteLine("玩家{0}贏了", PlayerName[0]);
                    break;
                }
                if (Flag[1]==false)
                {
                    PlayGame(1);
                }
                else
                {
                    Flag[1] = false;
                }
                if(PlayerPos[1] >= 99)
                {
                    Console.WriteLine("玩家{0}贏了", PlayerName[1]);
                    break;
                }
            }//while
            Console.ReadKey();


        }
        /// <summary>
        /// 畫(huà)游戲頭
        /// </summary>
        public static void TitleName()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("******************");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("******************");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("******************");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("****飛行棋項(xiàng)目****");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("******************");
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("******************");
            Console.ForegroundColor = ConsoleColor.DarkMagenta;
            Console.WriteLine("******************");
        }
        /// <summary>
        /// 將不同的值賦予不同的特殊符號(hào),方便畫(huà)出地圖
        /// </summary>
        public static void InitailMap()
        {
            int[] luckyturn = { 6, 23, 38, 45, 78, 90 };//幸運(yùn)輪盤(pán)
            for (int i = 0; i < luckyturn.Length; i++)
            {
                Maps[luckyturn[i]] = 1;
            }
            int[] landline = { 5, 22, 31, 44, 75, 87, 92 };//地雷
            for (int i = 0; i < landline.Length; i++)
            {
                Maps[landline[i]] = 2;
            }
            int[] pause = { 7, 15, 25, 46, 56, 84 };//暫停
            for (int i = 0; i < pause.Length; i++)
            {
                Maps[pause[i]] = 3;
            }
            int[] timeTunnel = { 9, 18, 29, 37, 42, 63, 72, 88, 96 };//時(shí)空隧道
            for (int i = 0; i < timeTunnel.Length; i++)
            {
                Maps[timeTunnel[i]] = 4;
            }
        }
        /// <summary>
        /// 畫(huà)地圖
        /// </summary>
        public static void DrawMap()
        {
            Console.WriteLine("圖例:幸運(yùn)輪盤(pán):▲  地雷:☆  暫停:○  時(shí)空隧道:¥");
            #region 第一橫行
            //第一橫行
            for (int i = 0; i < 30; i++)
            {
                Console.Write(DrawStringMap(i));//直接調(diào)用畫(huà)地圖的那個(gè)方法
            }//for
            #endregion 
            //畫(huà)完第一橫行需要換行
            Console.WriteLine();
            #region 第一豎行
            //畫(huà)第一豎行
            for (int i = 30; i < 35; i++)
            {
                for (int j = 0; j <= 28; j++)
                {
                    Console.Write("  ");//這里畫(huà)兩個(gè)空格
                }
                Console.Write(DrawStringMap(i));//直接調(diào)用畫(huà)地圖的那個(gè)方法
                Console.WriteLine();
            }
            #endregion
            #region 第二橫行
            for (int i = 64; i >= 35; i--)
            {
                Console.Write(DrawStringMap(i));
            }
            #endregion 
            //畫(huà)完第二橫行需要換行
            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 
            //畫(huà)完最后一行地圖需要換行
            Console.WriteLine();
        }
        #region 從畫(huà)地圖的方法中抽象出來(lái)的一種方法
        /// <summary>
        /// 從畫(huà)地圖的方法中抽象出來(lái)的一種方法
        /// </summary>
        /// <param name="i">傳參進(jìn)來(lái)的一個(gè)變量</param>
        /// <returns></returns>
        public static string DrawStringMap(int i)
        {
            //畫(huà)圖
            string str = "";
            if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i)
            {
                str = "<>";
            }
            else if (PlayerPos[0] == i)
            {
                str = "A";
            }
            else if (PlayerPos[1] == i)
            {
                str = "B";
            }
            else
            {
                switch (Maps[i])
                {
                    case 0:
                        Console.ForegroundColor = ConsoleColor.Red;
                        str = "□";
                        break;
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Green;
                        str = "▲";
                        break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.Gray;
                        str = "☆";
                        break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        str = "○";
                        break;
                    case 4:
                        Console.ForegroundColor = ConsoleColor.Blue;
                        str = "¥";
                        break;
                }//switch
            }//if
            return str;
        }
        #endregion
        /// <summary>
        /// 玩游戲
        /// </summary>
        /// <param name="playerNumber">傳遞進(jìn)來(lái)的一個(gè)參數(shù)來(lái)判定是誰(shuí)在玩游戲</param>
        public static void PlayGame(int playerNumber)
        {
            Random r = new Random();//設(shè)定隨機(jī)數(shù)
            int rNumber = r.Next(1, 7);//限定隨機(jī)數(shù)范圍在1-7之間
            Console.WriteLine("{0}按下任意鍵開(kāi)始擲骰子", PlayerName[playerNumber]);
            Console.ReadKey(true);
            Console.WriteLine("{0}擲出了{(lán)1}", PlayerName[playerNumber], rNumber);//擲出了隨機(jī)數(shù)1-7之間
            PlayerPos[playerNumber] += rNumber;//玩家坐標(biāo)加上擲出的隨機(jī)數(shù)
            ChangePos();//在每一個(gè)玩家坐標(biāo)變化的地方都要進(jìn)行一次限制,限制玩家坐標(biāo)在地圖0-99之內(nèi)
            Console.ReadKey(true);
            if (PlayerPos[playerNumber] == PlayerPos[1 - playerNumber])
            {
                Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退6格", PlayerName[playerNumber], PlayerName[1 - playerNumber], PlayerName[1 - playerNumber]);
                PlayerPos[1 - playerNumber] -= 6;
                ChangePos();
                Console.ReadKey(true);
            }
            else
            {
                switch (Maps[PlayerPos[playerNumber]])
                {
                    case 0:
                        Console.WriteLine("玩家{0}踩到了方塊,啥都沒(méi)有", PlayerName[playerNumber]);
                        Console.ReadKey(true);
                        break;
                    case 1:
                        Console.WriteLine("玩家{0}踩到了幸運(yùn)輪盤(pán),請(qǐng)選擇1--交換位置,2--轟炸對(duì)方", PlayerName[playerNumber]);
                        Console.ReadKey(true);
                        string input = Console.ReadLine();
                        while (true)
                        {
                            if (input == "1")
                            {
                                Console.WriteLine("玩家{0}跟玩家{1}交換位置", PlayerName[playerNumber], PlayerName[1 - playerNumber]);
                                Console.ReadKey(true);
                                int temp = PlayerPos[playerNumber];
                                PlayerPos[playerNumber] = PlayerPos[1 - playerNumber];
                                PlayerPos[1 - playerNumber] = temp;
                                ChangePos();
                                Console.WriteLine("交換完成,按任意鍵繼續(xù)游戲");
                                Console.ReadKey(true);
                                break;
                            }
                            else if (input == "2")
                            {
                                Console.WriteLine("玩家{0}選擇轟炸玩家{1},玩家{2}退6格", PlayerName[playerNumber], PlayerName[1 - playerNumber], PlayerName[1 - playerNumber]);
                                Console.ReadKey(true);
                                PlayerPos[1 - playerNumber] -= 6;
                                ChangePos();
                                Console.WriteLine("玩家{0}退了6格,按任意鍵繼續(xù)游戲", PlayerName[1 - playerNumber]);
                                Console.ReadKey(true);
                                break;
                            }
                            else
                            {
                                Console.WriteLine("你輸入的文本有誤,請(qǐng)重新輸入!");
                                input=Console.ReadLine();
                                Console.ReadKey(true);
                            }
                        }
                        break;
                    case 2:
                        Console.WriteLine("玩家{0}踩到了地雷,退6格", PlayerName[playerNumber]);
                        Console.ReadKey(true);
                        PlayerPos[playerNumber] -= 6;
                        ChangePos();
                        Console.ReadKey(true);
                        break;
                    case 3:
                        Console.WriteLine("玩家{0}踩到了暫停,暫停一回合", PlayerName[playerNumber]);
                        Flag[playerNumber] = true;
                        Console.ReadKey(true);
                        break;
                    case 4:
                        Console.WriteLine("玩家{0}踩到了時(shí)空隧道,前進(jìn)10格", PlayerName[playerNumber]);
                        Console.ReadKey(true);
                        PlayerPos[playerNumber] += 10;
                        ChangePos();
                        Console.ReadKey(true);
                        break;

                }//switch

            }//else
            ChangePos();//perfect
            Console.Clear();
            DrawMap();
        }
        /// <summary>
        /// 當(dāng)玩家坐標(biāo)發(fā)生改變的時(shí)候調(diào)用這個(gè)方法,用于限制玩家坐標(biāo)在0-99之間
        /// </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;
            }
        }
    }
}

基于winform制作的圖形界面程序

效果

代碼

using System;
using System.Drawing;
using System.Windows.Forms;
 
namespace 飛行棋
{
 public partial class Form1 : Form
 {
  public Form1()
  {
   InitializeComponent();
  }
  //創(chuàng)建一個(gè)數(shù)組裝游戲地板
  int[] mapList = new int[390];
  //創(chuàng)建裝圖片的數(shù)組
  PictureBox[] mappic = new PictureBox[390];
  //創(chuàng)建路的數(shù)組
  int[] road = new int[100];
  //創(chuàng)建地圖 
  Panel map = new Panel();
  int size = 30;
  //創(chuàng)建骰子
  PictureBox dice = new PictureBox();
  //初始位置的停放區(qū)域紅色的
  Panel plan1 = new Panel();
  //初始位置的停放區(qū)域綠色的
  Panel plan2 = new Panel();
  private void Form1_Load(object sender, EventArgs e)
  {
   this.Size = new Size(1200, 600);
   this.FormBorderStyle = FormBorderStyle.FixedSingle;
   this.Location = new Point(250, 100);
   this.BackColor = Color.Wheat;
   map.Size = new Size(30*size, 13*size);
   map.BorderStyle = BorderStyle.FixedSingle;
   map.Location = new Point(40,160);
   this.Controls.Add(map);
   //顯示圖片的方法
   Init();
 
    
   plan1.Size = new Size(100, 100);
   plan1.Location = new Point(map.Left, map.Top - 120);
   plan1.BackgroundImage = Image.FromFile("../../img/circle.png");
   plan1.BackgroundImageLayout = ImageLayout.Stretch;
   this.Controls.Add(plan1);
    
   plan2.Size = new Size(100, 100);
   plan2.Location = new Point(map.Left+120 ,map.Top - 120);
   plan2.BackgroundImage = Image.FromFile("../../img/circle.png");
   plan2.BackgroundImageLayout = ImageLayout.Stretch;
   this.Controls.Add(plan2);
 
   PictureBox redPlayer = new PictureBox();
   redPlayer.Size = new Size(80, 80);
   redPlayer.Image = Image.FromFile("../../img/red.png");
   redPlayer.Location = new Point(10, 10);
   redPlayer.SizeMode = PictureBoxSizeMode.StretchImage;
   plan1.Controls.Add(redPlayer);
 
   PictureBox greenPlayer = new PictureBox();
   greenPlayer.Size = new Size(80, 80);
   greenPlayer.Image = Image.FromFile("../../img/green.png");
   greenPlayer.Location = new Point(10, 10);
   greenPlayer.SizeMode = PictureBoxSizeMode.StretchImage;
   plan2.Controls.Add(greenPlayer);
 
   //創(chuàng)建對(duì)話框
   tall.Size = new Size(200, 500);
   tall.Location = new Point(map.Right + 20, 50);
   tall.ReadOnly = true;
   this.Controls.Add(tall);
   //玩家一:
   name.Size = new Size(100, 30);
   name.Location = new Point(45,10);
   this.Controls.Add(name);
   //玩家二:
   names.Size = new Size(100, 30);
   names.Location = new Point(160,10 );
   this.Controls.Add(names);
   btn.Location = new Point(300,10);
   btn.Text = "開(kāi)始游戲";
   btn.Size = new Size(100, 30);
   btn.BackColor = Color.Pink;
   btn.Click += Btn_Click;
   this.Controls.Add(btn);
 
   //骰子
   dice.Size = new Size(80, 80);
   dice.Image = Image.FromFile("../../img/roll.png");
   dice.Location = new Point(map.Right-160,map.Top-120);
   dice.SizeMode = PictureBoxSizeMode.StretchImage;
   this.Controls.Add(dice);
   dice.MouseClick += Dice_MouseClick;
    
    
  }
 
  private void Btn_Click(object sender, EventArgs e)
  {
 
   //創(chuàng)建初始的彈框
   Tall(string.Format("請(qǐng)兩人投擲骰子,{0}先手,點(diǎn)大的先走",name.Text));
    
   playName[0] = name.Text;
   playName[1] = names.Text;
   tall.Focus();
  }
 
  TextBox name = new TextBox();
  TextBox names = new TextBox();
  Button btn = new Button();
   
  //創(chuàng)鍵記錄的對(duì)話框
  RichTextBox tall = new RichTextBox();
  //創(chuàng)建隨機(jī)
  Random r = new Random();
  // 輪流投擲骰子 0代表紅方 1代表綠方
  bool[] playStart = new bool[2] { true, false };
  //記錄雙方當(dāng)前的位置
  int[] playPosition = new int[2] { -1, -1 };
  int[] playStand = new int[2] { -1, -1 };
  // 記錄骰子的點(diǎn)數(shù)
  int[] shaizi = new int[2];
  string[] playName = new string[2];
  //數(shù)組存儲(chǔ)點(diǎn)數(shù)
  int[] num = new int[2] ;
  //1.輪流投擲篩子決定誰(shuí)先出門(mén)
  private void Dice_MouseClick(object sender, MouseEventArgs e)
  {
   PlayDice();
   PlayGame();
 
 
  }
  private void PlayDice()
  {
   //紅方投擲 紅方為true 投擲完之后變?yōu)閒alse 綠方投擲
   if (playStart[0])
   {
    shaizi[0] = r.Next(1,7);
    Tall(String.Format("{1}投擲出{0}點(diǎn)", shaizi[0],playName[0]));
    playStart[0] = !playStart[0];
 
   }
   else
   {
    playStart[0] = !playStart[0];
   }
   //綠方投擲 綠方為false 綠方投擲完之后變?yōu)閠rue .輪到紅方投擲
   if (playStart[1])
   {
    shaizi[1] = r.Next(1, 7);
    Tall(String.Format("{1}投擲出{0}點(diǎn)", shaizi[1],playName[1]));
    playStart[1] = !playStart[1];
 
   }
   else
   {
    playStart[1] = !playStart[1];
   }
  }
  //決定游戲誰(shuí)先手
  private void OutDoor()
  {
   //紅方為true 綠方為false的時(shí)候一回合完了 一回合完之后對(duì)應(yīng)的骰子數(shù)都不為0
   if (playStart[0]&&!playStart[1]&&(shaizi[0]!=0||shaizi[1]!=0))
   {
    if (shaizi[0] == shaizi[1])
    {
     Tall("雙方點(diǎn)數(shù)相同,請(qǐng)重新投擲");
    }
    else
    {
     //第二回合
     st = false;
     if (shaizi[0] > shaizi[1])
     {
      Tall(String.Format("{0}點(diǎn)數(shù)較大,先行一步,{0}投擲",name.Text));
      playStart[0] = true;
      playStart[1] = false;
 
     }
     if (shaizi[0] < shaizi[1])
     {
      Tall(String.Format("{0}點(diǎn)數(shù)較大,先行一步,{0}投擲", names.Text));
      playStart[0] = false;
      playStart[1] = true;
     }
    }
   }
 
  }
 
 
  bool st = true;
  //控制游戲誰(shuí)先走
  private void PlayGame()
  {
   //判斷游戲剛開(kāi)始時(shí)候比點(diǎn)數(shù)先行
   if (st == true)
   {
    OutDoor();
    //都為false的時(shí)候綠方投擲
    if (!playStart[0]&&playStart[1])
    {
     Tall(string.Format("請(qǐng){0}投擲",names.Text));
    }//都為true的時(shí)候紅方投擲
    else if(playStart[0]&&!playStart[1])
    {
     Tall(string.Format("請(qǐng){0}投擲!",name.Text));
    }
   }
   else
   {
    if (playStart[0] && !playStart[1])//如果綠方大, 綠方為true
    {
     PlayReturn(1);
    }//紅方
    else if (!playStart[0] && playStart[1])
    {
     PlayReturn(0);
    } 
   }
 
  }
  /// <summary>
  /// 雙方輪流游戲
  /// </summary>
  /// 傳入?yún)?shù)index0為紅方 1為綠方
  bool[] re = new bool[2] { false, false };
  private void PlayReturn(int index)
  {
   //都沒(méi)出門(mén)
   if (playPosition[index] == -1)
   {
 
    switch (shaizi[index])
    {
     case 2:
     case 4:
      Tall(String.Format("{0}可以起步", playName[index]));
      playPosition[index] = 0;
      playStand[index] = 0;
      //如果兩個(gè)位置相等
      if (playPosition[1] == playPosition[0])
      {
       mappic[road[playPosition[index]]].Image = imageList1.Images[2];
      }
      else
      {
       mappic[road[playPosition[index]]].Image = imageList1.Images[index];
      }
      break;
     case 6:
      playStart[index] = true;
      playStart[1 - index] = false;
      Tall(String.Format("{0}可以起步", playName[index]));
      playPosition[index] = 0;
      playStand[index] = 0;
      if (playPosition[1] == playPosition[0])
      {
       mappic[road[playPosition[index]]].Image = imageList1.Images[2];
      }
      else
      {
       mappic[road[playPosition[index]]].Image = imageList1.Images[index];
      }
      Tall(String.Format("請(qǐng){0}投擲骰子", playName[index]));
      break;
     default:
      Tall(String.Format("很遺憾,{0}投擲出{1}點(diǎn)無(wú)法起步,輪到{2}投擲", playName[index], shaizi[index], playName[1 - index]));
      break;
    }
    if (playPosition[0] != -1)
    {
     plan1.Controls.Clear();
    }
    if (playPosition[1] != -1)
    {
     plan2.Controls.Clear();
    }
   }
   else
   {
    //改變位置之前記錄好之前的位置
    playStand[index] = playPosition[index];
    playPosition[index] += shaizi[index];
    if (playPosition[index] >= 99)
    {
     MessageBox.Show(playName[index] + "獲勝");
     playPosition[index] = 99;
     //改變圖片
     Change(index);
     return;
    }
    Tall(string.Format("{0}移動(dòng)了{(lán)1}步", playName[index], shaizi[index]));
    //改變圖片
    Change(index);
 
    //判斷移動(dòng)完成之后的位置是如何
    if (playPosition[index] == playPosition[1 - index])
    {
     playPosition[1 - index] = 0;
     playStand[1 - index] = playPosition[1 - index];
     Tall(String.Format("厲害!{0}精準(zhǔn)的將{1}踩回原點(diǎn),{0}當(dāng)前的位置是{2},{1}當(dāng)前的位置是{3},", playName[index], playName[1 - index], playPosition[index], playPosition[1 - index]));
     mappic[road[playPosition[index]]].Image = imageList1.Images[index];
     mappic[road[playPosition[1 - index]]].Image = imageList1.Images[1 - index];
     Tall(string.Format("{0}開(kāi)始投擲", playName[1 - index]));
    }
 
    switch (mapList[road[playPosition[index]]])
    {
     case 1:
      Tall(string.Format("{0}安全到達(dá)!當(dāng)前位置是{1}", playName[index], playPosition[index]));
      Tall(String.Format("{0}開(kāi)始投擲!", playName[1-index]));
      break;
     case 2:
      Tall(string.Format("很不幸,{0}踩中了香蕉皮,后退6步,當(dāng)前位置是{1}", playName[index], playPosition[index]));
      playStand[index] = playPosition[index];
      playPosition[index] -= 6;
      Change(index);
      /*Tall(string.Format("{0}當(dāng)前位置是{1}", playName[index], playPosition[index]));*/
      Tall(string.Format("{0}開(kāi)始投擲", playName[1 - index]));
      break;
     case 3:
      Tall(String.Format("恭喜!{0}踩中時(shí)空隧道,前進(jìn)6步!當(dāng)前位置是{1}", playName[index], playPosition[index]));
      playStand[index] = playPosition[index];
      playPosition[index] += 6;
      Change(index);
      /*Tall(string.Format("{0}當(dāng)前位置是{1}", playName[index], playPosition[index]));*/
      Tall(string.Format("{0}開(kāi)始投擲", playName[1 - index]));
      break;
     case 4:
      Tall(string.Format("好可惜,{0}踩中了陷阱,暫停一回合", playName[index]));
      re[index] = true;
      re[1 - index] =false;
      break;
     case 5:
      Tall(string.Format("真好,{0}踩中幸運(yùn)星,在玩一回合!當(dāng)前位置是{1}", playName[index], playPosition[index]));
      playStart[index] = true;
      playStart[1 - index] = false;
      Tall(string.Format("{0}繼續(xù)投擲!", playName[index]));
      break;
     case 6:
      Tall(string.Format("真好!{0}踩中秘籍,請(qǐng)選擇措施!當(dāng)前位置是{1}", playName[index], playPosition[index]));
      DialogResult result = MessageBox.Show("是否與對(duì)方更換位置!", "移魂大法", MessageBoxButtons.YesNo);
      if (result == DialogResult.Yes)
      {
       int temp = playPosition[index];
       playPosition[index] = playPosition[1 - index];
       playPosition[1 - index] = temp;
       playStand[index] = playPosition[index];
       playStand[1 - index] = playPosition[1 - index];
       mappic[road[playPosition[index]]].Image = imageList1.Images[index];
       mappic[road[playPosition[1 - index]]].Image = imageList1.Images[1 - index];
 
      }
      Tall(string.Format("{0}當(dāng)前位置是{1},{2}的位置是{3}", playName[index], playPosition[index], playName[1 - index], playPosition[1 - index]));
      Tall(string.Format("{0}開(kāi)始投擲。", playName[1 - index]));
      break;
     case 7:
      Tall(string.Format("幸運(yùn)!{0}獲得手槍,可選擇擊退對(duì)方3步!當(dāng)前位置是{1}", playName[index], playPosition[index]));
      DialogResult res = MessageBox.Show("是否選擇擊退對(duì)方三步!", "手槍!", MessageBoxButtons.YesNo);
      if (res == DialogResult.Yes)
      {
       playStand[1 - index] = playPosition[1 - index];
       playPosition[1 - index] -= 3;
       mappic[road[playPosition[1 - index]]].Image = imageList1.Images[1 - index];
       Change(1 - index);
      }
      /* Tall(string.Format("{0}被擊退對(duì)方3步!當(dāng)前位置是{1}", playName[1 - index], playPosition[1 - index]));*/
      Tall(string.Format("{0}開(kāi)始投擲。", playName[1 - index]));
      break;
     default:
      break;
    }
    if (re[index] && !re[1 - index])
    {
     playStart[index] = true;
     playStart[1 - index] = false;
     re[index] = false;
     re[1 - index] = false;
    }
 
   }
  }
 
  private void Change( int index)
  {
   //如果移動(dòng)完之后再同一個(gè)位置
   if (playPosition[1] == playPosition[0])
   {
    mappic[road[playPosition[index]]].Image = imageList1.Images[2];
   }
   else
   {//移動(dòng)完成之后顯示對(duì)應(yīng)玩家的圖片
    mappic[road[playPosition[index]]].Image = imageList1.Images[index];
   }
   //原本位置圖片的顯示,如果兩人在同一個(gè)位置站著,并且都在路上自己離開(kāi)之后,留下對(duì)方的圖片在原地在起點(diǎn)的時(shí)候
   if (playStand[0]==playStand[1]&&playStand[0]!=-1&&playStand[1]!=-1&&playPosition[1-index]==0)
   {
    mappic[road[playStand[index]]].Image = imageList1.Images[1 - index];
    mappic[road[playPosition[index]]].Image = imageList1.Images[ index];
   }
   else //如果兩人不再同一位置判斷之前的腳下是什么
   {
    switch (mapList[road[playStand[index]]])
    {
     //整個(gè)地圖的圖片
     case 0:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/water.gif");
      break;
     //游戲區(qū)域的路
     case 1:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/grass.png");
      break;
     case 2:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/sk.jpg");
      break;
     case 3:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/xj.jpg");
      break;
     case 4:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/xianjing.jpg");
      break;
     case 5:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/xx.jpg");
      break;
     case 6:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/jh.jpg");
      break;
     case 7:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/sq.jpg");
      break;
     case 10:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/start.png");
      break;
     case 11:
      mappic[road[playStand[index]]].Image = Image.FromFile("../../img/end.bmp");
      break;
     
    }
   }
  }
 
  void Tall(string str)
  {
   MessageBox.Show(str);
   tall.AppendText(str+"\r\n");
  }
 
  //創(chuàng)建一個(gè)顯示所有圖片的方法
  void Init()
  {
   //先調(diào)用地圖的
   CreateMap();
   //在調(diào)用道具的 先有地圖再有道具
   CreateGear();
   for (int i = 0; i < mapList.Length; i++)
   {
    //創(chuàng)建圖片每循環(huán)一次創(chuàng)建一個(gè)
    PictureBox pic = new PictureBox();
    //圖片的大小等于30
    pic.Size = new Size(size, size);
    //判斷mapList索引對(duì)應(yīng)的東西
    switch (mapList[i])
    {
     //整個(gè)地圖的圖片
     case 0:
     pic.Image = Image.FromFile("../../img/water.gif");
     break;
     //游戲區(qū)域的路
     case 1:
     pic.Image = Image.FromFile("../../img/grass.png");
     break;
     case 2:
     pic.Image = Image.FromFile("../../img/sk.jpg");
     break;
     case 3:
     pic.Image = Image.FromFile("../../img/xj.jpg");
     break;
     case 4:
     pic.Image = Image.FromFile("../../img/xianjing.jpg");
     break;
     case 5:
     pic.Image = Image.FromFile("../../img/xx.jpg");
     break;
     case 6:
     pic.Image = Image.FromFile("../../img/jh.jpg");
     break;
     case 7:
     pic.Image = Image.FromFile("../../img/sq.jpg");
     break;
     case 10:
     pic.Image = Image.FromFile("../../img/start.png");
     break;
     case 11:
     pic.Image = Image.FromFile("../../img/end.bmp");
     break;
 
    }
    //拉伸圖片
    pic.SizeMode = PictureBoxSizeMode.StretchImage;
    mappic[i] = pic;
    //算出圖片的坐標(biāo)
    pic.Left = i % 30 * size;
    pic.Top = i / 30 * size;
    map.Controls.Add(pic);
   }
  }
  //給整個(gè)地圖添加圖片
  void CreateMap()
  {
   //調(diào)用鋪路的方法
   CreateRoad();
   for (int i = 0; i < road.Length; i++)
   {
    mapList[road[i]] = 1;
   }
   //起始圖片的索引位置
   mapList[0] = 10;
   //結(jié)束圖片對(duì)應(yīng)的索引位置
   mapList[mapList.Length - 1] = 11;
  } 
  //算出路怎么鋪
  void CreateRoad()
  {
   //111111
   //  1
   //111111
   //1
   //111111
   //第一行鋪的路30個(gè)
   for (int i = 0; i < 30; i++)
   {
    road[i] = i;
   }
   //第2個(gè)列的路
   for (int i = 30; i <= 35; i++)
   {
    road[i] = road[i - 1] + 30;
   }
   //第三個(gè)路
   for (int i = 36; i <65; i++)
   {
    road[i] = road[i - 1] - 1;
   }
   //第4列的路
   for (int i = 65; i <=70; i++)
   {
    road[i] = road[i - 1] + 30;
   }
   //第五行的數(shù)
   for (int i =71; i <100; i++)
   {
    road[i] = road[i - 1] + 1;
   }
  }
 
  //定義道具的數(shù)組
  int[] back = { 7, 27, 42, 62, 73, 96 };
  int[] forword = { 10, 25, 33, 65, 80, 88 };
  int[] stop = { 3, 20, 35, 50, 60, 70, 90 };
  int[] star = { 5, 28, 45, 71, 85 };
  int[] change = { 4, 55, 75, 98 };
  int[] gun = { 11, 32, 66, 83 };
  //定義一個(gè)道具放置位置的方法
  void CreateGear()
  {
   for (int i = 0; i < back.Length; i++)
   {
    //將地圖對(duì)應(yīng)的路然后將索引換成對(duì)應(yīng)的道具
    mapList[road[back[i]]] = 2;
   }
   for (int i = 0; i < forword.Length; i++)
   {
    mapList[road[forword[i]]] = 3;
   }
   for (int i = 0; i < stop.Length; i++)
   {
    mapList[road[stop[i]]] = 4;
   }
   for (int i = 0; i <star.Length; i++)
   {
    mapList[road[star[i]]] = 5;
   }
   for (int i = 0; i < change.Length; i++)
   {
    mapList[road[change[i]]] = 6;
   }
   for (int i = 0; i < gun.Length; i++)
   {
    mapList[road[gun[i]]] = 7;
   }
  }
 }
}

以上就是c# 編寫(xiě)的簡(jiǎn)單飛行棋游戲的詳細(xì)內(nèi)容,更多關(guān)于c# 飛行棋游戲的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • c#關(guān)于JWT跨域身份驗(yàn)證的實(shí)現(xiàn)代碼

    c#關(guān)于JWT跨域身份驗(yàn)證的實(shí)現(xiàn)代碼

    這篇文章主要介紹了c#關(guān)于JWT跨域身份驗(yàn)證的實(shí)現(xiàn)代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • C#實(shí)現(xiàn)子窗體與父窗體通信方法實(shí)例總結(jié)

    C#實(shí)現(xiàn)子窗體與父窗體通信方法實(shí)例總結(jié)

    這篇文章主要介紹了C#實(shí)現(xiàn)子窗體與父窗體通信方法,實(shí)例總結(jié)了常用的四種窗體通信方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • C#中使用ArrayPool和MemoryPool實(shí)例

    C#中使用ArrayPool和MemoryPool實(shí)例

    對(duì)資源的可復(fù)用是提升應(yīng)用程序性能的一個(gè)非常重要的手段,比如本篇要分享的 ArrayPool 和 MemoryPool,它們就有效的減少了內(nèi)存使用和對(duì)GC的壓力,從而提升應(yīng)用程序性能。感興趣的可以了解一下
    2021-05-05
  • C# ref and out的使用小結(jié)

    C# ref and out的使用小結(jié)

    這篇文章主要介紹了C# ref and out的使用小結(jié),幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-03-03
  • C#、ASP.NET通用擴(kuò)展工具類之LogicSugar

    C#、ASP.NET通用擴(kuò)展工具類之LogicSugar

    這篇文章主要介紹了C#、ASP.NET通用擴(kuò)展工具類之LogicSugar,本文直接給出實(shí)現(xiàn)代碼和使用方法示例,需要的朋友可以參考下
    2015-06-06
  • c#中文gbk編碼查詢示例代碼

    c#中文gbk編碼查詢示例代碼

    c#中文gbk編碼查詢示例,大家參考使用吧
    2013-12-12
  • WPF自定義路由事件的實(shí)例教程

    WPF自定義路由事件的實(shí)例教程

    &#65279;WPF中有兩種事件模型,一種是在WinForm時(shí)代就存在的CLR事件,另一種是WPF時(shí)代的路由事件,這篇文章主要給大家介紹了關(guān)于WPF自定義路由事件的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • C#如何實(shí)現(xiàn)對(duì)sql server數(shù)據(jù)庫(kù)的增刪改查

    C#如何實(shí)現(xiàn)對(duì)sql server數(shù)據(jù)庫(kù)的增刪改查

    本文的主要內(nèi)容是C#實(shí)現(xiàn)對(duì)sql server數(shù)據(jù)庫(kù)的增刪改查,示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-08-08
  • C#排序算法的比較分析

    C#排序算法的比較分析

    這篇文章主要介紹了C#排序算法的比較,實(shí)例分析幾種比較常見(jiàn)的算法,并對(duì)其時(shí)間復(fù)雜度與穩(wěn)定性進(jìn)行了詳細(xì)的分析,需要的朋友可以參考下
    2014-11-11
  • Unity利用材質(zhì)自發(fā)光實(shí)現(xiàn)物體閃爍

    Unity利用材質(zhì)自發(fā)光實(shí)現(xiàn)物體閃爍

    這篇文章主要為大家詳細(xì)介紹了Unity利用材質(zhì)自發(fā)光實(shí)現(xiàn)物體閃爍,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-04-04

最新評(píng)論