forked from emilybache/Tennis-Refactoring-Kata
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cafa8e0
commit 99a8057
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <string> | ||
|
||
std::string tennis_score(int player1Score, int player2Score) | ||
{ | ||
std::string result = ""; | ||
std::string player1Name = "player1"; | ||
std::string player2Name = "player2"; | ||
|
||
if (player1Score == player2Score) | ||
{ | ||
// tie score | ||
switch (player1Score) | ||
{ | ||
case 0: result += "Love-All"; break; | ||
case 1: result += "Fifteen-All"; break; | ||
case 2: result += "Thirty-All"; break; | ||
default: result += "Deuce"; break; | ||
} | ||
} | ||
else if (player1Score >= 4 || player2Score >= 4) | ||
{ | ||
// end-game score | ||
if (player1Score - player2Score == 1) | ||
{ | ||
result += "Advantage " + player1Name; | ||
} | ||
else if (player1Score - player2Score == -1) | ||
{ | ||
result += "Advantage " + player2Name; | ||
} | ||
else if (player1Score - player2Score >= 2) | ||
{ | ||
result += "Win for " + player1Name; | ||
} | ||
else | ||
{ | ||
result += "Win for " + player2Name; | ||
} | ||
} else { | ||
// regular score | ||
switch (player1Score) { | ||
case 0: | ||
result += "Love"; | ||
break; | ||
case 1: | ||
result += "Fifteen"; | ||
break; | ||
case 2: | ||
result += "Thirty"; | ||
break; | ||
default: | ||
result += "Forty"; | ||
break; | ||
} | ||
result += "-"; | ||
switch (player2Score) { | ||
case 0: | ||
result += "Love"; | ||
break; | ||
case 1: | ||
result += "Fifteen"; | ||
break; | ||
case 2: | ||
result += "Thirty"; | ||
break; | ||
default: | ||
result += "Forty"; | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} |