Created
October 10, 2012 09:53
-
-
Save NikkiBuck/3864450 to your computer and use it in GitHub Desktop.
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
CLASS | |
namespace DiceGame | |
{ | |
class TwoDice | |
{ | |
private static string filepath = @"C:\Users\Talia\Desktop\PROG 120\DiceGame\dice\"; | |
private int value; | |
private Image image1; | |
private Image image2; | |
private Image image3; | |
private Image image4; | |
private Image image5; | |
private Image image6; | |
public TwoDice() | |
{ | |
value = 1; | |
image1 = Image.FromFile(filepath + "die-1.gif"); | |
image2 = Image.FromFile(filepath + "die-2.gif"); | |
image3 = Image.FromFile(filepath + "die-3.gif"); | |
image4 = Image.FromFile(filepath + "die-4.gif"); | |
image5 = Image.FromFile(filepath + "die-5.gif"); | |
image6 = Image.FromFile(filepath + "die-6.gif"); | |
} | |
public void Roll() | |
{ | |
Random r = new Random(); | |
value = r.Next(1, 7); | |
} | |
public int getValue() | |
{ | |
return value; | |
} | |
public Image getImage() | |
{ | |
if (value == 1) | |
{ | |
return image1; | |
} | |
else if (value == 2) | |
{ | |
return image2; | |
} | |
else if (value == 3) | |
{ | |
return image3; | |
} | |
else if (value == 4) | |
{ | |
return image4; | |
} | |
else if (value == 5) | |
{ | |
return image5; | |
} | |
else return image6; | |
} | |
public string ValueToString() | |
{ | |
return value.ToString(); | |
} | |
} | |
} | |
========================================================================== | |
FORM | |
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Windows.Forms; | |
namespace DiceGame | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
int sum1; | |
int sum2; | |
int dealer = 0; | |
int player = 0; | |
int games = 0; | |
private void dealerRollButton_Click(object sender, EventArgs e) | |
{ | |
TwoDice dealer1 = new TwoDice(); | |
TwoDice dealer2 = new TwoDice(); | |
dealer1.Roll(); | |
dealer2.Roll(); | |
dealerDice1PicBx.Image = dealer1.getImage(); | |
dealerDice2PicBx.Image = dealer2.getImage(); | |
sum1 = AddItUp(dealer1.ValueToString(), dealer2.ValueToString()); | |
dealerRollLabel.Text = "Dealer got a " + dealer1.ValueToString() + " and a " + dealer2.ValueToString() + ", making a score of " + sum1 + "."; | |
playerRollButton.Enabled = true; | |
dealerRollButton.Enabled = false; | |
} | |
private void playerRollButton_Click(object sender, EventArgs e) | |
{ | |
TwoDice player1 = new TwoDice(); | |
TwoDice player2 = new TwoDice(); | |
player1.Roll(); | |
player2.Roll(); | |
playerDice1PicBx.Image = player1.getImage(); | |
playerDice2PicBx.Image = player2.getImage(); | |
sum2 = AddItUp(player1.ValueToString(), player2.ValueToString()); | |
PlayerRollLabel.Text = "Player got a " + player1.ValueToString() + " and a " + player2.ValueToString() + ", making a score of " + sum2 + "."; | |
ScoreboardUpdate(); | |
playerRollButton.Enabled = false; | |
dealerRollButton.Enabled = true; | |
} | |
private int AddItUp(Object value1, Object value2) | |
{ | |
int sum; | |
sum = Convert.ToInt32(value1) + Convert.ToInt32(value2); | |
return sum; | |
} | |
private void ScoreboardUpdate() | |
{ | |
if (sum1 >= sum2) | |
{ | |
dealer++; | |
dealerWinsTxtBx.Text = Convert.ToString(dealer); | |
outcomeLabel.Text = "Dealer Wins!"; | |
} | |
else | |
{ | |
player++; | |
playerWinsTxtBx.Text = Convert.ToString(player); | |
outcomeLabel.Text ="Player Wins!"; | |
} | |
games++; | |
totalGamesTxtBx.Text = Convert.ToString(games); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment