Created
September 17, 2019 03:46
-
-
Save IntegerMan/25f840b63277e0c0f27206015bf27c1b to your computer and use it in GitHub Desktop.
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
using System.Collections.Generic; | |
using System.Linq; | |
namespace MattEland.Starship.Logic | |
{ | |
public class GameRepository | |
{ | |
private readonly IList<GameState> _games = new List<GameState>(); | |
public GameRepository() | |
{ | |
// Start with some sample data | |
CreateNewGame(); | |
} | |
public IEnumerable<GameState> Games => _games; | |
public GameState GetGame(int id) => _games.FirstOrDefault(g => g.Id == id); | |
public GameState CreateNewGame() | |
{ | |
int id = _games.Count + 1; | |
var game = new GameState(id); | |
_games.Add(game); | |
return game; | |
} | |
public bool DeleteGame(int id) | |
{ | |
var game = _games.FirstOrDefault(g => g.Id == id); | |
return game != null && _games.Remove(game); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment