Skip to content

Commit

Permalink
Show how the grade for a single team is computed.
Browse files Browse the repository at this point in the history
  • Loading branch information
hpinsley committed Jan 6, 2013
1 parent fb87b99 commit e3855eb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
28 changes: 27 additions & 1 deletion NFLRanking/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,35 @@ public static void GetStats() {
}

foreach (Team team in teamManager.GetTeams()) {
LogMsg("Team Manager has {0}", team);
LogMsg("{0} is graded a {1}", team, team.Grade);
}

Team giants = teamManager.GetTeam("NY Giants");
ShowTeamGames(giants);

}

private static void ShowTeamGames(Team team) {
LogMsg("Games for {0}", team.Name);
int cumGrade = 0;
int delta;
foreach (Game game in team.GetGames()) {
if (game.IsTie) {
LogMsg("{0} tied {1}",
team.Name, (team == game.Winner) ? game.Loser.Name : game.Winner.Name);
}
else if (team == game.Winner) {
delta = game.Loser.Wins;
cumGrade += delta;
Console.WriteLine("{0} beat {1} {2} {3}\tCredit:{4} Total:{5}", team.Name, game.Loser.Record, game.Loser, game.Score, delta, cumGrade);
}
else if (team == game.Loser) {
delta = -1 * game.Winner.Losses;
cumGrade += delta;
Console.WriteLine("{0} lost to {1} {2} {3}\tCredit:{4} Total:{5}", team.Name, game.Winner.Record, game.Winner, game.Score, delta, cumGrade);
}
}
LogMsg("\n{0} final grade is {1}", team.Name, team.Grade);
}
}
}
12 changes: 9 additions & 3 deletions ScoreParser/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ public class Game {
public Team Winner { get; private set; }
public Team Loser { get; private set; }
public bool IsTie { get; private set; }
public string Score { get; private set; }

public Game(ITeamManager teamManager) {
_teamManager = teamManager;
}

public override string ToString() {
return string.Format("Game:[{0}]; Winner:{1} Loser:{2} {3}",
GameDescription, Winner, Loser, IsTie ? "A Tie!" : "");
return string.Format("{0} over {1} {2} {3}",
Winner, Loser, Score, IsTie ? "A Tie!" : "");
}

public void InitFromGameDescription(string gameDescription) {
Expand All @@ -35,7 +36,10 @@ public void InitFromGameDescription(string gameDescription) {
Loser = _teamManager.GetTeam(teamAndScore2.Item1);
}

IsTie = teamAndScore1.Item2 == teamAndScore2.Item2;
int score1 = teamAndScore1.Item2;
int score2 = teamAndScore2.Item2;
Score = score1 > score2 ? string.Format("{0}-{1}", score1, score2) : string.Format("{0}-{1}", score2, score1);
IsTie = score1 == score2;

if (IsTie) {
Winner.AddTie();
Expand All @@ -45,6 +49,8 @@ public void InitFromGameDescription(string gameDescription) {
Winner.AddWin();
Loser.AddLoss();
}
Winner.AddGame(this);
Loser.AddGame(this);
}

private Tuple<string, int> GetTeamAndScore(string teamAndScore) {
Expand Down
22 changes: 20 additions & 2 deletions ScoreParser/Team.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
namespace ScoreParser {
using System.Collections.Generic;

namespace ScoreParser {
public class Team {

public string Name { get; private set; }
public int Wins { get; private set; }
public int Losses { get; private set; }
public int Ties { get; private set; }
public int Grade { get; private set; }
public string Record {
get { return string.Format("{0}-{1}-{2}", Wins, Losses, Ties); }
}

private List<Game> _games = new List<Game>();

public Team(string name) {
Name = name;
Expand All @@ -14,19 +21,30 @@ public Team(string name) {
public void AddWin() {
++Wins;
}

public void AddLoss() {
++Losses;
}

public void AddTie() {
++Ties;
}

public void AddGame(Game game) {
_games.Add(game);
}

public void IncrementGrade(int amount) {
Grade += amount;
}

public IEnumerable<Game> GetGames() {
return _games;
}

public override string ToString() {
return string.Format("{0} {1}-{2}-{3}: Grade: {4}", Name, Wins, Losses, Ties, Grade);
return Name;
}

}
}

0 comments on commit e3855eb

Please sign in to comment.