NMDanny

Cube

Feb 27th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Cube2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Player Danny=new Player();
  14.             Player Moshe=new Player();
  15.             bool doub = false;
  16.             while (Danny.Win() != true && Moshe.Win() != true)
  17.             {
  18.                 doub = Danny.Roll(doub);
  19.                 Console.WriteLine("Danny's sum is " + Danny.getPoints());
  20.                 doub = Moshe.Roll(doub);
  21.                 Console.WriteLine("Moshe's sum is " + Moshe.getPoints());
  22.             }
  23.             if (Danny.Win() == true && Moshe.Win() == true)
  24.                 Console.WriteLine("Tie");
  25.             else if (Danny.Win() == true && Moshe.Win() == false)
  26.                 Console.WriteLine("Danny won");
  27.             else Console.WriteLine("Moshe won");
  28.         }
  29.     }
  30.     class Player
  31.     {
  32.         private int points;
  33.         public Player()
  34.         {
  35.             points = 0;
  36.         }
  37.         public bool Roll(bool doublePoints) // מציבים האם השחקן הקודם קיבל דאבל
  38.         {
  39.            
  40.             Random rand = new Random();
  41.             int R1 = rand.Next(1, 7);
  42.             rand = new Random(points++); //  points++ כדי שהראנדום ישתנה כל הטלת קובייה
  43.             int R2 = rand.Next(1, 7);
  44.             if (doublePoints == true) // אם לשחקן הקודם היה דאבל, אז השחקן עכשיו יקבל פי 2 ניקוד
  45.                 points = points + 2 * (R1 + R2);
  46.             else
  47.                 points = points + R1 + R2;
  48.             return (R1 == R2); // אם השחקן עכשיו קיבל דאבל, אז זה מחזיר אמת
  49.         }
  50.         public int getPoints()
  51.         {
  52.             return points;
  53.         }
  54.         public bool Win()
  55.         {
  56.             if (points >= 100)
  57.                 return true;
  58.             else return false;
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment