diff --git a/source/Trek-12/ConsoleApp/Program.cs b/source/Trek-12/ConsoleApp/Program.cs index 38d2c35..13ca4b4 100644 --- a/source/Trek-12/ConsoleApp/Program.cs +++ b/source/Trek-12/ConsoleApp/Program.cs @@ -1,4 +1,4 @@ -// See https://aka.ms/new-console-template for more information +// See https://aka.ms/new-console-template for more information using Models; using Models.Events; @@ -45,6 +45,7 @@ class Program // Initialisation Game.InitializeGame(map, player); + Game.GameLoop(); } diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index 374152d..d6b8763 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -106,6 +106,7 @@ namespace Models.Game public Operation PlayerOperation { get; set; } public Cell PlayerCell { get; set; } + public int Resultat { get; set; } public Rules.Rules GameRules { get; } @@ -372,7 +373,7 @@ namespace Models.Game /// /// The cell chosen by the player to place the result. /// The result of the dice operation to be placed in the cell. - private void PlaceResult(Cell playerChoice) + private void PlaceResult(Cell playerChoice, int result) { IEnumerable ValidCell = from cell in UsedMap.Boards @@ -383,9 +384,11 @@ namespace Models.Game { if (item.X == playerChoice.X && item.Y == playerChoice.Y) { - item.Value = PlayerCell.Value; + item.Value = result; return; } + + } } @@ -405,22 +408,22 @@ namespace Models.Game where cell.Value != null && cell.Valid == true && cell != playerChoice select cell; - foreach (var item in ValidCell) - { + foreach (var item in ValidCell) + { if (!GameRules.IsCellAdjacent(playerChoice, item)) - continue; - if (!((playerChoice.Value - item.Value) == 1 || (playerChoice.Value - item.Value) == -1)) - continue; + continue; + if (!((playerChoice.Value - item.Value) == 1 || (playerChoice.Value - item.Value) == -1)) + continue; if (!GameRules.IsInRopePaths(item,UsedMap.RopePaths,index)) { UsedMap.RopePaths.Add(new List { playerChoice, item }); return; - } + } if (!GameRules.AsValue(playerChoice, UsedMap.RopePaths, index)) { UsedMap.RopePaths[index].Add(playerChoice); return; - } + } } } @@ -462,17 +465,13 @@ namespace Models.Game /// /// The main game loop that runs while the game is active. /// - private void GameLoop() + public void GameLoop() { while (IsRunning) { RollAllDice(); - int res = PlayerChooseOperation(); - PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,Turn)); + Resultat = PlayerChooseOperation(); PlayerSelectionCell(); - PlayerCell.Value = res; - AddToRopePath(PlayerCell,UsedMap.Boards.ToList()); - PlaceResult(PlayerCell); BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList())); Turn++; } @@ -485,6 +484,7 @@ namespace Models.Game { PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(PlayerOperation)); } + PlayerOption?.Invoke(this, new PlayerOptionEventArgs(UsedMap.Boards.ToList(), ResultOperation(PlayerOperation), Turn)); return ResultOperation(PlayerOperation); } @@ -496,6 +496,7 @@ namespace Models.Game PlayerChooseCell?.Invoke(this, new PlayerChooseCellEventArgs(PlayerCell)); } MarkOperationAsChecked(PlayerOperation); + PlaceResult(PlayerCell, Resultat); } /// diff --git a/source/Trek-12/Trek-12/Views/PageBoard.xaml b/source/Trek-12/Trek-12/Views/PageBoard.xaml index 397b0eb..d9aef40 100644 --- a/source/Trek-12/Trek-12/Views/PageBoard.xaml +++ b/source/Trek-12/Trek-12/Views/PageBoard.xaml @@ -6,52 +6,70 @@ BackgroundColor="Bisque"> - - + + -