-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTennisGame2.php
151 lines (131 loc) · 3.89 KB
/
TennisGame2.php
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
class TennisGame2 implements TennisGame
{
private $P1point = 0;
private $P2point = 0;
private $P1res = "";
private $P2res = "";
private $player1Name = "";
private $player2Name = "";
public function __construct($player1Name, $player2Name)
{
$this->player1Name = $player1Name;
$this->player2Name = $player2Name;
}
public function getScore()
{
$score = "";
if ($this->P1point == $this->P2point && $this->P1point < 4) {
if ($this->P1point == 0) {
$score = "Love";
}
if ($this->P1point == 1) {
$score = "Fifteen";
}
if ($this->P1point == 2) {
$score = "Thirty";
}
$score .= "-All";
}
if ($this->P1point == $this->P2point && $this->P1point >= 3) {
$score = "Deuce";
}
if ($this->P1point > 0 && $this->P2point == 0) {
if ($this->P1point == 1) {
$this->P1res = "Fifteen";
}
if ($this->P1point == 2) {
$this->P1res = "Thirty";
}
if ($this->P1point == 3) {
$this->P1res = "Forty";
}
$this->P2res = "Love";
$score = "{$this->P1res}-{$this->P2res}";
}
if ($this->P2point > 0 && $this->P1point == 0) {
if ($this->P2point == 1) {
$this->P2res = "Fifteen";
}
if ($this->P2point == 2) {
$this->P2res = "Thirty";
}
if ($this->P2point == 3) {
$this->P2res = "Forty";
}
$this->P1res = "Love";
$score = "{$this->P1res}-{$this->P2res}";
}
if ($this->P1point > $this->P2point && $this->P1point < 4) {
if ($this->P1point == 2) {
$this->P1res = "Thirty";
}
if ($this->P1point == 3) {
$this->P1res = "Forty";
}
if ($this->P2point == 1) {
$this->P2res = "Fifteen";
}
if ($this->P2point == 2) {
$this->P2res = "Thirty";
}
$score = "{$this->P1res}-{$this->P2res}";
}
if ($this->P2point > $this->P1point && $this->P2point < 4) {
if ($this->P2point == 2) {
$this->P2res = "Thirty";
}
if ($this->P2point == 3) {
$this->P2res = "Forty";
}
if ($this->P1point == 1) {
$this->P1res = "Fifteen";
}
if ($this->P1point == 2) {
$this->P1res = "Thirty";
}
$score = "{$this->P1res}-{$this->P2res}";
}
if ($this->P1point > $this->P2point && $this->P2point >= 3) {
$score = "Advantage player1";
}
if ($this->P2point > $this->P1point && $this->P1point >= 3) {
$score = "Advantage player2";
}
if ($this->P1point >= 4 && $this->P2point >= 0 && ($this->P1point - $this->P2point) >= 2) {
$score = "Win for player1";
}
if ($this->P2point >= 4 && $this->P1point >= 0 && ($this->P2point - $this->P1point) >= 2) {
$score = "Win for player2";
}
return $score;
}
private function SetP1Score($number)
{
for ($i = 0; $i < $number; $i++) {
$this->P1Score();
}
}
private function SetP2Score($number)
{
for ($i = 0; $i < $number; $i++) {
$this->P2Score();
}
}
private function P1Score()
{
$this->P1point++;
}
private function P2Score()
{
$this->P2point++;
}
public function wonPoint($player)
{
if ($player == "player1") {
$this->P1Score();
} else {
$this->P2Score();
}
}
}