Last active
August 29, 2015 14:24
-
-
Save 200even/a17a8a3f320b3333e4aa to your computer and use it in GitHub Desktop.
Scott Day 3 Pig Dice Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Pig_Game | |
{ | |
//class Player | |
//{ | |
// public string Name; | |
// public int Bank; | |
// public int TurnsTaken; | |
//} | |
class Program | |
{ | |
//Player[] pigPlayers = new Player[2]; | |
static int bank = 0; | |
static int currentPlayer = 0; | |
static void Main(string[] args) | |
{ | |
PromptAndClear("Welcome to Pig!"); | |
bool gameOver = false; | |
int turnTotal = 0; | |
while (!gameOver) | |
{ | |
if (currentPlayer == 0) | |
{ | |
Console.WriteLine("Player {0}", currentPlayer + 1); | |
int dice = RollDice(); | |
displayDice(dice); | |
Console.WriteLine("You rolled a {0}", dice); | |
if (dice == 1) | |
{ | |
PromptAndClear("Hit enter to start next turn."); | |
//Next turn | |
turnTotal = 0; | |
currentPlayer++; | |
continue; | |
} | |
turnTotal += dice; | |
if (bank + turnTotal >= 100) | |
{ | |
PromptAndClear("You reached 100!"); | |
gameOver = true; | |
continue; | |
} | |
//Choose continue or next turn | |
Console.WriteLine("Your total is {0}. Your total for this round is {1}.", bank, turnTotal); | |
int choice = HoldOrRoll(); | |
switch (choice) | |
{ | |
case 1: | |
break; | |
default: //all other choices are treated as continuing turn | |
bank += turnTotal; | |
turnTotal = 0; | |
PromptAndClear(string.Format("Your current total is {0}. Press enter to continue.", bank)); | |
currentPlayer++; | |
continue; | |
} | |
} | |
if (currentPlayer == 1) | |
{ | |
Console.WriteLine("Player {0}", currentPlayer + 1); | |
int dice = RollDice(); | |
displayDice(dice); | |
Console.WriteLine("You rolled a {0}", dice); | |
if (dice == 1) | |
{ | |
PromptAndClear("Hit enter to start next turn."); | |
turnTotal = 0; | |
currentPlayer = switchPlayer(currentPlayer); | |
continue; | |
} | |
turnTotal += dice; | |
if (bank + turnTotal >= 100) | |
{ | |
PromptAndClear("You reached 100!"); | |
gameOver = true; | |
continue; | |
} | |
//Choose continue or next turn | |
Console.WriteLine("Your total is {0}. Your total for this round is {1}.", bank, turnTotal); | |
int choice = HoldOrRoll(); | |
switch (choice) | |
{ | |
case 1: | |
break; | |
default: //all other choices are treated as continuing turn | |
//Add wallet to bank, clear wallet, and roll function | |
bank += turnTotal; | |
turnTotal = 0; | |
PromptAndClear(string.Format("Your current total is {0}. Press enter to continue.", bank)); | |
//Switch to next player | |
currentPlayer = switchPlayer(currentPlayer); | |
continue; | |
} | |
} | |
} | |
} | |
private static void displayDice(int dice) | |
{ | |
switch (dice) | |
{ | |
case 1: | |
Console.WriteLine(" -------"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | O |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" -------"); | |
break; | |
case 2: | |
Console.WriteLine(" -------"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | O O |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" -------"); | |
break; | |
case 3: | |
Console.WriteLine(" -------"); | |
Console.WriteLine(" | O |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | O |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | O |"); | |
Console.WriteLine(" -------"); | |
break; | |
case 4: | |
Console.WriteLine(" -------"); | |
Console.WriteLine(" | O O |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | O O |"); | |
Console.WriteLine(" -------"); | |
break; | |
case 5: | |
Console.WriteLine(" -------"); | |
Console.WriteLine(" | O O |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | O |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | O O |"); | |
Console.WriteLine(" -------"); | |
break; | |
case 6: | |
Console.WriteLine(" -------"); | |
Console.WriteLine(" | O O |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | O O |"); | |
Console.WriteLine(" | |"); | |
Console.WriteLine(" | O O |"); | |
Console.WriteLine(" -------"); | |
break; | |
default: | |
break; | |
} | |
} | |
private static int switchPlayer(int currentPlayer) | |
{ | |
currentPlayer++; | |
if (currentPlayer > 1) | |
{ | |
currentPlayer = 0; | |
} | |
return currentPlayer; | |
} | |
private static void PromptAndClear(string message) | |
{ | |
Console.WriteLine(message); | |
Console.ReadLine(); | |
Console.Clear(); | |
} | |
private static int HoldOrRoll() | |
{ | |
Console.WriteLine("Continue (1) or hold (2) and move to next turn."); | |
string input = Console.ReadLine(); | |
int choice; | |
while (!int.TryParse(input, out choice)) | |
{ | |
Console.WriteLine("Invalid choice. Try again."); | |
input = Console.ReadLine(); | |
} | |
return choice; | |
} | |
private static int RollDice() | |
{ | |
Random rnd = new Random(); | |
int dice = rnd.Next(1, 7); // creates a number between 1 and 6 | |
return dice; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment