Skip to content

Instantly share code, notes, and snippets.

@IntegerMan
Created September 17, 2019 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IntegerMan/25f840b63277e0c0f27206015bf27c1b to your computer and use it in GitHub Desktop.
Save IntegerMan/25f840b63277e0c0f27206015bf27c1b to your computer and use it in GitHub Desktop.
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