GildedRose-Refactoring-Kata/Tennis/csharp/TennisGame2.cs
2013-02-01 15:38:54 +01:00

145 lines
2.5 KiB
C#

using System;
namespace Tennis
{
public class TennisGame2 : TennisGame
{
public int P1point = 0;
public int P2point = 0;
public string P1res = "";
public string P2res = "";
private string player1Name;
private string player2Name;
public TennisGame2 (string player1Name, string player2Name)
{
this.player1Name = player1Name;
this.player2Name = player2Name;
}
public string GetScore(){
string score = "";
if (P1point == P2point && P1point < 4)
{
if (P1point==0)
score = "Love";
if (P1point==1)
score = "Fifteen";
if (P1point==2)
score = "Thirty";
if (P1point==3)
score = "Forty";
score += "-All";
}
if (P1point==P2point && P1point>3)
score = "Deuce";
if (P1point > 0 && P2point==0)
{
if (P1point==1)
P1res = "Fifteen";
if (P1point==2)
P1res = "Thirty";
if (P1point==3)
P1res = "Forty";
P2res = "Love";
score = P1res + "-" + P2res;
}
if (P2point > 0 && P1point==0)
{
if (P2point==1)
P2res = "Fifteen";
if (P2point==2)
P2res = "Thirty";
if (P2point==3)
P2res = "Forty";
P1res = "Love";
score = P1res + "-" + P2res;
}
if (P1point>P2point && P1point < 4)
{
if (P1point==2)
P1res="Thirty";
if (P1point==3)
P1res="Forty";
if (P2point==1)
P2res="Fifteen";
if (P2point==2)
P2res="Thirty";
score = P1res + "-" + P2res;
}
if (P2point>P1point && P2point < 4)
{
if (P2point==2)
P2res="Thirty";
if (P2point==3)
P2res="Forty";
if (P1point==1)
P1res="Fifteen";
if (P1point==2)
P1res="Thirty";
score = P1res + "-" + P2res;
}
if (P1point > P2point && P2point >= 3)
{
score = "Advantage player1";
}
if (P2point > P1point && P1point >= 3)
{
score = "Advantage player2";
}
if (P1point>=4 && P2point>=0 && (P1point-P2point)>=2)
{
score = "Win for player1";
}
if (P2point>=4 && P1point>=0 && (P2point-P1point)>=2)
{
score = "Win for player2";
}
return score;
}
public void SetP1Score(int number){
for (int i = 0; i < number; i++)
{
P1Score();
}
}
public void SetP2Score(int number){
for (int i = 0; i < number; i++)
{
P2Score();
}
}
public void P1Score(){
P1point++;
}
public void P2Score(){
P2point++;
}
public void WonPoint(string player) {
if (player == "player1")
P1Score();
else
P2Score();
}
}
}