-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cpp
206 lines (162 loc) · 7.05 KB
/
Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/****************************************************************************************************
* * Program name: CS162 Project3
* * Author: Taekyoung Kim
* * Date: 02/05/2019
* * Description: This is Game.cpp file for CS162 Project3
* * This project demonstrates a fantasy combat game.
* * There are 5 characters that have different ability and power.
* * The real game is done with a dice.
******************************************************************************************************/
#include <iostream>
#include <random>
#include <climits>
#include "Game.h"
#include "inputVal.h"
#include "Character.h"
#include "HarryP.h"
#include "Barbarian.h"
#include "BlueMen.h"
#include "Medusa.h"
#include "Vampire.h"
Game::Game() = default;
Game::~Game() = default;
//{delete [] player1;
//delete [] player2;}
void Game::play(){
double fighter1;
int numForP1;
double fighter2;
int numForP2;
int playAgain;
do {
std::cout <<"\nWelcome to the fantasy World!" << std::endl;
std::cout <<"Now, you will have your warriors for the battle."<<std::endl;
std::cout <<"Warriors who get a higher number in dices win the game."<< std::endl;
std::cout <<"Some of characters has armor that can be added to the sum" << std::endl;
std::cout <<"Warriors are 5 characters and two each characters, and they have different ability and skills."<<std::endl;
std::cout <<"So, they can fight with a same character. Let me introduce them."<<std::endl;
std::cout <<"\nNumber 1: Vampire. Her strength is 18, highest one and her armor is 1.";
std::cout <<"Although her attack and defence ability are lower than others, she has special skill, Charm.";
std::cout <<"\nNumber 2: Barbarian. His strength is 12. His ability for attack and defense is average, 0 armor.";
std::cout <<"\nNumber 3: Blue Men. his attach and defense ability are the highest, and he has 3 armor. ";
std::cout <<"But, he lose a weakness. His defense will decrease as same as he lose the strength by 1/3.";
std::cout <<"\nNumber 4: Medusa, her attack and defense ability is a little lower than others, but she has Glare.";
std::cout <<"If she roll number 12 on her dice, she will win the game. She also has 3 armor.";
std::cout <<"\nNumber 5: Happy porter, he has average attack and defense abilities and 0 armor";
std::cout <<"However, he has special skill, Hogwarts that allows him a second life with 20 strengths,";
std::cout <<"But, this is only one time chance."<< std::endl;
std::cout <<"\nNow please choose two warriors who are going to fight."<< std::endl;
std::cout<<"The first player will attack first."<<std::endl;
std::cout <<"First warrior: ";
std::cin >> fighter1;
numForP1 = inputVal(fighter1);
std::cout <<"Second warrior: ";
std::cin >> fighter2;
numForP2 = inputVal(fighter2);
switch(numForP1) {
case 1:
player1 = new Vampire();
std::cout<<"Your choice for player1: 'Vampire' "<<std::endl;
break;
case 2:
player1 = new Barbarian();
std::cout<<"Your choice for player1: 'Barbarian' "<<std::endl;
break;
case 3:
player1 = new BlueMen();
std::cout<<"Your choice for player1:'Blue men' "<<std::endl;
break;
case 4:
player1 = new Medusa();
std::cout<<"Your choice for player1: 'Medusa' "<<std::endl;
break;
case 5:
player1 = new HarryP();
std::cout<<"Your choice for player1: 'Harry Potter' "<<std::endl;
break;
default:
break;
}
switch(numForP2) {
case 1:
player2= new Vampire();
std::cout<<"Your choice for player2: 'Vampire' "<<std::endl;
break;
case 2:
player2= new Barbarian();
std::cout<<"Your choice for player2: 'Barbarian' "<<std::endl;
break;
case 3:
player2= new BlueMen();
std::cout<<"Your choice for player2: 'Blue men' "<<std::endl;
break;
case 4:
player2= new Medusa();
std::cout<<"Your choice for player2: 'Medusa' "<<std::endl;
break;
case 5:
player2= new HarryP();
std::cout<<"Your choice for player2: 'Harry Potter' "<<std::endl;
break;
default:
break;
}
int round = 1;
int impact;
do {
std::cout << "--------------" << std::endl;
std::cout << " Round: " << round << std::endl;
std::cout << "--------------" << std::endl;
for (int i = 0; i < 2; i++) {
std::cout << "Fight number " << i + 1 << std::endl;
if (i == 0) {
impact = player1->Attack();
player2->Defense(impact);
if (player2->getStrength() > 0) {
std::cout<<"New strength: "<<player2->getStrength()<<std::endl;
}
else//(player2->getStrength() <= 0){
{
std::cout<<"New strength: "<< 0 <<std::endl;
std::cout<<std::endl;
std::cout<<"Player 2: "<<player2->getName()<<" died. Game Over!"<<std::endl;
break;
}
std::cout<<std::endl;
}
else // i=1
{
impact = player2->Attack();
player1->Defense(impact);
if (player1->getStrength() > 0) {
std::cout<<"New strength: "<<player1->getStrength()<<std::endl;
}
else//(player1->getStrength() <= 0){
{
std::cout<<"New strength: "<< 0 <<std::endl;
std::cout<<std::endl;
std::cout<<"Player 1 "<<player1->getName()<<" died. Game Over!"<<std::endl;
break;
}
std::cout<<std::endl;
}
}
round ++;
std::cout<<std::endl;
}while(player1->getStrength() > 0 && player2->getStrength() > 0 );
std::cin.clear();
std::cin.ignore(INT_MAX, '\n');
std::cout<<"\nIf you want to play again, input 1. Otherwise, click any keys! ";
std::cin>>playAgain;
std::cout<<"----------------------------------------------------"<<std::endl;
}while(playAgain == 1);
std::cout<<"So you want to exit. Good buy!"<<std::endl;
//delete [] player1;
// delete [] player2;
if(!(player1= nullptr)) {
delete [] player1;
}
if(!(player2= nullptr)) {
delete [] player2;
}
}