Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cstdlib>
- // System switcher: 1 - Linux 2 - Windows
- #define system_switch 2
- // Control of game balance
- #define POP 9999 // Population
- #define TAX_RATE_WHITE 2
- #define TAX_RATE_BLACK 2
- #define CASH 1000 // Start money
- using namespace std;
- char menu();
- int Troll_battle();
- void clscr();
- // Stats of Units
- const int Mill_costs = 10;
- const int Arch_costs = 20;
- const int Pike_costs = 30;
- const int Cava_costs = 35;
- class town
- {
- public:
- int population;
- long int gold;
- struct{
- int barracks;
- int barracks_lvl;
- int homes;
- int homes_lvl;
- } building;
- struct{
- int HP;
- int DEF;
- int DAM;
- int unit_val;
- } Military;
- struct{
- int HP;
- int DEF;
- int DAM;
- int unit_val;
- } Archers;
- struct{
- int HP;
- int DEF;
- int DAM;
- int unit_val;
- } Pikemen;
- struct{
- int HP;
- int DEF;
- int DAM;
- int unit_val;
- } Cavalry;
- };
- struct Troll{
- int HP;
- int DEF;
- int DAM;
- } Troll;
- town white, black;
- int main()
- {
- char choice;
- int win = 0, homes_timer = 0, barracks_timer = 0;
- // Initial conditions
- white.population = POP;
- white.building.homes = POP/4;
- white.building.homes_lvl = 1;
- white.building.barracks = 0;
- white.building.barracks_lvl = 0;
- white.gold = CASH;
- white.Military.unit_val = 0;
- white.Archers.unit_val = 0;
- white.Pikemen.unit_val = 0;
- white.Cavalry.unit_val = 0;
- white.Military.HP = 100;
- white.Archers.HP = 80;
- white.Pikemen.HP = 120;
- white.Cavalry.HP = 150;
- white.Military.DEF = 50;
- white.Archers.DEF = 30;
- white.Pikemen.DEF = 100;
- white.Cavalry.DEF = 110;
- white.Military.DAM = 100;
- white.Archers.DAM = 130;
- white.Pikemen.DAM = 165;
- white.Cavalry.DAM = 150;
- black = white;
- Troll.HP = 99999;
- Troll.DEF = 50000;
- Troll.DAM = 25000;
- // Balance
- for (int i = 1; win == 0; i++)
- {
- cout << "\t\t\t _._.= " << i << " day =._._" << endl << endl;
- cout << "Gold: " << white.gold << endl;
- cout << "Population: " << white.population << " people" << endl;
- if (white.Military.unit_val > 0)
- cout << "Military: " << white.Military.unit_val << endl;
- if (white.Archers.unit_val > 0)
- cout << "Archers: " << white.Archers.unit_val << endl;
- if (white.Pikemen.unit_val > 0)
- cout << "Pikemen: " << white.Pikemen.unit_val << endl;
- if (white.Cavalry.unit_val > 0)
- cout << "Cavalry: " << white.Cavalry.unit_val << endl;
- int err;
- // Dialog
- do{
- choice = menu();
- err = 0;
- switch(choice)
- {
- case 'j':
- if (white.gold != 0)
- {
- white.gold = 0;
- cout << "\nTaki thank you! *Rebe love you*\n";
- }
- case 'w':
- break;
- case '1':
- if ((white.gold - 600) < 0)
- {
- cout << "\nNot enough gold\n";
- err = 1;
- }
- else
- {
- if (homes_timer != 0)
- {
- cout << "\nWait when previous home will be completed!\n";
- err = 1;
- }
- else{
- white.gold -= 600;
- cout << "\nAfter 2 days build will be complete\n\n";
- homes_timer = i + 2;
- err = 1;
- }
- }
- break;
- case '2':
- if((white.gold - 2000) < 0 || white.building.homes_lvl < 1)
- {
- cout << "\nNot enough gold and/or lvl for build\n";
- err = 1;
- }
- else
- {
- if (homes_timer != 0)
- {
- cout << "\nWait when previous home will be completed!\n";
- err = 1;
- }
- else{
- white.gold -= 2000;
- cout << "\nAfter 3 days build will be complete\n\n";
- homes_timer = i + 3;
- err = 1;
- }
- }
- break;
- case '3':
- if((white.gold - 5000) < 0 || white.building.homes_lvl < 2)
- {
- cout << "\nNot enough gold and/or lvl for build\n";
- err = 1;
- }
- else
- {
- if (homes_timer != 0)
- {
- cout << "\nWait when previous home will be completed!\n";
- err = 1;
- }
- else{
- white.gold -= 5000;
- cout << "\nAfter 5 days build will be complete\n\n";
- homes_timer = i + 5;
- err = 1;
- }
- }
- break;
- case 'f':
- if ((white.gold - 1000) < 0)
- {
- cout << "\nNot enough gold\n";
- err = 1;
- }
- else
- {
- if (barracks_timer != 0)
- {
- cout << "\nWait when previous barracks will be completed!\n";
- err = 1;
- }
- else{
- white.gold -= 1000;
- cout << "\nAfter 2 days build will be complete\n";
- barracks_timer = i + 2;
- err = 1;
- }
- }
- break;
- case 's':
- if((white.gold - 5000) < 0 || white.building.barracks_lvl < 1)
- {
- cout << "\nNot enough gold and/or lvl for build\n";
- err = 1;
- }
- else
- {
- if (barracks_timer != 0)
- {
- cout << "\nWait when previous barak will be completed!\n";
- err = 1;
- }
- else{
- white.gold -= 5000;
- cout << "\nAfter 4 days build will be complete\n";
- barracks_timer = i + 4;
- err = 1;
- }
- }
- break;
- case 't':
- if((white.gold - 12000) < 0 || white.building.barracks_lvl < 2)
- {
- cout << "\nNot enough gold and/or lvl for build\n";
- err = 1;
- }
- else
- {
- if (barracks_timer != 0)
- {
- cout << "\nWait when previous home will be completed!\n";
- err = 1;
- }
- else{
- white.gold -= 12000;
- cout << "\nAfter 6 days build will be complete\n";
- barracks_timer = i + 6;
- err = 1;
- }
- }
- break;
- case 'm':
- if ((white.gold - Mill_costs * 60) < 0)
- {
- cout << "\nNot enough gold\n";
- err = 1;
- }
- else
- {
- if (white.building.barracks < 1)
- {
- cout << "\nFirst of all build barracks!\n";
- err = 1;
- }
- else
- {
- white.Military.unit_val += 60;
- cout << "\nNew military: Ok sir! Let's rush enemy!\n";
- err = 1;
- }
- }
- break;
- case 'a':
- if ((white.gold - Arch_costs * 40) < 0)
- {
- cout << "\nNot enough gold\n";
- err = 1;
- }
- else
- {
- if (white.building.barracks < 1)
- {
- cout << "\nFirst of all build barracks!\n";
- err = 1;
- }
- else
- {
- if (white.building.barracks_lvl < 2)
- {
- cout << "\nYour barracks lvl is too low for this units!\n";
- err = 1;
- }
- else
- {
- white.Archers.unit_val += 40;
- cout << "\nNew archers: Our arrows belong to you and incur death of your enemies!\n";
- err = 1;
- }
- }
- }
- break;
- case 'p':
- if ((white.gold - Pike_costs * 30) < 0)
- {
- cout << "\nNot enough gold\n";
- err = 1;
- }
- else
- {
- if (white.building.barracks < 1)
- {
- cout << "\nFirst of all build barracks!\n";
- err = 1;
- }
- else
- {
- if (white.building.barracks_lvl < 3)
- {
- cout << "\nYour barracks lvl is too low for this units!\n";
- err = 1;
- }
- else
- {
- white.Pikemen.unit_val += 30;
- cout << "\nNew pikemen: Our pikes is so long that you can't be afraid that enemy comes!\n";
- err = 1;
- }
- }
- }
- break;
- case 'c':
- if ((white.gold - Cava_costs * 30) < 0)
- {
- cout << "\nNot enough gold\n";
- err = 1;
- }
- else
- {
- if (white.building.barracks < 1)
- {
- cout << "\nFirst of all build barracks!\n";
- err = 1;
- }
- else
- {
- if (white.building.barracks_lvl < 3)
- {
- cout << "\nYour barracks lvl is too low for this units!\n";
- err = 1;
- }
- else
- {
- white.Cavalry.unit_val += 30;
- cout << "\nNew cavalries: Feel like a Chingisxan)\n";
- err = 1;
- }
- }
- }
- break;
- case 'k':
- if (white.Military.unit_val < 1)
- {
- if (white.Archers.unit_val < 1)
- {
- if (white.Pikemen.unit_val < 1 )
- {
- if (white.Cavalry.unit_val < 1 )
- {
- cout << "\n\tWhat about you thinking man? You haven't no one unit!\n";
- cout << "\tIf you hoped overcome Troll king the power of thought \n\tI must disappoint you(\n";
- cout << "\tIt feature will added in next releases(when AMO-sphere will discovered)!\n";
- err = 1;
- break;
- }
- win = Troll_battle();
- }
- win = Troll_battle();
- }
- win = Troll_battle();
- }
- win = Troll_battle();
- break;
- }
- }while(err != 0);
- if (homes_timer != 0 && i == homes_timer)
- {
- cout << "\nOne home was completed!\n\n";
- white.building.homes_lvl++;
- white.building.homes++;
- homes_timer = 0;
- }
- if (barracks_timer != 0 && i == barracks_timer)
- {
- cout << "\nOne barracks was completed!\n\n";
- white.building.barracks_lvl++;
- white.building.barracks++;
- barracks_timer = 0;
- }
- // Every step changes
- white.gold += TAX_RATE_WHITE * white.population * 0.1; // Tax
- black.gold += TAX_RATE_BLACK * black.population * 0.1;
- white.population += white.population * 0.1 * white.building.homes_lvl / TAX_RATE_WHITE + 1; // Growth
- black.population += black.population * 0.1 * black.building.homes_lvl / TAX_RATE_BLACK + 1;
- clscr();
- }
- if (win == 1)
- {
- cout << "\tIt's WIN! My congratulations!!!\n\n";
- return 0;
- }
- if (win == -1)
- {
- cout << "\tGame Over! My congratulations!)azaza\n\n";
- return 0;
- }
- }
- char menu()
- {
- char m;
- do{
- cout << "\n\tWhat we will doing today?\n\n" << "(G)o into battle" << "\nBuild new (h)omes\n" << "Build new (b)arracks\n"
- << "Buy (u)nits in barracks\n" << "Spend some money on (j)ews\n" << "Just (w)ait\n"<< "\nYour choice: ";
- cin >> m;
- }while(!strchr("ghbjwu", tolower(m)));
- m = tolower(m); // User can enter U or u - it will work
- if (m == 'h')
- {
- do{
- cout << "\n\tYou can build one of three types of homes:\n\n" << "(1)-st lvl: need 600 gold and 2 days\n"
- << "(2)-nd lvl: need 2000 gold + 1 lvl and 3 days\n" << "(3)-rd lvl: need 5000 gold + 2 lvl and 5 days\n"
- << "\nYour choice: ";
- cin >> m;
- }while(!strchr("123", tolower(m)));
- }
- if (m == 'b')
- {
- do{
- cout << "\n\tYou can build one of three types of barracks:\n\n" << "(F)irst lvl: need 1000 gold and 2 days\n"
- << "(S)econd lvl: need 5000 gold + 1 lvl and 4 days\n" << "(T)hird lvl: need 12000 gold + 2 lvl and 6 days\n"
- << "\nYour choice: ";
- cin >> m;
- }while(!strchr("fst", tolower(m)));
- }
- if (m == 'u')
- {
- do{
- cout << "\n\tSelect unit type:\n\n" << "(M)ilitary(1-st lvl of barracks) 60 units cost: " << Mill_costs * 60
- << "\n(A)rchers(2-nd lvl of barracks) 40 units cost: " << Arch_costs * 40
- << "\n(P)ikemen(3-st lvl of barracks) 30 units cost: " << Pike_costs * 30
- << "\n(C)avalry (3-st lvl of barracks) 30 units cost: "<< Cava_costs * 30
- << "\n*Note: you can buy only troop of units"<< "\n\nYour choice: ";
- cin >> m;
- }while(!strchr("mapc", tolower(m)));
- }
- if (m == 'g')
- {
- cout << "\n\tSo, you are want to die or kill somebody?) Good solution :3\n\tWhere are we will going?\n\n"
- << "Troll (k)ing\n (Giant fat guy, if you'll overcome him you'll get\n a lot of money and glad + glory + princess with big tits)"
- << "\n(More enemies soon)" << "\n\nYour choice: ";
- cin >> m;
- }
- m = tolower(m);
- return m;
- }
- int Troll_battle()
- {
- int win = 0, my_damage = 0;
- int my_hp = (white.Military.HP * white.Military.unit_val + white.Archers.HP * white.Archers.unit_val + white.Pikemen.HP * white.Pikemen.unit_val + white.Cavalry.HP * white.Cavalry.unit_val);
- for (int i = 1; win == 0; i++)
- {
- clscr();
- cout << "\t\t\t\t |--| Move " << i << " |--|\n\n";
- cout << "\tTroll now: " << Troll.HP << " HP\n";
- cout << "\tYour army now: " << my_hp << " HP\n\n\n";
- if (white.Military.unit_val > 0)
- {
- my_damage = white.Military.DAM * white.Military.unit_val - Troll.DEF;
- if (my_damage > 0)
- {
- Troll.HP -= my_damage;
- cout << " - Military caused damage: " << my_damage << " HP\n";
- }
- else
- cout << " Units can't punch Troll king's defense\n";
- cout << " - Troll HP now: " << Troll.HP << " \n\n";
- }
- if (white.Pikemen.unit_val > 0 )
- {
- my_damage = white.Pikemen.DAM * white.Pikemen.unit_val - Troll.DEF;
- if (my_damage > 0)
- {
- Troll.HP -= my_damage;
- cout << " - Pikemen caused damage: " << my_damage << " HP\n";
- }
- else
- cout << " Units can't punch Troll king's defense\n";
- cout << " - Troll HP now: " << Troll.HP << " \n\n";
- }
- if (white.Cavalry.unit_val > 0 )
- {
- my_damage = white.Cavalry.DAM * white.Cavalry.unit_val - Troll.DEF;
- if (my_damage > 0)
- {
- Troll.HP -= my_damage;
- cout << " - Cavalry caused damage: " << my_damage << " HP\n";
- }
- else
- cout << " Units can't punch Troll king's defense\n";
- cout << " - Troll HP now: " << Troll.HP << " \n\n";
- }
- if (white.Archers.unit_val > 0)
- {
- my_damage = white.Archers.DAM * white.Archers.unit_val - Troll.DEF;
- if (my_damage > 0)
- {
- Troll.HP -= my_damage;
- cout << " - Archers caused damage: " << my_damage << " HP\n";
- }
- else
- cout << " Units can't punch Troll king's defense\n";
- cout << " - Troll HP now: " << Troll.HP << " \n\n";
- }
- if (Troll.HP > 0)
- {
- my_hp -= Troll.DAM;
- cout << " - Troll king caused damage: " << Troll.DAM << " HP\n";
- }
- if (Troll.HP <= 0)
- {
- win = 1;
- cout << "\n\n\t\t\t \tEnd of the battle!\n\n";
- }
- if (my_hp <= 0)
- {
- win = -1;
- cout << "\n\n\t\t\t \tEnd of the battle\n\n";
- }
- }
- return win;
- }
- void clscr()
- {
- int pause;
- if (system_switch == 1)
- {
- cout << "\nFor continue press any symbol + Enter\nSymbol: ";
- cin >> pause;
- cout << "\n";
- system("clear");
- }
- else
- if (system_switch == 2)
- {
- system("PAUSE");
- system("cls");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement