public NewGameViewModel() { MapTypes = new ObservableCollection <MapStrategy> { new DemoMap(), new SmallMap(), new StandardMap() }; StartGameCommand = new RelayCommand(() => { Messenger.Default.Send(new NavigationViewMessage(new GameViewModel())); Messenger.Default.Send(new GameMessage( NewGameBuilder.Create() .SetMap(selectedMapType) .SetPlayerName(player1Name) .SetPlayerName(player2Name) .Build(), false )); }, () => { return(selectedMapType != null && !string.IsNullOrWhiteSpace(player1Name) && !string.IsNullOrWhiteSpace(player2Name)); }); BackCommand = new RelayCommand(() => { Messenger.Default.Send(new NavigationSubviewMessage(new MainMenuViewModel())); }); }
public void GameTest() { var game = NewGameBuilder.Create() .SetMap(new DemoMap()) .SetPlayerName("Player 1") .SetPlayerName("Player 2") .Build(); Assert.AreEqual(game.Map.Size, 6); }
public void StructTest() { var game = NewGameBuilder.Create() .SetMap(new DemoMap()) .SetPlayerName("PLayer 1") .SetPlayerName("Player 2") .Build(); var moveManager = new MoveManager(game); var i = moveManager.GetBestMove(game.GetCurrentPlayer(), game.GetCurrentPlayer().Units[0]); }
public void TestPlayerRaceRandomization() { Game Game = null; IGameBuilder builder = NewGameBuilder.Create(). SetMap(new DemoMap()). SetPlayerName("Player 1"). SetPlayerName("Player 2"). SetPlayerName("Player 3"); IDictionary <Type, IDictionary <string, int> > racesResults = new Dictionary <Type, IDictionary <string, int> >(); IDictionary <String, int> dict = null; int i = 0; while (i++ < 1000) { Game = builder.Build(); for (var j = 0; j < Game.Players.Count; j++) { var name = Game.Players[j].Name; var race = Game.Players[j].Race; if (racesResults.ContainsKey(race.GetType())) { dict = racesResults[race.GetType()]; if (dict.ContainsKey(name)) { dict[name]++; } else { dict[name] = 1; } } else { dict = new Dictionary <String, int>(); dict.Add(name, 1); racesResults[race.GetType()] = dict; } } } var normalDistribMean = 1.0 / racesResults.Keys.Count; foreach (var type in racesResults.Keys) { foreach (var name in racesResults[type].Keys) { var percentage = racesResults[type][name] / (double)racesResults[type].Values.Sum(); Assert.IsTrue(normalDistribMean - 0.1 < percentage && percentage < normalDistribMean + 0.1); } } }
public void NextPlayerTest() { var game = NewGameBuilder.Create() .SetMap(new DemoMap()) .SetPlayerName("Player 1") .SetPlayerName("Player 2") .Build(); var p1 = game.Players[0]; var p2 = game.Players[1]; Assert.AreSame(p1, game.GetCurrentPlayer()); game.NextPlayer(); Assert.AreSame(p2, game.GetCurrentPlayer()); }
public void SaveLoadGameTest() { var game = NewGameBuilder.Create() .SetMap(new DemoMap()) .SetPlayerName("Player 1") .SetPlayerName("Player 2") .Build(); for (var i = 0; i < game.Players.Count; i++) { game.Players[0].Units[i].Position = new Position(0, 0); game.Players[1].Units[i].Position = new Position(5, 5); } game.DoAction(new MoveAction(game.Map, game.GetCurrentPlayer().Units[0], new Position(1, 1))); game.NextPlayer(); game.DoAction(new MoveAction(game.Map, game.GetCurrentPlayer().Units[0], new Position(5, 5))); game.NextPlayer(); var path = "tmp.bin"; game.SaveGame(path); var loadedGame = Game.LoadGame(path); for (var i = 0; i < game.Players.Count; i++) { Assert.AreEqual(game.Players[i].Name, loadedGame.Players[i].Name); Assert.AreEqual(game.Players[i].VictoryPoints, loadedGame.Players[i].VictoryPoints); for (var j = 0; j < game.Players[i].Units.Count; j++) { Assert.AreEqual(game.Players[i].Units[j].Position, loadedGame.Players[i].Units[j].Position); } } Assert.AreEqual(game.MaximumNumberTurns, loadedGame.MaximumNumberTurns); Assert.AreEqual(game.CurrentTurn, loadedGame.CurrentTurn); }