Dice Poker
#pragma
once
namespace
DicePoker
{
using
namespace System;
using
namespace System::ComponentModel;
using
namespace System::Collections;
using
namespace System::Windows::Forms;
using
namespace System::Data;
using
namespace System::Drawing;
///
<summary>
/// Summary for Form1
///
/// WARNING: If you change the name of
this class, you will need to change the
///
'Resource File Name' property for the managed resource compiler tool
///
associated with all .resx files this class depends on.
Otherwise,
///
the designers will not be able to interact properly with localized
///
resources associated with this form.
///
</summary>
public ref
class Form1 :
public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
<summary>
/// Clean up any resources being used.
///
</summary>
///
<param name="disposing">"description of
the parameter"</param>
private:
System::Windows::Forms::Label^
lblWelcome;
private:
System::Windows::Forms::PictureBox^
pbxDie1;
private:
System::Windows::Forms::PictureBox^
pbxDie2;
private:
System::Windows::Forms::PictureBox^
pbxDie4;
protected:
protected:
private:
System::Windows::Forms::PictureBox^
pbxDie3;
private:
System::Windows::Forms::PictureBox^
pbxDie5;
private:
System::Windows::Forms::CheckBox^
chkDie1;
private:
System::Windows::Forms::CheckBox^
chkDie2;
private:
System::Windows::Forms::CheckBox^
chkDie3;
private:
System::Windows::Forms::CheckBox^
chkDie4;
private:
System::Windows::Forms::CheckBox^
chkDie5;
private:
System::Windows::Forms::CheckBox^
chkKeepAll;
private:
System::Windows::Forms::Button^
btnRollDice;
private:
System::Windows::Forms::Button^
btnExit;
private:
System::Windows::Forms::GroupBox^
grpScoring;
private:
System::Windows::Forms::GroupBox^
grpOutput;
private:
System::Windows::Forms::Timer^
tmrRoll;
private:
System::Windows::Forms::Label^
lblLegend1;
private:
System::Windows::Forms::TextBox^
txtOutput;
private:
System::Windows::Forms::Label^
lblLegend3;
private:
System::Windows::Forms::Label^
lblLegend2;
private:
System::Windows::Forms::ImageList^
imlDiceList;
private:
System::ComponentModel::IContainer^
components;
private:
///
<summary>
/// Required designer variable.
///
</summary>
//Game timer counter
Int32 intTimerCntr;
//Handle for random number generator
Random^ randNumGen;
//Used to control display of Checkbox
controls
Boolean blnExcludeList;
//Number of dollars in player's account
Int32 intTotalDollars;
Int32 intNoOfRolls; //Tracks the number of
die rolls
Int32 intDice1; //Number 1 die
Int32 intDice2; //Number 2 die
Int32 intDice3; //Number 3 die
Int32 intDice4; //Number 4 die
Int32 intDice5; //Number 5 die
#pragma
region
Windows Form Designer generated code
///
<summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
///
</summary>
void InitializeComponent(void)
{
this->components = (gcnew
System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^
resources = (gcnew
System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->lblWelcome = (gcnew
System::Windows::Forms::Label());
this->pbxDie1 = (gcnew
System::Windows::Forms::PictureBox());
this->pbxDie2 = (gcnew
System::Windows::Forms::PictureBox());
this->pbxDie4 = (gcnew
System::Windows::Forms::PictureBox());
this->pbxDie3 = (gcnew
System::Windows::Forms::PictureBox());
this->pbxDie5 = (gcnew
System::Windows::Forms::PictureBox());
this->chkDie1 = (gcnew
System::Windows::Forms::CheckBox());
this->chkDie2 = (gcnew
System::Windows::Forms::CheckBox());
this->chkDie3 = (gcnew
System::Windows::Forms::CheckBox());
this->chkDie4 = (gcnew
System::Windows::Forms::CheckBox());
this->chkDie5 = (gcnew
System::Windows::Forms::CheckBox());
this->chkKeepAll = (gcnew
System::Windows::Forms::CheckBox());
this->btnRollDice = (gcnew
System::Windows::Forms::Button());
this->btnExit = (gcnew
System::Windows::Forms::Button());
this->grpScoring = (gcnew
System::Windows::Forms::GroupBox());
this->lblLegend3 = (gcnew
System::Windows::Forms::Label());
this->lblLegend2 = (gcnew
System::Windows::Forms::Label());
this->lblLegend1 = (gcnew
System::Windows::Forms::Label());
this->grpOutput = (gcnew
System::Windows::Forms::GroupBox());
this->txtOutput = (gcnew
System::Windows::Forms::TextBox());
this->tmrRoll = (gcnew
System::Windows::Forms::Timer(this->components));
this->imlDiceList = (gcnew
System::Windows::Forms::ImageList(this->components));
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie2))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie4))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie3))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie5))->BeginInit();
this->grpScoring->SuspendLayout();
this->grpOutput->SuspendLayout();
this->SuspendLayout();
//
// lblWelcome
//
this->lblWelcome->AutoSize =
true;
this->lblWelcome->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif",
12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->lblWelcome->ForeColor =
System::Drawing::SystemColors::Desktop;
this->lblWelcome->Location =
System::Drawing::Point(177, 9);
this->lblWelcome->Name = L"lblWelcome";
this->lblWelcome->Size =
System::Drawing::Size(287, 20);
this->lblWelcome->TabIndex = 0;
this->lblWelcome->Text = L"Welcome
to Visual C++ Dice Poker!";
//
// pbxDie1
//
this->pbxDie1->BorderStyle =
System::Windows::Forms::BorderStyle::Fixed3D;
this->pbxDie1->Location =
System::Drawing::Point(37, 44);
this->pbxDie1->Name = L"pbxDie1";
this->pbxDie1->Size =
System::Drawing::Size(75, 47);
this->pbxDie1->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pbxDie1->TabIndex = 1;
this->pbxDie1->TabStop =
false;
//
// pbxDie2
//
this->pbxDie2->BorderStyle =
System::Windows::Forms::BorderStyle::Fixed3D;
this->pbxDie2->Location =
System::Drawing::Point(159, 44);
this->pbxDie2->Name = L"pbxDie2";
this->pbxDie2->Size =
System::Drawing::Size(75, 47);
this->pbxDie2->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pbxDie2->TabIndex = 2;
this->pbxDie2->TabStop =
false;
//
// pbxDie4
//
this->pbxDie4->BorderStyle =
System::Windows::Forms::BorderStyle::Fixed3D;
this->pbxDie4->Location =
System::Drawing::Point(403, 44);
this->pbxDie4->Name = L"pbxDie4";
this->pbxDie4->Size =
System::Drawing::Size(75, 47);
this->pbxDie4->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pbxDie4->TabIndex = 3;
this->pbxDie4->TabStop =
false;
//
// pbxDie3
//
this->pbxDie3->BorderStyle =
System::Windows::Forms::BorderStyle::Fixed3D;
this->pbxDie3->Location =
System::Drawing::Point(281, 44);
this->pbxDie3->Name = L"pbxDie3";
this->pbxDie3->Size =
System::Drawing::Size(75, 47);
this->pbxDie3->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pbxDie3->TabIndex = 4;
this->pbxDie3->TabStop =
false;
//
// pbxDie5
//
this->pbxDie5->BorderStyle =
System::Windows::Forms::BorderStyle::Fixed3D;
this->pbxDie5->Location =
System::Drawing::Point(525, 44);
this->pbxDie5->Name = L"pbxDie5";
this->pbxDie5->Size =
System::Drawing::Size(75, 47);
this->pbxDie5->SizeMode =
System::Windows::Forms::PictureBoxSizeMode::StretchImage;
this->pbxDie5->TabIndex = 5;
this->pbxDie5->TabStop =
false;
//
// chkDie1
//
this->chkDie1->AutoSize =
true;
this->chkDie1->Location =
System::Drawing::Point(48, 125);
this->chkDie1->Name = L"chkDie1";
this->chkDie1->Size =
System::Drawing::Size(47, 17);
this->chkDie1->TabIndex = 6;
this->chkDie1->Text = L"Keep";
this->chkDie1->Visible =
false;
//
// chkDie2
//
this->chkDie2->AutoSize =
true;
this->chkDie2->Location =
System::Drawing::Point(171, 125);
this->chkDie2->Name = L"chkDie2";
this->chkDie2->Size =
System::Drawing::Size(47, 17);
this->chkDie2->TabIndex = 7;
this->chkDie2->Text = L"Keep";
this->chkDie2->Visible =
false;
//
// chkDie3
//
this->chkDie3->AutoSize =
true;
this->chkDie3->Location =
System::Drawing::Point(293, 125);
this->chkDie3->Name = L"chkDie3";
this->chkDie3->Size =
System::Drawing::Size(47, 17);
this->chkDie3->TabIndex = 8;
this->chkDie3->Text = L"Keep";
this->chkDie3->Visible =
false;
//
// chkDie4
//
this->chkDie4->AutoSize =
true;
this->chkDie4->Location =
System::Drawing::Point(417, 125);
this->chkDie4->Name = L"chkDie4";
this->chkDie4->Size =
System::Drawing::Size(47, 17);
this->chkDie4->TabIndex = 9;
this->chkDie4->Text = L"Keep";
this->chkDie4->Visible =
false;
//
// chkDie5
//
this->chkDie5->AutoSize =
true;
this->chkDie5->Location =
System::Drawing::Point(539, 125);
this->chkDie5->Name = L"chkDie5";
this->chkDie5->Size =
System::Drawing::Size(47, 17);
this->chkDie5->TabIndex = 10;
this->chkDie5->Text = L"Keep";
this->chkDie5->Visible =
false;
//
// chkKeepAll
//
this->chkKeepAll->AutoSize =
true;
this->chkKeepAll->Location =
System::Drawing::Point(295, 172);
this->chkKeepAll->Name = L"chkKeepAll";
this->chkKeepAll->Size =
System::Drawing::Size(61, 17);
this->chkKeepAll->TabIndex = 11;
this->chkKeepAll->Text = L"Keep
All";
this->chkKeepAll->Visible =
false;
this->chkKeepAll->CheckedChanged +=
gcnew System::EventHandler(this,
&Form1::chkKeepAll_CheckedChanged);
//
// btnRollDice
//
this->btnRollDice->AutoEllipsis =
true;
this->btnRollDice->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif",
8.25F, System::Drawing::FontStyle::Bold,
System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->btnRollDice->Location =
System::Drawing::Point(188, 168);
this->btnRollDice->Name = L"btnRollDice";
this->btnRollDice->Size =
System::Drawing::Size(75, 23);
this->btnRollDice->TabIndex = 12;
this->btnRollDice->Text = L"Roll
Dice";
this->btnRollDice->Click +=
gcnew System::EventHandler(this,
&Form1::btnRollDice_Click);
//
// btnExit
//
this->btnExit->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif",
8.25F, System::Drawing::FontStyle::Bold,
System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->btnExit->Location =
System::Drawing::Point(388, 168);
this->btnExit->Name = L"btnExit";
this->btnExit->Size =
System::Drawing::Size(75, 23);
this->btnExit->TabIndex = 13;
this->btnExit->Text = L"Quit";
this->btnExit->Click +=
gcnew System::EventHandler(this,
&Form1::btnExit_Click);
//
// grpScoring
//
this->grpScoring->Controls->Add(this->lblLegend3);
this->grpScoring->Controls->Add(this->lblLegend2);
this->grpScoring->Controls->Add(this->lblLegend1);
this->grpScoring->Location =
System::Drawing::Point(13, 207);
this->grpScoring->Name = L"grpScoring";
this->grpScoring->Size =
System::Drawing::Size(627, 76);
this->grpScoring->TabIndex = 14;
this->grpScoring->TabStop =
false;
this->grpScoring->Text = L"Scoring:";
//
// lblLegend3
//
this->lblLegend3->AutoSize =
true;
this->lblLegend3->Location =
System::Drawing::Point(221, 57);
this->lblLegend3->Name = L"lblLegend3";
this->lblLegend3->Size =
System::Drawing::Size(184, 13);
this->lblLegend3->TabIndex = 2;
this->lblLegend3->Text = L"3
of a kind = $1
Low Straight = $3";
//
// lblLegend2
//
this->lblLegend2->AutoSize =
true;
this->lblLegend2->Location =
System::Drawing::Point(221, 35);
this->lblLegend2->Name = L"lblLegend2";
this->lblLegend2->Size =
System::Drawing::Size(183, 13);
this->lblLegend2->TabIndex = 1;
this->lblLegend2->Text = L"4
of a kind = $3
High Straight = $3";
//
// lblLegend1
//
this->lblLegend1->AutoSize =
true;
this->lblLegend1->Location =
System::Drawing::Point(221, 16);
this->lblLegend1->Name = L"lblLegend1";
this->lblLegend1->Size =
System::Drawing::Size(175, 13);
this->lblLegend1->TabIndex = 0;
this->lblLegend1->Text = L"5
of a kind = $4
Full House = $2";
//
// grpOutput
//
this->grpOutput->Controls->Add(this->txtOutput);
this->grpOutput->Location =
System::Drawing::Point(13, 290);
this->grpOutput->Name = L"grpOutput";
this->grpOutput->Size =
System::Drawing::Size(627, 144);
this->grpOutput->TabIndex = 15;
this->grpOutput->TabStop =
false;
this->grpOutput->Text = L"Game
Status:";
//
// txtOutput
//
this->txtOutput->Location =
System::Drawing::Point(7, 20);
this->txtOutput->Multiline =
true;
this->txtOutput->Name = L"txtOutput";
this->txtOutput->ReadOnly =
true;
this->txtOutput->Size =
System::Drawing::Size(614, 118);
this->txtOutput->TabIndex = 0;
//
// tmrRoll
//
this->tmrRoll->Tick +=
gcnew System::EventHandler(this,
&Form1::tmrRoll_Tick);
//
// imlDiceList
//
this->imlDiceList->ImageStream =
(cli::safe_cast<System::Windows::Forms::ImageListStreamer^
>(resources->GetObject(L"imlDiceList.ImageStream")));
this->imlDiceList->Images->SetKeyName(0,
L"1.bmp");
this->imlDiceList->Images->SetKeyName(1,
L"2.bmp");
this->imlDiceList->Images->SetKeyName(2,
L"3.bmp");
this->imlDiceList->Images->SetKeyName(3,
L"4.bmp");
this->imlDiceList->Images->SetKeyName(4,
L"5.bmp");
this->imlDiceList->Images->SetKeyName(5,
L"6.bmp");
//
// Form1
//
this->AutoScaleDimensions =
System::Drawing::SizeF(6, 13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize =
System::Drawing::Size(650, 444);
this->Controls->Add(this->grpOutput);
this->Controls->Add(this->grpScoring);
this->Controls->Add(this->btnExit);
this->Controls->Add(this->btnRollDice);
this->Controls->Add(this->chkKeepAll);
this->Controls->Add(this->chkDie5);
this->Controls->Add(this->chkDie4);
this->Controls->Add(this->chkDie3);
this->Controls->Add(this->chkDie2);
this->Controls->Add(this->chkDie1);
this->Controls->Add(this->pbxDie5);
this->Controls->Add(this->pbxDie3);
this->Controls->Add(this->pbxDie4);
this->Controls->Add(this->pbxDie2);
this->Controls->Add(this->pbxDie1);
this->Controls->Add(this->lblWelcome);
this->Cursor =
System::Windows::Forms::Cursors::Hand;
this->FormBorderStyle =
System::Windows::Forms::FormBorderStyle::Fixed3D;
this->MaximizeBox =
false;
this->Name = L"Form1";
this->Text = L"Dice
Poker";
this->Load +=
gcnew System::EventHandler(this,
&Form1::Form1_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie2))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie4))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie3))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^
>(this->pbxDie5))->EndInit();
this->grpScoring->ResumeLayout(false);
this->grpScoring->PerformLayout();
this->grpOutput->ResumeLayout(false);
this->grpOutput->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma
endregion
private: System::Void
Form1_Load(System::Object^
sender, System::EventArgs^ e) {
//Seed random number generator with
current time
DateTime moment = DateTime::Now;
randNumGen = gcnew Random(
moment.Millisecond );
// Set starting game variables
pbxDie1->Image = imlDiceList->Images[0];
pbxDie2->Image = imlDiceList->Images[0];
pbxDie3->Image = imlDiceList->Images[0];
pbxDie4->Image = imlDiceList->Images[0];
pbxDie5->Image = imlDiceList->Images[0];
blnExcludeList = false;
intTimerCntr = 0;
//Set starting money
intTotalDollars = 20;
//Set beginning text
txtOutput->Text = \
String::Concat( "Welcome! Are you ready
"
"to play Dice Poker?\r\r\nYou have ",
intTotalDollars.ToString(),
" dollars in your account." );
}
private:
System::Void btnRollDice_Click(System::Object^
sender, System::EventArgs^
e) {
//See if the die have been rolled twice
if( intNoOfRolls == 2 )
{
//Change button display text
btnRollDice->Text = "Roll Dice";
//Reset to 0 to get game ready for new
hand
intNoOfRolls = 0;
}
//if( the first roll has been made toggle
the display of the
//CheckBox control and keep track of the
number of rolls
if( btnRollDice->Text ==
"Roll Dice" )
{
blnExcludeList = false;
intNoOfRolls += 1;
}
else
{
blnExcludeList = true;
intNoOfRolls += 1;
}
//Start the Timer control
tmrRoll->Enabled = true;
}
private:
Void RollTheDice( Int32 diceNo ) {
//Stores randomly generated number
representing the role of a die
Int32 intRoll;
//These variables are used to track which
die the player chooses
//to hold onto over his/her first roll
Boolean blnSkipCase1 = false,
blnSkipCase2 = false,
blnSkipCase3 = false,
blnSkipCase4 = false,
blnSkipCase5 = false;
//Flag die the player wants to hold
if( blnExcludeList =
true )
{
if( chkDie1->Checked ==
true )
blnSkipCase1 = true;
if( chkDie2->Checked ==
true )
blnSkipCase2 = true;
if( chkDie3->Checked ==
true )
blnSkipCase3 = true;
if( chkDie4->Checked ==
true )
blnSkipCase4 = true;
if( chkDie5->Checked ==
true )
blnSkipCase5 = true;
}
//Simulate a 6-sided die
intRoll = randNumGen->Next( 6 ) + 1;
//For each die number, display the correct
graphic
switch( diceNo )
{
case 1 :
//Update image for the first die as it spins
//Player elected not to hold
if( blnSkipCase1 ==
false )
{
pbxDie1->Image = imlDiceList->Images[intRoll - 1];
intDice1 = intRoll;
}
break;
case 2 :
//Update image for the second die as it spins
//Player elected not to hold
if( blnSkipCase2 ==
false )
{
pbxDie2->Image = imlDiceList->Images[intRoll - 1];
intDice2 = intRoll;
}
break;
case 3 :
//Update image for the third die as it spins
//Player elected not to hold
if( blnSkipCase3 ==
false )
{
pbxDie3->Image = imlDiceList->Images[intRoll - 1];
intDice3 = intRoll;
}
break;
case 4 :
//Update image for the fourth die as it spins
//Player elected not to hold
if( blnSkipCase4 ==
false )
{
pbxDie4->Image = imlDiceList->Images[intRoll - 1];
intDice4 = intRoll;
}
break;
case 5 :
//Update image for the fifth die as it spins
//Player elected not to hold
if( blnSkipCase5 ==
false )
{
pbxDie5->Image = imlDiceList->Images[intRoll - 1];
intDice5 = intRoll;
}
break;
}
}
private:
System::Void tmrRoll_Tick(System::Object^
sender, System::EventArgs^
e) {
//Set amount of time to show dice rolling
const Int32 cintRollPeriod = 5;
//Roll each die
for( Int32 intDiceCntr = 1;
intDiceCntr <= 5;
intDiceCntr++ )
RollTheDice( intDiceCntr );
intTimerCntr += 1;
//Increment counter by one
//Disable timer & display CheckBox
controls at the
//
end of each roll
if( intTimerCntr > cintRollPeriod )
{
intTimerCntr = 0;
//Reset timer counter
//Disable timer control
tmrRoll->Enabled = false;
if( intNoOfRolls == 1 )
{
//Prepare game for second roll
btnRollDice->Text = "Roll Again";
//Enable Checkbox controls
chkDie1->Visible = true;
chkDie2->Visible = true;
chkDie3->Visible = true;
chkDie4->Visible = true;
chkDie5->Visible = true;
chkKeepAll->Visible = true;
}
if( intNoOfRolls == 2 )
{
//Prepare game for a new hand
btnRollDice->Text = "Roll Dice";
chkDie1->Checked = false;
//Disable CheckBox controls
chkDie2->Checked = false;
chkDie3->Checked = false;
chkDie4->Checked = false;
chkDie5->Checked = false;
chkKeepAll->Checked = false;
chkDie1->Visible = false;
//Hide CheckBox controls
chkDie2->Visible = false;
chkDie3->Visible = false;
chkDie4->Visible = false;
chkDie5->Visible = false;
chkKeepAll->Visible = false;
//Keeps track of score
TotalTheScore();
//Display the player's account status
UpdateAccountStatus();
//See if player has gone broke
if( intTotalDollars <= 0 )
//End the game
EndOfGame();
}
}
}
private:
Void TotalTheScore( Void ) {
//Declare array to be used to keep count
of number
//
in each hand
const Int32 intMaxNoDie = 7;
Int32 intDieArray[intMaxNoDie];
//Declare variable used to control loop
execution
Int32 intCounter = 1;
//Clear the dice array
for( intCounter = 0; intCounter <
intMaxNoDie;
intCounter++ )
intDieArray[intCounter] = 0;
//Iterate six times and keep count of the
total number of
//1s, 2s, 3s, 4s, 5s and 6s that have been
rolled
for(
intCounter = 1; intCounter <= 6; intCounter++ )
{
if( intDice1 == intCounter )
intDieArray[intCounter] += 1;
if( intDice2 == intCounter )
intDieArray[intCounter] += 1;
if( intDice3 == intCounter )
intDieArray[intCounter] += 1;
if( intDice4 == intCounter )
intDieArray[intCounter] += 1;
if( intDice5 == intCounter )
intDieArray[intCounter] += 1;
}
//Iterate six times looking for winning
hands
for( intCounter = 1; intCounter <=
6; intCounter++ )
{
//See if the player has 5 of a kind
if( intDieArray[intCounter] == 5 )
{
//Update player's account
intTotalDollars += 4;
txtOutput->Text = "\r\r\nWinner: 5 of a
kind!"
" You win 4 dollars!";
return;
}
//See if the player has 4 of a kind
if( intDieArray[intCounter] == 4 )
{
//Update player's account
intTotalDollars += 3;
txtOutput->Text = "\r\r\nWinner: 4 of a
kind!"
" You win 3 dollars.";
return;
}
//See if the player has 3 of a kind or a
full house
if( intDieArray[intCounter] == 3 )
{
//Player has 3 of a kind
for( Int32 intCounter2 = 1;
intCounter2 <= 6;
intCounter2++ )
{
//See if player has a full house
if( intDieArray[intCounter2] == 2 )
{
//Update player's account
intTotalDollars += 2;
txtOutput->Text = "\r\r\nWinner:"
" Full house!
You win 2 dollars.";
return;
}
}
intTotalDollars += 1;
//Update player's account
txtOutput->Text = "\r\r\nWinner: 3 of a
"
"kind! You win 1 dollar.";
return;
}
}
//Iterate through die 2 - 6 looking for a
High Straight
for( intCounter = 2; intCounter <=
6; intCounter++ )
{
if( intDieArray[intCounter] != 1 )
break;
//No need to keep looking any further
else
{
if( intCounter == 6 )
{
//Update player's account
intTotalDollars += 3;
txtOutput->Text = "\r\r\nWinner: "
"High Straight! You win 3 dollars.";
return;
}
}
}
//Iterate through die 1 - 5 looking for a
Low Straight
for(
intCounter = 1; intCounter <= 5; intCounter++ )
{
if( intDieArray[intCounter] != 1 )
break;
//No need to keep looking any further
else
{
if( intCounter == 5 )
{
//Update player's account
intTotalDollars += 3;
txtOutput->Text = "\r\r\nWinner: Low"
" Straight! You win 3 dollars.";
return;
}
}
}
//Update player's account
intTotalDollars -= 2;
txtOutput->Text = "\r\r\nSorry, You lost
this "
"hand! You lose 2 dollars.";
}
private:
Void EndOfGame( Void ) {
//Variable used to hold player response
Windows::Forms::DialogResult drPlayAgain;
//Clear out any status messages
txtOutput->Text = "";
//Prompt player to try again
drPlayAgain = MessageBox::Show( "Sorry,
you are "
"broke. The game is over. Would you like
to "
"play again?",
"Dice Poker",
MessageBoxButtons::YesNo, MessageBoxIcon::Question,
MessageBoxDefaultButton::Button1 );
//if( player clicks on Yes set up a new
game
if( drPlayAgain ==
Windows::Forms::DialogResult::Yes )
{
//Reset the bank account
intTotalDollars = 20;
pbxDie1->Image = imlDiceList->Images[0];
pbxDie2->Image = imlDiceList->Images[1];
pbxDie3->Image = imlDiceList->Images[2];
pbxDie4->Image = imlDiceList->Images[3];
pbxDie5->Image = imlDiceList->Images[4];
//Set beginning text
txtOutput->Text = \
String::Concat( "Welcome! Are you ready
"
"to play Dice Poker?\r\r\nYou have ",
intTotalDollars.ToString(),
" dollars in your account." );
}
else
//player wants to quit
this->Close();
}
private:
Void UpdateAccountStatus( Void ) {
txtOutput->Text = \
String::Concat( txtOutput->Text,
"\r\r\nYou have ",
intTotalDollars.ToString(),
" dollars in your account." );
}
private:
System::Void btnExit_Click(System::Object^
sender, System::EventArgs^
e) {
this->Close();
}
private:
System::Void chkKeepAll_CheckedChanged(System::Object^
sender, System::EventArgs^
e) {
//if( the player selects the CheckBox
//
labeled KeepAll, select the other
//
CheckBox controls
if(
chkKeepAll->Checked == true )
{
btnRollDice->Text = "Stick";
chkDie1->Checked = true;
chkDie2->Checked = true;
chkDie3->Checked = true;
chkDie4->Checked = true;
chkDie5->Checked = true;
}
else
{
//if( the player clears the CheckBox
//
labeled KeepAll, clear the other
//
CheckBox controls
btnRollDice->Text = "Roll Again";
chkDie1->Checked = false;
chkDie2->Checked = false;
chkDie3->Checked = false;
chkDie4->Checked = false;
chkDie5->Checked = false;
}
}
};
}