Merge branch 'dev' of codefirst.iut.uca.fr:remi.lavergne/Trek-12 into dev
continuous-integration/drone/push Build is failing Details

pull/112/head
Rémi LAVERGNE 11 months ago
commit 60c8f76e01

@ -101,7 +101,7 @@ namespace Models.Game
public Dice Dice2 { get; private set; } public Dice Dice2 { get; private set; }
[DataMember] [DataMember]
public int Turn { get; private set; } public int Turn { get; set; }
public Operation PlayerOperation { get; set; } public Operation PlayerOperation { get; set; }
@ -394,6 +394,11 @@ namespace Models.Game
{ {
if (item.X == playerChoice.X && item.Y == playerChoice.Y) if (item.X == playerChoice.X && item.Y == playerChoice.Y)
{ {
if (result > 12 || (result > 6 && item.IsDangerous == true))
{
item.SetPenalty();
PlayerCell.SetPenalty();
}
item.Value = result; item.Value = result;
OnPropertyChanged(nameof(UsedMap.Boards)); OnPropertyChanged(nameof(UsedMap.Boards));
return; return;
@ -552,26 +557,17 @@ namespace Models.Game
if (cell.X < 0 || cell.X >= UsedMap.Boards.Count / 6 || cell.Y < 0 || cell.Y >= 6) if (cell.X < 0 || cell.X >= UsedMap.Boards.Count / 6 || cell.Y < 0 || cell.Y >= 6)
{ {
return false; return false;
//throw new InvalidCellCoordinatesException("Invalid cell coordinates. Please choose again.");
} }
if (!GameRules.IsCellValid(cell, UsedMap.Boards.ToList())) if (!GameRules.IsCellValid(cell, UsedMap.Boards.ToList()))
{ {
return false; return false;
//throw new InvalidCellException("Cell is not valid. Please choose again.");
} }
bool res = true;
if (!res)
{
return false;
//throw new InvalidPlaceResultException("Cell is not valid for place result. Please choose again.");
}
GameRules.IsZoneValidAndAddToZones(cell, UsedMap); GameRules.IsZoneValidAndAddToZones(cell, UsedMap);
AddToRopePath(cell, GameRules.EveryAdjacentCells(cell, UsedMap.Boards.ToList())); AddToRopePath(cell, GameRules.EveryAdjacentCells(cell, UsedMap.Boards.ToList()));
CellChosen?.Invoke(this, new CellChosenEventArgs(cell, result)); CellChosen?.Invoke(this, new CellChosenEventArgs(cell, result));
return true; return true;
//BoardUpdated?.Invoke(this, EventArgs.Empty);
} }
/// <summary> /// <summary>
@ -594,7 +590,7 @@ namespace Models.Game
foreach (var cells in Boards) foreach (var cells in Boards)
if (cells.Penalty) if (cells.Penalty)
{ {
if (cells.Valid == false || cells.Value == null) if (!cells.Valid || cells.Value == null)
continue; continue;
result += 3; result += 3;
} }
@ -605,7 +601,7 @@ namespace Models.Game
{ {
foreach (var cells in Boards) foreach (var cells in Boards)
{ {
if (cells == null || cells.Value == null || cells.Valid == false) if (cells == null || cells.Value == null || !cells.Valid)
continue; continue;
if (!UsedMap.IsCellInZones(cells) && !UsedMap.IsCellInRopePath(cells)) if (!UsedMap.IsCellInZones(cells) && !UsedMap.IsCellInRopePath(cells))
cells.SetPenalty(); cells.SetPenalty();
@ -619,7 +615,7 @@ namespace Models.Game
{ {
points += GameRules.ScoreRopePaths(UsedMap.RopePaths[i]); points += GameRules.ScoreRopePaths(UsedMap.RopePaths[i]);
} }
points += CalculusOfPenalty(UsedMap.Boards); points -= CalculusOfPenalty(UsedMap.Boards);
return points ?? 0; return points ?? 0;
} }

@ -22,7 +22,7 @@ namespace Models.Game
if (isChecked == value) if (isChecked == value)
return; return;
isChecked = value; isChecked = value;
OnPropertyChanged("IsChecked"); OnPropertyChanged(nameof(IsChecked));
} }
} }

