forked from ChicoState/PigsGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperson.cpp
More file actions
71 lines (57 loc) · 1.45 KB
/
person.cpp
File metadata and controls
71 lines (57 loc) · 1.45 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "person.h"
#include "computer.h"
#include<iostream>
#include<string>
#include<assert.h>
#include<stdlib.h>
#include<time.h>
using namespace std;
Person::Person()
{
player_total_score = 0;
}
void Person::play_game()
{
string initial_input;
int roll_value = 0;
int current_roll = 0;
int running_total = 0;
cout << "Player, your total score is: " << player_total_score << endl;
cout << "Player, would you like to roll, or will you hold?" << endl;
getline(cin, initial_input);
while(initial_input != "hold" && current_roll == 0)
{
current_roll = player_roll();
cout << "You rolled a: " << current_roll << endl;
if(current_roll == 1)
{
break;
}
running_total += current_roll;
cout << "So far, your score for this round is: " << running_total << endl;
cout << "Player, would you like to roll, or will you hold?" << endl;
getline(cin, initial_input);
current_roll = 0;
continue;
}
if(current_roll == 1)
{
cout << "You rolled a 1, no points added for current turn" << endl;
running_total = 0;
player_total_score += running_total;
cout << "Your score is still: " << player_total_score << endl;
}
if(initial_input == "hold")
{
cout << "player decided to hold" << endl;
player_total_score += running_total;
cout << "Your score is: " << player_total_score << endl;
}
}
int Person::player_roll()
{
int dice_roll;
srand(time(NULL));
dice_roll = (rand()%6) + 1;
return dice_roll;
}