ConsoleApp #109

Merged
remi.lavergne merged 2 commits from ConsoleApp into dev 11 months ago

@ -85,7 +85,7 @@ class Program
static void OnPlayerOption(object sender, PlayerOptionEventArgs e) static void OnPlayerOption(object sender, PlayerOptionEventArgs e)
{ {
Console.WriteLine(); Console.WriteLine();
if(e.Turn != 1) if (e.Turn != 1)
{ {
IEnumerable<Cell> PlayedCellsQuery = IEnumerable<Cell> PlayedCellsQuery =
from cell in e.Board from cell in e.Board
@ -110,6 +110,7 @@ class Program
Console.Write($"{e.Resultat}"); Console.Write($"{e.Resultat}");
Console.ResetColor(); Console.ResetColor();
} }
} }
} }
} }

@ -317,7 +317,7 @@ namespace Models.Game
/// </summary> /// </summary>
/// <param name="playerChoice">The cell chosen by the player to place the result.</param> /// <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> /// <param name="result">The result of the dice operation to be placed in the cell.</param>
private void PlaceResult(Cell playerChoice, int result) private void PlaceResult(Cell playerChoice)
{ {
IEnumerable<Cell> ValidCell = IEnumerable<Cell> ValidCell =
from cell in UsedMap.Boards from cell in UsedMap.Boards
@ -326,8 +326,11 @@ namespace Models.Game
select cell; select cell;
foreach (var item in ValidCell) foreach (var item in ValidCell)
{ {
if(item.X == playerChoice.X && item.Y == playerChoice.Y) if (item.X == playerChoice.X && item.Y == playerChoice.Y)
item.Value = result; {
item.Value = PlayerCell.Value;
return;
}
} }
} }
@ -336,35 +339,32 @@ namespace Models.Game
/// </summary> /// </summary>
/// <param name="playerChoice"></param> /// <param name="playerChoice"></param>
/// <param name="adjacentes"></param> /// <param name="adjacentes"></param>
private void AddToRopePath(Cell playerChoice,List<Cell> adjacentes) private void AddToRopePath(Cell playerChoice,List<Cell> board)
{ {
int index =0;
foreach (var cells in adjacentes.Where(cells => cells.Value - playerChoice.Value == 1 || cells.Value - playerChoice.Value == -1))
{
// Le cas si il n'existe aucun chemin de corde
if (UsedMap.RopePaths.Count == 0)
{
// Creer un nouveau chemin de corde avec la cellule choisi par le joueur et celle adjacente
UsedMap.RopePaths.Add(new List<Cell> {playerChoice, cells});
}
if(Turn==1) return;
int index = 0;
// A modifier dans le cas ou il est possible de fusionner deux chemins de corde IEnumerable<Cell> ValidCell =
if (GameRules.IsInRopePaths(playerChoice, UsedMap.RopePaths, index)) break; from cell in UsedMap.Boards
where cell.Value != null && cell.Valid == true && cell != playerChoice
// Le cas si il existe des chemins de corde select cell;
// Est-ce que la cellule adjacentes fait parti d'un chemin de corde foreach (var item in ValidCell)
if (!GameRules.IsInRopePaths(cells,UsedMap.RopePaths,index)) {
{ if (!GameRules.IsCellAdjacent(playerChoice, item))
UsedMap.RopePaths.Add(new List<Cell> { playerChoice, cells }); continue;
if (!((playerChoice.Value - item.Value) == 1 || (playerChoice.Value - item.Value) == -1))
continue; continue;
if (!GameRules.IsInRopePaths(item,UsedMap.RopePaths,index))
{
UsedMap.RopePaths.Add(new List<Cell> { playerChoice, item });
return;
} }
if (!GameRules.AsValue(playerChoice, UsedMap.RopePaths, index))
if (!GameRules.AsValue(playerChoice,UsedMap.RopePaths,index))
{ {
UsedMap.RopePaths[index].Add(playerChoice); UsedMap.RopePaths[index].Add(playerChoice);
return;
} }
} }
} }
@ -410,17 +410,17 @@ namespace Models.Game
/// </summary> /// </summary>
private void GameLoop() private void GameLoop()
{ {
int res = 0,turn = 1;
Cell cell;
while (IsRunning) while (IsRunning)
{ {
RollAllDice(); RollAllDice();
res = PlayerChooseOperation(); int res = PlayerChooseOperation();
PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,turn)); PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,Turn));
PlayerSelectionCell(); PlayerSelectionCell();
PlaceResult(PlayerCell,res); PlayerCell.Value = res;
AddToRopePath(PlayerCell,UsedMap.Boards.ToList());
PlaceResult(PlayerCell);
BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList())); BoardUpdated?.Invoke(this, new BoardsUpdateEventArgs(UsedMap.Boards.ToList()));
turn++; Turn++;
} }
} }

@ -87,28 +87,23 @@ public partial class PageBoard : ContentPage
private void HigherClicked(object sender, EventArgs e) private void HigherClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.HIGHER);
Higher.IsVisible = false; Higher.IsVisible = false;
} }
private void LowerClicked(object sender, EventArgs e) private void LowerClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.LOWER);
} }
private void AdditionClicked(object sender, EventArgs e) private void AdditionClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.ADDITION);
} }
private void SubstractionClicked(object sender, EventArgs e) private void SubstractionClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.SUBTRACTION);
} }
private void MultiplicationClicked(object sender, EventArgs e) private void MultiplicationClicked(object sender, EventArgs e)
{ {
GameManager.MarkOperationAsChecked(Operation.MULTIPLICATION);
} }
private void DiceButton_Clicked(object sender, EventArgs e) private void DiceButton_Clicked(object sender, EventArgs e)

Loading…
Cancel
Save