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.Events;
@ -45,6 +45,7 @@ class Program
// Initialisation
Game.InitializeGame(map, player);
Game.GameLoop();
}

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

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

@ -10,6 +10,10 @@ public partial class PageBoard : ContentPage
{
public Game GameManager => (App.Current as App).Manager;
public int Resultat { get; set; }
public Cell ChoosenCell { get; set; }
public PageBoard()
{
InitializeComponent();
@ -21,6 +25,7 @@ public partial class PageBoard : ContentPage
GameManager.DiceRolled += ResultHigher;
GameManager.DiceRolled += ResultSubstraction;
GameManager.DiceRolled += ResultMultiplication;
GameManager.PlayerOption += GameManager_PlayerOption;
// We add this game to the list of games
GameManager.AddGame(GameManager);
@ -28,6 +33,18 @@ public partial class PageBoard : ContentPage
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)
{
Multiplication.IsVisible = true;
@ -66,8 +83,11 @@ public partial class PageBoard : ContentPage
private void TheGame_DiceRolled(object? sender, Models.Events.DiceRolledEventArgs e)
{
YellowDice.IsVisible = true;
RedDice.IsVisible = true;
Dice1.Text = $"{e.Dice1Value}";
Dice2.Text = $"{e.Dice2Value}";
RollButton.IsEnabled = false;
}
private void OnOperationCellSelected(object sender, SelectionChangedEventArgs e)
@ -87,27 +107,43 @@ public partial class PageBoard : ContentPage
private void HigherClicked(object sender, EventArgs e)
{
Higher.IsVisible = false;
GameManager.PlayerOperation = Operation.HIGHER;
Resultat = GameManager.PlayerChooseOperation();
}
private void LowerClicked(object sender, EventArgs e)
{
GameManager.PlayerOperation = Operation.LOWER;
Resultat = GameManager.PlayerChooseOperation();
}
private void AdditionClicked(object sender, EventArgs e)
{
GameManager.PlayerOperation = Operation.ADDITION;
Resultat = GameManager.PlayerChooseOperation();
}
private void SubstractionClicked(object sender, EventArgs e)
{
GameManager.PlayerOperation = Operation.SUBTRACTION;
Resultat = GameManager.PlayerChooseOperation();
}
private void MultiplicationClicked(object sender, EventArgs e)
{
GameManager.PlayerOperation = Operation.MULTIPLICATION;
Resultat = GameManager.PlayerChooseOperation();
}
private void DiceButton_Clicked(object sender, EventArgs e)
{
GameManager.RollAllDice();
}
private void OnCellSelected(object sender, SelectionChangedEventArgs e)
{
ChoosenCell = (Cell)e.CurrentSelection[0];
GameManager.PlayerCell = ChoosenCell;
GameManager.PlayerSelectionCell();
}
}
Loading…
Cancel
Save