//--------------------------------------------------------------------------- // UCLAopoly // A Local Version of Monopoly // Revised May 28, 2002 //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GIFImage" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //------------------------------------------------------- Program Begins Here // this holds the number of visits to each square int monopoly[40]; int roll; int square = 0; int turn; // this holds the frequencies of each throw of a pair of dice int rollTot[13]; int row; int draw; //-------------------------------------------------------------- Update Data void update (void) { Form1->Edit1->Text = turn; monopoly[square] ++; row = 4; if (square < 30) row = 3; if (square < 20) row = 2; if (square < 10) row = 1; Form1->Canvas->TextOut( row * 50 + 430, // X (square - (row * 10)) * 20 + 250, // Y monopoly[square]); // visits Application->ProcessMessages(); } //------------------------------------------------------------- Roll the Dice void rollTheDice (void) { Form1->Edit1->Text = turn; for (turn = 0; turn <= 10000; turn++ ) { roll = random(6) + 1 + random(6) + 1; rollTot[roll] ++; square = square + roll; if (square >= 40) square = square - 40; //------------------------------------------------------ AFTER THE ROLL Again: //-------------------------------------------------- ACADEMIC PROBATION if (square == 30) { update(); square = 10; // go home update(); } //--------------------------------------------------------- CONTINGENCY else if (square == 7 || square == 22 || square == 37) { update(); // draw one card from 15 draw = random(15); if (draw == 0) { square = 6; // go to Westwood Village update(); } else if (draw == 1) { square = 6; // go to Westwood Village update(); } else if (draw == 2) { square = 10; // go home update(); } else if (draw == 3) { square = 27; // go to Rose Bowl update(); } else if (draw == 4) { square = 34; // go to Powell Library update(); } else if (draw == 5) { square = 35; // go to Fraternity Row (Hilgard) update(); } else; } //--------------------------------------------------------- CAMPUS MAIL else if (square == 2 || square == 17 || square == 33) { update(); // draw one card from 15 draw = random(15); if (draw == 0) { // // leave home free } else if (draw == 1) { square = 10; // Suspended, go home update(); } // the following require another roll of the dice else if (draw == 2) { square = square - 5; // Lot 32 go back 5 if (square < 0) square = square + 40; update(); goto Again; } else if (draw == 3) { roll = random(6) + 1 + random(6) + 1; // Monday Morning roll square = square - roll; // and move backwards if (square < 0) square = square + 40; update(); goto Again; } else; } //------------------------------------------------ AN UNEVENTFUL SQUARE else update(); } } //------------------------------------------------------ Roll the Dice Button void __fastcall TForm1::ButtonRollTheDiceClick(TObject *Sender) { rollTheDice(); } //---------------------------------------------------- Randomize on Form Show void __fastcall TForm1::FormShow(TObject *Sender) { Randomize(); } //----------------------------------------------------------------------- END