From b0dd986d4b58a9787f18d4e67c860350cad68ba2 Mon Sep 17 00:00:00 2001 From: Dahartz99 <71881195+Dahartz99@users.noreply.github.com> Date: Fri, 20 Nov 2020 11:30:54 +0800 Subject: [PATCH 1/5] Update war.cpp --- war.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/war.cpp b/war.cpp index 50451a1..ea182aa 100644 --- a/war.cpp +++ b/war.cpp @@ -2,19 +2,22 @@ #include "events.h" #include "globalvar.h" #include +// if inventory is vector +#include using namespace std; - -void war( charhp, charap, map inventory, foehp, forap, string monster){ +// what if the inventory consist of two vectors +void war( charhp, charap, vector inventory_p, vector inventory_pvalue , foehp, forap, string monster){ while (charhp >0 && foehp >0){ //player's turn int choosein, i = 1, damage = 0; - if (inventory.size() == 0){ + if (inventory_p.size() == 0){ cout << "Your inventory is empty" << endl; } - if (inventory.size() = 1){ - map::iterator itr; - for(itr = inventory.begin(); itr != inventory.end(); itr++){ - cout << i << ") " << "You only have " << (*itr).first << "with damage of " << (*itr).second << "." <::iterator itr; + //for(itr = inventory_p.begin(); itr != inventory_p.end(); itr++){ + //cout << i << ") " << "You only have " << (*itr).first << "with damage of " << (*itr).second << "." < inventory, foehp, forap, string monst while (flag == true){ if (choosein <=1 && choosein >=0){ if (choosein == 1){ - cout << "You are attacking the "<< monster << " with a " << " << ; //have to figure how to add key here(weapon name) + cout << "You are attacking the "<< monster << " with a " << " << ; inventory_p[0] damage = inventory[key]; //figure this out as well foehp -= damage; } From e01402e01987a501c085f05dadd3020ae6b53661 Mon Sep 17 00:00:00 2001 From: Dahartz99 <71881195+Dahartz99@users.noreply.github.com> Date: Fri, 20 Nov 2020 11:53:04 +0800 Subject: [PATCH 2/5] Update war.cpp --- war.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/war.cpp b/war.cpp index ea182aa..55c2d6c 100644 --- a/war.cpp +++ b/war.cpp @@ -28,7 +28,7 @@ void war( charhp, charap, vector inventory_p, vector inventory_pval if (choosein <=1 && choosein >=0){ if (choosein == 1){ cout << "You are attacking the "<< monster << " with a " << " << ; inventory_p[0] - damage = inventory[key]; //figure this out as well + damage = inventory_pvalue[0]; //figure this out as well foehp -= damage; } if (choosein == 0){ @@ -43,14 +43,17 @@ void war( charhp, charap, vector inventory_p, vector inventory_pval } } } - if (inventory.size <=3 && inventory.size > 1){ - i = 1; - map::iterator itr; - for(itr = inventory.begin(); itr != inventory.end(); itr++){ - cout << i << ") " << "You have " << (*itr).first << "with damage of " << (*itr).second << "." < 1){ + i = 0; + for(int index = 0; index < inventory_p.size(); index++) { + cout << i+1 << ") " << "You have " << inventory_p[i] << "with damage of " << inventory_pvalue[i] << "." << endl; i++; } cout << "Choose one option number from above?"; + for (int count = 1; count <= i; count++){ + cout << "Input " << count << " to pick the weapon" <> choosein; if (choosein == 1){ From 5782f50f57c720400d3e8c1a184201bd71af1d3d Mon Sep 17 00:00:00 2001 From: Dahartz99 <71881195+Dahartz99@users.noreply.github.com> Date: Fri, 20 Nov 2020 12:04:39 +0800 Subject: [PATCH 3/5] Update war.cpp --- war.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/war.cpp b/war.cpp index 55c2d6c..5194d00 100644 --- a/war.cpp +++ b/war.cpp @@ -27,7 +27,7 @@ void war( charhp, charap, vector inventory_p, vector inventory_pval while (flag == true){ if (choosein <=1 && choosein >=0){ if (choosein == 1){ - cout << "You are attacking the "<< monster << " with a " << " << ; inventory_p[0] + cout << "You are attacking the "<< monster << " with a " << inventory_p[0] << endl; damage = inventory_pvalue[0]; //figure this out as well foehp -= damage; } @@ -57,5 +57,34 @@ void war( charhp, charap, vector inventory_p, vector inventory_pval } cin >> choosein; if (choosein == 1){ + bool flag = true; + while (flag == true){ + if (choosein <=3 && choosein >=0){ + if (choosein == 3){ + cout << "You are attacking the "<< monster << " with a " << inventory_p[2] << endl; + damage = inventory_pvalue[2]; + foehp -= damage; + } + if (choosein == 2){ + cout << "You are attacking the "<< monster << " with a " << inventory_p[1] << endl; + damage = inventory_pvalue[1]; + foehp -= damage; + } + if (choosein == 1){ + cout << "You are attacking the "<< monster << " with a " << inventory_p[0] << endl; + damage = inventory_pvalue[0]; + foehp -= damage; + } + if (choosein == 0){ + cout << "You attack the monster with you hands" << endl; + damage = charap; + foehp -= damage; + } + } + else{ + cout << "Oops! No such option in the inventory. Choose again: "; + cin >> choosein; + } + } //monster's turn From eaf6c21683b1a2e276bb08a189e6d801d12a1b15 Mon Sep 17 00:00:00 2001 From: Dahartz99 <71881195+Dahartz99@users.noreply.github.com> Date: Fri, 20 Nov 2020 12:32:35 +0800 Subject: [PATCH 4/5] Update war.cpp --- war.cpp | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/war.cpp b/war.cpp index 5194d00..26d5f57 100644 --- a/war.cpp +++ b/war.cpp @@ -15,9 +15,6 @@ void war( charhp, charap, vector inventory_p, vector inventory_pval } if (inventory_p.size() = 1){ cout << " 1 " << "You only have " << inventory_p[0] << "with damage of " << inventory_pvalue[0] << "." <::iterator itr; - //for(itr = inventory_p.begin(); itr != inventory_p.end(); itr++){ - //cout << i << ") " << "You only have " << (*itr).first << "with damage of " << (*itr).second << "." < inventory_p, vector inventory_pval cout << "Input 0 if you do not want to use any weapon" <> choosein; - if (choosein == 1){ - bool flag = true; - while (flag == true){ - if (choosein <=3 && choosein >=0){ - if (choosein == 3){ - cout << "You are attacking the "<< monster << " with a " << inventory_p[2] << endl; - damage = inventory_pvalue[2]; - foehp -= damage; - } - if (choosein == 2){ - cout << "You are attacking the "<< monster << " with a " << inventory_p[1] << endl; - damage = inventory_pvalue[1]; - foehp -= damage; - } - if (choosein == 1){ - cout << "You are attacking the "<< monster << " with a " << inventory_p[0] << endl; - damage = inventory_pvalue[0]; - foehp -= damage; - } - if (choosein == 0){ - cout << "You attack the monster with you hands" << endl; - damage = charap; - foehp -= damage; - } + bool flag = true; + while (flag == true){ + if (choosein <=3 && choosein >=0){ + if (choosein == 3){ + cout << "You are attacking the "<< monster << " with a " << inventory_p[2] << endl; + damage = inventory_pvalue[2]; + foehp -= damage; } - else{ - cout << "Oops! No such option in the inventory. Choose again: "; - cin >> choosein; + if (choosein == 2){ + cout << "You are attacking the "<< monster << " with a " << inventory_p[1] << endl; + damage = inventory_pvalue[1]; + foehp -= damage; + } + if (choosein == 1){ + cout << "You are attacking the "<< monster << " with a " << inventory_p[0] << endl; + damage = inventory_pvalue[0]; + foehp -= damage; + } + if (choosein == 0){ + cout << "You attack the monster with you hands" << endl; + damage = charap; + foehp -= damage; } } + else{ + cout << "Oops! No such option in the inventory. Choose again: "; + cin >> choosein; + } + } //monster's turn From f40e8ef3280bd7b3af059ad764fa92d61bd7d93d Mon Sep 17 00:00:00 2001 From: Dahartz99 <71881195+Dahartz99@users.noreply.github.com> Date: Fri, 20 Nov 2020 13:37:26 +0800 Subject: [PATCH 5/5] Update war.cpp --- war.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/war.cpp b/war.cpp index 26d5f57..9caf240 100644 --- a/war.cpp +++ b/war.cpp @@ -1,13 +1,12 @@ #include #include "events.h" #include "globalvar.h" -#include // if inventory is vector #include using namespace std; // what if the inventory consist of two vectors void war( charhp, charap, vector inventory_p, vector inventory_pvalue , foehp, forap, string monster){ - while (charhp >0 && foehp >0){ + while (charhp > 0 && foehp >0){ //player's turn int choosein, i = 1, damage = 0; if (inventory_p.size() == 0){ @@ -25,8 +24,10 @@ void war( charhp, charap, vector inventory_p, vector inventory_pval if (choosein <=1 && choosein >=0){ if (choosein == 1){ cout << "You are attacking the "<< monster << " with a " << inventory_p[0] << endl; - damage = inventory_pvalue[0]; //figure this out as well - foehp -= damage; + damage = inventory_pvalue[0]; + foehp -= damage; + inventory_p.erase (inventory_p.begin()); + inventory_pvalue.erase (inventory_pvalue.begin()); } if (choosein == 0){ cout << "You attack the monster with you hands" << endl; @@ -59,17 +60,23 @@ void war( charhp, charap, vector inventory_p, vector inventory_pval if (choosein == 3){ cout << "You are attacking the "<< monster << " with a " << inventory_p[2] << endl; damage = inventory_pvalue[2]; - foehp -= damage; + foehp -= damage; + inventory_p.erase (inventory_p.begin()+2); + inventory_pvalue.erase (inventory_pvalue.begin()+2); } if (choosein == 2){ cout << "You are attacking the "<< monster << " with a " << inventory_p[1] << endl; damage = inventory_pvalue[1]; - foehp -= damage; + foehp -= damage; + inventory_p.erase (inventory_p.begin()+1); + inventory_pvalue.erase (inventory_pvalue.begin()+1); } if (choosein == 1){ cout << "You are attacking the "<< monster << " with a " << inventory_p[0] << endl; damage = inventory_pvalue[0]; - foehp -= damage; + foehp -= damage; + inventory_p.erase (inventory_p.begin()); + inventory_pvalue.erase (inventory_pvalue.begin()); } if (choosein == 0){ cout << "You attack the monster with you hands" << endl;