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