Merge PageBoard into dev (#110)
continuous-integration/drone/push Build is failing Details

pull/112/head
Rémi LAVERGNE 11 months ago
commit 62ff6c130f

@ -1,4 +1,4 @@
// See https://aka.ms/new-console-template for more information // See https://aka.ms/new-console-template for more information
using Models; using Models;
using Models.Events; using Models.Events;
@ -45,6 +45,7 @@ class Program
// Initialisation // Initialisation
Game.InitializeGame(map, player); Game.InitializeGame(map, player);
Game.GameLoop();
} }

@ -106,6 +106,7 @@ namespace Models.Game
public Operation PlayerOperation { get; set; } public Operation PlayerOperation { get; set; }
public Cell PlayerCell { get; set; } public Cell PlayerCell { get; set; }
public int Resultat { get; set; }
public Rules.Rules GameRules { get; } public Rules.Rules GameRules { get; }
@ -372,7 +373,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) private void PlaceResult(Cell playerChoice, int result)
{ {
IEnumerable<Cell> ValidCell = IEnumerable<Cell> ValidCell =
from cell in UsedMap.Boards from cell in UsedMap.Boards
@ -383,9 +384,11 @@ namespace Models.Game
{ {
if (item.X == playerChoice.X && item.Y == playerChoice.Y) if (item.X == playerChoice.X && item.Y == playerChoice.Y)
{ {
item.Value = PlayerCell.Value; item.Value = result;
return; return;
} }
} }
} }
@ -405,22 +408,22 @@ namespace Models.Game
where cell.Value != null && cell.Valid == true && cell != playerChoice where cell.Value != null && cell.Valid == true && cell != playerChoice
select cell; select cell;
foreach (var item in ValidCell) foreach (var item in ValidCell)
{ {
if (!GameRules.IsCellAdjacent(playerChoice, item)) if (!GameRules.IsCellAdjacent(playerChoice, item))
continue; continue;
if (!((playerChoice.Value - item.Value) == 1 || (playerChoice.Value - item.Value) == -1)) if (!((playerChoice.Value - item.Value) == 1 || (playerChoice.Value - item.Value) == -1))
continue; continue;
if (!GameRules.IsInRopePaths(item,UsedMap.RopePaths,index)) if (!GameRules.IsInRopePaths(item,UsedMap.RopePaths,index))
{ {
UsedMap.RopePaths.Add(new List<Cell> { playerChoice, item }); UsedMap.RopePaths.Add(new List<Cell> { playerChoice, item });
return; 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; return;
} }
} }
} }
@ -462,17 +465,13 @@ namespace Models.Game
/// <summary> /// <summary>
/// The main game loop that runs while the game is active. /// The main game loop that runs while the game is active.
/// </summary> /// </summary>
private void GameLoop() public void GameLoop()
{ {
while (IsRunning) while (IsRunning)
{ {
RollAllDice(); RollAllDice();
int res = PlayerChooseOperation(); Resultat = PlayerChooseOperation();
PlayerOption?.Invoke(this,new PlayerOptionEventArgs(UsedMap.Boards.ToList(),res,Turn));
PlayerSelectionCell(); PlayerSelectionCell();
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++;
} }
@ -485,6 +484,7 @@ namespace Models.Game
{ {
PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(PlayerOperation)); PlayerChooseOp?.Invoke(this, new PlayerChooseOperationEventArgs(PlayerOperation));
} }
PlayerOption?.Invoke(this, new PlayerOptionEventArgs(UsedMap.Boards.ToList(), ResultOperation(PlayerOperation), Turn));
return ResultOperation(PlayerOperation); return ResultOperation(PlayerOperation);
} }
@ -496,6 +496,7 @@ namespace Models.Game
PlayerChooseCell?.Invoke(this, new PlayerChooseCellEventArgs(PlayerCell)); PlayerChooseCell?.Invoke(this, new PlayerChooseCellEventArgs(PlayerCell));
} }
MarkOperationAsChecked(PlayerOperation); MarkOperationAsChecked(PlayerOperation);
PlaceResult(PlayerCell, Resultat);
} }
/// <summary> /// <summary>

