public MainViewModel() { BlockMove = new BlockMoveCommand(this); SaveTime = new SaveTimeCommand(this); Iteration = new IterationCommand(this); StartGame = new StartGameCommand(this); NewGame = new NewGameCommand(this); _Blocks = new List <Block>(); IsSaveButtonVisible = false; _IsSelected = false; _IsEnded = false; IsStartButtonVisible = true; SGeometryType = GeometryTypes.Diamond; SelectedColour = Colors.Black.ToString(); UserName = ""; leadboard = XDocument.Load("../../Resources/Results.xml"); ResultList = new LeadboradList(this); BlockQuantites = new ObservableCollection <BlockQuantityModel>() { new BlockQuantityModel(7), new BlockQuantityModel(6), new BlockQuantityModel(5), new BlockQuantityModel(4), new BlockQuantityModel(3) }; SBlockQuantity = new BlockQuantityModel(7); fillList(); }
public async Task <string> HandleAsync(NewGameCommand command, CancellationToken cancellationToken) { if (command == null) { throw new ArgumentNullException(nameof(command)); } using (var session = _documentStore.OpenAsyncSession()) { var gameId = _guidProvider.GenerateGuidString(); var game = _gameGenerator.GenerateGame(command.TableRows, command.TableColumns, command.MineCount); var player1MarkTable = _playerMarksGenerator.GenerateDefaultPlayerMarksTable(command.TableRows, command.TableColumns); var player1MarksDocumentId = session.GetPlayerMarksDocumentId(gameId, command.HostPlayerId); var player1MarksDocument = new PlayerMarks { Marks = player1MarkTable, Id = player1MarksDocumentId }; // TODO: Validate that the invited player's Id is not the same as the host's Id. game.Id = _documentStore.GetPrefixedDocumentId <Game>(gameId); game.InvitedPlayerId = string.IsNullOrWhiteSpace(command.InvitedPlayerId) ? null : command.InvitedPlayerId; game.Player1.PlayerId = command.HostPlayerId; game.Player1.DisplayName = command.HostPlayerDisplayName; await session.StoreAsync(game, cancellationToken).ConfigureAwait(false); await session.StoreAsync(player1MarksDocument, cancellationToken).ConfigureAwait(false); await session.SaveChangesAsync(cancellationToken).ConfigureAwait(false); return(gameId); } }
public void IsValidPlace() { var command = new NewGameCommand { Players = new List <Player> { new Player { Cards = new List <Card>() } } }; var game = new Game(command); Assert.IsFalse(game.Board.IsValidPlace(-1, -1)); Assert.IsFalse(game.Board.IsValidPlace(-1, 0)); Assert.IsFalse(game.Board.IsValidPlace(0, -1)); for (var row = 0; row < 3; row++) { for (var column = 0; column < 3; column++) { Assert.IsTrue(game.Board.IsValidPlace(row, column)); } } Assert.IsFalse(game.Board.IsValidPlace(3, 3)); Assert.IsFalse(game.Board.IsValidPlace(3, 0)); Assert.IsFalse(game.Board.IsValidPlace(0, 3)); }
public static Configuration Build(NewGameCommand command) { var rules = Empty(); if (command.EnableSameRule) { rules = rules.EnableSame(); } if (command.EnableSameWallRule) { rules = rules.EnableSameWall(); } if (command.EnablePlusRule) { rules = rules.EnablePlus(); } if (command.EnableComboRule) { rules = rules.EnableCombo(); } if (command.EnableElementalRule) { rules = rules.EnableElemental(command.ProbabilityOfElementary); } return(rules); }
public Game CreateNewGame(NewGameCommand command) { _validator.ValidateAndThrow(command); var game = new Game(command); return(game); }
public IActionResult Post([FromBody] NewGameCommand command) { var game = _gameService.CreateNewGame(command); Games.Add(game.Id, game); return(Ok(game)); }
public GameViewModel() { Game = new Game() { Board = new string[][] { new string[] { "", "", "" }, new string[] { "", "", "" }, new string[] { "", "", "" } } }; ResetGameScore(); NewGame = new NewGameCommand(this); ResetGame = new ResetGameCommand(this); PlayMove = new PlayMoveCommand(this); }
public Game(NewGameCommand command) { Configuration = RulesConfigurationBuilder.Build(command); Board = new Board(this, command.Rows, command.Columns); Players = command.Players; CurrentPlayer = command.Players.Find(command.StartPlayerId) ?? Players.Random(); UpdateScoreboard(); Board.AfterPlacedCard += AfterPlacedCard; }
public void Rows() { var command = new NewGameCommand(); for (var rows = -1000; rows <= 0; rows++) { command.Rows = rows; Assert.AreEqual(1, command.Rows); } for (var rows = 1; rows <= 1000; rows++) { command.Rows = rows; Assert.AreEqual(rows, command.Rows); } }
public void Columns() { var command = new NewGameCommand(); for (var columns = -1000; columns <= 0; columns++) { command.Columns = columns; Assert.AreEqual(1, command.Columns); } for (var columns = 1; columns <= 1000; columns++) { command.Columns = columns; Assert.AreEqual(columns, command.Columns); } }
public void ProbabilityOfElementary() { var command = new NewGameCommand(); for (var probability = -1000d; probability <= 0; probability += 0.1246) { command.ProbabilityOfElementary = probability; Assert.AreEqual(0, command.ProbabilityOfElementary); } for (var probability = 0d; probability <= 1; probability += 0.1246) { command.ProbabilityOfElementary = probability; Assert.AreEqual(probability, command.ProbabilityOfElementary); } for (var probability = 1d; probability <= 1000; probability += 0.1246) { command.ProbabilityOfElementary = probability; Assert.AreEqual(1, command.ProbabilityOfElementary); } }
public void Run() { var player01 = new Player { Id = 1.ToGuid(), Name = "Squall Leonhart", Color = Color.Magenta, Cards = new List <Card> { CardBuilder.Build(1).WithPoints(5, 6, 5, 4), CardBuilder.Build(2).WithPoints(5, 7, 2, 3), CardBuilder.Build(3).WithPoints(3, 6, 2, 6), CardBuilder.Build(4).WithPoints(7, 1, 6, 4), CardBuilder.Build(5).WithPoints(3, 6, 2, 7) } }; var player02 = new Player { Id = 2.ToGuid(), Name = "Rinoa Heartilly", Color = Color.Blue, Cards = new List <Card> { CardBuilder.Build(6).WithPoints(4, 6, 9, 10), CardBuilder.Build(7).WithPoints(10, 4, 10, 2), CardBuilder.Build(8).WithPoints(6, 8, 5, 10), CardBuilder.Build(9).WithPoints(2, 9, 6, 10), CardBuilder.Build(10).WithPoints(3, 5, 10, 8) } }; var newGameCommand = new NewGameCommand { Rows = 3, Columns = 3, EnableSameRule = false, EnableSameWallRule = false, EnablePlusRule = false, EnableComboRule = false, EnableElementalRule = false, ProbabilityOfElementary = 0.2d, StartPlayerId = player02.Id, Players = new List <Player> { player01, player02 } }; var cardValidator = new CardValidator(); var playerValidator = new PlayerValidator(cardValidator); var newGameCommandValidator = new NewGameCommandValidator(playerValidator); var gameService = new GameService(newGameCommandValidator); var game = gameService.CreateNewGame(newGameCommand); Assert.AreEqual(game.Board.Rows, 3); Assert.AreEqual(game.Board.Columns, 3); for (var row = 0; row < game.Board.Rows; row++) { for (var column = 0; column < game.Board.Columns; column++) { Assert.IsTrue(game.Board[row, column].Empty); } } Assert.AreEqual(player01.Cards.Count, 5); Assert.AreEqual(player02.Cards.Count, 5); Assert.AreEqual(game.CurrentPlayer.Id, player02.Id); Assert.AreEqual(5, game.Scoreboard[player01.Id]); Assert.AreEqual(5, game.Scoreboard[player02.Id]); Assert.IsFalse(game.Finished); /* 1º JOGADA */ game.Play(new PlayCommand(player02.Id, 10, 0, 0)); Assert.IsFalse(game.Board[0, 0].Empty); Assert.AreEqual(game.Board[0, 0].Card.Id, 10.ToGuid()); Assert.AreEqual(game.Board[0, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[0, 1].Empty); Assert.IsTrue(game.Board[0, 2].Empty); Assert.IsTrue(game.Board[1, 0].Empty); Assert.IsTrue(game.Board[1, 1].Empty); Assert.IsTrue(game.Board[1, 2].Empty); Assert.IsTrue(game.Board[2, 0].Empty); Assert.IsTrue(game.Board[2, 1].Empty); Assert.IsTrue(game.Board[2, 2].Empty); Assert.AreEqual(5, game.Scoreboard[player01.Id]); Assert.AreEqual(5, game.Scoreboard[player02.Id]); Assert.IsFalse(game.Finished); /* 2º JOGADA */ game.Play(new PlayCommand(player01.Id, 1, 2, 0)); Assert.IsFalse(game.Board[0, 0].Empty); Assert.AreEqual(game.Board[0, 0].Card.Id, 10.ToGuid()); Assert.AreEqual(game.Board[0, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[0, 1].Empty); Assert.IsTrue(game.Board[0, 2].Empty); Assert.IsTrue(game.Board[1, 0].Empty); Assert.IsTrue(game.Board[1, 1].Empty); Assert.IsTrue(game.Board[1, 2].Empty); Assert.IsFalse(game.Board[2, 0].Empty); Assert.AreEqual(game.Board[2, 0].Card.Id, 1.ToGuid()); Assert.AreEqual(game.Board[2, 0].Owner.Id, player01.Id); Assert.IsTrue(game.Board[2, 1].Empty); Assert.IsTrue(game.Board[2, 2].Empty); Assert.AreEqual(5, game.Scoreboard[player01.Id]); Assert.AreEqual(5, game.Scoreboard[player02.Id]); Assert.IsFalse(game.Finished); /* 3º JOGADA */ game.Play(new PlayCommand(player02.Id, 6, 1, 0)); Assert.IsFalse(game.Board[0, 0].Empty); Assert.AreEqual(game.Board[0, 0].Card.Id, 10.ToGuid()); Assert.AreEqual(game.Board[0, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[0, 1].Empty); Assert.IsTrue(game.Board[0, 2].Empty); Assert.IsFalse(game.Board[1, 0].Empty); Assert.AreEqual(game.Board[1, 0].Card.Id, 6.ToGuid()); Assert.AreEqual(game.Board[1, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[1, 1].Empty); Assert.IsTrue(game.Board[1, 2].Empty); Assert.IsFalse(game.Board[2, 0].Empty); Assert.AreEqual(game.Board[2, 0].Card.Id, 1.ToGuid()); Assert.AreEqual(game.Board[2, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[2, 1].Empty); Assert.IsTrue(game.Board[2, 2].Empty); Assert.AreEqual(4, game.Scoreboard[player01.Id]); Assert.AreEqual(6, game.Scoreboard[player02.Id]); Assert.IsFalse(game.Finished); /* 4º JOGADA */ game.Play(new PlayCommand(player01.Id, 2, 1, 2)); Assert.IsFalse(game.Board[0, 0].Empty); Assert.AreEqual(game.Board[0, 0].Card.Id, 10.ToGuid()); Assert.AreEqual(game.Board[0, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[0, 1].Empty); Assert.IsTrue(game.Board[0, 2].Empty); Assert.IsFalse(game.Board[1, 0].Empty); Assert.AreEqual(game.Board[1, 0].Card.Id, 6.ToGuid()); Assert.AreEqual(game.Board[1, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[1, 1].Empty); Assert.IsFalse(game.Board[1, 2].Empty); Assert.AreEqual(game.Board[1, 2].Card.Id, 2.ToGuid()); Assert.AreEqual(game.Board[1, 2].Owner.Id, player01.Id); Assert.IsFalse(game.Board[2, 0].Empty); Assert.AreEqual(game.Board[2, 0].Card.Id, 1.ToGuid()); Assert.AreEqual(game.Board[2, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[2, 1].Empty); Assert.IsTrue(game.Board[2, 2].Empty); Assert.AreEqual(4, game.Scoreboard[player01.Id]); Assert.AreEqual(6, game.Scoreboard[player02.Id]); Assert.IsFalse(game.Finished); /* 5º JOGADA */ game.Play(new PlayCommand(player02.Id, 8, 2, 2)); Assert.IsFalse(game.Board[0, 0].Empty); Assert.AreEqual(game.Board[0, 0].Card.Id, 10.ToGuid()); Assert.AreEqual(game.Board[0, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[0, 1].Empty); Assert.IsTrue(game.Board[0, 2].Empty); Assert.IsFalse(game.Board[1, 0].Empty); Assert.AreEqual(game.Board[1, 0].Card.Id, 6.ToGuid()); Assert.AreEqual(game.Board[1, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[1, 1].Empty); Assert.IsFalse(game.Board[1, 2].Empty); Assert.AreEqual(game.Board[1, 2].Card.Id, 2.ToGuid()); Assert.AreEqual(game.Board[1, 2].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 0].Empty); Assert.AreEqual(game.Board[2, 0].Card.Id, 1.ToGuid()); Assert.AreEqual(game.Board[2, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[2, 1].Empty); Assert.IsFalse(game.Board[2, 2].Empty); Assert.AreEqual(game.Board[2, 2].Card.Id, 8.ToGuid()); Assert.AreEqual(game.Board[2, 2].Owner.Id, player02.Id); Assert.AreEqual(3, game.Scoreboard[player01.Id]); Assert.AreEqual(7, game.Scoreboard[player02.Id]); Assert.IsFalse(game.Finished); /* 6º JOGADA */ game.Play(new PlayCommand(player01.Id, 3, 2, 1)); Assert.IsFalse(game.Board[0, 0].Empty); Assert.AreEqual(game.Board[0, 0].Card.Id, 10.ToGuid()); Assert.AreEqual(game.Board[0, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[0, 1].Empty); Assert.IsTrue(game.Board[0, 2].Empty); Assert.IsFalse(game.Board[1, 0].Empty); Assert.AreEqual(game.Board[1, 0].Card.Id, 6.ToGuid()); Assert.AreEqual(game.Board[1, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[1, 1].Empty); Assert.IsFalse(game.Board[1, 2].Empty); Assert.AreEqual(game.Board[1, 2].Card.Id, 2.ToGuid()); Assert.AreEqual(game.Board[1, 2].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 0].Empty); Assert.AreEqual(game.Board[2, 0].Card.Id, 1.ToGuid()); Assert.AreEqual(game.Board[2, 0].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 1].Empty); Assert.AreEqual(game.Board[2, 1].Card.Id, 3.ToGuid()); Assert.AreEqual(game.Board[2, 1].Owner.Id, player01.Id); Assert.IsFalse(game.Board[2, 2].Empty); Assert.AreEqual(game.Board[2, 2].Card.Id, 8.ToGuid()); Assert.AreEqual(game.Board[2, 2].Owner.Id, player02.Id); Assert.AreEqual(3, game.Scoreboard[player01.Id]); Assert.AreEqual(7, game.Scoreboard[player02.Id]); Assert.IsFalse(game.Finished); /* 7º JOGADA */ game.Play(new PlayCommand(player02.Id, 9, 1, 1)); Assert.IsFalse(game.Board[0, 0].Empty); Assert.AreEqual(game.Board[0, 0].Card.Id, 10.ToGuid()); Assert.AreEqual(game.Board[0, 0].Owner.Id, player02.Id); Assert.IsTrue(game.Board[0, 1].Empty); Assert.IsTrue(game.Board[0, 2].Empty); Assert.IsFalse(game.Board[1, 0].Empty); Assert.AreEqual(game.Board[1, 0].Card.Id, 6.ToGuid()); Assert.AreEqual(game.Board[1, 0].Owner.Id, player02.Id); Assert.IsFalse(game.Board[1, 1].Empty); Assert.AreEqual(game.Board[1, 1].Card.Id, 9.ToGuid()); Assert.AreEqual(game.Board[1, 1].Owner.Id, player02.Id); Assert.IsFalse(game.Board[1, 2].Empty); Assert.AreEqual(game.Board[1, 2].Card.Id, 2.ToGuid()); Assert.AreEqual(game.Board[1, 2].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 0].Empty); Assert.AreEqual(game.Board[2, 0].Card.Id, 1.ToGuid()); Assert.AreEqual(game.Board[2, 0].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 1].Empty); Assert.AreEqual(game.Board[2, 1].Card.Id, 3.ToGuid()); Assert.AreEqual(game.Board[2, 1].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 2].Empty); Assert.AreEqual(game.Board[2, 2].Card.Id, 8.ToGuid()); Assert.AreEqual(game.Board[2, 2].Owner.Id, player02.Id); Assert.AreEqual(2, game.Scoreboard[player01.Id]); Assert.AreEqual(8, game.Scoreboard[player02.Id]); Assert.IsFalse(game.Finished); /* 8º JOGADA */ game.Play(new PlayCommand(player01.Id, 4, 0, 1)); Assert.IsFalse(game.Board[0, 0].Empty); Assert.AreEqual(game.Board[0, 0].Card.Id, 10.ToGuid()); Assert.AreEqual(game.Board[0, 0].Owner.Id, player02.Id); Assert.IsFalse(game.Board[0, 1].Empty); Assert.AreEqual(game.Board[0, 1].Card.Id, 4.ToGuid()); Assert.AreEqual(game.Board[0, 1].Owner.Id, player01.Id); Assert.IsTrue(game.Board[0, 2].Empty); Assert.IsFalse(game.Board[1, 0].Empty); Assert.AreEqual(game.Board[1, 0].Card.Id, 6.ToGuid()); Assert.AreEqual(game.Board[1, 0].Owner.Id, player02.Id); Assert.IsFalse(game.Board[1, 1].Empty); Assert.AreEqual(game.Board[1, 1].Card.Id, 9.ToGuid()); Assert.AreEqual(game.Board[1, 1].Owner.Id, player02.Id); Assert.IsFalse(game.Board[1, 2].Empty); Assert.AreEqual(game.Board[1, 2].Card.Id, 2.ToGuid()); Assert.AreEqual(game.Board[1, 2].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 0].Empty); Assert.AreEqual(game.Board[2, 0].Card.Id, 1.ToGuid()); Assert.AreEqual(game.Board[2, 0].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 1].Empty); Assert.AreEqual(game.Board[2, 1].Card.Id, 3.ToGuid()); Assert.AreEqual(game.Board[2, 1].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 2].Empty); Assert.AreEqual(game.Board[2, 2].Card.Id, 8.ToGuid()); Assert.AreEqual(game.Board[2, 2].Owner.Id, player02.Id); Assert.AreEqual(2, game.Scoreboard[player01.Id]); Assert.AreEqual(8, game.Scoreboard[player02.Id]); Assert.IsFalse(game.Finished); /* 9º JOGADA */ game.Play(new PlayCommand(player02.Id, 7, 0, 2)); Assert.IsFalse(game.Board[0, 0].Empty); Assert.AreEqual(game.Board[0, 0].Card.Id, 10.ToGuid()); Assert.AreEqual(game.Board[0, 0].Owner.Id, player02.Id); Assert.IsFalse(game.Board[0, 1].Empty); Assert.AreEqual(game.Board[0, 1].Card.Id, 4.ToGuid()); Assert.AreEqual(game.Board[0, 1].Owner.Id, player02.Id); Assert.IsFalse(game.Board[0, 2].Empty); Assert.AreEqual(game.Board[0, 2].Card.Id, 7.ToGuid()); Assert.AreEqual(game.Board[0, 2].Owner.Id, player02.Id); Assert.IsFalse(game.Board[1, 0].Empty); Assert.AreEqual(game.Board[1, 0].Card.Id, 6.ToGuid()); Assert.AreEqual(game.Board[1, 0].Owner.Id, player02.Id); Assert.IsFalse(game.Board[1, 1].Empty); Assert.AreEqual(game.Board[1, 1].Card.Id, 9.ToGuid()); Assert.AreEqual(game.Board[1, 1].Owner.Id, player02.Id); Assert.IsFalse(game.Board[1, 2].Empty); Assert.AreEqual(game.Board[1, 2].Card.Id, 2.ToGuid()); Assert.AreEqual(game.Board[1, 2].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 0].Empty); Assert.AreEqual(game.Board[2, 0].Card.Id, 1.ToGuid()); Assert.AreEqual(game.Board[2, 0].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 1].Empty); Assert.AreEqual(game.Board[2, 1].Card.Id, 3.ToGuid()); Assert.AreEqual(game.Board[2, 1].Owner.Id, player02.Id); Assert.IsFalse(game.Board[2, 2].Empty); Assert.AreEqual(game.Board[2, 2].Card.Id, 8.ToGuid()); Assert.AreEqual(game.Board[2, 2].Owner.Id, player02.Id); Assert.AreEqual(1, game.Scoreboard[player01.Id]); Assert.AreEqual(9, game.Scoreboard[player02.Id]); Assert.IsTrue(game.Finished); }
public EndWindow(OptionsViewModel optionsViewModel) { this.optionsView = optionsViewModel; this.endGameCommand = new EndGameCommand(optionsView, bvm); this.newGameCommand = new NewGameCommand(optionsView, this); }