Merge OperationGridBinding into dev #105
continuous-integration/drone/push Build is failing Details

pull/108/head
Rémi LAVERGNE 11 months ago
commit 0e06232715

@ -86,8 +86,17 @@ namespace Models.Game
[DataMember]
public Player? CurrentPlayer { get; private set; }
private Map? _usedMap;
[DataMember]
public Map? UsedMap { get; private set; }
public Map? UsedMap
{
get => _usedMap;
set
{
_usedMap = value;
OnPropertyChanged(nameof(UsedMap));
}
}
public Dice Dice1 { get; private set;}
@ -215,16 +224,19 @@ namespace Models.Game
/// Marks an operation as checked in the operation grid of the game.
/// </summary>
/// <param name="operation"></param>
private void MarkOperationAsChecked(Operation operation)
public void MarkOperationAsChecked(Operation operation)
{
int operationIndex = (int)operation;
int operationsPerType = 4; // Chaque type d'opération peut être fait 4 fois
IEnumerable<OperationCell> sortPaths =
from cell in UsedMap.OperationGrid
where cell.Y == operationIndex
select cell;
for (int i = operationIndex * operationsPerType; i < (operationIndex + 1) * operationsPerType; i++)
foreach (var item in sortPaths)
{
if (!UsedMap.OperationGrid[i].IsChecked)
if (!item.IsChecked)
{
UsedMap.OperationGrid[i].Check();
item.Check();
break;
}
}

@ -11,10 +11,12 @@ namespace Models.Game
/// </summary>
public enum Operation
{
ADDITION,
SUBTRACTION,
MULTIPLICATION,
LOWER,
HIGHER
HIGHER,
SUBTRACTION,
ADDITION,
MULTIPLICATION
}
}

@ -7,13 +7,24 @@ namespace Models.Game
/// Represents a cell in the operation grid of the game.
/// </summary>
[DataContract]
public class OperationCell : Position
public class OperationCell : Position, INotifyPropertyChanged
{
/// <summary>
/// It tells if the operation is checked or not in the operation grid of the game.
/// </summary>
[DataMember]
public bool IsChecked { get; private set; }
private bool isChecked;
public bool IsChecked
{
get => isChecked;
set
{
if (isChecked == value)
return;
isChecked = value;
OnPropertyChanged("IsChecked");
}
}
/// <summary>
/// Constructor of the OperationCell class.
@ -25,6 +36,16 @@ namespace Models.Game
IsChecked = false;
}
public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
/// <summary>
/// Check the operation cell.
/// </summary>

@ -9,7 +9,6 @@
<ItemGroup>
<Folder Include="Rules\" />
<Folder Include="Game\" />
<Folder Include="Events\" />
<Folder Include="Interfaces\" />
</ItemGroup>

@ -80,7 +80,12 @@
</CollectionView>
<!-- Operation Grid -->
<CollectionView Grid.Row="0" Grid.Column="2"
<Grid Grid.Row="0" Grid.Column="2"
ColumnDefinitions="auto,*"
RowDefinitions="*,auto">
<!--Images des operations -->
<!--Grille de la partie-->
<CollectionView Grid.Column="1"
ItemsSource="{Binding UsedMap.OperationGrid}"
ItemsLayout="VerticalGrid,4"
WidthRequest="200"
@ -107,5 +112,35 @@
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<!--Les bouttons de selection d'operation-->
<HorizontalStackLayout Grid.Row="1"
Grid.ColumnSpan="2">
<Button HeightRequest="50"
WidthRequest="100"
x:Name="Lower"
Clicked="LowerClicked"
IsVisible="False"/>
<Button HeightRequest="50"
WidthRequest="100"
x:Name="Higher"
Clicked="HigherClicked"
IsVisible="False"/>
<Button HeightRequest="50"
WidthRequest="100"
x:Name="Substraction"
Clicked="SubstractionClicked"
IsVisible="False"/>
<Button HeightRequest="50"
WidthRequest="100"
x:Name="Addition"
Clicked="AdditionClicked"
IsVisible="False"/>
<Button HeightRequest="50"
WidthRequest="100"
x:Name="Multiplication"
Clicked="MultiplicationClicked"
IsVisible="False"/>
</HorizontalStackLayout>
</Grid>
</Grid>
</ContentPage>

