mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
37 lines
870 B
Java
37 lines
870 B
Java
|
|
public class TennisGame3 implements TennisGame {
|
|
|
|
private int p2;
|
|
private int p1;
|
|
private String p1N;
|
|
private String p2N;
|
|
|
|
public TennisGame3(String p1N, String p2N) {
|
|
this.p1N = p1N;
|
|
this.p2N = p2N;
|
|
}
|
|
|
|
public String getScore() {
|
|
String s;
|
|
if (p1 < 4 && p2 < 4) {
|
|
String[] p = new String[]{"Love", "Fifteen", "Thirty", "Forty"};
|
|
s = p[p1];
|
|
return (p1 == p2) ? s + "-All" : s + "-" + p[p2];
|
|
} else {
|
|
if (p1 == p2)
|
|
return "Deuce";
|
|
s = p1 > p2 ? p1N : p2N;
|
|
return ((p1-p2)*(p1-p2) == 1) ? "Advantage " + s : "Win for " + s;
|
|
}
|
|
}
|
|
|
|
public void wonPoint(String playerName) {
|
|
if (playerName == "player1")
|
|
this.p1 += 1;
|
|
else
|
|
this.p2 += 1;
|
|
|
|
}
|
|
|
|
}
|