-
November 28th, 2012, 07:48 AM
#1
Looking for help on dice game.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace project2
{
public partial class pressYourLuck : Form
{
public pressYourLuck()
{
InitializeComponent();
}
// THIS ALL WORKS AND IS COMPLETE
private void beginButton_Click(object sender, EventArgs e)
{
// ENABLE BUTTONS
rollButton.Enabled = true;
startOverButton.Enabled = true;
beginButton.Enabled = false;
messageLabel.Visible = true;
// INITIALIZED BEGINNING EARNINGS
int startEarnings;
startEarnings = 0;
liveEarningsLabel.Text = startEarnings.ToString();
// DISPLAY POP UP MESSAGE TO START GAME
MessageBox.Show("Press your luck and roll again, if you dare!");
}
// PLAYER DICE ROLL WORKS AND IS COMPLETE
private int Playerroll()
{
// ASSIGN VARIABLE AND CREATES RANDOM OBJECT
int roll;
Random rand = new Random();
// GET RANDOM INT FROM 0 - 6
roll = rand.Next(6) + 1;
// DISPLAY DICE BASED ON ROLL
if (roll == 1)
{
rollDicePictureBox.Image = Properties.Resources._1Die;
}
if (roll == 2)
{
rollDicePictureBox.Image = Properties.Resources._2Die;
}
if (roll == 3)
{
rollDicePictureBox.Image = Properties.Resources._3Die;
}
if (roll == 4)
{
rollDicePictureBox.Image = Properties.Resources._4Die;
}
if (roll == 5)
{
rollDicePictureBox.Image = Properties.Resources._5Die;
}
if (roll == 6)
{
rollDicePictureBox.Image = Properties.Resources._6Die;
}
return roll;
}
private void rollButton_Click(object sender, EventArgs e)
{
// IMPORT METHOD FOR DISPLAYING PLAYER ROLL
int playerRoll;
playerRoll = Playerroll();
}
private void startOverButton_Click(object sender, EventArgs e)
{
messageLabel.Text = "";
liveEarningsLabel.Text = "";
rollButton.Enabled = false;
startOverButton.Enabled = false;
messageLabel.Visible = false;
beginButton.Enabled = true;
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
Problem Areas:
Above I have attached my current code to my dice game. I am to complete the following:
I need to set a random max roll a player can roll before the player loses. I know how to create a random number, but my issue is that it keeps resetting the max number. (25 max)
increment players roll, and if exceed max roll the player will lose.
For every successful roll the player will earn $100 and increment.
What I have complete:
I have initialized the program game. when player click begin game all button become active, then initialize message box, and enables players start value.
Start over button will disable all buttons and enable the begin button again.
Roll dice will random between 1 and 6 and display the players dice he or she rolled. In addition, my message box on what the player rolls is complete.
Exit button works.
Any help is appreciated
Best Regards
Josh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|