diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index 2e780d7..3ae76e4 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -363,54 +363,119 @@ namespace QwirkleClassLibrary return false; } - public int GetPlayerScore(Player player, List cellsPlayed, Board board) + // public int GetPlayerScore(Player player, List cellsPlayed, Board b) + // { + // // Compte le nombre de tuiles et ajoute ce nombre au score + // int score = cellsPlayed.Count; + // + // // Check les lignes / colonnes adjacentes aux tuiles placées + // for(int i= 0; i < cellsPlayed.Count; i++) + // { + // // A chaque tour, crée la liste des 4 cellules adjacentes à la cellule sélectionnée + // var surroundingCells = new[] + // { + // b.GetCell(cellsPlayed[i].GetX + 1, cellsPlayed[i].GetY), + // b.GetCell(cellsPlayed[i].GetX - 1, cellsPlayed[i].GetY), + // b.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY + 1), + // b.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY - 1) + // }; + // + // // Parcourt le tableau dans la direction par rapport à ces cellules adjacentes + // foreach (var cell in surroundingCells) + // { + // // Si la cellule adjacente ne contient pas de tuile, on passe à la cellule adjacente suivante + // if (cell?.GetTile == null) break; + // + // if (cellsPlayed.Contains(cell) != true) + // { + // + // var dx = cell.GetX - cellsPlayed[i].GetX; + // var dy = cell.GetY - cellsPlayed[i].GetY; + // + // for (int j = 1; j < b.Rows; j++) + // { + // var extendedCell = b.GetCell(cellsPlayed[i].GetX + j * dx, cellsPlayed[i].GetY + j * dy); + // + // if (extendedCell?.GetTile == null) + // { + // break; + // } + // + // score += 1; + // + // } + // } + // } + // + // } + // + // ScoreBoard.Add(player, score); + // + // return score; + // } + + public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, Board b) { - // Compte le nombre de tuiles et ajoute ce nombre au score int score = cellsPlayed.Count; - // Check les lignes / colonnes adjacentes aux tuiles placées - for(int i= 0; i < cellsPlayed.Count; i++) + foreach (var cell in cellsPlayed) { - // A chaque tour, crée la liste des 4 cellules adjacentes à la cellule sélectionnée - var surroundingCells = new[] - { - board.GetCell(cellsPlayed[i].GetX + 1, cellsPlayed[i].GetY), - board.GetCell(cellsPlayed[i].GetX - 1, cellsPlayed[i].GetY), - board.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY + 1), - board.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY - 1) - }; - - // Parcourt le tableau dans la direction par rapport à ces cellules adjacentes - foreach (var cell in surroundingCells) + score += CalculateAdjacentScore(cell, b, cellsPlayed); + } + + + if(ScoreBoard.TryAdd(player, score) == false) + { + ScoreBoard[player] += score; + } + + return score; + } + + private int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed) + { + int score = 0; + + var surroundingCells = new[] + { + b.GetCell(cell.GetX + 1, cell.GetY), + b.GetCell(cell.GetX - 1, cell.GetY), + b.GetCell(cell.GetX, cell.GetY + 1), + b.GetCell(cell.GetX, cell.GetY - 1) + }; + + foreach (var adjacentCell in surroundingCells) + { + if (adjacentCell?.GetTile == null || cellsPlayed.Contains(adjacentCell)) { - // Si la cellule adjacente ne contient pas de tuile, on passe à la cellule adjacente suivante - if (cell?.GetTile == null) break; + continue; + } - else if (cellsPlayed.Contains(cell) != true) - { + int dx = adjacentCell.GetX - cell.GetX; + int dy = adjacentCell.GetY - cell.GetY; - var dx = cell.GetX - cellsPlayed[i].GetX; - var dy = cell.GetY - cellsPlayed[i].GetY; + score += CalculateLineScore(cell, dx, dy, b); + } - for (int j = 1; j < board.Rows; j++) - { - var extendedCell = board.GetCell(cellsPlayed[i].GetX + j * dx, cellsPlayed[i].GetY + j * dy); + return score; + } - if (extendedCell?.GetTile == null) - { - break; - } + private int CalculateLineScore(Cell cell, int dx, int dy, Board b) + { + int score = 0; - score += 1; + for (int i = 1; i < b.Rows; i++) + { + var extendedCell = b.GetCell(cell.GetX + i * dx, cell.GetY + i * dy); - } - } + if (extendedCell?.GetTile == null) + { + break; } + score++; } - ScoreBoard.Add(player, score); - return score; } diff --git a/Qwirkle/QwirkleClassLibrary/IPlayer.cs b/Qwirkle/QwirkleClassLibrary/IPlayer.cs index 3bc87ce..cc7e3c6 100644 --- a/Qwirkle/QwirkleClassLibrary/IPlayer.cs +++ b/Qwirkle/QwirkleClassLibrary/IPlayer.cs @@ -1,3 +1,5 @@ +using System.Collections.ObjectModel; + namespace QwirkleClassLibrary; public interface IPlayer @@ -12,5 +14,5 @@ public interface IPlayer public bool SwapTiles(Player player, List tilesToSwap); - public int GetPlayerScore(Player player, List cellsPlayed, Board board); + public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, Board b); } \ No newline at end of file diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index fc739b3..eb6ec76 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -134,7 +134,7 @@ static void MenuSwitch(Game game) WriteLine("[1] Place your tiles"); WriteLine("[2] Swap your tiles"); - WriteLine("[3] Skip your turn"); + WriteLine("[3] End your turn / Skip your turn"); try { @@ -155,6 +155,7 @@ static void MenuSwitch(Game game) enter = 3; break; case 3: + WriteLine("Your score on this turn : " + game.GetPlayerScore(game.GetPlayingPlayer(), game.CellsUsed, game.GetBoard())); game.EmptyCellUsed(); return; } diff --git a/Qwirkle/cm7/cm7.cs b/Qwirkle/cm7/cm7.cs new file mode 100644 index 0000000..21194e3 --- /dev/null +++ b/Qwirkle/cm7/cm7.cs @@ -0,0 +1,28 @@ +// DataBinding Baby !! + +// Applcation se basant sur le site wtatennis.com + +// class : Player, Place (Birth Places), Manager, IPersistanceManager +// enum : Hand (lfet-handed or right-handed) + +// Player.cs + +public string FirstName +{ + get => firstName; + set + { + if(value == firstName) return; + firstName = value; + OnPropertyChanged(); + } +} + +private string firstName; + +public event PropertyChangedEventHandler PropertyChanged; + +public void OnPropertyChanged([CallerMemberName] string propertyName = null) +{ + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); +} \ No newline at end of file diff --git a/Qwirkle/cm7/cm7.xaml b/Qwirkle/cm7/cm7.xaml new file mode 100644 index 0000000..3ef2d31 --- /dev/null +++ b/Qwirkle/cm7/cm7.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + +