|
|
|
@ -9,6 +9,10 @@ using Models.Rules;
|
|
|
|
|
|
|
|
|
|
namespace Models.Game
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The Game class represents a game session in the application.
|
|
|
|
|
/// It contains all the necessary properties and methods to manage a game, including the game loop, dice rolling, and use of the game rules.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Game
|
|
|
|
|
{
|
|
|
|
|
private bool _isRunning;
|
|
|
|
@ -28,6 +32,11 @@ namespace Models.Game
|
|
|
|
|
public event EventHandler<GameEndedEventArgs> GameEnded;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="Game"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="player">The player who play the game.</param>
|
|
|
|
|
/// <param name="map">The map to be used in the game.</param>
|
|
|
|
|
public Game(Player player, Map map)
|
|
|
|
|
{
|
|
|
|
|
_isRunning = false;
|
|
|
|
@ -39,6 +48,9 @@ namespace Models.Game
|
|
|
|
|
GameRules = new Rules.Rules();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Rolls all the dice.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void RollAllDice()
|
|
|
|
|
{
|
|
|
|
|
Dice1.Roll();
|
|
|
|
@ -80,6 +92,12 @@ namespace Models.Game
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Places the result of a dice operation into a chosen cell on the game board.
|
|
|
|
|
/// The result can be placed in the chosen cell if it's the first turn or if the chosen cell is valid according to the game rules.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="playerChoice">The cell chosen by the player to place the result.</param>
|
|
|
|
|
/// <param name="result">The result of the dice operation to be placed in the cell.</param>
|
|
|
|
|
public void PlaceResult(Cell playerChoice, int result)
|
|
|
|
|
{
|
|
|
|
|
if (Turn == 1 || GameRules.NearCellIsValid(playerChoice, UsedMap.Boards))
|
|
|
|
@ -92,9 +110,9 @@ namespace Models.Game
|
|
|
|
|
{
|
|
|
|
|
int index =0;
|
|
|
|
|
|
|
|
|
|
foreach (var cells in adjacentes)
|
|
|
|
|
{
|
|
|
|
|
// La cellule choisi peut creer/s'ajouter a un chemin de corde
|
|
|
|
|
foreach (var cells in adjacentes)
|
|
|
|
|
{
|
|
|
|
|
// La cellule choisi peut creer/s'ajouter a un chemin de corde
|
|
|
|
|
if (cells.Value - playerChoice.Value == 1 || cells.Value - playerChoice.Value == -1)
|
|
|
|
|
{
|
|
|
|
|
// Le cas si il n'existe aucun chemin de corde
|
|
|
|
@ -127,7 +145,7 @@ namespace Models.Game
|
|
|
|
|
// Ajouter au chemin
|
|
|
|
|
// {playerChoice.Value} existe dans le chemin de corde pas possible
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -142,18 +160,21 @@ namespace Models.Game
|
|
|
|
|
GameLoop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main game loop that runs while the game is active.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async void GameLoop()
|
|
|
|
|
{
|
|
|
|
|
while (_isRunning)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (CheckGameEnd()) //TODO Règle pour check si fin de jeu
|
|
|
|
|
{
|
|
|
|
|
_isRunning = false;
|
|
|
|
|
//TODO Code pour comptabiliser les points
|
|
|
|
|
GameEnded?.Invoke(this, new GameEndedEventArgs(//player));
|
|
|
|
|
//GameEnded?.Invoke(this, new GameEndedEventArgs(player));
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
await Task.Delay(1000); // 1 seconde
|
|
|
|
|
}
|
|
|
|
|