c#對戰遊戲

來源:互聯網
上載者:User

標籤:amp   else   shang   alt   ret   sleep   bsp   分享   color   

namespace 對戰遊戲
{
       class Program
    {
        public struct ZhanShi
        {
            public string MingZi;
            public int GongJi;
            public int XueLiang;
        }


        static void Main(string[] args)
        {
         建立戰士給戰士賦予屬性
            ZhanShi zs1 = new ZhanShi();
            zs1.MingZi = "張無忌";
            zs1.GongJi = 100;
            zs1.XueLiang = 1000;

            ZhanShi zs2 = new ZhanShi();
            zs2.MingZi = "洪七公";
            zs2.GongJi = 150;
            zs2.XueLiang = 700;
       
            //對打
            while (true)
            {
                int ShangHai = Program.PuTongGongJi(zs1.GongJi);
                zs2.XueLiang = zs2.XueLiang - ShangHai;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(zs1.MingZi + " 對 " + zs2.MingZi + " 發動了普通攻擊,造成了" + ShangHai + "點傷害, " + zs2.MingZi + " 剩餘" + zs2.XueLiang + "點血量!");
                Console.WriteLine();
                System.Threading.Thread.Sleep(1000);

                ShangHai = Program.PuTongGongJi(zs2.GongJi);
                zs1.XueLiang = zs1.XueLiang - ShangHai;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(zs2.MingZi + " 對 " + zs1.MingZi + " 發動了普通攻擊,造成了" + ShangHai + "點傷害, " + zs1.MingZi + " 剩餘" + zs1.XueLiang + "點血量!");
                Console.WriteLine();

                System.Threading.Thread.Sleep(1000);

                if (zs1.XueLiang <= 0 || zs2.XueLiang <= 0)
                {
                    if (zs1.XueLiang <= 0 && zs2.XueLiang <= 0)
                    {
                        Console.WriteLine("二位同歸於盡了!!!");
                    }
                    else
                    {
                        if (zs1.XueLiang <= 0)
                        {
                            Console.WriteLine(zs2.MingZi + "獲得了最終勝利!!!");
                        }
                        else
                        {
                            Console.WriteLine(zs1.MingZi + "獲得了最終勝利!!!");
                        }
                    }
                    break;
                }
            }

            //判斷輸贏


            Console.ReadKey();
        }
                      產生浮動攻擊力
        /// <summary>
        /// 產生普通攻擊的浮動攻擊值
        /// </summary>
        /// <param name="a">普通攻擊的基礎攻擊力</param>
        /// <returns></returns>
        public static int PuTongGongJi(int a)
        {
            int cc = 0;
            Random r = new Random();
            int aa = r.Next(0, 141);
            int bb = r.Next(0, 2);
            if (bb == 0)
            {
                cc = a + aa;
            }
            else
            {
                cc = a - aa;
            }
            return cc;
        }
    }
}

c#對戰遊戲

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.