- 最後登錄
- 2023-5-31
- 在線時間
- 0 小時
- 註冊時間
- 2008-1-20
- 閱讀權限
- 30
- 精華
- 0
- UID
- 3315428
- 帖子
- 317
- 積分
- 1000 點
- 潛水值
- 16095 米
| 分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。 FUCK2752186 發表於 2014-7-6 04:18 PM
程式不太會寫...,大大的程式,小弟我實在霧煞煞XD
目前小弟我只會寫兩人擲骰子 (PS.我忘了說我是在練ASP ...
我寫的程式。- // 三人丟骰子,比較輸贏
- private void ThreeDice()
- {
- int pointA = this.DicePoint();
- int pointB = this.DicePoint();
- int pointC = this.DicePoint();
- string result = this.DiceResult(pointA, pointB, pointC);
- Console.WriteLine("A的點數: {0}", pointA);
- Console.WriteLine("B的點數: {0}", pointB);
- Console.WriteLine("C的點數: {0}", pointC);
- Console.WriteLine(result);
- Console.WriteLine();
- }
- // 丟出骰子,得到點數
- private int DicePoint()
- {
- Random r = new Random(Guid.NewGuid().GetHashCode());
- return r.Next(1, 7);
- }
- // 輸贏結果
- private string DiceResult(int pointA, int pointB, int pointC)
- {
- int[] pointArray = this.SortFormSmallToBig(pointA, pointB, pointC);
- string result = this.JudgeWinner(pointA, pointB, pointC, pointArray);
- return result;
- }
- // 排序,由小到大
- private int[] SortFormSmallToBig(int pointA, int pointB, int pointC)
- {
- int[] pointArray = { pointA, pointB, pointC };
- Array.Sort(pointArray);
- return pointArray;
- }
- // 判斷贏家
- private string JudgeWinner(int pointA, int pointB, int pointC, int[] sortedPoint)
- {
- string result = null;
- int max = sortedPoint[2];
- int mid = sortedPoint[1];
- int min = sortedPoint[0];
- if (max == min)
- {
- result = "三人平手";
- }
- else if (max == mid)
- {
- if (pointC == min)
- {
- result = "A與B平手獲勝";
- }
- else if (pointB == min)
- {
- result = "A與C平手獲勝";
- }
- else
- {
- result = "B與C平手獲勝";
- }
- }
- else
- {
- if (pointA == max)
- {
- result = "A獲勝";
- }
- else if (pointB == max)
- {
- result = "B獲勝";
- }
- else
- {
- result = "C獲勝";
- }
- }
- return result;
- }
複製代碼 ...
|
|