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

C#實(shí)現(xiàn)飛行棋源碼

 更新時(shí)間:2020年02月05日 15:18:49   作者:張三千8800  
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)飛行棋源碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

游戲規(guī)則

如果玩家A踩到了玩家B,玩家B退6格
踩到了1幸運(yùn)輪盤,a交換位置,b轟炸對(duì)方使對(duì)方退6格
踩到了2地雷,退6格
踩到了3暫停,暫停一回合
踩到了4時(shí)空隧道,進(jìn)10格
踩到了方塊,什么都不干
0表示普通關(guān)卡
1表示幸運(yùn)輪盤◎
2表示地雷★
3表示暫?!?br /> 4表示時(shí)空隧道卍

關(guān)于飛行棋源碼的解析,下一篇文章發(fā)出。

源碼

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

namespace 飛行棋
{
 class Program
 {
  //我們用靜態(tài)字段來模擬全局變量
  static int[] Maps=new int[100];
  //聲明一個(gè)靜態(tài)字段的數(shù)組用來存儲(chǔ)玩家A和玩家B的坐標(biāo)
  static int[] playerPos = new int[2];
  //存儲(chǔ)兩個(gè)玩家的姓名
  static string[] playerNames = new string[2];
  //兩個(gè)玩家的標(biāo)記
  static bool[] flags = new bool[2]; //flags[0]玩家A和flags[1]玩家B默認(rèn)都是false
  static void Main(string[] args)
  {
   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("姓名不能為空,請(qǐng)重新輸入");
     playerNames[1] = Console.ReadLine();
    }
    else
    {
     Console.WriteLine("玩家B姓名不能重復(fù),請(qǐng)重新輸入");
     playerNames[1] = Console.ReadLine();
    }
   }
   #endregion
   //玩家姓名寫好后,進(jìn)行清屏
   Console.Clear(); //清屏
   GameShow();
   Console.WriteLine("{0}的士兵用A表示", playerNames[0]);
   Console.WriteLine("{0}的士兵用B表示", playerNames[1]);
   Initailmap(); //初始化地圖
   DrowMap();  //畫出地圖---注意:畫地圖前首先應(yīng)初始化地圖