@ -3,6 +3,7 @@ using System.Diagnostics;
namespace Trek_12.Views;
using Models.Events;
using Models.Game;
public partial class PageBoard : ContentPage
@ -12,15 +13,57 @@ public partial class PageBoard : ContentPage
public PageBoard()
{
InitializeComponent();
GameManager.DiceRolled += TheGame_DiceRolled;
BindingContext = GameManager;
GameManager.DiceRolled += TheGame_DiceRolled;
GameManager.DiceRolled += ResultAddition;
GameManager.DiceRolled += ResultLower;
GameManager.DiceRolled += ResultHigher;
GameManager.DiceRolled += ResultSubstraction;
GameManager.DiceRolled += ResultMultiplication;
// We add this game to the list of games
GameManager.AddGame(GameManager);
GameManager.OnPropertyChanged(nameof(GameManager.Games));
GameManager.SaveData();
}
private void ResultMultiplication(object? sender, DiceRolledEventArgs e)
{
Multiplication.IsVisible = true;
Multiplication.Text = $"Mult {e.Dice1Value*e.Dice2Value}";
}
private void ResultSubstraction(object? sender, DiceRolledEventArgs e)
{
Substraction.IsVisible = true;
if (GameManager.Dice1.IsLower(GameManager.Dice2))
Substraction.Text = $"Sub {e.Dice2Value - e.Dice1Value}";
else Substraction.Text = $"Sub {e.Dice1Value - e.Dice2Value}";
}
private void ResultHigher(object? sender, DiceRolledEventArgs e)
{
Higher.IsVisible = true;
if (GameManager.Dice1.IsLower(GameManager.Dice2))
Higher.Text = $"Higher {e.Dice2Value}";
else Higher.Text = $"Higher {e.Dice1Value}";
}
private void ResultLower(object? sender, DiceRolledEventArgs e)
{
Lower.IsVisible = true;
if(GameManager.Dice1.IsLower(GameManager.Dice2))
Lower.Text = $"Lower {e.Dice1Value}";
else Lower.Text = $"Lower {e.Dice2Value}";
}
private void ResultAddition(object? sender, DiceRolledEventArgs e)
{
Addition.IsVisible = true;
Addition.Text = $"Add {e.Dice1Value+e.Dice2Value}";
}
private void TheGame_DiceRolled(object? sender, Models.Events.DiceRolledEventArgs e)
{
Dice1.Text = $"{e.Dice1Value}";
@ -30,7 +73,7 @@ public partial class PageBoard : ContentPage
private void OnOperationCellSelected(object sender, SelectionChangedEventArgs e)
{
Debug.WriteLine("OnOperationCellSelected"); // Debug
if (e.CurrentSelection.Count > 0) // Si un élément est sélectionné
if (e.CurrentSelection.Count > 0) // Si un <EFBFBD>l<EFBFBD>ment est s<>lectionn<6E>
{
var selectedCell = (OperationCell)e.CurrentSelection[0];
if (selectedCell != null && !selectedCell.IsChecked)
@ -38,11 +81,37 @@ public partial class PageBoard : ContentPage
selectedCell.Check();
Debug.WriteLine("OperationCell at ({0}, {1}) is checked", selectedCell.X, selectedCell.Y); // Debug
}
((CollectionView)sender).SelectedItem = null; // Déselectionne l'élément pour la CollectionView
((CollectionView)sender).SelectedItem = null; // D<EFBFBD>selectionne l'<27>l<EFBFBD>ment pour la CollectionView
}
}
private void DiceButton_Clicked(object sender, EventArgs e)
private void HigherClicked(object sender, EventArgs e)
{
GameManager.MarkOperationAsChecked(Operation.HIGHER);
Higher.IsVisible = false;
}
private void LowerClicked(object sender, EventArgs e)
{
GameManager.MarkOperationAsChecked(Operation.LOWER);
}
private void AdditionClicked(object sender, EventArgs e)
{
GameManager.MarkOperationAsChecked(Operation.ADDITION);
}
private void SubstractionClicked(object sender, EventArgs e)
{
GameManager.MarkOperationAsChecked(Operation.SUBTRACTION);
}
private void MultiplicationClicked(object sender, EventArgs e)
{
GameManager.MarkOperationAsChecked(Operation.MULTIPLICATION);
}
private void Button_Clicked(object sender, EventArgs e)
{
GameManager.RollAllDice();
}

Loading…
Cancel
Save