I have a game that consists of multiple countries and each of them has several choices.
For instance, First Country(France) has multiple choices, Choice 1, Choice 2, Choice 3, .......etc
And the idea of the code is that if France gets number 6(the dice´result) it gets one (choice)soldier of its multiple ones into the game(exactly at the starting point so that contributes into the game).
And as it is shown each choice would make the code longer and longer .... Since i have multiple countries with multiple choices.
I am trying to improve my current code so that its easy to read. So the current code works well but i want to improve it and short it, maybe if i can avoid the repetition show that would significantly reduce.
So is there a smarter way to implement that so that it works as now but with a shorten type ?
bool Game::Move(string choice, int rrr)
{
if (choice == "Choice1")
{
if (Choice1 == francestart)
{
if (rrr == 6)
{
if (Choice1->next == Choice2 || Choice1->next == Choice3 || Choice1->next == Choice4) //if piece would land on space where another piece of the same country is occupying
{
cout << "You cannot move " << (choice) << " out of the start position because one of your other pieces is occupying the space" << endl;
return false;
}
else
{
Choice1 = Choice1->next;
Rest(choice);
return true;
}
}
else
{
cout << "You cannot move " << (choice) << " " << " out of the start position because you did not rrr a 6" << endl;
return false;
}
}
else
{
Node* tttt;
tttt = Choice1;
bool ReturnBack = false; //tttt will go towards home country if true
for (int i = 0; i < rrr; i++)
{
if (tttt->value == 90) //last space before going home, tells it to go to home space
{
ReturnBack = true;
}
if (!ReturnBack)
{
tttt = tttt->next;
}
if (ReturnBack)
{
tttt = tttt->out;
}
if (tttt == NULL) //if run out of spaces
{
cout << "You cannot move " << (choice) << " " << (rrr) << " spaces because there is not enough spaces to travel" << endl;
return false;
}
}
if (tttt == Choice2 || tttt == Choice3 || tttt == Choice4) //if space is occupied
{
cout << "You cannot move " << (choice) << " " << (rrr) << " spaces because another one of your pieces is occupying that space" << endl;
return false;
}
else
{
Choice1 = tttt;
Rest(choice);
return true;
}
}
}
if (choice == "Choice2")
{
if (Choice2 == francestart)
{
if (rrr == 6)
{
if (Choice2->next == Choice1 || Choice2->next == Choice3 || Choice2->next == Choice4) //if piece would land on space where another piece of the same country is occupying
{
cout << "You cannot move " << (choice) << " out of the start position because one of your other pieces is occupying the space" << endl;
return false;
}
else
{
Choice2 = Choice21->next;
Rest(choice);
return true;
}
}
else
{
cout << "You cannot move " << (choice) << " " << " out of the start position because you did not rrr a 6" << endl;
return false;
}
}
else
{
Node* tttt;
tttt = Choice2;
bool ReturnBack = false; //tttt will go towards home country if true
for (int i = 0; i < rrr; i++)
{
if (tttt->value == 24) //last space before going home, tells it to go to home space
{
ReturnBack = true;
}
if (!ReturnBack)
{
tttt = tttt->next;
}
if (ReturnBack)
{
tttt = tttt->out;
}
if (tttt == NULL) //if run out of spaces
{
cout << "You cannot move " << (choice) << " " << (rrr) << " spaces because there is not enough spaces to travel" << endl;
return false;
}
}
if (tttt == Choice1 || tttt == Choice3 || tttt == Choice4) //if space is occupied
{
cout << "You cannot move " << (choice) << " " << (rrr) << " spaces because another one of your pieces is occupying that space" << endl;
return false;
}
else
{
Choice2 = tttt;
Rest(choice);
return true;
}
}
}
And i still have
if (choice == "Choice1")
{
if (Choice1 == italystart)
{
if (rrr == 6)
And so on ?