From 7b18b7c8b48cd6f761960027c66c047f083458e6 Mon Sep 17 00:00:00 2001 From: "Jezae Thomas (thoma339)" Date: Wed, 26 Feb 2020 08:11:31 +0000 Subject: [PATCH 1/3] Update main.cpp --- Map with monster/main.cpp | 296 +++++++++++++++++++++++++++----------- 1 file changed, 216 insertions(+), 80 deletions(-) diff --git a/Map with monster/main.cpp b/Map with monster/main.cpp index 28fd976..00c512f 100644 --- a/Map with monster/main.cpp +++ b/Map with monster/main.cpp @@ -1,23 +1,27 @@ #include "stats.h" #include "combat.h" #include "map.h" +#include "items.h" #include using namespace std; - int classInput; int typeInput; int monsterMove; bool inCombat; +bool play; +bool InventoryCheck; string playerClass; string monsterType; +string ItemInput; +string changeInput; int main() { srand(time(NULL)); cout << "[1] Warrior [2] Rogue [3] Mage" << endl; - cout << "Enter your class: "; classInput = 0; while ( classInput == 0 ) { + cout << "Enter your class: "; cin >> classInput; if ( classInput == 1 || classInput == 2 || classInput == 3 ) { switch ( classInput ) { @@ -34,97 +38,229 @@ int main() { break; } else { - cout << "Invalid entry. Try again" << endl; + classInput = 0; + cout << "Invalid entry. Try again \n" << endl; } } system("cls"); Player PlayerObj(classInput); Map MapObj; - inCombat = false; - monsterMove = 3; - while ( inCombat == false ) { - MapObj.drawMap(); - MapObj.movePlayer(); - monsterMove--; - if ( monsterMove == 0 ) { - MapObj.moveMonster(); - monsterMove = 3; - } - if ( MapObj.getPlayerY() == MapObj.getMonsterY() && MapObj.getPlayerX() == MapObj.getMonsterX() ) { - inCombat = true; - } - } - typeInput = rand() % 3 + 1; - Monster MonsterObj(typeInput); - switch ( typeInput ) { - case 1: - monsterType = "Beast"; - break; - case 2: - monsterType = "Phantom"; - break; - case 3: - monsterType = "Elf"; - break; - } - Combat CombatObj(PlayerObj.getVitality(), MonsterObj.getVitality(), PlayerObj.getAgility(), MonsterObj.getAgility(), PlayerObj.getEnergy(), MonsterObj.getEnergy()); - CombatObj.start(PlayerObj.getVitality(), PlayerObj.getStrength(), PlayerObj.getAgility(), PlayerObj.getDurability(), PlayerObj.getPrecision(), PlayerObj.getEnergy(), MonsterObj.getVitality(), MonsterObj.getStrength(), MonsterObj.getAgility(), MonsterObj.getDurability(), MonsterObj.getPrecision(), MonsterObj.getEnergy(), playerClass, monsterType); - while ( CombatObj.isCombatOver() == false ) { - if ( CombatObj.getPlayerFirst() == true ) { - CombatObj.playerAction(CombatObj.preTurn(), PlayerObj.getStrength(), PlayerObj.getPrecision(), MonsterObj.getAgility(), MonsterObj.getDurability()); - if ( CombatObj.isCombatOver() == true ) { - cout << "Player wins" << endl; - cout << "You gained 2000 experience points" << endl; - PlayerObj.setExp(2000); - if ( PlayerObj.getExp() >= PlayerObj.getLevelUpThreshold() ) { - PlayerObj.levelUp(); - cout << "Level Up!" << endl; - cout << "Vitality: " << PlayerObj.getVitality() << endl; - cout << "Strength: " << PlayerObj.getStrength() << endl; - cout << "Agility: " << PlayerObj.getAgility() << endl; - cout << "Durability: " << PlayerObj.getDurability() << endl; - cout << "Precision: " << PlayerObj.getPrecision() << endl; - cout << "Energy: " << PlayerObj.getEnergy() << endl; - system("pause"); - } - break; + Items ItemObj; + play = true; + while (play == true) + { + inCombat = false; + InventoryCheck = false; + monsterMove = 3; + while ( inCombat == false && InventoryCheck == false && play == true ) { + MapObj.drawMap(); + MapObj.movePlayer(); + monsterMove--; + if ( monsterMove == 0 ) { + MapObj.moveMonster(); + monsterMove = 3; + } + if ( MapObj.getPlayerY() == MapObj.getMonsterY() && MapObj.getPlayerX() == MapObj.getMonsterX() ) { + inCombat = true; + + } + if ( MapObj.getPlayerY() == MapObj.getItemY() && MapObj.getPlayerX() == MapObj.getItemX() ) { + system("cls"); + ItemObj.setNewItem(); + MapObj.set_item_x_y(); + system("pause"); + } + if (MapObj.getinventoryCheck() == true){ + InventoryCheck = true; } - CombatObj.monsterAction(MonsterObj.getStrength(), MonsterObj.getPrecision(), PlayerObj.getAgility(), PlayerObj.getDurability()); - if ( CombatObj.isCombatOver() == true ) { - cout << "Monster wins" << endl; - cout << "Game over" << endl; - exit(0); - break; + if (MapObj.getquit() == true){ + play = false; } } - else { - CombatObj.monsterAction(MonsterObj.getStrength(), MonsterObj.getPrecision(), PlayerObj.getAgility(), PlayerObj.getDurability()); - if ( CombatObj.isCombatOver() == true ) { - cout << "Monster wins" << endl; - cout << "Game over" << endl; - exit(0); - break; + if(inCombat == true){ + typeInput = rand() % 3 + 1; + Monster MonsterObj(typeInput); + switch ( typeInput ) { + case 1: + monsterType = "Beast"; + break; + case 2: + monsterType = "Phantom"; + break; + case 3: + monsterType = "Elf"; + break; } - CombatObj.playerAction(CombatObj.preTurn(), PlayerObj.getStrength(), PlayerObj.getPrecision(), MonsterObj.getAgility(), MonsterObj.getDurability()); - if ( CombatObj.isCombatOver() == true ) { - cout << "Player wins" << endl; - cout << "You gained 2000 experience points" << endl; - PlayerObj.setExp(2000); - if ( PlayerObj.getExp() >= PlayerObj.getLevelUpThreshold() ) { - PlayerObj.levelUp(); - cout << "Level Up!" << endl; - cout << "Vitality: " << PlayerObj.getVitality() << endl; - cout << "Strength: " << PlayerObj.getStrength() << endl; - cout << "Agility: " << PlayerObj.getAgility() << endl; - cout << "Durability: " << PlayerObj.getDurability() << endl; - cout << "Precision: " << PlayerObj.getPrecision() << endl; - cout << "Energy: " << PlayerObj.getEnergy() << endl; + Combat CombatObj(PlayerObj.getVitality(), MonsterObj.getVitality(), PlayerObj.getAgility(), MonsterObj.getAgility(), PlayerObj.getEnergy(), MonsterObj.getEnergy()); + CombatObj.start(PlayerObj.getVitality(), PlayerObj.getStrength(), PlayerObj.getAgility(), PlayerObj.getDurability(), PlayerObj.getPrecision(), PlayerObj.getEnergy(), MonsterObj.getVitality(), MonsterObj.getStrength(), MonsterObj.getAgility(), MonsterObj.getDurability(), MonsterObj.getPrecision(), MonsterObj.getEnergy(), playerClass, monsterType); + while ( CombatObj.isCombatOver() == false ) { + if ( CombatObj.getPlayerFirst() == true ) { + CombatObj.playerAction(CombatObj.preTurn(), PlayerObj.getStrength(), PlayerObj.getPrecision(), MonsterObj.getAgility(), MonsterObj.getDurability()); + if ( CombatObj.isCombatOver() == true ) { + cout << "Player wins" << endl; + cout << "You gained 2000 experience points" << endl; + PlayerObj.setExp(2000); + if ( PlayerObj.getExp() >= PlayerObj.getLevelUpThreshold() ) { + PlayerObj.levelUp(); + cout << "Level Up!" << endl; + cout << "Vitality: " << PlayerObj.getVitality() << endl; + cout << "Strength: " << PlayerObj.getStrength() << endl; + cout << "Agility: " << PlayerObj.getAgility() << endl; + cout << "Durability: " << PlayerObj.getDurability() << endl; + cout << "Precision: " << PlayerObj.getPrecision() << endl; + cout << "Energy: " << PlayerObj.getEnergy() << endl; + system("pause"); + } + break; + } + CombatObj.monsterAction(MonsterObj.getStrength(), MonsterObj.getPrecision(), PlayerObj.getAgility(), PlayerObj.getDurability()); + if ( CombatObj.isCombatOver() == true ) { + cout << "Monster wins" << endl; + cout << "Game over" << endl; + exit(0); + break; + } + } + else { + CombatObj.monsterAction(MonsterObj.getStrength(), MonsterObj.getPrecision(), PlayerObj.getAgility(), PlayerObj.getDurability()); + if ( CombatObj.isCombatOver() == true ) { + cout << "Monster wins" << endl; + cout << "Game over" << endl; + exit(0); + break; + } + CombatObj.playerAction(CombatObj.preTurn(), PlayerObj.getStrength(), PlayerObj.getPrecision(), MonsterObj.getAgility(), MonsterObj.getDurability()); + if ( CombatObj.isCombatOver() == true ) { + cout << "Player wins" << endl; + cout << "You gained 2000 experience points" << endl; + PlayerObj.setExp(2000); + if ( PlayerObj.getExp() >= PlayerObj.getLevelUpThreshold() ) { + PlayerObj.levelUp(); + cout << "Level Up!" << endl; + cout << "Vitality: " << PlayerObj.getVitality() << endl; + cout << "Strength: " << PlayerObj.getStrength() << endl; + cout << "Agility: " << PlayerObj.getAgility() << endl; + cout << "Durability: " << PlayerObj.getDurability() << endl; + cout << "Precision: " << PlayerObj.getPrecision() << endl; + cout << "Energy: " << PlayerObj.getEnergy() << endl; + system("pause"); + } + break; + } + } + } + } + if (InventoryCheck == true){ + changeInput = "go"; + while (changeInput != "0") { + system("cls"); + cout << "press [0] to return back to the game.\n" << endl; + ItemObj.printBag(); + cout << "\n" << endl; + cout << "Do you want to equip item [e] or remove it [r]\n" << endl; + cin >> changeInput; + if (changeInput == "e") + { + system("cls"); + ItemObj.printBag(); + cout << " \n"<< endl; + cout << "what do you want to equip: "; + string user_item; + cin >> user_item; + int a = ItemObj.get_ID(user_item); + + if (a==-1){cout << "invalid input" << endl;system("pause");} + else + { + ItemObj.Item_id = a; + int* stat_changes = ItemObj.add_item(); + int p_stat = PlayerObj.getStrength(); + PlayerObj.setStrength((p_stat + stat_changes[0])); + p_stat = PlayerObj.getAgility(); + PlayerObj.setAgility((p_stat + stat_changes[1])); + p_stat = PlayerObj.getDurability(); + PlayerObj.setDurability((p_stat + stat_changes[2])); + p_stat = PlayerObj.getEnergy(); + PlayerObj.setEnergy((p_stat + stat_changes[3])); + p_stat = PlayerObj.getVitality(); + PlayerObj.setVitality((p_stat + stat_changes[4])); + p_stat = PlayerObj.getPrecision(); + PlayerObj.setPrecision((p_stat + stat_changes[5])); + + + cout << "the players stats are : " << endl; + cout << "Strength: " << PlayerObj.getStrength() << endl; + cout << "Agility: " << PlayerObj.getAgility() << endl; + cout << "Durability: " << PlayerObj.getDurability() << endl; + cout << "Energy: " << PlayerObj.getEnergy() << endl; + cout << "Vitality: " << PlayerObj.getVitality() << endl; + cout << "Precision: " << PlayerObj.getPrecision() << endl; + cout << " " << endl; + system("pause"); + } + } + else if (changeInput == "r") + { + system("cls"); + ItemObj.printequiped(); + string user_item; + cin >> user_item; + int a = ItemObj.get_ID(user_item); + + if (a==-1){cout << "invalid input" << endl;system("pause");} + else if(a==-2){/**/} + else + { + ItemObj.Item_id = a; + int* stat_changes = ItemObj.removeitem(); + int p_stat = PlayerObj.getStrength(); + PlayerObj.setStrength((p_stat + stat_changes[0])); + p_stat = PlayerObj.getAgility(); + PlayerObj.setAgility((p_stat + stat_changes[1])); + p_stat = PlayerObj.getDurability(); + PlayerObj.setDurability((p_stat + stat_changes[2])); + p_stat = PlayerObj.getEnergy(); + PlayerObj.setEnergy((p_stat + stat_changes[3])); + p_stat = PlayerObj.getVitality(); + PlayerObj.setVitality((p_stat + stat_changes[4])); + p_stat = PlayerObj.getPrecision(); + PlayerObj.setPrecision((p_stat + stat_changes[5])); + + cout << "the players stats are : " << endl; + cout << "Strength: " << PlayerObj.getStrength() << endl; + cout << "Agility: " << PlayerObj.getAgility() << endl; + cout << "Durability: " << PlayerObj.getDurability() << endl; + cout << "Energy: " << PlayerObj.getEnergy() << endl; + cout << "Vitality: " << PlayerObj.getVitality() << endl; + cout << "Precision: " << PlayerObj.getPrecision() << endl; + cout << " " << endl; + } + + } + else if (changeInput == "0") + { + system("cls"); + InventoryCheck = false; + MapObj.setinventoryCheck(); + } + else if (changeInput == "q") + { + changeInput = "0"; + play = false; + } + else + { + cout << "invalid input pls try again" << endl; system("pause"); } - break; + + + + } + InventoryCheck = false; } } return 0; -} \ No newline at end of file +} From 3dd709679853a8343fac6cc41ac6306fb3beea27 Mon Sep 17 00:00:00 2001 From: "Jezae Thomas (thoma339)" Date: Wed, 26 Feb 2020 08:11:59 +0000 Subject: [PATCH 2/3] Update map.h --- Map with monster/map.h | 54 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/Map with monster/map.h b/Map with monster/map.h index 7e1ebaf..a50c02f 100644 --- a/Map with monster/map.h +++ b/Map with monster/map.h @@ -13,7 +13,7 @@ class Map { {'#', ' ', ' ', ' ', ' ', ' ', '#'}, {'#', ' ', ' ', ' ', ' ', ' ', '#'}, {'#', ' ', ' ', '*', ' ', ' ', '#'}, - {'#', ' ', ' ', ' ', ' ', ' ', '#'}, + {'#', ' ', ' ', ' ', 'C', ' ', '#'}, {'#', 'M', ' ', ' ', ' ', ' ', '#'}, {'#', '#', '#', '#', '#', '#', '#'}}; int kbinput; @@ -21,7 +21,11 @@ class Map { int playerY = 3; int monsterX = 1; int monsterY = 5; + int itemX = 4; + int itemY = 4; int col, row; + bool inventoryCheck = false; + bool quit = false; public: Map() { @@ -35,6 +39,8 @@ class Map { } cout << endl; } + cout << "press [0] at anytime to open your bag " << endl; + cout << "press [q] at anytime to quit the game " << endl; } void movePlayer() { @@ -67,6 +73,16 @@ class Map { playerX += 1; map[playerY][playerX] = '*'; break; + + case 48: // [0] key + if(inventoryCheck == true) break; + inventoryCheck = true; + break; + + case 113: // [q] key + if(quit == true) break; + quit = true; + break; } } @@ -74,26 +90,26 @@ class Map { srand(time(NULL)); switch ( rand() % 4 + 1 ) { case 1: // Up - if(map[monsterY-1][monsterX] == '#') break; + if(map[monsterY-1][monsterX] == '#' || map[monsterY-1][monsterX] == 'C') break; map[monsterY][monsterX] = ' '; monsterY -= 1; map[monsterY][monsterX] = 'M'; break; case 2: // Down - if(map[monsterY+1][monsterX] == '#') break; + if(map[monsterY+1][monsterX] == '#' || map[monsterY+1][monsterX] == 'C' ) break; map[monsterY][monsterX] = ' '; monsterY += 1; map[monsterY][monsterX] = 'M'; break; case 3: // Left - if(map[monsterY][monsterX-1] == '#') break; + if(map[monsterY][monsterX-1] == '#' || map[monsterY][monsterX-1] == 'C') break; map[monsterY][monsterX] = ' '; monsterX -= 1; map[monsterY][monsterX] = 'M'; break; case 4: // Right - if(map[monsterY][monsterX+1] == '#') break; + if(map[monsterY][monsterX+1] == '#' || map[monsterY][monsterX+1] == 'C') break; map[monsterY][monsterX] = ' '; monsterX += 1; map[monsterY][monsterX] = 'M'; @@ -109,6 +125,14 @@ class Map { return playerY; } + int getItemX() const { + return itemX; + } + + int getItemY() const { + return itemY; + } + int getMonsterX() const { return monsterX; } @@ -116,6 +140,24 @@ class Map { int getMonsterY() const { return monsterY; } + + bool getinventoryCheck() const { + return inventoryCheck; + } + + void setinventoryCheck(){ + inventoryCheck = false; + } + + void set_item_x_y(){ + map[itemY][itemX] == ' '; + itemX = 0; + itemY = 0; + } + + bool getquit() const { + return quit; + } }; -#endif \ No newline at end of file +#endif From 86ec2ddcd4bb11c6dcf446813b3c1333c5e38f4e Mon Sep 17 00:00:00 2001 From: "Jezae Thomas (thoma339)" Date: Wed, 26 Feb 2020 08:12:38 +0000 Subject: [PATCH 3/3] Create items.h --- Map with monster/items.h | 171 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 Map with monster/items.h diff --git a/Map with monster/items.h b/Map with monster/items.h new file mode 100644 index 0000000..5a89ec8 --- /dev/null +++ b/Map with monster/items.h @@ -0,0 +1,171 @@ +#include +#include +#include +using namespace std; +#include "stats.h" + + + + +class Items +{ + public: + int Item_id = -1; + vector all_possible_items { "stick", "shield", "armour", "sword",}; + vector player_bag { "stick", "shield", "armour","stick"}; + vector equippedItems {}; + + + void printBag() + { + cout << "your bag: \n" ; + for (int it = 0; it <= (player_bag.size()-1); it++) + { + cout << player_bag[it] << " , " ; + } + } + + void printequiped() + { + if (equippedItems.size()==0) + { + cout << "You have no items equipped. enter skip to continue" << endl; + } + else + { + for (int it = 0; it <= (equippedItems.size()-1); it++) + { + cout << equippedItems[it] << " , " ; + } + + cout << " \n"<< endl; + cout << "what do you want to remove \n" << endl; + } + } + + + int get_ID(string uitem) + { + for (int it = 0; it <= (all_possible_items.size()-1); it++) + { + if( all_possible_items[it]==uitem) + { + int num = it; + return num; + } + } + if (uitem == "skip") + { + int num= -2; + return num; + } + else + { + int num = -1; + return num; + } + } + + + int* add_item() + { + if(equippedItems.size() == 4 ) + { + system("cls"); + cout << "you have equiped max number of items remove some to equip a new item " << endl; + static int changes[6] = {0,0,0,0,0,0};return changes; + + } + else + { + vector temp {}; + int count = 0; + for (int it = (player_bag.size()-1); it >=0 ; it--) + { + if (player_bag[it] == all_possible_items[Item_id] && count == 0) + { + equippedItems.push_back(player_bag[it]); + player_bag.pop_back(); + count +=1; + } + else + { + temp.push_back(player_bag[it]); + player_bag.pop_back(); + } + } + + for (int it2 = (temp.size()-1) ; it2 >=0; it2--) + { + string tempp = temp.back(); + temp.pop_back(); + player_bag.push_back(tempp); + } + + cout << "you have equipped " << all_possible_items[Item_id] << "\n" << endl; + + if (Item_id == 0){static int changes[6] = {5,2,0,0,0,0};return changes;} + else if (Item_id == 1){static int changes[6] = {0,-2,5,0,0,-1};return changes;} + else if (Item_id == 2){static int changes[6] = {0,-3,3,0,7,0};return changes;} + else if (Item_id == 3){static int changes[6] = {10,-2,0,0,0,1};return changes;} + } + } + + + int* removeitem() + { + if (equippedItems.empty()) + { + cout << "everthing has been removed \n" << endl; + } + else + { + vector temp {}; + int count = 0; + + for (int it = (equippedItems.size()-1); it >=0 ; it--) + { + if (equippedItems[it] == all_possible_items[Item_id] && count == 0) + { + player_bag.push_back(equippedItems[it]); + equippedItems.pop_back(); + count +=1; + } + else + { + temp.push_back(equippedItems[it]); + equippedItems.pop_back(); + } + } + + for (int it2 = (temp.size()-1) ; it2 >=0; it2--) + { + string tempp = temp.back(); + temp.pop_back(); + equippedItems.push_back(tempp); + } + cout << "you have unequipped " << all_possible_items[Item_id] << "\n" << endl; + + if (Item_id == 0){static int changes[6] = {-5,-2,0,0,0,0};return changes;} + else if (Item_id == 1){static int changes[6] = {0,2,-5,0,0,1};return changes;} + else if (Item_id == 2){static int changes[6] = {0,3,-3,0,-7,0};return changes;} + else if (Item_id == 3){static int changes[6] = {-10,2,0,0,0,-1};return changes;} + + + + } + } + + + void setNewItem() + { + int randNumber = rand() % all_possible_items.size(); + player_bag.push_back(all_possible_items[randNumber]); + cout << "the chest has given you a " << all_possible_items[randNumber] << "\n" << endl; + printBag(); + + + } + + +};