-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
74 lines (64 loc) · 2.45 KB
/
Player.cs
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
namespace PassThePigs
{
public class Player
{
// References:
public string name;
public Scoreboard points;
public int score;
public int scoreBeforeThrow;
public Player(string name)
{
this.name = name;
this.points = new Scoreboard();
this.scoreBeforeThrow = this.points.points;
}
public void UseTurn()
{
ScoreBeforeThrow();
while (true)
{
// Makes a new pig
PigJar pig = new PigJar();
// Score is what Throw value is
score = pig.TossingPigs();
// Records your Throw() to player points and does what RecordResult switch case does
this.points.RecordResult(score);
// Checks if player gets Pig out. Player get 0 points from this round. Breaks loop and passes turn to next player
if (score >= 141 && score <= 155)
{
this.points.points = scoreBeforeThrow;
Console.WriteLine(this.name + " has now " + this.points.CountScore() + " points.");
break;
}
// Checks if player gets Makin' Bacon. Resets points back to 0 and passes turn to next player.
if (score >= 156 && score <= 160)
{
Console.WriteLine(this.name + " has now " + this.points.CountScore() + " points.");
break;
}
// Tells player how many points at the moment
Console.WriteLine(this.name + " has now " + this.points.CountScore() + " points.");
// Checks if players points is 100 or higher after recording score.
if (!this.points.PointsOver100())
{
Console.WriteLine("Player " + this.name + " got over 100 points and won!");
Environment.Exit(0);
}
// Asks if player wants to continue or pass turn to next player.
Console.WriteLine("Do you want to throw again? (Yes / No)");
if (Console.ReadLine() == "No")
{
break;
}
Console.WriteLine("");
}
}
// Method to store points where player started current turn.
public int ScoreBeforeThrow()
{
this.scoreBeforeThrow = this.points.points;
return scoreBeforeThrow;
}
}
}