@ -6,52 +6,70 @@
BackgroundColor="Bisque"> BackgroundColor="Bisque">
<Grid RowDefinitions="*,auto" ColumnDefinitions="auto,*,auto"> <Grid RowDefinitions="*,auto" ColumnDefinitions="auto,*,auto">
<HorizontalStackLayout> <Grid RowDefinitions="auto,auto"
<Frame BorderColor="DarkGray" Grid.Column="0"
HorizontalOptions="Center"
VerticalOptions="Center"
Margin="50,0,0,0">
<HorizontalStackLayout HorizontalOptions="Center"
Margin="0,20,0,0">
<Frame BorderColor="DarkGray"
HeightRequest="50" HeightRequest="50"
WidthRequest="50" WidthRequest="50"
Grid.Column="0" Grid.Column="0"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" VerticalOptions="Center"
Padding="0"> Padding="0"
<Label Text="{Binding Dice1.Value}" BackgroundColor="Yellow"
FontSize="16" IsVisible="Hidden"
x:Name="YellowDice">
<Label Text="{Binding Dice1.Value}"
FontSize="Large"
VerticalOptions="Center" VerticalOptions="Center"
HorizontalOptions="Center" HorizontalOptions="Center"
TextColor="Black" TextColor="Black"
x:Name="Dice1"/> x:Name="Dice1"
</Frame> FontAttributes="Bold"/>
<Frame BorderColor="DarkGray" </Frame>
<Frame BorderColor="DarkGray"
HeightRequest="50" HeightRequest="50"
WidthRequest="50" WidthRequest="50"
Grid.Column="0" Grid.Column="0"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" VerticalOptions="Center"
Padding="0"> Padding="0"
BackgroundColor="Red"
IsVisible="Hidden"
x:Name="RedDice">
<Label Text="{Binding Dice2.Value}" <Label Text="{Binding Dice2.Value}"
FontSize="16" FontSize="Large"
VerticalOptions="Center" VerticalOptions="Center"
HorizontalOptions="Center" HorizontalOptions="Center"
TextColor="Black" TextColor="Black"
x:Name="Dice2"/> x:Name="Dice2"
FontAttributes="Bold"/>
</Frame> </Frame>
</HorizontalStackLayout>
<Button Text="Roll" <Button Text="Roll"
HeightRequest="200" HeightRequest="25"
WidthRequest="200" WidthRequest="100"
Clicked="DiceButton_Clicked"/> Clicked="DiceButton_Clicked"
</HorizontalStackLayout> Grid.Row="1"
<Image Source="maptest.png" Aspect="AspectFit" Grid.ColumnSpan="2" Grid.RowSpan="3"/> Margin="0,50,0,0"
x:Name="RollButton"/>
</Grid>
<CollectionView ItemsSource="{Binding UsedMap.Boards}" <CollectionView ItemsSource="{Binding UsedMap.Boards}"
Grid.Row="1"
Grid.Column="1" Grid.Column="1"
SelectionMode="Single" SelectionMode="Single"
WidthRequest="350" WidthRequest="350"
HeightRequest="350" HeightRequest="350"
ItemsLayout="VerticalGrid,7" ItemsLayout="VerticalGrid,7"
BackgroundColor="Aqua"> x:Name="Board"
SelectionChanged="OnCellSelected">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate x:Name="Cellule">
<Grid VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="50" WidthRequest="50"> <Grid VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="50" WidthRequest="50">
<Frame <Frame
@ -64,7 +82,15 @@
Opacity="0.7" Opacity="0.7"
VerticalOptions="Center" VerticalOptions="Center"
HorizontalOptions="Center" HorizontalOptions="Center"
Padding="0"> Padding="0"
x:Name="CellValid">
<Label Text="{Binding Value}"
x:Name="CellValue"
FontSize="Large"
VerticalOptions="Center"
HorizontalOptions="Center"
TextColor="Black"
FontAttributes="Bold"/>
<Frame.Triggers> <Frame.Triggers>
<DataTrigger TargetType="Frame" Binding="{Binding IsDangerous}" Value="True"> <DataTrigger TargetType="Frame" Binding="{Binding IsDangerous}" Value="True">
<Setter Property="BorderColor" Value="Black"/> <Setter Property="BorderColor" Value="Black"/>
@ -82,7 +108,7 @@
<!-- Operation Grid --> <!-- Operation Grid -->
<Grid Grid.Row="0" Grid.Column="2" <Grid Grid.Row="0" Grid.Column="2"
ColumnDefinitions="auto,*" ColumnDefinitions="auto,*"
RowDefinitions="*,auto"> RowDefinitions="auto,auto">
<!--Images des operations --> <!--Images des operations -->
<!--Grille de la partie--> <!--Grille de la partie-->
<CollectionView Grid.Column="1" <CollectionView Grid.Column="1"
@ -114,7 +140,8 @@
</CollectionView> </CollectionView>
<!--Les bouttons de selection d'operation--> <!--Les bouttons de selection d'operation-->
<HorizontalStackLayout Grid.Row="1" <HorizontalStackLayout Grid.Row="1"
Grid.ColumnSpan="2"> Grid.ColumnSpan="2"
VerticalOptions="Center">
<Button HeightRequest="50" <Button HeightRequest="50"
WidthRequest="100" WidthRequest="100"
x:Name="Lower" x:Name="Lower"

