hi, can anyone help me with my code, any help will be much appreciated. The design should follow object oriented principles and use the UML tools. It should be a board game based on a “Monopoly-style” board made of 36 squares. The game is for two players who first enter their names and then take turns. On each turn, a die is thrown and the score dictates how many squares the player can move around the board. Each time a player moves past the "Start" square they collect a "token". Play continues until one player has collected five tokens. The user interface can be a console application with all input and output made through a “command line” prompt.
There should be submited: use case diagram(s), candidate and refined class names, classes, class diagram(s), either a collaboration diagram or a sequence diagram. A basic solution to the programming part of the task would operate in a console window with text prompts and outputs indicating what dice score had been rolled. At the design stage there can be produced CRC cards for the classes, and both the sequence diagram and the collaboration diagram. Here is the code but I think it needs some improvements to meet the criteria:
[
#include <iostream>
#include <ctime>
class cPlayer
{
public:
int pos;
int pts;
};
cPlayer p1, p2;
int random(int nMin, int nMax)
{ return rand() % (nMax - nMin + 1) + nMin; }
int main()
{
srand(static_cast<unsigned int>(time(NULL)));
p1.pos = 0 ; p1.pts = 0 ;
p2.pos = 0 ; p2.pts = 0 ;
int i = 0 ;
while(true)
{
i = random(1,6);
std::cout << "Player 1 (is on the square " << p1.pos << ") rolled: " << i << std::endl;
while(i > 0)
{
p1.pos++;
if(p1.pos == 36)
{
p1.pos = 0;
p1.pts++;
if(p1.pts == 5) break;
}
i--;
}
std::cout << "Player 1 came to square " << p1.pos << " (" << p1.pts << " token)" << std::endl;
if(p1.pts == 5) break;
i = random(1,6);
std::cout << "Player 2 (is on the square " << p2.pos << ") rolled: " << i << std::endl;
while(i > 0)
{
p2.pos++;
if(p2.pos == 36)
{
p2.pos = 0;
p2.pts++;
if(p2.pts == 5) break;
}
i--;
}
std::cout << "Player 2 came to square " << p2.pos << " (" << p2.pts << " token)" << std::endl;
if(p2.pts == 5) break;
}
if(p1.pts == 5) std::cout << "The winner is Player 1" << std::endl;
if(p2.pts == 5) std::cout << "The winner is Player 2" << std::endl;
system("PAUSE");
return 0;
}
/]