Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update war.cpp #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 56 additions & 18 deletions war.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include <iostream>
#include "events.h"
#include "globalvar.h"
#include <map>
// if inventory is vector
#include <vector>
using namespace std;

void war( charhp, charap, map<string, int> inventory, foehp, forap, string monster){
while (charhp >0 && foehp >0){
// what if the inventory consist of two vectors
void war( charhp, charap, vector<string> inventory_p, vector<int> 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<string, int>::iterator itr;
for(itr = inventory.begin(); itr != inventory.end(); itr++){
cout << i << ") " << "You only have " << (*itr).first << "with damage of " << (*itr).second << "." <<endl;
if (inventory_p.size() = 1){
cout << " 1 " << "You only have " << inventory_p[0] << "with damage of " << inventory_pvalue[0] << "." <<endl;
}
cout << "Input 1 to pick the weapon" <<endl;
cout << "Input 0 if you do not want to use any weapon" <<endl;
Expand All @@ -24,9 +23,11 @@ void war( charhp, charap, map<string, int> 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)
damage = inventory[key]; //figure this out as well
foehp -= damage;
cout << "You are attacking the "<< monster << " with a " << inventory_p[0] << endl;
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;
Expand All @@ -40,16 +41,53 @@ void war( charhp, charap, map<string, int> inventory, foehp, forap, string monst
}
}
}
if (inventory.size <=3 && inventory.size > 1){
i = 1;
map<string, int>::iterator itr;
for(itr = inventory.begin(); itr != inventory.end(); itr++){
cout << i << ") " << "You have " << (*itr).first << "with damage of " << (*itr).second << "." <<endl;
if (inventory_p.size() <=3 && inventory_p.size() > 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" <<endl;
}
cout << "Input 0 if you do not want to use any weapon" <<endl;
}
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;
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;
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;
inventory_p.erase (inventory_p.begin());
inventory_pvalue.erase (inventory_pvalue.begin());
}
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