-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 296171c
Showing
222 changed files
with
2,316 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
1 | ||
3 | ||
1 | ||
3 | ||
1 | ||
3 | ||
2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
1 | ||
1 | ||
3 | ||
1 | ||
2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} |
Oops, something went wrong.