DOC

SystemCollectionsGeneric

By Roy Hughes,2014-11-11 02:13
13 views 0
SystemCollectionsGeneric

using System;

    using System.Collections.Generic;

    using System.Text;

namespace homework3_27

    {

     class Program

     {

     static void Main(string[] args)

     {

     int game = 0, newgm =0, pmy = 1000, cmy = 1000, con = 0;

     while (newgm >=0)

     {

     Console.Write("\n ++ Johnny21點遊戲 ++ (請按任意鍵開始)");

     Console.ReadLine();

     do

     {

     int a = 0, b = 0, an = 0, bn = 0, pa = 0, ca = 0, ean, n, i, cs, win;

     int pt = 0,ppt = 0, ppt1 = 0, ppt2 = 0,cpt = 0, cpt1 = 0, cpt2 = 0, pcn = 0, ccn = 0;

     char kk;

     string nn = "", cd = "", pcd = "玩家的牌:", ccd = "電腦的牌:", pv = ccd, rcpt = "", rppt = "";

     Random ro = new Random();

     con++;

     Console.WriteLine("\n==================={0}局開始===================\n", con);

     Console.WriteLine("玩家籌碼:{0,4:C0} 電腦籌碼:{1,4:C0}", pmy, cmy);

     do

     {

     Console.Write("一場10元為底,要再多加多少籌碼?");

     ean = Convert.ToInt32(Console.ReadLine()) + 10;

     if (ean > pmy)

     Console.WriteLine("你沒那麼多籌碼喔!請再輸入一次!");

     }

     while (ean > pmy);

     for (i = 1; i <= 10; i++)

     {

     pt = 0;

     kk = (char)(ro.Next(4) + 3);

     n = ro.Next(13) + 1;

     //n = Convert.ToInt32(Console.ReadLine());

     nn = (n == 1) ? "A" : (n == 11) ? "J" : (n == 12) ? "Q" : (n == 13) ? "K" : Convert.ToString(n);

     cd = "(" + kk + nn + ")";

     pt = (n > 10) ? 10 : n;

     if (i == 1 || i == 3 || an > 0)

     {

     ccd = ccd + cd;

     ca = (n == 1) ? ca + 1 : ca;

     cpt1 = cpt1 + pt;

     cpt2 = (ca > 0) ? cpt1 + 10 : cpt1;

     cpt = (cpt2 > 21) ? cpt1 : cpt2;

     ccn++;

     }

     if (i == 2 || i == 4 || bn > 0)

     {

     pcd = pcd + cd;

     pa = (n == 1) ? pa + 1 : pa ;

     ppt1 = ppt1 + pt;

     ppt2 = (pa > 0) ? 10 + ppt1 : ppt1;

     ppt = (ppt2 > 21) ? ppt1 : ppt2;

     //Console.WriteLine("pa:{0} ppt1:{1} ppt2:{2}",pa,ppt1,ppt2);

     pcn++;

     }

     cs = (an == -1 && bn == -1) ? i - 1 : i;

     pv = (i == 3) ? pv + "(??)" + cd : (bn == -1) ? ccd : pv;

     if (i >= 4)

     {

     Console.WriteLine("\n===================我是分隔線===================\n");

     Console.WriteLine("發牌次數{0}", cs);

     Console.WriteLine(pv);

     Console.WriteLine(pcd);

     }

     rppt = (pcn == 5 && ppt1 <= 21) ? "BLACK JACK!!" : Convert.ToString(ppt);

     rcpt = (ccn == 5 && cpt1 <= 21) ? "BLACK JACK!!" : Convert.ToString(cpt);

     if (pcn == 5 || ppt1 == 21 || ppt2 == 21)

     {

     Console.WriteLine("你目前點數:{0}", rppt);

     b = 0;

     bn = -1;

     }

     if (ppt1 > 21)

     {

     Console.WriteLine("你的牌爆掉了~~!");

     b = 0;

     bn = -1;

     }

     if (cpt1 > 21)

     {

     Console.WriteLine("電腦的牌爆掉了~~!");

     a = 0;

     an = -1;

     break;

     }

     if (a == 0 && an == -1)

     break;

     b = (i >= 4 && bn >= 0) ? 1 : 0;

     while (b == 1)

     {

     Console.Write("你目前點數:{0},補牌?(輸入\"0\"補牌或輸入\"1\"不補)", rppt);

     if (Console.ReadLine() == "0" || ppt1 < 16)

     {

     bn++;

     b = 0;

     }

     else

     {

     bn = -1;

     b = 0;

     }

     }

     a = (bn == -1) ? 1 : 0;

     while (a == 1)

     {

     if (cpt1 == 21 || ccn == 5 || (cpt >= ppt && ppt <= 21) || (cpt >= 16 && ppt > 21))

     {

     an = -1;

     a = 0;

     break;

     }

     else

     {

     an++;

     a = 0;

     }

     }

     }

     Console.WriteLine("比較結果==>電腦{0},玩家{1}", rcpt, rppt);

     win = (cpt > 21 && ppt > 21) ? 1 : ((ppt <= 21 && pcn == 5 && ccn != 5) || (ppt > cpt && ppt <= 21 && cpt

    <= 21 && ccn != 5) || (cpt > 21 && ppt <= 21)) ? 2 : 3;

     switch (win)

     {

     case 1:

     {

     Console.WriteLine("此局不分勝負!");

     break;

     }

     case 2:

     {

     pmy = pmy + ean;

     cmy = cmy - ean;

     Console.WriteLine("玩家贏得此局,並贏得{0:C0}籌碼,目前你有{1:C0}的籌碼!", ean, pmy);

     break;

     }

     case 3:

     {

     pmy = pmy - ean;

     cmy = cmy + ean;

     Console.WriteLine("玩家輸掉此局,並輸掉{0:C0}籌碼,目前你有{1:C0}的籌碼!", ean, pmy);

     break;

     }

     }

     Console.WriteLine("\n==================={0}局結束===================\n", con);

     if (pmy <= 0)

     {

     Console.WriteLine("很抱歉!你的籌碼為{0:C0}!\n *****GAME OVER*****", pmy);

     break;

     }

     if (cmy <= 0)

     {

     Console.WriteLine("電腦的籌碼都被你贏光了~~!\n也許你比比爾蓋茲還聰明呢!\nGAME OVER");

     break;

     }

     Console.Write("\"0\"結束目前遊戲或按任意鍵繼續:");

     if (Console.ReadLine() == "0")

     game = -1;

     else

     {

     game++;

     }

     }

     while (game >= 0);

     Console.Write("(1)開啟新遊戲\n(2)不玩了!\n請選擇:");

     if (Console.ReadLine() == "1")

     {

     pmy = 1000; cmy = 1000;

     Console.Write("新遊戲開啟中......\n\n");

     newgm++;

     }

     else

     {

     Console.Write("遊戲關閉中......");

     newgm = -1;

     }

     }

     }

     }

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com