Document 13957517

advertisement
Engr 123
Assignment 6
Oddly enough!
Assigned: March 2, 2016
Due: March 21, 2016
For this assignment you will write a C# GUI program to play the game of Oddly Enough.
In this game there are an odd number of counters arranged in a random number of piles.
There are two players and the players take turns removing from 1 to 3 counters from a
single pile. The game continues until all of the counters are gone at which time the
player with an odd number of counters is the winner.
As a simple example, consider a game in which ther are only three piles with three
counters in pile 1, two counters in pile 2, and two counters in pile 3 for a total of 7
counters in three piles. Graphically this might look like this:
P1
P2
P3
x
Player 1 = 0
x
x
x
Player 2 = 0
x
x
x
Turn 1: Player 1 takes three counters from P1:
P1
P2
P3
Player 1 = 3
x
x
Player 2 = 0
x
x
Turn 2: Player 2 takes two counters from P2:
P1
P2
P3
Player 1 = 3
x
Player 2 = 2
x
Turn 3: Player 1 takes two counters from P3:
P1
P2
P3
Player 1 = 5
Player 2 = 2
In this case Player 1 wins since she has an odd number of counters.
For this assignment the number of piles will be a random number in the range 2 to 7. The
number of counters in each pile will also be a random number in the range 1 to 5. The
total number of counters in all piles must be odd.
At a minimum, your GUI must provide the following:
1. Up to 7 piles. These may be text boxes or labels that are "read only".
2. A mechanism for each player to select a pile and a number of counters to be taken
from that pile. You can do this with text boxes, numeric up/down counters, or
radio buttons.
3. A status window where you present the score and other status information.
4. A button for taking turns.
One such GUI is shown in Figure 1. There are many other arrangements for the GUI and
you should be creative and work out your own GUI for this problem.
Figure 1
One possible GUI for assignment 6. The piles are text boxes with labels. Each player has a numeric
up/down box to choose a pile and counter number. There is one button which has a label which changes to
indicate the turn and there is one label (at the bottom) for status information.
Hint: The number of piles is variable from 2 to 7 so that in Figure 1 the number of text boxes
must be variable from 2 to 7. One way to do this is to select a random number from 2 to 7 and
make the appropriate number of text boxes invisible by setting their visibility property to false. It
is also much less cumbersome to manipulate the text boxes if they are in an array. For example,
the following code creates 7 text boxes and places them in an array:
private TextBox [] txtArr = new TextBox[7];
private void Form1_Load(object sender, EventArgs e)
{int i, cntr;
txtArr[0] = txtP1; //txtP1 to txtP7 are text boxes
txtArr[1] = txtP2; // created in the design
txtArr[2] = txtP3;
txtArr[3] = txtP4;
txtArr[4] = txtP5;
txtArr[5] = txtP6;
txtArr[6] = txtP7;
}
To make all but the first two text boxes invisible:
for(i=2;i<numPiles;i++)
{txtArr[i].Visible = false;
}
After you get your program running correctly, place a copy of the design into the project
folder as a doc or docx file. Right click on the project folder and choose Send To →
Compressed zip file. Rename the compressed zip file as Asn06XXX.zip where XXX are
you three initials. Upload the renamed file to \\cecsfp01\users\everyone\engr123.
Download