   //當(dāng)玩家A和玩家B沒有一個(gè)人到達(dá)終點(diǎn)的時(shí)候都在游戲中
   while (playerPos[0] < 99 && playerPos[1] < 99)
   {
    if (flags[0] == false)
    {
     PlayGame(0);     
    }
    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;
    }
   }
   Console.ReadKey();
  }
  /// <summary>
  /// 設(shè)置游戲頭及輸出內(nèi)容的顏色
  /// </summary>
  public static void GameShow()
  {
   Console.ForegroundColor = ConsoleColor.Blue;  //設(shè)置輸出內(nèi)容的前景色
   Console.WriteLine("**********************");
   Console.ForegroundColor = ConsoleColor.Cyan;
   Console.WriteLine("**********************");
   Console.ForegroundColor = ConsoleColor.Red;
   Console.WriteLine("******飛行棋大戰(zhàn)******");
   Console.ForegroundColor = ConsoleColor.Yellow;
   Console.WriteLine("**********************");
   Console.ForegroundColor = ConsoleColor.DarkGray;
   Console.WriteLine("**********************");
   Console.ForegroundColor = ConsoleColor.Green;
   Console.WriteLine("**********************");
  }
  /// <summary>
  /// 初始化地圖
  /// </summary>
  public static void Initailmap()
  {
   int[] lucklyturn = { 6, 23, 40, 55, 69, 83 }; //幸運(yùn)輪盤
   for (int i = 0; i < lucklyturn.Length; i++)
   {
    int index = lucklyturn[i];  
    Maps[index] = 1; //將幸運(yùn)輪盤的位置處值都設(shè)為1
   }
   int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷
   for (int i = 0; i < landMine.Length; i++)
   {
    int index = landMine[i];
    Maps[index] = 2;  //將地雷的位置處值都設(shè)為2
   }
   int[] pause = { 9, 27, 60, 93 }; //暫停
   for (int i = 0; i < pause.Length; i++)
   {
    int index = pause[i];
    Maps[index] = 3;  //將暫停的位置處值都設(shè)為3
   }
   int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//時(shí)空隧道
   for (int i = 0; i <timeTunnel.Length; i++)
   {
    int index=timeTunnel[i];
    Maps[index] = 4;  //將時(shí)空隧道的位置處值都設(shè)為4
   }
  }
  /// <summary>
  /// 畫出地圖
  /// </summary>
  public static void DrowMap()
  {
   Console.WriteLine("圖例:普通方塊:□ 幸運(yùn)輪盤:◎ 地雷:★  暫停:▲  時(shí)空隧道:卍");
   //第一橫行0--29
   for (int i = 0; i <= 29; i++)
   {
    Console.Write(DrowStringMap(i)); //輸出返回的當(dāng)前單元格的圖形
   }
   //畫完第一行后換行
   Console.WriteLine();
   //第一豎行30--34
   for (int i = 30; i <= 34; i++)
   {
    for (int j = 0; j < 29; j++)
    {
     Console.Write(" "); //兩個(gè)空格
    }
    Console.Write(DrowStringMap(i)); 
    Console.WriteLine(); 
   }
   //第二橫行35--64
   for (int i = 64; i >=35; i--)
   {
    Console.Write(DrowStringMap(i));
   }
   //第二橫行打印完后換行
   Console.WriteLine();
   //第二豎行65--69
   for (int i = 65; i <= 69; i++)
   {
    Console.Write(DrowStringMap(i));
    Console.WriteLine();
   }
   //第三橫行70--99
   for (int i = 70; i <= 99; i++)
   {
    Console.Write(DrowStringMap(i));
   }
   Console.WriteLine(); //畫完最后一行地圖后應(yīng)該換行
  }
  /// <summary>
  /// 畫當(dāng)前的單元格的圖案
  /// </summary>
  /// <param name="i">傳入當(dāng)前單元格的索引</param>
  /// <returns>返回當(dāng)前單元格的圖形</returns>
  public static string DrowStringMap(int i)
  {
   string str = " ";
    //如果玩家A和玩家B的坐標(biāo)相同并且都在地圖上畫一個(gè)<>(因?yàn)閯傞_始和結(jié)束的時(shí)候玩家可能去地圖外)
    if (playerPos[0] == playerPos[1] && playerPos[0] == i)
    {
     Console.ForegroundColor = ConsoleColor.Blue;
     str="<>";
    }
    else if (playerPos[0] == i)
    {
     Console.ForegroundColor = ConsoleColor.Blue;
     str="A";
    }
    else if (playerPos[1] == i)
    {
     Console.ForegroundColor = ConsoleColor.Blue;
     str="B";
    }
    else
    {
     switch (Maps[i])
     {
      case 0:
       Console.ForegroundColor = ConsoleColor.DarkYellow;
       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;
     }
    } //else
    return str;
  }
  /// <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); //ReadKey是重載函數(shù),里面參數(shù)為true表示不顯示按下的鍵。
   Console.WriteLine("{0}擲出了{(lán)1}", playerNames[playerNumber], rNumber);
   Console.ReadKey(true);
   Console.WriteLine("{0}按任意鍵開始行動(dòng)", playerNames[playerNumber]);
   Console.ReadKey(true);
   playerPos[playerNumber] += rNumber;
   ChangePos();
   Console.WriteLine("玩家{0}行動(dòng)完了", playerNames[playerNumber]);
   Console.ReadKey(true);
   //玩家A有可能踩到玩家B
   if (playerPos[playerNumber] == playerPos[1 - playerNumber])
   {
    Console.WriteLine("玩家{0}踩到了玩家{1},{2}退6格", playerNames[0], playerNames[1], playerNames[1]);
    playerPos[1 - playerNumber] -= 6;  //如果玩家A踩到了玩家B,玩家B退6格
    ChangePos();
    Console.ReadKey(true);
   }
   //玩家A有可能踩到方塊,時(shí)空隧道,暫停,地雷,幸運(yùn)輪盤
   else
   {
    switch (Maps[playerPos[playerNumber]])
    {
     case 0:
      Console.WriteLine("玩家{0}踩到了方塊,安全", playerNames[playerNumber]);
      Console.ReadKey(true);
      break;
     case 1:
      Console.WriteLine("玩家{0}踩到了幸運(yùn)輪盤,請(qǐng)選擇a換位置;b轟炸對(duì)方,讓對(duì)方退6格", playerNames[playerNumber]);
      string input = Console.ReadLine();
      while (true)
      {
       if (input == "a")
       {
        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("玩家{0}和玩家{1}位置交換成功,按任意鍵繼續(xù)游戲。", playerNames[playerNumber], playerNames[1 - playerNumber]);
        Console.ReadKey(true);
        break;
       }
       else if (input == "b")
       {
        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("只能輸入a或者b,輸入錯(cuò)誤,請(qǐng)重新輸入");
        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}踩到了時(shí)空隧道,前進(jìn)10格", playerNames[playerNumber]);
      playerPos[playerNumber] += 10;
      ChangePos();
      break;
    } //switch
   } //else
   ChangePos();
   Console.Clear();
   //清屏
   DrowMap();  //重新畫
  }
  /// <summary>
  /// 當(dāng)玩家坐標(biāo)發(fā)生改變的時(shí)候調(diào)用
  /// </summary>
  public static void ChangePos()
  {
   if (playerPos[0] < 0)
   {
    playerPos[0] = 0;
   }
   else if (playerPos[0] >99)
   {
    playerPos[0] = 99;
   }
   else if (playerPos[1] < 0)
   {
    playerPos[1] = 0;
   }
   else if (playerPos[1] > 99)
   {
    playerPos[1] = 99;
   }
   
  }
 }
}

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