@ -10,6 +10,10 @@ public partial class PageBoard : ContentPage
{ {
public Game GameManager => (App.Current as App).Manager; public Game GameManager => (App.Current as App).Manager;
public int Resultat { get; set; }
public Cell ChoosenCell { get; set; }
public PageBoard() public PageBoard()
{ {
InitializeComponent(); InitializeComponent();
@ -21,6 +25,7 @@ public partial class PageBoard : ContentPage
GameManager.DiceRolled += ResultHigher; GameManager.DiceRolled += ResultHigher;
GameManager.DiceRolled += ResultSubstraction; GameManager.DiceRolled += ResultSubstraction;
GameManager.DiceRolled += ResultMultiplication; GameManager.DiceRolled += ResultMultiplication;
GameManager.PlayerOption += GameManager_PlayerOption;
// We add this game to the list of games // We add this game to the list of games
GameManager.AddGame(GameManager); GameManager.AddGame(GameManager);
@ -28,6 +33,18 @@ public partial class PageBoard : ContentPage
GameManager.SaveData(); GameManager.SaveData();
} }
private void GameManager_PlayerOption(object? sender, PlayerOptionEventArgs e)
{
/* IEnumerable<Cell> PlayedCellsQuery =
from cell in e.Board
where cell.Valid == true
where cell.Value != null
select cell;*/
// prévisualisation des zone disponible, Je ne sais pas comment ca marche... 😵
}
private void ResultMultiplication(object? sender, DiceRolledEventArgs e) private void ResultMultiplication(object? sender, DiceRolledEventArgs e)
{ {
Multiplication.IsVisible = true; Multiplication.IsVisible = true;
@ -66,8 +83,11 @@ public partial class PageBoard : ContentPage
private void TheGame_DiceRolled(object? sender, Models.Events.DiceRolledEventArgs e) private void TheGame_DiceRolled(object? sender, Models.Events.DiceRolledEventArgs e)
{ {
YellowDice.IsVisible = true;
RedDice.IsVisible = true;
Dice1.Text = $"{e.Dice1Value}"; Dice1.Text = $"{e.Dice1Value}";
Dice2.Text = $"{e.Dice2Value}"; Dice2.Text = $"{e.Dice2Value}";
RollButton.IsEnabled = false;
} }
private void OnOperationCellSelected(object sender, SelectionChangedEventArgs e) private void OnOperationCellSelected(object sender, SelectionChangedEventArgs e)
@ -87,27 +107,43 @@ public partial class PageBoard : ContentPage
private void HigherClicked(object sender, EventArgs e) private void HigherClicked(object sender, EventArgs e)
{ {
Higher.IsVisible = false; GameManager.PlayerOperation = Operation.HIGHER;
Resultat = GameManager.PlayerChooseOperation();
} }
private void LowerClicked(object sender, EventArgs e) private void LowerClicked(object sender, EventArgs e)
{ {
GameManager.PlayerOperation = Operation.LOWER;
Resultat = GameManager.PlayerChooseOperation();
} }
private void AdditionClicked(object sender, EventArgs e) private void AdditionClicked(object sender, EventArgs e)
{ {
GameManager.PlayerOperation = Operation.ADDITION;
Resultat = GameManager.PlayerChooseOperation();
} }
private void SubstractionClicked(object sender, EventArgs e) private void SubstractionClicked(object sender, EventArgs e)
{ {
GameManager.PlayerOperation = Operation.SUBTRACTION;
Resultat = GameManager.PlayerChooseOperation();
} }
private void MultiplicationClicked(object sender, EventArgs e) private void MultiplicationClicked(object sender, EventArgs e)
{ {
GameManager.PlayerOperation = Operation.MULTIPLICATION;
Resultat = GameManager.PlayerChooseOperation();
} }
private void DiceButton_Clicked(object sender, EventArgs e) private void DiceButton_Clicked(object sender, EventArgs e)
{ {
GameManager.RollAllDice(); GameManager.RollAllDice();
} }
private void OnCellSelected(object sender, SelectionChangedEventArgs e)
{
ChoosenCell = (Cell)e.CurrentSelection[0];
GameManager.PlayerCell = ChoosenCell;
GameManager.PlayerSelectionCell();
}
} }
Loading…
Cancel
Save