Skip to content

Commit

Permalink
upload
Browse files Browse the repository at this point in the history
  • Loading branch information
clariechek committed Jan 16, 2023
0 parents commit 296171c
Show file tree
Hide file tree
Showing 222 changed files with 2,316 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Detective.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <string>
#include "User.h"
#include "Detective.h"

// implementation of Detective constructor with name and balance
Detective::Detective(std::string name, int balance):User(name,balance) {
counter = 0;
}

// implementation special() function
void Detective::special(User *detective) {
counter+=1;
if (counter==3) {
addBalance(200000);
std::cout<<"You earned $200,000!"<<std::endl;
counter=0;
}
else {
std::cout<<"You have to investigate for another "<<3-counter<<" rounds."<<std::endl;
}
}

// implementation of Detective destructor
Detective::~Detective() {
counter = 0;
}
19 changes: 19 additions & 0 deletions Detective.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef DETECTIVE_H
#define DETECTIVE_H
#include <iostream>
#include <string>
#include "User.h"

// class definition for a detective
class Detective : public User {

public:
Detective(std::string name, int balance);

int counter;

void special(User *detective);

~Detective();
};
#endif
Binary file added Detective_test
Binary file not shown.
27 changes: 27 additions & 0 deletions Detective_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include "Detective.h"

// Test for Detective methods
int main() {
int count = 0;
User* detectives[5];

detectives[0] = new Detective("Tom", 100000);
detectives[1] = new Detective("Jane", 0);
detectives[2] = new Detective("Frank", 5000);
detectives[3] = new Detective("Nancy", -1);
detectives[4] = new Detective("Gale", 400000);
while (count < 3) {
count++;
for (int num=0; num<5; num++) {
std::cout << "\nTest" << num+1 << std::endl;
std::cout << "Detective " << num+1 << ": Name: " << detectives[num]->getName() << " Balance: $" << detectives[num]->getBalance() << std::endl;
detectives[num]->special(detectives[num]);
std::cout << "Detective " << num+1 << ": Name: " << detectives[num]->getName() << " Balance: $" << detectives[num]->getBalance() << std::endl;
}
}
for (int i=0; i<5; i++) {
delete detectives[i];
}
return 0;
}
75 changes: 75 additions & 0 deletions Detective_testExpectedOutput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

Test1
Detective 1: Name: Tom Balance: $100000
You have to investigate for another 2 rounds.
Detective 1: Name: Tom Balance: $100000

Test2
Detective 2: Name: Jane Balance: $0
You have to investigate for another 2 rounds.
Detective 2: Name: Jane Balance: $0

Test3
Detective 3: Name: Frank Balance: $5000
You have to investigate for another 2 rounds.
Detective 3: Name: Frank Balance: $5000

Test4
Detective 4: Name: Nancy Balance: $-1
You have to investigate for another 2 rounds.
Detective 4: Name: Nancy Balance: $-1

Test5
Detective 5: Name: Gale Balance: $400000
You have to investigate for another 2 rounds.
Detective 5: Name: Gale Balance: $400000

Test1
Detective 1: Name: Tom Balance: $100000
You have to investigate for another 1 rounds.
Detective 1: Name: Tom Balance: $100000

Test2
Detective 2: Name: Jane Balance: $0
You have to investigate for another 1 rounds.
Detective 2: Name: Jane Balance: $0

Test3
Detective 3: Name: Frank Balance: $5000
You have to investigate for another 1 rounds.
Detective 3: Name: Frank Balance: $5000

Test4
Detective 4: Name: Nancy Balance: $-1
You have to investigate for another 1 rounds.
Detective 4: Name: Nancy Balance: $-1

Test5
Detective 5: Name: Gale Balance: $400000
You have to investigate for another 1 rounds.
Detective 5: Name: Gale Balance: $400000

Test1
Detective 1: Name: Tom Balance: $100000
You earned $200,000!
Detective 1: Name: Tom Balance: $300000

Test2
Detective 2: Name: Jane Balance: $0
You earned $200,000!
Detective 2: Name: Jane Balance: $200000

Test3
Detective 3: Name: Frank Balance: $5000
You earned $200,000!
Detective 3: Name: Frank Balance: $205000

Test4
Detective 4: Name: Nancy Balance: $-1
You earned $200,000!
Detective 4: Name: Nancy Balance: $199999

Test5
Detective 5: Name: Gale Balance: $400000
You earned $200,000!
Detective 5: Name: Gale Balance: $600000
63 changes: 63 additions & 0 deletions PVP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
#include <string>
#include "User.h"

extern double action(User*);
extern void check_action(User*,User*,double,int);
extern int check_balance(User*);
extern bool return_to_menu(std::string);

