Hey all,
I'm making a Dark GDK Game of Nim, in which the following conditions have to be met:
1. Must use stacks to hold piles of chips
2. number of piles is inputted by user, and must be between 3 and 5, inclusively
3. number of stones is chosen by user, must be at least as many chips as the number of piles
4. chips are assigned randomly to piles, must be shown graphically, and updated at each turn
5. The players take turns choosing the pile to remove from, and the number of chips to remove – must ask the user how many chips they want, from which pile, and validate the input.
6. Last player to remove a stone wins
Now, I've been struggling to write this code, since I rarely use Dark GDK, but I have come up with this:
#include "DarkGDK.h"
#include <stack>
using namespace std;
void DarkGDK(void)
{
stack<int> pile[5];
int numPiles = 0, numChips = 0;
int counter = 0;
int numberToRemove = 0;
int pileToRemoveFrom = 0;
dbSetImageColorKey(255,0,0);
dbLoadImage("chip.bmp", 1);
dbPrint("Enter the number of piles to use: ");
numPiles = atoi(dbInput());
while(numPiles < 3 || numPiles > 5)
{
dbPrint("Error! The number of piles must be between 3 and 5, inclusive.");
dbPrint("Please re-enter the number of piles: ");
numPiles = atoi(dbInput());
}
dbPrint("Enter the number of chips: ");
numChips = atoi(dbInput());
while(numChips < numPiles)
{
dbPrint("Error! The number of chips must be at least equal to the number of piles.");
dbPrint("Please re-enter the number of chips: ");
numChips = atoi(dbInput());
}
//Put chips to pile
//only puts it in the piles that are allowed to use
for(int i =0; i<numChips; i++)
{
pile[counter].push(1);
if(counter>(numPiles-1))
counter=0;
counter++;
}
while(LoopGDK())
{
//ask user which pile to take from
//ask user how many to take
//check to see if that stack has any left on it
//if it does not, output an error and do not change the turn
//if it does, do a for loop and pop of the top things
//to display, do a nested for loop
dbPrint("Which pile do you want to remove from?");
pileToRemoveFrom = atoi(dbInput());
dbPrint("How many do you want to remove?");
numberToRemove = atoi(dbInput());
if(pile[pileToRemoveFrom].empty())
dbPrint("Pile has 0 chips left!");
else
{
for(int i = 0; i < numPiles; i++)
{
for(int j = 0; j <pile[i].size(); j++)
{
dbPasteImage(1, 40 + i*150, 80 + 80*j, 1);
}
}
//to remove, pop off the right amount
for(int s = 0; s < numberToRemove; s++)
{
pile[pileToRemoveFrom].pop();
}
//Look in the book for stuff about dbSync and examples of that.
//you will need to write a thing to see if the current player won.
//aka, all piles are now empty
}
}
return;
}
I need help visually displaying the chips so that each pile will be displayed in correct rows and columns.
Can someone please help me, I am new to Dark GDK and this is urgent.
Thank you very much!