-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrock.cpp
More file actions
55 lines (50 loc) · 1.9 KB
/
Copy pathrock.cpp
File metadata and controls
55 lines (50 loc) · 1.9 KB
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
/*********************************************************************
* Author: Noah Buchen, Alexandra Henley, Elliott Lapinel, Patrick
* Rice, and Samantha Tone
* Date: 10/25/2017
* Description: The Rock Class will have it's own fight function.
* That will override the Tool base class.
*********************************************************************/
#include "rock.hpp"
/*********************************************************************
* Default constructor for Rock class
*********************************************************************/
Rock::Rock(){
this->strength = 1;
this->type = 'r';
}
/*********************************************************************
* Constructor that takes in user chosen strength
* @param userInput is the strength from the user selection
*********************************************************************/
Rock::Rock(int userInput) : Tool(userInput){
this->type = 'r';
}
/*********************************************************************
* The fight function returns who wins based on what two tools are
* fighting.
* @param computer is the Tool that is being faught
*********************************************************************/
char Rock::fight(Tool *computer) {
char winner; // 'h', 'c', 't' (human, computer, tie)
// rock against paper, rock strength is halved or inversely computer is doubled!
if(computer->getType() == 'p') {
if ((computer->getStrength() * 2) < strength)
winner = 'h';
else if ((computer->getStrength() * 2) > strength)
winner = 'c';
else
winner = 't';
}//rock vs. scissors, rock strength is doubled
else if (computer->getType() == 's') {
if (computer->getStrength() < (strength * 2))
winner = 'h';
else if (computer->getStrength() > (strength *2))
winner = 'c';
else
winner = 't';
}
else //rock vs. rock
winner = 't';
return winner;
}