@ -1,5 +1,6 @@
using System.ComponentModel ;
using System.Diagnostics ;
using Microsoft.VisualBasic ;
namespace Trek_12.Views ;
@ -10,7 +11,7 @@ public partial class PageBoard : ContentPage
{
public Game GameManager = > ( App . Current as App ) . Manager ;
public int Result at { get ; set ; }
public int Result { get ; set ; }
public Cell ChoosenCell { get ; set ; }
@ -26,13 +27,46 @@ public partial class PageBoard : ContentPage
GameManager . DiceRolled + = ResultSubstraction ;
GameManager . DiceRolled + = ResultMultiplication ;
GameManager . PlayerOption + = GameManager_PlayerOption ;
// We add this game to the list of games
GameManager . CellChosen + = HandleCellChosen ;
GameManager . AddGame ( GameManager ) ;
GameManager . OnPropertyChanged ( nameof ( GameManager . Games ) ) ;
GameManager . SaveData ( ) ;
}
private void HandleCellChosen ( object sender , CellChosenEventArgs e )
{
YellowDice . IsVisible = false ;
RedDice . IsVisible = false ;
RollButton . IsEnabled = true ;
}
private void ResetOperationButtonsAndDice ( )
{
Lower . IsVisible = false ;
Higher . IsVisible = false ;
Substraction . IsVisible = false ;
Addition . IsVisible = false ;
Multiplication . IsVisible = false ;
RollButton . IsEnabled = true ;
YellowDice . IsVisible = false ;
RedDice . IsVisible = false ;
}
private void SetOperationButtonState ( Button selectedButton )
{
// Deselect all buttons
Lower . BackgroundColor = Colors . DarkSalmon ;
Higher . BackgroundColor = Colors . DarkSalmon ;
Substraction . BackgroundColor = Colors . DarkSalmon ;
Addition . BackgroundColor = Colors . DarkSalmon ;
Multiplication . BackgroundColor = Colors . DarkSalmon ;
// Select the clicked button
selectedButton . BackgroundColor = Colors . LightCoral ;
}
private void GameManager_PlayerOption ( object? sender , PlayerOptionEventArgs e )
{
/ * IEnumerable < Cell > PlayedCellsQuery =
@ -92,8 +126,7 @@ public partial class PageBoard : ContentPage
private void OnOperationCellSelected ( object sender , SelectionChangedEventArgs e )
{
Debug . WriteLine ( "OnOperationCellSelected" ) ; // Debug
if ( e . CurrentSelection . Count > 0 ) // Si un <20> l<EFBFBD> ment est s<> lectionn<6E>
if ( e . CurrentSelection . Count > 0 ) // Si un élément est sélectionné
{
var selectedCell = ( OperationCell ) e . CurrentSelection [ 0 ] ;
if ( selectedCell ! = null & & ! selectedCell . IsChecked )
@ -101,38 +134,48 @@ 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 <EFBFBD> selectionne l'<27> l<EFBFBD> ment pour la CollectionView
( ( CollectionView ) sender ) . SelectedItem = null ; // D éselectionne l'élé ment pour la CollectionView
}
}
private void HigherClicked ( object sender , EventArgs e )
{
GameManager . PlayerOperation = Operation . HIGHER ;
Resultat = GameManager . PlayerChooseOperation ( ) ;
SetOperationButtonState ( ( Button ) sender ) ;
Result = GameManager . ResultOperation ( Operation . HIGHER ) ;
GameManager . HandlePlayerOperation ( Operation . HIGHER ) ;
}
private void LowerClicked ( object sender , EventArgs e )
{
GameManager . PlayerOperation = Operation . LOWER ;
Resultat = GameManager . PlayerChooseOperation ( ) ;
SetOperationButtonState ( ( Button ) sender ) ;
Result = GameManager . ResultOperation ( Operation . LOWER ) ;
GameManager . HandlePlayerOperation ( Operation . LOWER ) ;
}
private void AdditionClicked ( object sender , EventArgs e )
{
GameManager . PlayerOperation = Operation . ADDITION ;
Resultat = GameManager . PlayerChooseOperation ( ) ;
SetOperationButtonState ( ( Button ) sender ) ;
Result = GameManager . ResultOperation ( Operation . ADDITION ) ;
GameManager . HandlePlayerOperation ( Operation . ADDITION ) ;
}
private void SubstractionClicked ( object sender , EventArgs e )
{
GameManager . PlayerOperation = Operation . SUBTRACTION ;
Resultat = GameManager . PlayerChooseOperation ( ) ;
SetOperationButtonState ( ( Button ) sender ) ;
Result = GameManager . ResultOperation ( Operation . SUBTRACTION ) ;
GameManager . HandlePlayerOperation ( Operation . SUBTRACTION ) ;
}
private void MultiplicationClicked ( object sender , EventArgs e )
{
GameManager . PlayerOperation = Operation . MULTIPLICATION ;
Resultat = GameManager . PlayerChooseOperation ( ) ;
SetOperationButtonState ( ( Button ) sender ) ;
Result = GameManager . ResultOperation ( Operation . MULTIPLICATION ) ;
GameManager . HandlePlayerOperation ( Operation . MULTIPLICATION ) ;
}
private void DiceButton_Clicked ( object sender , EventArgs e )
@ -140,10 +183,33 @@ public partial class PageBoard : ContentPage
GameManager . RollAllDice ( ) ;
}
private void OnCellSelected ( object sender , SelectionChangedEventArgs e )
private async void OnCellSelected ( object sender , SelectionChangedEventArgs e )
{
ChoosenCell = ( Cell ) e . CurrentSelection [ 0 ] ;
GameManager . PlayerCell = ChoosenCell ;
GameManager . PlayerSelectionCell ( ) ;
if ( ! GameManager . DiceRolledFlag )
{
await DisplayAlert ( "Action Required" , "You must roll the dice first." , "OK" ) ;
return ;
}
if ( ! GameManager . OperationChosenFlag )
{
await DisplayAlert ( "Action Required" , "You must choose an operation first." , "OK" ) ;
return ;
}
if ( e . CurrentSelection . Count > 0 )
{
ChoosenCell = ( Cell ) e . CurrentSelection [ 0 ] ;
GameManager . PlayerCell = ChoosenCell ;
GameManager . Resultat = Result ;
OnPropertyChanged ( nameof ( GameManager . PlayerCell ) ) ;
OnPropertyChanged ( nameof ( GameManager . Resultat ) ) ;
GameManager . PlayerSelectionCell ( ) ;
( ( CollectionView ) sender ) . SelectedItem = null ;
ResetOperationButtonsAndDice ( ) ;
}
}
}