@ -25,6 +25,8 @@ namespace Models.Rules
{ {
if (!IsCellEmpty(playerChoicePosition)) return false; if (!IsCellEmpty(playerChoicePosition)) return false;
if (playerChoicePosition.Valid == false) return false;
if (EveryAdjacentCells(playerChoicePosition, cells).Count == 1) return false; if (EveryAdjacentCells(playerChoicePosition, cells).Count == 1) return false;
return true; return true;

@ -251,13 +251,17 @@ public class GameTests
Assert.NotNull(_game.GameRules); Assert.NotNull(_game.GameRules);
_game.UsedMap.Boards[0].Value = 1; _game.UsedMap.Boards[0].Value = 1;
_game.UsedMap.Boards[1].Value = 2; _game.UsedMap.Boards[1].Value = 2;
_game.UsedMap.Boards[0].Valid = true;
_game.UsedMap.Boards[1].Valid = true;
_game.UsedMap.Boards[2].Valid = true;
var methodInfo = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance); var methodInfo = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(methodInfo); Assert.NotNull(methodInfo);
var cell = new Cell(0, 2); _game.PlayerCell = new Cell(2, 0);
cell.Value = 3; _game.PlayerCell.Value = 3;
methodInfo.Invoke(_game, new object[] { cell, 3 }); methodInfo.Invoke(_game, new object[] { _game.PlayerCell, 3 });
//_game.UsedMap.Boards[2].Value = _game.PlayerCell.Value;
Assert.Equal(3, _game.UsedMap.Boards[2].Value); Assert.Equal(3, _game.UsedMap.Boards[2].Value);
} }
@ -270,8 +274,11 @@ public class GameTests
_game.InitializeGame(map, player, false); _game.InitializeGame(map, player, false);
var cell = new Cell(0, 1); var cell = new Cell(1, 0);
cell.Valid = true;
_game.UsedMap.Boards[0].Valid = true;
_game.UsedMap.Boards[0].Value = 1; _game.UsedMap.Boards[0].Value = 1;
_game.UsedMap.Boards[1].Valid = true;
bool result = _game.HandlePlayerChoice(cell, 1); bool result = _game.HandlePlayerChoice(cell, 1);
Assert.True(result); Assert.True(result);
} }
@ -329,14 +336,16 @@ public class GameTests
var player = new Player("test_player", "DefaultProfilePicture"); var player = new Player("test_player", "DefaultProfilePicture");
var map = new Map("test_name", "test_background.png"); var map = new Map("test_name", "test_background.png");
_game.InitializeGame(map, player, false); _game.InitializeGame(map, player, false);
_game.UsedMap.Boards[1].Valid = true;
_game.UsedMap.Boards[2].Valid = true;
_game.UsedMap.Boards[1].Value = 5; _game.UsedMap.Boards[1].Value = 5;
var methodInfo = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance); var methodInfo = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(methodInfo); Assert.NotNull(methodInfo);
var cell = new Cell(0, 2); _game.PlayerCell = new Cell(2, 0);
cell.Value = 14; _game.PlayerCell.Value = 14;
methodInfo.Invoke(_game, new object[] { cell, 14 }); methodInfo.Invoke(_game, new object[] { _game.PlayerCell, 14 });
Assert.True(_game.UsedMap.Boards[2].Penalty); Assert.True(_game.UsedMap.Boards[2].Penalty);
} }
@ -347,15 +356,19 @@ public class GameTests
var player = new Player("test_player", "DefaultProfilePicture"); var player = new Player("test_player", "DefaultProfilePicture");
var map = new Map("test_name", "test_background.png"); var map = new Map("test_name", "test_background.png");
_game.InitializeGame(map, player, false); _game.InitializeGame(map, player, false);
_game.UsedMap.Boards[1].Valid = true;
_game.UsedMap.Boards[2].Valid = true;
_game.UsedMap.Boards[1].Value = 5; _game.UsedMap.Boards[1].Value = 5;
_game.UsedMap.Boards[2].IsDangerous = true; _game.UsedMap.Boards[2].IsDangerous = true;
var methodInfo = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance); var methodInfo = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(methodInfo); Assert.NotNull(methodInfo);
var cell = new Cell(0, 2); _game.PlayerCell = new Cell(2, 0);
cell.Value = 7; _game.PlayerCell.Value = 7;
methodInfo.Invoke(_game, new object[] { cell, 7 }); methodInfo.Invoke(_game, new object[] { _game.PlayerCell, 7 });
Assert.True(_game.UsedMap.Boards[2].Penalty); Assert.True(_game.UsedMap.Boards[2].Penalty);
} }
@ -415,42 +428,133 @@ public class GameTests
} }
[Fact] [Fact]
public void CalculusOfPenalty_ReallyCalculusPenalty() public void CalculusOfPenalty_ReallyCalculusPenalty_ForZonesAndDangerousCellsAndOverTwelve()
{ {
var player = new Player("test_player", "DefaultProfilePicture"); var player = new Player("test_player", "DefaultProfilePicture");
var map = new Map("test_name", "test_background.png"); var map = new Map("test_name", "test_background.png");
_game.InitializeGame(map, player, false); _game.InitializeGame(map, player, false);
var methodInfo = typeof(Game).GetMethod("AddToRopePath", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(methodInfo);
_game.UsedMap.Boards[0].Valid = true; _game.UsedMap.Boards[7].Valid = true;
_game.UsedMap.Boards[1].Valid = true; _game.UsedMap.Boards[8].Valid = true;
_game.UsedMap.Boards[2].Valid = true; _game.UsedMap.Boards[9].Valid = true;
_game.UsedMap.Boards[3].Valid = true; _game.UsedMap.Boards[10].Valid = true;
_game.UsedMap.Boards[11].Valid = true;
_game.UsedMap.Boards[12].Valid = true;
_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);
_game.PlayerCell = new Cell(4, 1);
_game.PlayerCell.Value = 7;
_game.PlayerCell.Valid = true;
_game.PlayerCell.IsDangerous = true;
place.Invoke(_game, new object[] { _game.PlayerCell, 7 }); //One penalty
_game.PlayerCell = new Cell(5, 1);
_game.PlayerCell.Value = 14;
_game.PlayerCell.Valid = true;
place.Invoke(_game, new object[] { _game.PlayerCell, 14 });
_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()) }); foreach (var cells in _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.GameRules.IsZoneValidAndAddToZones(cells, _game.UsedMap);
_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); _game.PutPenaltyForLostCells(_game.UsedMap.Boards);
Assert.True(_game.UsedMap.Boards[3].Penalty); Assert.True(_game.UsedMap.Boards[11].Penalty);
Assert.Equal(9, _game.CalculusOfPenalty(_game.UsedMap.Boards));
Assert.Equal(3, _game.CalculusOfPenalty(_game.UsedMap.Boards)); }
[Fact]
public void DoesDeleteGame_ReallyDeleteGame()
{
Game game = new Game();
Game game1 = new Game();
game.AddGame(game);
game.AddGame(game1);
game.DeleteGame();
Assert.DoesNotContain(game1, game.Games);
} }
[Fact] [Fact]
public void CalculusOfPenalty_ReallyCalculusPenalty_ForZonesAndDangerousCellsAndOverTwelve() public void DoesDeleteGame_DoNotDeleteNoGame()
{ {
var player = new Player("test_player", "DefaultProfilePicture"); bool res = _game.DeleteGame();
var map = new Map("test_name", "test_background.png"); Assert.False(res);
_game.InitializeGame(map, player, false); }
[Fact]
public void CanIModifyAPlayer()
{
Game game = new Game();
Player player = new Player("test", "DefaultProfilePicture");
game.AddPlayer(player);
game.ModifyPlayer("test", "newName");
Assert.Equal("newName", game.Players[0].Pseudo);
}
[Fact]
public void CanIModifyANonExistentPlayer()
{
Game game = new Game();
var res = game.ModifyPlayer("nope", "newName");
Assert.False(res);
}
[Fact]
public void CanIRollDice()
{
_game.InitializeGame(new Map("test", "test.png"), new Player("test", "test.png"), false);
_game.RollAllDice();
Assert.NotNull(_game.Dice1);
Assert.NotNull(_game.Dice2);
Assert.True(_game.Dice1.Value >= 0 && _game.Dice1.Value <= 5 );
Assert.True(_game.Dice2.Value >= 1 && _game.Dice2.Value <= 6 );
}
[Fact]
public void CanIStartGame()
{
_game.InitializeGame(new Map("test", "test.png"), new Player("test", "test.png"), false);
var start = typeof(Game).GetMethod("StartGame", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(start);
start.Invoke(_game, null);
Assert.True(_game.IsRunning);
}
[Fact]
public void CanIEndGame()
{
_game.InitializeGame(new Map("test", "test.png"), new Player("test", "test.png"), false);
var start = typeof(Game).GetMethod("StartGame", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(start);
start.Invoke(_game, null);
var end = typeof(Game).GetMethod("EndGame", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(end);
end.Invoke(_game, new object[] { 14 } );
Assert.False(_game.IsRunning);
}
[Fact]
public void CalculusOfPointsWorksWellOrNot()
{
_game.InitializeGame(new Map("test", "test.png"), new Player("test", "test.png"), false);
_game.UsedMap.Boards[7].Valid = true; _game.UsedMap.Boards[7].Valid = true;
_game.UsedMap.Boards[8].Valid = true; _game.UsedMap.Boards[8].Valid = true;
@ -459,24 +563,20 @@ public class GameTests
_game.UsedMap.Boards[11].Valid = true; _game.UsedMap.Boards[11].Valid = true;
_game.UsedMap.Boards[12].Valid = true; _game.UsedMap.Boards[12].Valid = true;
_game.UsedMap.Boards[10].Value = 2; // 1,3 // penalty _game.UsedMap.Boards[10].Value = 2; // penalty (- 3)
_game.UsedMap.Boards[7].Value = 5; // 1,0 _game.UsedMap.Boards[7].Value = 5; //5 + 2 = 7
_game.UsedMap.Boards[8].Value = 5; // 1,1 _game.UsedMap.Boards[8].Value = 5;
_game.UsedMap.Boards[9].Value = 5; // 1,2 _game.UsedMap.Boards[9].Value = 5;
var place = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance); var place = typeof(Game).GetMethod("PlaceResult", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(place); Assert.NotNull(place);
var cell = new Cell(1, 4); _game.PlayerCell = new Cell(4, 1);
cell.Value = 7; _game.PlayerCell.Value = 7;
cell.Valid = true; _game.PlayerCell.Valid = true;
cell.IsDangerous = true; _game.PlayerCell.IsDangerous = true;
place.Invoke(_game, new object[] { cell, 7 }); //One penalty place.Invoke(_game, new object[] { _game.PlayerCell, 7 }); //One penalty
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()) foreach (var cells in _game.UsedMap.Boards.ToList())
@ -487,7 +587,39 @@ public class GameTests
_game.PutPenaltyForLostCells(_game.UsedMap.Boards); _game.PutPenaltyForLostCells(_game.UsedMap.Boards);
Assert.True(_game.UsedMap.Boards[11].Penalty); Assert.True(_game.UsedMap.Boards[11].Penalty);
Assert.Equal(9, _game.CalculusOfPenalty(_game.UsedMap.Boards));
Assert.Equal(1, _game.FinalCalculusOfPoints());
} }
[Fact]
public void CalculusOfPointsWorksWellOrNotForRopePathes()
{
_game.InitializeGame(new Map("test", "test.png"), new Player("test", "test.png"), false);
var methodInfo = typeof(Game).GetMethod("AddToRopePath", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(methodInfo);
_game.Turn = 2;
_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[7].Value = 5; //7 + 2 = 9
methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[7], _game.UsedMap.Boards.ToList() });
_game.UsedMap.Boards[8].Value = 6;
methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[8], _game.UsedMap.Boards.ToList() });
_game.UsedMap.Boards[9].Value = 7;
methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[9], _game.UsedMap.Boards.ToList() });
_game.UsedMap.Boards[10].Value = 2; // penalty (- 3)
methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[10], _game.UsedMap.Boards.ToList() });
_game.PutPenaltyForLostCells(_game.UsedMap.Boards);
Assert.True(_game.UsedMap.Boards[10].Penalty);
Assert.Equal(6, _game.FinalCalculusOfPoints());
}
} }

@ -44,6 +44,7 @@ public class RulesTests
{ {
Rules rules = new Rules(); Rules rules = new Rules();
Map map = new Map("test", "background"); Map map = new Map("test", "background");
map.Boards[0].Valid = true;
Cell selectedCell = map.Boards[0]; Cell selectedCell = map.Boards[0];
Assert.True(rules.IsCellValid(selectedCell, map.Boards.ToList())); Assert.True(rules.IsCellValid(selectedCell, map.Boards.ToList()));
} }

Loading…
Cancel
Save