Hello. I am working on a game called Kingdom Management. It was working fine until I added in the buildings you can make. Then it started skipping over the building, lawmaking, do nothing, and quit sections. All it could do is research.
Here is the code:
/*******************************************************************************
Kingdom Management the Game v.A-0
Creator: Bryce A Hart (BAH)
Owner: " " " (""")
Title: Kingdom Management, the Game
Version: Alpha 0.0.0
Notes: PROOF OF CREATION/OWNERSHIP: DATE CREATED (Shows while hovering mouse over file)
1/21/2010.
*******************************************************************************/
#include<iostream>
using namespace std;
int main(){
//This is a game where you manage a kingdom and try to end with the most gold, land, or army.
//Intro
cout << "Welcome to Kingdom Management."<<endl;
cout << "Let's begin."<<endl;
system("pause");
//Declare Variables (STATS)
int selection, selection1, selection2, selection3, selection4, selection5, selection6, selection7; // This holds a selection for a console input (cin).
int redo = 1; // This is for while loops at selections.
int gold; // This is the ammount of money the kingdom has.
int army; // This is the size of the kingdom's army.
int pop = 10; // This is your population of workers available.
int glory = 0; //This is your kingdom's "score."
int turn = 1; //This is what turn you are on.
//GAME BEGINS
while (redo == 1){
cout << "What type of kingdom would you like to have? Here are your selections:"<<endl;
cout << "(1)Aggressive: \t 20 Gold \t 50 Army"<<endl;
cout << "(2)Wealthy: \t 50 Gold \t 20 Army"<<endl;
cout << "(3)Balance: \t 35 Gold \t 35 Army"<<endl;
cout << "Type the number in parenthasese next to the one you want: "<<endl;
cin >> selection1;
if (selection1 == 1){
gold = 20;
army = 50;
redo = 0;
}
else if (selection1 == 2){
gold = 50;
army = 25;
redo = 0;
}
else if (selection1 == 3){
gold = 10;
army = 10;
redo = 0;
}
else{
cout << "Wrong Selection."<<endl;
redo = 1;
}
}//ENDS WHILE LOOP
cout << "Nice selection."<<endl;
//Declare Variables (BUILDINGS AND RESEARCH)
//Buildings
int barracks = 0; //Tells whether or not you have a barracks.
int town_hall = 0; //Tells whether or not you have a town hall.
int market = 0; //Tells whether or not you have a market.
int farm = 0; // Tells whether or not you have a farm.
//Research
int lawmaking = 0; //Tells if you have researched lawmaking or not.
int siege_weapon = 0; //Tells if you have researched seige weapons.
int agriculture = 0; //Tells if you have researched large-area agriculture.
int livestock = 0; //Tells if you have researched raising livestock.
redo = 1;
while (redo == 1){
if (army == 0){
cout << "Game Over. Your army has 0 people."<<endl;
return 0;
}
else if (gold == 0){
cout << "Game Over. You ran your kingdom out of money and were overthrown."<<endl;
}
else {
if (turn == 1){
cout << "Population is the ammount of workers you have available."<<endl;
cout << "Glory is your score. It is based on your actions as king."<<endl;
}
else {
cout << endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
}
cout << "TURN "<<turn<<endl;
cout << "====================="<<endl;
if (barracks == 1){
army = army + 5;
}
else if (market == 1){
if (farm == 1){
gold = gold + 2;
}
if (livestock == 1){
gold = gold + 2;
}
gold = gold + 5;
}
else if (pop < 3){
pop = pop + 1;
}
else if (pop > 3, pop < 5){
pop = pop + 2;
}
else if (pop >5, pop < 10){
pop = pop + 3;
}
else if (pop > 10){
pop = pop + 5;
}
cout << "Population: \t" << pop <<endl;
cout << "Gold: \t \t"<< gold <<endl;
cout << "Army: \t \t"<< army <<endl;
cout << "Glory: \t \t" << glory <<endl;
system("pause");
cout << "What would you like to do?"<<endl;
cout << "(1)Research"<<endl<<"(2)Build"<<endl<<"(3)Enact Law (COMING SOON)"<<endl;
cout << "(4)Nothing"<<endl<<"(5)Quit Game"<<endl;
cin >> selection;
if (selection == 1){
cout << "Here is the research list. Please select one."<<endl;
cout << "-#-|----NAME---- \t ----COST---- \t ----DESCRIPTION----"<<endl;
cout << "(1)|Lawmaking \t \t 5G, 0A, 0P \t Step 1 To Enacting Laws"<<endl;
cout << "(2)|Siege Weapons \t 10G, 3A, 3P \t Better Fighting Power"<<endl;
cout << "(3)|Agriculture \t 5G, 0A, 5P \t Step 1 To Markets"<<endl;
cout << "(4)|Livestock \t \t 10G, 0A, 10P \t Better Markets"<<endl;
cin >> selection3;
if (selection3 == 1){
if (lawmaking == 0){
gold = gold - 5;
lawmaking = 1;
cout << "You have researched LAWMAKING."<<endl;
turn = turn + 1;
}
else{
cout << "You have already researched LAWMAKING."<<endl;
}
}
else if (selection3 == 2){
if (siege_weapon == 0){
gold = gold - 10;
army = army - 3;
pop = pop - 3;
siege_weapon = 1;
cout << "You have reasearched SIEGE WEAPONS."<<endl;
turn = turn + 1;
}
else {
cout << "You have already resarched SIEGE WEAPONS."<<endl;
}
}
else if (selection3 == 3){
if (agriculture == 0){
gold = gold - 5;
pop = pop - 5;
agriculture = 1;
cout << "You have reasearched AGRICULTURE."<<endl;
turn = turn + 1;
}
else {
cout << "You have already resarched AGRICULTURE."<<endl;
}
}
else if (selection3 == 4){
if (livestock == 0){
gold = gold - 10;
pop = pop - 10;
livestock = 1;
cout << "You have reasearched LIVESTOCK."<<endl;
turn = turn + 1;
}
else {
cout << "You have already resarched LIVESTOCK."<<endl;
redo = 1;
}
}
else if (selection == 2){
cout << "Here is the building list."<<endl;
cout << "-#-|----NAME---- \t ----COST---- \t ---------DESCRIPTION---------"<<endl;
cout << "(1)|Barracks \t 10G, 5A, 5P \t Adds 5 to your army each turn."<<endl;
cout << "(2)|Town Hall \t 10G, 1A, 5P \t Unlocks Lawmaking."<<endl;
cout << "(3)|Market \t 5G, 0A, 3P \t Adds 5 gold every turn."<<endl;
cout << "(4)|Farm \t 5G, 0A, 5P \t Market Upgrade."<<endl;
cout << "What shall you build?"<<endl;
cin >> selection5;
if (selection5 == 1){
if (barracks == 0){
gold = gold - 10;
army = army - 5;
pop = pop - 5;
barracks = 1;
cout << "You have built a BARRACKS."<<endl;
turn = turn + 1;
redo = 1;
}
else{
cout << "You already have a BARRACKS."<<endl;
redo = 1;
}
}
else if (selection5 == 2){
if (town_hall == 0){
if (lawmaking == 1){
town_hall = 1;
cout << "You have built a TOWN HALL."<<endl;
turn = turn + 1;
redo = 1;
}
else
cout << "You must have researched in LAWMAKING to make a TOWN HALL."<<endl;
redo = 1;
}
else{
cout << "You already have a BARRACKS."<<endl;
redo = 1;
}
}
else if (selection5 == 3){
if (farm == 0){
gold = gold - 5;
pop = pop - 3;
farm = 1;
cout << "You have built a MARKET."<<endl;
turn = turn + 1;
redo = 1;
}
else{
cout << "You already have a MARKET."<<endl;
redo = 1;
}
}
else if (selection5 == 4){
if (farm == 0){
if (agriculture == 1){
gold = gold - 5;
pop = pop - 5;
farm = 1;
cout << "You have built a FARM."<<endl;
turn = turn + 1;
redo = 1;
}
else
cout << "You need to research AGRICULTURE first."<<endl;
redo = 1;
}
else{
cout << "You already have a FARM."<<endl;
redo = 1;
}
}
else if (selection == 3){
if (town_hall == 1){
cout << "LAWMAKING COMING SOON."<<endl;
turn = turn + 1;
redo = 1;
}
else
cout << "You must research Lawmaking and build a Town Hall before you can make laws."<<endl;
}
else if (selection == 4){
cout << "You wait out the turn. The people want a working king!"<<endl;
turn = turn + 1;
redo = 1;
}
else if (selection == 5){
cout << "Are you sure you want to quit?"<<endl;
cout << "(1)Quit \t (2)Stay"<<endl;
cin >> selection4;
if (selection4 == 1){
cout << "Goodbye!"<<endl;
cout << "You ended the game with the following stats:"<<endl;
cout << "You finished on turn "<<turn<<"."<<endl;
cout << "Population: \t" << pop <<endl;
cout << "Gold: \t \t"<< gold <<endl;
cout << "Army: \t \t"<< army <<endl;
cout << "Glory: \t \t" << glory <<endl;
return 0;
}
else {
cout << "Good! Let's continue!"<<endl;
redo = 1;
}
}
else {
cout << "Wrong Selection."<<endl;
redo = 1;
}
}
}
}
}
}
There you go.
I work in the Dev-C++ Environment.