diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index 3f4335e..e79df2a 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -479,7 +479,7 @@ namespace Models.Game { if (cells == null || cells.Value == null || cells.Valid == false) continue; - if (!UsedMap.IsCellInZones(cells) || !UsedMap.IsCellInRopePath(cells)) + if (!UsedMap.IsCellInZones(cells) && !UsedMap.IsCellInRopePath(cells)) cells.SetPenalty(); } } diff --git a/source/Trek-12/Tests/GameTests.cs b/source/Trek-12/Tests/GameTests.cs index 96d1bdf..e8203ff 100644 --- a/source/Trek-12/Tests/GameTests.cs +++ b/source/Trek-12/Tests/GameTests.cs @@ -4,6 +4,7 @@ using Models.Game; using Models.Interfaces; using System.Reflection; using static System.Type; +using Xunit.Abstractions; namespace Tests; @@ -452,29 +453,49 @@ public class GameTests var player = new Player("test_player", "DefaultProfilePicture"); var map = new Map("test_name", "test_background.png"); _game.InitializeGame(map, player); + var methodInfo = typeof(Game).GetMethod("AddToRopePath", BindingFlags.NonPublic | BindingFlags.Instance); + Assert.NotNull(methodInfo); _game.UsedMap.Boards[0].Valid = true; _game.UsedMap.Boards[1].Valid = true; _game.UsedMap.Boards[2].Valid = true; + _game.UsedMap.Boards[3].Valid = true; + + + _game.UsedMap.Boards[0].Value = 0; + methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[0], _game.GameRules.EveryAdjacentCells(_game.UsedMap.Boards[0], _game.UsedMap.Boards.ToList()) }); + _game.UsedMap.Boards[1].Value = 1; + methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[1], _game.GameRules.EveryAdjacentCells(_game.UsedMap.Boards[1], _game.UsedMap.Boards.ToList()) }); + _game.UsedMap.Boards[2].Value = 2; + methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[2], _game.GameRules.EveryAdjacentCells(_game.UsedMap.Boards[2], _game.UsedMap.Boards.ToList()) }); + _game.UsedMap.Boards[3].Value = 5; + + _game.PutPenaltyForLostCells(_game.UsedMap.Boards); + + Assert.True(_game.UsedMap.Boards[3].Penalty); + + Assert.Equal(3, _game.CalculusOfPenalty(_game.UsedMap.Boards)); + + } + + [Fact] + public void CalculusOfPenalty_ReallyCalculusPenalty_ForZonesAndDangerousCellsAndOverTwelve() + { + var player = new Player("test_player", "DefaultProfilePicture"); + var map = new Map("test_name", "test_background.png"); + _game.InitializeGame(map, player); + _game.UsedMap.Boards[7].Valid = true; _game.UsedMap.Boards[8].Valid = true; _game.UsedMap.Boards[9].Valid = true; _game.UsedMap.Boards[10].Valid = true; _game.UsedMap.Boards[11].Valid = true; _game.UsedMap.Boards[12].Valid = true; - _game.UsedMap.Boards[13].Valid = true; - - _game.UsedMap.Boards[0].Value = 0; - _game.UsedMap.Boards[1].Value = 1; - _game.UsedMap.Boards[2].Value = 2; - _game.UsedMap.Boards[8].Value = 5; - _game.UsedMap.Boards[7].Value = 5; - _game.UsedMap.Boards[9].Value = 5; - _game.UsedMap.Boards[10].Value = 6; - _game.UsedMap.Boards[11].IsDangerous = true; - _game.UsedMap.Boards[12].Value = 13; //One penalty because it is over 12 - _game.UsedMap.Boards[13].Value = 9; //One penalty because it is lost + _game.UsedMap.Boards[10].Value = 2; // 1,3 // penalty + _game.UsedMap.Boards[7].Value = 5; // 1,0 + _game.UsedMap.Boards[8].Value = 5; // 1,1 + _game.UsedMap.Boards[9].Value = 5; // 1,2 var place = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance); Assert.NotNull(place); @@ -485,21 +506,20 @@ public class GameTests cell.IsDangerous = true; place.Invoke(_game, new object[] { cell, 7 }); //One penalty - var methodInfo = typeof(Game).GetMethod("AddToRopePath", BindingFlags.NonPublic | BindingFlags.Instance); - Assert.NotNull(methodInfo); + var othercell = new Cell(1, 5); + cell.Value = 14; + cell.Valid = true; + place.Invoke(_game, new object[] { othercell, 14 }); + foreach (var cells in _game.UsedMap.Boards.ToList()) { _game.GameRules.IsZoneValidAndAddToZones(cells, _game.UsedMap); - methodInfo.Invoke(_game, new object[] { cells, _game.GameRules.EveryAdjacentCells(cells, _game.UsedMap.Boards.ToList()) }); } _game.PutPenaltyForLostCells(_game.UsedMap.Boards); - Assert.True(_game.UsedMap.Boards[10].Penalty); Assert.True(_game.UsedMap.Boards[11].Penalty); - Assert.True(_game.UsedMap.Boards[12].Penalty); - Assert.Equal(9, _game.CalculusOfPenalty(_game.UsedMap.Boards)); }