bool PVP(User** users) {
// Function that takes in 2 players and runs the Multiplayer Mode
double player_choice = 0;
bool restart = true;
bool condition = true;
int multiplayer_end = 0;
int game_round = 0;

// PVP Loop
while (restart == true) {
while (condition == true) {
game_round++;
std::cout << "---ROUND " << game_round <<"---"<<std::endl;
std::cout << users[0][0].getName() << "'s current balance: " << "$" << users[0][0].getBalance() << std::endl;
std::cout << users[1][0].getName() << "'s current balance: " << "$" << users[1][0].getBalance() << std::endl;
for (int turn = 0; turn < 2; turn++) {
player_choice = action(users[turn]);

if (turn == 0) {
check_action(users[turn], users[1], player_choice, turn);
}
else if (turn == 1) {
check_action(users[turn], users[0], player_choice, turn);
}
multiplayer_end = check_balance(users[turn]);
if (multiplayer_end == 1) {
if (turn == 0) {
std::cout << users[1][0].getName() << " HAS WON THE GAME!!" << std::endl;
condition = false;
break;
}
else if (turn == 1) {
std::cout << users[0][0].getName() << " HAS WON THE GAME!!" << std::endl;
condition = false;
break;
}
}
if (multiplayer_end == 2) {
condition = false;
}
else {
continue;
}
}
}
std::cout << "END OF ROUND " << game_round << std::endl;
restart = return_to_menu("Multiplayer");
//reset
users[0][0].setBalance(150000);
users[1][0].setBalance(150000);
}

return restart;
}
Binary file added PVP_test
Binary file not shown.
21 changes: 21 additions & 0 deletions PVP_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
#include <string>
#include "User.h"
#include "Thief.h"
#include "Detective.h"

//extern double action(User*);
//extern void check_action(User*,User*,double,int);
//extern int check_balance(User*);
//extern bool return_to_menu(std::string);
extern bool PVP(User** users);
//extern std::string* select_name(std::string*, std::string);

int main() {
//std::string* usernames = {"Hello", "World"};
// usernames = select_name(usernames, "Multiplayer");
User *user1= new Thief("Tom", 480000);
User *user2=new Detective("Jerry",300000);
User* users[2] = {user1, user2};
std::cout <<PVP(users);
}
56 changes: 56 additions & 0 deletions PVP_testExpectedOutput01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---ROUND 1---
Tom's current balance: $480000
Jerry's current balance: $300000
----------Tom's Turn----------
Tom's Balance: $480000
What would you like to do Tom ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: Tom passed their turn

----------Jerry's Turn----------
Jerry's Balance: $300000
What would you like to do Jerry ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: You have to investigate for another 2 rounds.
Jerry's Balance: $300000

---ROUND 2---
Tom's current balance: $480000
Jerry's current balance: $300000
----------Tom's Turn----------
Tom's Balance: $480000
What would you like to do Tom ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: Tom passed their turn

----------Jerry's Turn----------
Jerry's Balance: $300000
What would you like to do Jerry ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: You have to investigate for another 1 rounds.
Jerry's Balance: $300000

---ROUND 3---
Tom's current balance: $480000
Jerry's current balance: $300000
----------Tom's Turn----------
Tom's Balance: $480000
What would you like to do Tom ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: Tom passed their turn

----------Jerry's Turn----------
Jerry's Balance: $300000
What would you like to do Jerry ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: You earned $200,000!
Jerry's Balance: $500000

Jerry HAS ACHIEVED $500,000!
Jerry HAS WON THE GAME!!
END OF ROUND 3
Do you wish to continue? Enter 1.Yes or 2.No:
Exiting Multiplayer Mode...
Returning to Main Menu...

0
39 changes: 39 additions & 0 deletions PVP_testExpectedOutput02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---ROUND 1---
Tom's current balance: $480000
Jerry's current balance: $300000
----------Tom's Turn----------
Tom's Balance: $480000
What would you like to do Tom ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: Tom passed their turn

----------Jerry's Turn----------
Jerry's Balance: $300000
What would you like to do Jerry ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: Jerry passed their turn

---ROUND 2---
Tom's current balance: $480000
Jerry's current balance: $300000
----------Tom's Turn----------
Tom's Balance: $480000
What would you like to do Tom ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: You stole $20,000!
Tom's Balance: $500000

Tom HAS ACHIEVED $500,000!
Tom HAS WON THE GAME!!
----------Jerry's Turn----------
Jerry's Balance: $280000
What would you like to do Jerry ?
1.Pass 2.Gamble 3.Special Ability
Enter 1, 2 or 3: Jerry passed their turn

END OF ROUND 2
Do you wish to continue? Enter 1.Yes or 2.No:
Exiting Multiplayer Mode...
Returning to Main Menu...

0
7 changes: 7 additions & 0 deletions PVP_testInput01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1
3
1
3
1
3
2
5 changes: 5 additions & 0 deletions PVP_testInput02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1
1
3
1
2
4 changes: 4 additions & 0 deletions PVP_test_testadder
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo Test 01: pass, Jerry wins
./PVP_test < PVP_testInput01.txt | diff - PVP_testExpectedOutput01.txt
echo Test 02: pass, Tom wins
./PVP_test < PVP_testInput02.txt | diff - PVP_testExpectedOutput02.txt
19 changes: 19 additions & 0 deletions Thief.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <string>
#include "User.h"
#include "Thief.h"

// implementation of Thief constructor with name and balance
Thief::Thief(std::string name, int balance):User(name,balance) {
};

// implementation of special() function
void Thief::special(User *opponent) {
opponent->minusBalance(20000);
addBalance(20000);
std::cout<<"You stole $20,000!"<<std::endl;
}

// implementation of Thief destructor
Thief::~Thief() {
}
Loading

0 comments on commit 296171c

Please sign in to comment.