-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrazySquirrel.cpp
132 lines (115 loc) · 4.14 KB
/
CrazySquirrel.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
// CrazySquirrel.cpp
// Game Tester
// Created by Yinghan Ma on 11/22/17.
// Copyright © 2017 Yinghan Ma. All rights reserved.
#include "CrazySquirrel.hpp"
#include "Enemy.hpp"
#include "Player.hpp"
#include "Map.hpp"
#include <string>
#include <vector>
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
//Constructor
CrazySquirrel::CrazySquirrel() {
name = "";
health = 0;
attack = 0;
defense = 0;
}
//Specific constructor that player can interact with
CrazySquirrel::CrazySquirrel(Player* p, Map* m) {
name = "Crazy Squirrel";
//Object of Player class allowing us to manipulate the Player
this->player = p;
this->map = m;
//notice how the following values are greater and less than Player values;
//This enemy should be killed in 1-2 turns
//This enemy will do a small to moderate amount of damage to Player when fought
//Classification: normal/common Enemy
health = 15;
attack = 3;
defense = 1;
}
//Use when Player attacks Enemy
//same code as in Player class
int CrazySquirrel::takeDamage(double playerAttack) {
double damageDone = defense - playerAttack;
if (damageDone < 0) {
//adding because damageDone will only be negative
health = health + damageDone;
} else {
damageDone = 0;
}
return damageDone;
}
//Basic attack for this enemy
//Will be the most common attack
void CrazySquirrel::normalAttack() {
cout << name << " bites your finger with its razor sharp teeth!" << endl;
int temp = player->takeDamage(attack);
cout << name << " does " << abs(temp) << " damage to you." << endl;
}
//Weak attack for this enemy
//Does half of the normal damage
// for the squirrel, try to make this attack swipe an item from the inventory
void CrazySquirrel::weakAttack() {
cout << name << " scratches your leg -- it was pretty pathetic." << endl;
int temp = player->takeDamage((.5 * attack));
cout << name << " does " << abs(temp) << " damage to you." << endl;
}
//Strong attack for this enemy
//Does 2 times normal damage
void CrazySquirrel::strongAttack() {
cout << name << " throws an explosive acorn at your face." << endl;
int temp = player->takeDamage(2 * attack);
cout << name << " does " << abs(temp) << " damage to you." << endl;
}
// holds enemy AI
// determines what attack the enemy will do
void CrazySquirrel::retaliate() {
//srand (time(NULL));
int randomNum = rand() % 4 + 1;
if (randomNum == 1) {
weakAttack();
} else if (randomNum == 2 || randomNum == 3) {
normalAttack();
} else {
strongAttack();
}
}
//This is where the entire interaction between the Player and this enemy takes place
void CrazySquirrel::fight() {
int userInput = 0;
cout << name << " comes into view." << endl;
//battle loop
while(health > 0 && player->gameOver == false) {
cout << "What will you do? \n(1) Kick the squirrel, Eddy Pineiro style." << endl;
cout << "(2) Grab the squirrel by its tail. \n(3) Run before the squirrel calls its crazy friends." << endl;
cin >> userInput;
player->getHealth();
if(userInput == 1) {
//normal player attack
cout << "You kick the squirrel across the room into a computer screen." << endl;
int temp = takeDamage(player->getAttack());
cout << "The squirrel looks pretty winded -- it takes " << abs(temp) << " damage.\n";
retaliate();
} else if (userInput == 2) {
//weak player attack
cout << "You swing the squirrel around by its tail like a helicopter rotor." << endl;
int temp = takeDamage((.5*player->getAttack()));
cout << "It becomes so dizzy it can't even move! Crazy Squirrel takes " << abs(temp) << " damage.\n";
retaliate();
} else if (userInput == 3) {
//run or quit battle
cout << "You manage to escape the rabid rodent!" << endl;
map->back();
break;
} else {
cout << "Yo, not cool. Try again." << endl;
}
}
cout << name << " scurries away into the shadows." << endl;
}