相關(guān)文章

  • 在Linux上運(yùn)行C#的方法

    在Linux上運(yùn)行C#的方法

    這篇文章主要介紹了在Linux上運(yùn)行C#的方法,實(shí)例分析了Linux平臺(tái)下Mono軟件包的應(yīng)用技巧,以及在此基礎(chǔ)之上的C#運(yùn)行方法,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2014-12-12
  • C#如何自動(dòng)選擇出系統(tǒng)中最合適的IP地址

    C#如何自動(dòng)選擇出系統(tǒng)中最合適的IP地址

    這篇文章介紹了C#如何自動(dòng)選擇出系統(tǒng)中最合適的IP地址,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-08-08
  • 淺析C#中的AsnycLocal與ThreadLocal

    淺析C#中的AsnycLocal與ThreadLocal

    這篇文章主要給大家介紹了關(guān)于C#中AsnycLocal與ThreadLocal的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-09-09
  • c#中的yield?return用法詳解

    c#中的yield?return用法詳解

    這篇文章主要介紹了c#中的yield?return用法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09
  • DevExpress實(shí)現(xiàn)TreeList向上遞歸獲取符合條件的父節(jié)點(diǎn)

    DevExpress實(shí)現(xiàn)TreeList向上遞歸獲取符合條件的父節(jié)點(diǎn)

    這篇文章主要介紹了DevExpress實(shí)現(xiàn)TreeList向上遞歸獲取符合條件的父節(jié)點(diǎn),需要的朋友可以參考下
    2014-08-08
  • C#單線程和多線程端口掃描器詳解

    C#單線程和多線程端口掃描器詳解

    這篇文章主要為大家詳細(xì)介紹了C#單線程和多線程端口掃描器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • 深入分析c# 繼承

    深入分析c# 繼承

    這篇文章主要介紹了c# 繼承的相關(guān)資料,文中講解的非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • C#中讀取XML文件的四種常用方法

    C#中讀取XML文件的四種常用方法

    Xml是Internet環(huán)境中跨平臺(tái)的,依賴于內(nèi)容的技術(shù),是當(dāng)前處理結(jié)構(gòu)化文檔信息的有力工具,下面我們就來看看C#中讀取XML文件的方法都有哪些吧
    2025-02-02
  • choosesubject c# switch

    choosesubject c# switch

    c# switch 實(shí)例代碼。
    2009-07-07
  • C#并查集(union-find)算法詳解

    C#并查集(union-find)算法詳解

    本文詳細(xì)講解了C#并查集(union-find)算法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04

最新評(píng)論

英超| 南宫市| 林甸县| 故城县| 田阳县| 嵊州市| 绥江县| 托克托县| 德州市| 丰原市| 土默特左旗| 公主岭市| 青州市| 尚义县| 永平县| 临颍县| 扎赉特旗| 河北省| 高邑县| 西青区| 巫溪县| 陈巴尔虎旗| 秦皇岛市| 景东| 平陆县| 彭州市| 论坛| 镇坪县| 宣威市| 陵川县| 桓台县| 鹿泉市| 庆元县| 南城县| 阿勒泰市| 泽普县| 张家界市| 江都市| 秦安县| 井冈山市| 龙胜|