Guest User

Untitled

a guest
Jun 17th, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.88 KB | None | 0 0
  1. using System;
  2.  
  3. namespace LeftRightCenter
  4. {
  5.     class Player
  6.     {
  7.         //fields       
  8.         private int _quarters = 4;
  9.         private string _name = "";
  10.        
  11.         public int Quarters {
  12.             get{ return _quarters; }
  13.             set{ _quarters += value; }
  14.         }
  15.        
  16.         public string Name{ get { return _name;}}
  17.        
  18.         public Player(string name)
  19.         {
  20.             _name = name;    
  21.         }
  22.        
  23.     }
  24.     class Dice
  25.     {  
  26.         Random _random = new Random ();
  27.         public int Roll ()
  28.         {          
  29.             int diceSide;
  30.             diceSide = _random.Next (0, 6);
  31.             diceSide = (diceSide > 2) ? 3 : diceSide;          
  32.             return diceSide;           
  33.         }
  34.         public Dice ()
  35.         {
  36.         }
  37.        
  38.     }
  39.     class MainClass
  40.     {
  41.         static int activePlayer = 0;
  42.         static int theCup       = 0;
  43.        
  44.         static Player[] thePlayers = {
  45.             new Player ("Jessica"),
  46.             new Player ("Isaac"),
  47.             new Player ("Ed"),
  48.             new Player ("Bella"),
  49.             new Player ("Elisa"),
  50.             new Player ("Fake RedHead"),
  51.             new Player ("Linda"),
  52.             new Player ("MJ"),
  53.             new Player ("Irene"),
  54.             new Player("Devin")
  55.         };
  56.        
  57.         static Dice[] theDice = new Dice[3]{new Dice(), new Dice(), new Dice()};                       
  58.        
  59.         private static void MoveQuarter (int direction)
  60.         {          
  61.             int numberOfPlayers = thePlayers.Length - 1;           
  62.             switch (direction) {
  63.             case 0:
  64.                 Console.WriteLine (thePlayers [activePlayer].Name + " Rolls Center");
  65.                 thePlayers [activePlayer].Quarters = -1;
  66.                 theCup++;
  67.                 break;
  68.             case 1:
  69.                 Console.WriteLine (thePlayers [activePlayer].Name + " Rolls Left");
  70.                 thePlayers [activePlayer].Quarters = -1;
  71.                 int leftPlayer = (activePlayer == 0) ? numberOfPlayers : activePlayer - 1;
  72.                 thePlayers [leftPlayer].Quarters = +1;
  73.                 break;
  74.             case 2:
  75.                 Console.WriteLine (thePlayers [activePlayer].Name + " Rolls Right");
  76.                 thePlayers [activePlayer].Quarters = -1;
  77.                 int rightPlayer = (activePlayer == numberOfPlayers) ? 0 : activePlayer + 1;
  78.                 thePlayers [rightPlayer].Quarters = +1;
  79.                 break;                         
  80.             default:
  81.                 Console.WriteLine (thePlayers [activePlayer].Name + " Rolls Dot");
  82.                 break;
  83.             }          
  84.            
  85.         }
  86.        
  87.         public static void Main (string[] args)
  88.         {
  89.             int cupEndPoint = thePlayers.Length * 4 - 1;                           
  90.             while (theCup < cupEndPoint) {
  91.                 activePlayer = (activePlayer < thePlayers.Length - 1) ? activePlayer + 1 : 0;
  92.                 if (thePlayers [activePlayer].Quarters == 0) {
  93.                     continue;
  94.                 }
  95.                 foreach (Dice rattle in theDice) {                 
  96.                     if (thePlayers [activePlayer].Quarters > 0 && theCup < cupEndPoint) {                      
  97.                         MoveQuarter (rattle.Roll ());  
  98.                     }                  
  99.                 }
  100.                 Console.WriteLine (
  101.                     thePlayers [activePlayer].Name + " now has {0} Quarters and there are {1} Quarters In the Cup",
  102.                     thePlayers [activePlayer].Quarters,
  103.                     theCup
  104.                 );
  105.             }
  106.             foreach (Player player in thePlayers) {
  107.                 if (player.Quarters == 1) {
  108.                     Console.WriteLine (player.Name + " WINS! and recieves {0} QUARTERS!", theCup + 1);
  109.                 } else {
  110.                     continue;
  111.                 }
  112.             }
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment