🚧 Avancement du databinding et du plateau de jeu
continuous-integration/drone/push Build is failing Details

pull/96/head
Lucas DUFLOT 1 year ago
parent e8336afd10
commit 3fe358fce7

@ -26,6 +26,9 @@
/// </summary> /// </summary>
private bool IsDangerous { get; set; } private bool IsDangerous { get; set; }
public bool Valid { get; set; }
/// <summary> /// <summary>
/// Atribute to know if the cell is a penalty cell. /// Atribute to know if the cell is a penalty cell.
/// </summary> /// </summary>
@ -41,6 +44,7 @@
{ {
IsDangerous = isDangerous; IsDangerous = isDangerous;
Penalty = false; Penalty = false;
Valid = false;
} }
/// <summary> /// <summary>

@ -119,7 +119,7 @@ namespace Models.Game
/// <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, int result)
{ {
if (Turn == 1 || GameRules.NearCellIsValid(playerChoice, UsedMap.Boards)) if (Turn == 1 || GameRules.NearCellIsValid(playerChoice, UsedMap.Boards.ToList()))
{ {
playerChoice.Value = result; playerChoice.Value = result;
BoardUpdated?.Invoke(this, EventArgs.Empty); BoardUpdated?.Invoke(this, EventArgs.Empty);
@ -226,14 +226,14 @@ namespace Models.Game
throw new InvalidCellCoordinatesException("Invalid cell coordinates. Please choose again."); throw new InvalidCellCoordinatesException("Invalid cell coordinates. Please choose again.");
} }
if (!GameRules.IsCellValid(cell, UsedMap.Boards)) if (!GameRules.IsCellValid(cell, UsedMap.Boards.ToList()))
{ {
throw new InvalidCellException("Cell is not valid. Please choose again."); throw new InvalidCellException("Cell is not valid. Please choose again.");
} }
PlaceResult(cell, result); PlaceResult(cell, result);
GameRules.IsZoneValidAndAddToZones(cell, UsedMap); GameRules.IsZoneValidAndAddToZones(cell, UsedMap);
AddToRopePath(cell, GameRules.EveryAdjacentCells(cell, UsedMap.Boards)); AddToRopePath(cell, GameRules.EveryAdjacentCells(cell, UsedMap.Boards.ToList()));
CellChosen?.Invoke(this, new CellChosenEventArgs(cell, result)); CellChosen?.Invoke(this, new CellChosenEventArgs(cell, result));
BoardUpdated?.Invoke(this, EventArgs.Empty); BoardUpdated?.Invoke(this, EventArgs.Empty);
} }

@ -11,7 +11,8 @@ namespace Models.Game
/// <summary> /// <summary>
/// It is the list of cells on the map. /// It is the list of cells on the map.
/// </summary> /// </summary>
public List<Cell> Boards { get; private set; } public ReadOnlyObservableCollection<Cell> Boards { get; private set; }
ObservableCollection<Cell> board = new ObservableCollection<Cell>();
/// <summary> /// <summary>
/// It is the backgrond image of the map /// It is the backgrond image of the map
@ -40,7 +41,8 @@ namespace Models.Game
/// <param name="background">The background of the map.</param> /// <param name="background">The background of the map.</param>
public Map(string background) public Map(string background)
{ {
Boards = InitializeBoards(); Boards = new ReadOnlyObservableCollection<Cell>(board);
InitializeBoards(board);
Background = background; Background = background;
OperationGrid = new ReadOnlyObservableCollection<OperationCell>(operationGrid); OperationGrid = new ReadOnlyObservableCollection<OperationCell>(operationGrid);
InitializeOperationGrid(operationGrid); InitializeOperationGrid(operationGrid);
@ -52,14 +54,31 @@ namespace Models.Game
/// Initializes the boards of the map. /// Initializes the boards of the map.
/// </summary> /// </summary>
/// <returns>Return the boards</returns> /// <returns>Return the boards</returns>
private List<Cell> InitializeBoards() private void InitializeBoards(ObservableCollection<Cell> board)
{ {
var boards = new List<Cell>(); for (int i = 0; i < 49; i++) // 6x6 board
for (int i = 0; i < 36; i++) // 6x6 board
{ {
boards.Add(new Cell(i / 6, i % 6)); board.Add(new Cell(i / 7, i % 7));
} }
return boards; board[1].Valid = true;
board[3].Valid = true;
board[4].Valid = true;
board[5].Valid = true;
board[9].Valid = true;
board[12].Valid = true;
board[15].Valid = true;
board[16].Valid = true;
board[17].Valid = true;
board[21].Valid = true;
board[24].Valid = true;
board[25].Valid = true;
board[28].Valid = true;
board[30].Valid = true;
board[31].Valid = true;
board[32].Valid = true;
board[40].Valid = true;
board[41].Valid = true;
board[48].Valid = true;
} }
/// <summary> /// <summary>

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -95,7 +96,7 @@ namespace Models.Rules
List<Cell> adjacentCells = new List<Cell>(); List<Cell> adjacentCells = new List<Cell>();
adjacentCells = EveryAdjacentCells(chosenCell, map.Boards); adjacentCells = EveryAdjacentCells(chosenCell, map.Boards.ToList());
foreach(var cells in adjacentCells) foreach(var cells in adjacentCells)
{ {

@ -5,10 +5,33 @@
Title="Board"> Title="Board">
<Grid RowDefinitions="*,auto"> <Grid RowDefinitions="*,auto">
<Grid ColumnDefinitions="*,auto"> <Grid ColumnDefinitions="*,auto">
<CollectionView ItemsSource="{Binding ListMap[0].Boards}"
Grid.Column="0"
SelectionMode="Single"
WidthRequest="350"
HeightRequest="350"
ItemsLayout="VerticalGrid,7"
BackgroundColor="Aqua">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame
IsVisible="{Binding Valid}"
BorderColor="DarkGray"
CornerRadius="25"
HeightRequest="50"
WidthRequest="50"
BackgroundColor="Transparent"
VerticalOptions="Center"
HorizontalOptions="Center"
>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<CollectionView ItemsSource="{Binding ListMap[0].OperationGrid}" <CollectionView ItemsSource="{Binding ListMap[0].OperationGrid}"
ItemsLayout="HorizontalGrid,5" ItemsLayout="VerticalGrid,5"
Grid.Column="1" Grid.Column="1"
HeightRequest="250" WidthRequest="250"
SelectionMode="Single" SelectionMode="Single"
Margin="20"> Margin="20">
<CollectionView.ItemTemplate > <CollectionView.ItemTemplate >

Loading…
Cancel
Save