public void Init(ServerApi api, Player player, GameState game, Map map) { this.api = api; this.player = player; this.game = game; this.map = map; }
public GamesControllerTests() { _dummyGameState = GetDummyGameState(); _dummyPlayer = GetDummyPlayer(); _gameStateProvider = Substitute.For<IGameStateProvider>(); _gameStateProvider.CreateGame(Arg.Any<string>()).ReturnsForAnyArgs(ValidationResult<GameState>.Success.WithData(_dummyGameState)); _gameStateProvider.JoinGame(Arg.Any<Guid>(), Arg.Any<Guid>()).ReturnsForAnyArgs(ValidationResult<GameState>.Success.WithData(_dummyGameState)); _controller = new GamesController(_gameStateProvider); }
public ValidationResult<GameState> CreateGame(string name) { if (_repo.GetByName(name) != null) return ValidationResult<GameState>.Failure("A game by that name already exists"); var id = Guid.NewGuid(); var gameState = new GameState { Id = id, Name = name, MapId = _mapProvider.GetRandomMap().Id }; _repo.Add(gameState); _repo.Save(); return ValidationResult<GameState>.Success.WithData(gameState); }
public ValidationResult Save(GameState state) { var gs = _repo.FindBy(s => s.Id == state.Id); if (gs == null) { return ValidationResult.Failure("Game not found"); } _repo.Add(state); _repo.Save(); return ValidationResult.Success; }
public void Save(GameState state) { var gs = _repo.FindBy(s => s.Id == state.Id); if (gs == null) { state.Id = Guid.NewGuid(); _repo.Add(state); } else { _repo.Add(state); } }
public void Add_AddGameToMongoRepo_NoExceptionsThrown() { //Assign GameState state = new GameState(); state.Id = Guid.NewGuid(); state.Name = "Test"; //Act _repo.Add(state); var result = _repo.Get(state.Id); //Assert Assert.AreNotEqual(state, result); Assert.AreEqual(state.Id, result.Id); Assert.AreEqual(state.Name, result.Name); }
public void LeaveGame_ForUserInCorrectGame_UsesRepository() { // arrange var gameId = Guid.NewGuid(); const string userName = "******"; var currentGame = new GameState { Id = gameId, Players = new List<GamePlayer> { new GamePlayer { Player = new Player { Name = userName } } } }; var results = new[] { currentGame }.AsQueryable(); _db.FindBy(Arg.Any<Expression<Func<GameState, bool>>>()) .Returns(results); // act _controller.LeaveGame(gameId, userName); // assert _db.Received().Add(currentGame); }
private static void ViewGame(Guid id) { Console.Clear(); CurrentGame = CurrentGames[id]; int col2Left = Console.WindowWidth - 20; // Draw the map Console.SetCursorPosition(0, 0); Console.Write("Map"); Console.SetCursorPosition(col2Left, 0); Console.Write("Players"); Console.SetCursorPosition(0, 1); Console.WriteLine(new String('-', Console.WindowWidth)); var currentMap = CurrentMaps[CurrentGame.MapId]; for (int i = 0; i < currentMap.Length; i++) { Console.SetCursorPosition(0, 2 + i); var row = currentMap[i]; Console.Write(String.Join("", row)); } // Write out the players for (int i = 0; i < CurrentGame.Players.Count; i++) { Console.SetCursorPosition(col2Left, 2 + i); Console.Write(String.Format("{2}{0} - {3}pts", CurrentGame.Players[i].Player.Name, CurrentGame.Players[i].Id, CurrentGame.Players[i].IsAlive ? "" : "x", CurrentGame.Players[i].Score)); } Console.SetCursorPosition(0, Console.WindowHeight - 4); Console.WriteLine("[R] Refresh"); Console.WriteLine("[X] Exit"); Choose(new Dictionary<char, Action> { { 'R', Refresh }, { 'X', ListGames }, }); }
private static void UpdateGame(GameState game) { if (CurrentGames.ContainsKey(game.Id)) { CurrentGames[game.Id] = game; } else { CurrentGames.Add(game.Id, game); } }
public ActionResult CreateGame(string name) { var state = new GameState { Name = name }; _db.Save(state); return View(new { ok = true }); }
private static void UpdateMap(GameState game, string[] map) { if (CurrentMaps.ContainsKey(game.Id)) { CurrentMaps[game.MapId] = map; } else { CurrentMaps.Add(game.MapId, map); } }
private static void GetMap(GameState game) { api.GetMap(game.MapId, (data, ex) => { if (ex != null) { Error(ex); return; } if (!data.Ok) { BadResponse(); return; } UpdateMap(game, data.Map); }); }