I am trying to develop a one-player text based football game in C++ strictly in the console without graphics. I am developing the game logic here below vs the CPU and I also need to do the vice versa (CPU vs User). How could I do this without a ton of if statements. I am not sure how to accomplish this same code below as a lookup table and I know I need some randomness so it is not predictable.
For this example below, the scenario would be which down are we in (4th in this example), how many yards to go (2 yards), the offensive's team running attribute (choice = Bears), the defense run attribute (o_choice = Bengals) and the play called (playbook_choice = 1 which is QB Sneak). Any help would be much appreciated, I have been banging my head against on the wall on this. I have not incorporated the attributes ratings below into the code below because I am not sure how and the numbers represent only the teams chosen. The Bears would have offensive running and pass ratings, and defensive running and pass ratings (so 4 ratings in total), same goes for the Bengals.
Code: Select all
//test logic
if (playbook_choice == 1 && choice == 1 && o_choice == 2) { //if qb sneak is called by the user controlled bears vs the cpu bengals
int current_down_yards = 0,down = 4 ,yards = 2; // current down is 4th and 2 --- setting the down and distance
cout << "It is 4th down and 2 yards to go" << endl; // print it out to the user --- setting the down and distance
if (down == 2 || down == 3 || down == 4 && yards < 3) { //if its 2nd , 3rd of 4th down and less than 3 yards to go
current_down_yards = rand() % 16; // give a rate of completion of randomness from 1-15 yards for a QB sneak --- need to take account for the strength
// of the defense's attribute rating and offense's running rating -- to include for a loss as well as a gain in yardage
cout << "The QB ran for " << current_down_yards << " " << "yards" << endl;
}
}