Correction de tous les tests et fusion de ce qu'a fait Lucas
continuous-integration/drone/push Build is passing Details

pull/112/head
Remi NEVEU 11 months ago
commit 38a9c8a8e7

@ -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();
} }

@ -23,6 +23,8 @@ namespace Models.Game
[DataContract] [DataContract]
public class Game : INotifyPropertyChanged public class Game : INotifyPropertyChanged
{ {
public bool IsPreviousGameNotFinished { get; private set; }
/* Persistence Interface */ /* Persistence Interface */
public IPersistence PersistenceManager { get; set; } public IPersistence PersistenceManager { get; set; }
@ -104,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; }
@ -134,23 +137,57 @@ namespace Models.Game
{ {
Maps.Add(map); Maps.Add(map);
} }
/// <summary>
/// Deletes the last game in the list of games. Use for avoiding stack not finished games.
/// </summary>
/// <returns></returns>
public bool DeleteGame()
{
if (Games.Count == 0)
{
return false;
}
Games.RemoveAt(Games.Count - 1); // Remove the last game
return true;
}
/// <summary>
/// Adds a new best score to the list of best scores. Or updates it if it already exists.
/// </summary>
/// <param name="finalScore">The final score of the game.</param>
public void AddBestScore(int finalScore) public void AddBestScore(int finalScore)
{ {
BestScore bs = new BestScore(UsedMap.Name, CurrentPlayer, 1, finalScore); BestScore bs = new BestScore(UsedMap.Name, CurrentPlayer, 1, finalScore);
foreach (var score in BestScores) var existingScore = BestScores.FirstOrDefault(score => score.Equals(bs));
{
if (!bs.Equals(score)) continue;
score.IncrGamesPlayed(); if (existingScore != null)
score.UpdateScore(finalScore); {
return; existingScore.IncrGamesPlayed();
existingScore.UpdateScore(finalScore);
}
else
{
BestScores.Add(bs);
} }
BestScores.Add(bs); // Sorting the best scores
BestScores.OrderByDescending(p => p.Score); List<BestScore> sortedScores = BestScores.OrderByDescending(score => score.Score).ToList();
for (int i = 0; i < sortedScores.Count; i++)
{
if (!BestScores[i].Equals(sortedScores[i]))
{
BestScores.Move(BestScores.IndexOf(sortedScores[i]), i);
}
}
} }
/// <summary>
/// Removes a player from the list of players.
/// </summary>
/// <param name="playerName"></param>
/// <returns>True if the player was removed successfully, false otherwise.</returns>
public bool RemovePlayer(string playerName) public bool RemovePlayer(string playerName)
{ {
Player player = Players.FirstOrDefault(p => p.Pseudo == playerName); Player player = Players.FirstOrDefault(p => p.Pseudo == playerName);
@ -163,6 +200,12 @@ namespace Models.Game
return true; return true;
} }
/// <summary>
/// Modifies the pseudo of a player.
/// </summary>
/// <param name="pseudo"></param>
/// <param name="newpseudo"></param>
/// <returns></returns>
public bool ModifyPlayer(string pseudo, string newpseudo) public bool ModifyPlayer(string pseudo, string newpseudo)
{ {
foreach (var index in Players) foreach (var index in Players)
@ -178,6 +221,10 @@ namespace Models.Game
return false; return false;
} }
/// <summary>
/// Removes a game from the list of games.
/// </summary>
/// <param name="playerName"></param>
public void CheckAndRemoveBestScoresDependencies(string playerName) public void CheckAndRemoveBestScoresDependencies(string playerName)
{ {
List<BestScore> bs = new List<BestScore>(); List<BestScore> bs = new List<BestScore>();
@ -193,7 +240,12 @@ namespace Models.Game
BestScores.Remove(score); BestScores.Remove(score);
} }
} }
/// <summary>
/// Modifies the pseudo of a player in the best scores.
/// </summary>
/// <param name="playerName"></param>
/// <param name="newPlayerName"></param>
public void CheckAndChangeBestScoresDependencies(string playerName, string newPlayerName) public void CheckAndChangeBestScoresDependencies(string playerName, string newPlayerName)
{ {
foreach (var bestScore in BestScores) foreach (var bestScore in BestScores)
@ -213,6 +265,10 @@ namespace Models.Game
} }
foreach (var game in data.Item2) foreach (var game in data.Item2)
{ {
if (game.IsRunning)
{
IsPreviousGameNotFinished = true;
}
Games.Add(game); Games.Add(game);
} }
foreach (var map in data.Item3) foreach (var map in data.Item3)
@ -317,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
@ -328,14 +384,16 @@ namespace Models.Game
{ {
if (item.X == playerChoice.X && item.Y == playerChoice.Y) if (item.X == playerChoice.X && item.Y == playerChoice.Y)
{ {
if (PlayerCell.Value > 12 || (PlayerCell.Value > 6 && item.IsDangerous == true)) if (result > 12 || (result > 6 && item.IsDangerous == true))
{ {
item.SetPenalty(); item.SetPenalty();
PlayerCell.SetPenalty(); PlayerCell.SetPenalty();
} }
item.Value = PlayerCell.Value; item.Value = result;
return; return;
} }
} }
} }
@ -398,7 +456,6 @@ namespace Models.Game
{ {
IsRunning = true; IsRunning = true;
GameStarted?.Invoke(this, new GameStartedEventArgs(CurrentPlayer)); GameStarted?.Invoke(this, new GameStartedEventArgs(CurrentPlayer));
//GameLoop();
} }
/// <summary> /// <summary>
@ -413,17 +470,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++;
} }
@ -436,6 +489,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);
} }
@ -447,6 +501,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>

@ -25,6 +25,8 @@ namespace Models.Rules
{ {
if (!IsCellEmpty(playerChoicePosition)) return false; if (!IsCellEmpty(playerChoicePosition)) return false;
if (playerChoicePosition.Valid == false) return false;
if (EveryAdjacentCells(playerChoicePosition, cells).Count == 1) return false; if (EveryAdjacentCells(playerChoicePosition, cells).Count == 1) return false;
return true; return true;

@ -260,7 +260,7 @@ public class GameTests
_game.PlayerCell = new Cell(2, 0); _game.PlayerCell = new Cell(2, 0);
_game.PlayerCell.Value = 3; _game.PlayerCell.Value = 3;
methodInfo.Invoke(_game, new object[] { _game.PlayerCell }); methodInfo.Invoke(_game, new object[] { _game.PlayerCell, 3 });
//_game.UsedMap.Boards[2].Value = _game.PlayerCell.Value; //_game.UsedMap.Boards[2].Value = _game.PlayerCell.Value;
Assert.Equal(3, _game.UsedMap.Boards[2].Value); Assert.Equal(3, _game.UsedMap.Boards[2].Value);
@ -274,8 +274,11 @@ public class GameTests
_game.InitializeGame(map, player, false); _game.InitializeGame(map, player, false);
var cell = new Cell(0, 1); var cell = new Cell(1, 0);
cell.Valid = true;
_game.UsedMap.Boards[0].Valid = true;
_game.UsedMap.Boards[0].Value = 1; _game.UsedMap.Boards[0].Value = 1;
_game.UsedMap.Boards[1].Valid = true;
bool result = _game.HandlePlayerChoice(cell, 1); bool result = _game.HandlePlayerChoice(cell, 1);
Assert.True(result); Assert.True(result);
} }
@ -342,7 +345,7 @@ public class GameTests
_game.PlayerCell = new Cell(2, 0); _game.PlayerCell = new Cell(2, 0);
_game.PlayerCell.Value = 14; _game.PlayerCell.Value = 14;
methodInfo.Invoke(_game, new object[] { _game.PlayerCell }); methodInfo.Invoke(_game, new object[] { _game.PlayerCell, 14 });
Assert.True(_game.UsedMap.Boards[2].Penalty); Assert.True(_game.UsedMap.Boards[2].Penalty);
} }
@ -365,7 +368,7 @@ public class GameTests
_game.PlayerCell = new Cell(2, 0); _game.PlayerCell = new Cell(2, 0);
_game.PlayerCell.Value = 7; _game.PlayerCell.Value = 7;
methodInfo.Invoke(_game, new object[] { _game.PlayerCell }); methodInfo.Invoke(_game, new object[] { _game.PlayerCell, 7 });
Assert.True(_game.UsedMap.Boards[2].Penalty); Assert.True(_game.UsedMap.Boards[2].Penalty);
} }
@ -424,39 +427,6 @@ public class GameTests
} }
[Fact]
public void CalculusOfPenalty_ReallyCalculusPenalty()
{
var player = new Player("test_player", "DefaultProfilePicture");
var map = new Map("test_name", "test_background.png");
_game.InitializeGame(map, player, false);
var methodInfo = typeof(Game).GetMethod("AddToRopePath", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(methodInfo);
_game.UsedMap.Boards[0].Valid = true;
_game.UsedMap.Boards[1].Valid = true;
_game.UsedMap.Boards[2].Valid = true;
_game.UsedMap.Boards[3].Valid = true;
_game.UsedMap.Boards[0].Value = 0;
//methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[0], _game.UsedMap.Boards.ToList() });
_game.UsedMap.Boards[1].Value = 1;
//methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[1], _game.UsedMap.Boards.ToList() });
_game.UsedMap.Boards[2].Value = 2;
//methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[2], _game.UsedMap.Boards.ToList() });
_game.UsedMap.Boards[3].Value = 5;
methodInfo.Invoke(_game, new object[] { _game.UsedMap.Boards[2], _game.UsedMap.Boards.ToList() });
_game.PutPenaltyForLostCells(_game.UsedMap.Boards);
Assert.True(_game.UsedMap.Boards[3].Penalty);
Assert.Equal(3, _game.CalculusOfPenalty(_game.UsedMap.Boards));
}
[Fact] [Fact]
public void CalculusOfPenalty_ReallyCalculusPenalty_ForZonesAndDangerousCellsAndOverTwelve() public void CalculusOfPenalty_ReallyCalculusPenalty_ForZonesAndDangerousCellsAndOverTwelve()
{ {
@ -483,12 +453,12 @@ public class GameTests
_game.PlayerCell.Value = 7; _game.PlayerCell.Value = 7;
_game.PlayerCell.Valid = true; _game.PlayerCell.Valid = true;
_game.PlayerCell.IsDangerous = true; _game.PlayerCell.IsDangerous = true;
place.Invoke(_game, new object[] { _game.PlayerCell }); //One penalty place.Invoke(_game, new object[] { _game.PlayerCell, 7 }); //One penalty
_game.PlayerCell = new Cell(5, 1); _game.PlayerCell = new Cell(5, 1);
_game.PlayerCell.Value = 14; _game.PlayerCell.Value = 14;
_game.PlayerCell.Valid = true; _game.PlayerCell.Valid = true;
place.Invoke(_game, new object[] { _game.PlayerCell }); place.Invoke(_game, new object[] { _game.PlayerCell, 14 });
foreach (var cells in _game.UsedMap.Boards.ToList()) foreach (var cells in _game.UsedMap.Boards.ToList())

@ -44,6 +44,7 @@ public class RulesTests
{ {
Rules rules = new Rules(); Rules rules = new Rules();
Map map = new Map("test", "background"); Map map = new Map("test", "background");
map.Boards[0].Valid = true;
Cell selectedCell = map.Boards[0]; Cell selectedCell = map.Boards[0];
Assert.True(rules.IsCellValid(selectedCell, map.Boards.ToList())); Assert.True(rules.IsCellValid(selectedCell, map.Boards.ToList()));
} }

@ -5,15 +5,15 @@ VisualStudioVersion = 17.8.34408.163
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trek-12", "Trek-12\Trek-12.csproj", "{41EE7BF8-DDE6-4B00-9434-076589C0B419}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Trek-12", "Trek-12\Trek-12.csproj", "{41EE7BF8-DDE6-4B00-9434-076589C0B419}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Models", "Models\Models.csproj", "{807AB723-7AD3-42DD-9DA6-7AA5B0A9AAB4}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{807AB723-7AD3-42DD-9DA6-7AA5B0A9AAB4}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{795F2C88-3C43-4795-9764-E52F7330888D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{795F2C88-3C43-4795-9764-E52F7330888D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{383C4215-C680-4C2E-BC7E-B62F0B164370}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{383C4215-C680-4C2E-BC7E-B62F0B164370}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataContractPersistence", "DataContractPersistence\DataContractPersistence.csproj", "{FC6A23C3-A1E3-4BF4-85B0-404D8574E190}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataContractPersistence", "DataContractPersistence\DataContractPersistence.csproj", "{FC6A23C3-A1E3-4BF4-85B0-404D8574E190}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stub", "Stub\Stub.csproj", "{49360F7D-C59D-4B4F-AF5A-73FF61D9EF9B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stub", "Stub\Stub.csproj", "{49360F7D-C59D-4B4F-AF5A-73FF61D9EF9B}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

@ -29,7 +29,7 @@ namespace Trek_12
Directory.CreateDirectory(FilePath); Directory.CreateDirectory(FilePath);
} }
File.Delete(Path.Combine(FilePath, FileName)); //File.Delete(Path.Combine(FilePath, FileName));
string fullPath = Path.Combine(FilePath, FileName); string fullPath = Path.Combine(FilePath, FileName);
if (File.Exists(fullPath)) if (File.Exists(fullPath))

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks> <TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> <!--<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>-->
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET --> <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> --> <!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
@ -38,6 +38,14 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('windows'))">
<TargetFrameworks>$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<WindowsPackageType>MSIX</WindowsPackageType>
<PackageCertificateThumbprint>404032fa5d4dc4c8bbf036505d2409963f355ebd</PackageCertificateThumbprint>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<!-- App Icon --> <!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\app_icon.png" /> <MauiIcon Include="Resources\AppIcon\app_icon.png" />

@ -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();
}
} }

@ -42,6 +42,16 @@
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<Button Text="Reprendre"
TextColor="White"
BackgroundColor="DarkRed"
FontAttributes="Bold"
FontSize="Large"
Grid.Row="2"
Margin="80"
HorizontalOptions="Center"
Clicked="ResumeButton_Clicked"
IsVisible="{Binding IsPreviousGameNotFinished}"/>
<Button Text="Retour" <Button Text="Retour"
FontAttributes="Bold" FontAttributes="Bold"
FontSize="Large" FontSize="Large"

@ -10,12 +10,16 @@ public partial class PageSelectMap : ContentPage
public Game SelectMapManager => (App.Current as App).Manager; public Game SelectMapManager => (App.Current as App).Manager;
private Map? _selectedMap; private Map? _selectedMap;
private bool previousGameRunning = false;
private bool isVisibleContinueButton = false;
protected override async void OnAppearing() protected override async void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
if (SelectMapManager.Games.Any(g => g.IsRunning)) if (SelectMapManager.Games.Any(g => g.IsRunning))
{ {
previousGameRunning = true;
await DisplayAlert("Warning", "You've previously quit in the middle of a game.\nIf you start a new game, this one will be permanently lost.", "I understand"); await DisplayAlert("Warning", "You've previously quit in the middle of a game.\nIf you start a new game, this one will be permanently lost.", "I understand");
} }
@ -59,8 +63,16 @@ public partial class PageSelectMap : ContentPage
SelectMapManager.InitializeGame(_selectedMap, chosenPlayer); SelectMapManager.InitializeGame(_selectedMap, chosenPlayer);
if (SelectMapManager.UsedMap == _selectedMap && Equals(SelectMapManager.CurrentPlayer, chosenPlayer)) if (SelectMapManager.UsedMap == _selectedMap && Equals(SelectMapManager.CurrentPlayer, chosenPlayer))
{ {
// Delete the previous game if it was running
if (previousGameRunning)
{
bool rep = SelectMapManager.DeleteGame();
SelectMapManager.SaveData();
if (rep) await DisplayAlert("Game deleted", "The previous game has been deleted because you started a new one.", "OK");
}
await Shell.Current.GoToAsync(nameof(PageBoard)); await Shell.Current.GoToAsync(nameof(PageBoard));
} }
else else
@ -79,4 +91,17 @@ public partial class PageSelectMap : ContentPage
return SelectMapManager.Players.FirstOrDefault(p => p.Pseudo == pseudo); return SelectMapManager.Players.FirstOrDefault(p => p.Pseudo == pseudo);
} }
private async void ResumeButton_Clicked(object sender, EventArgs e)
{
Game game = SelectMapManager.Games.FirstOrDefault(g => g.IsRunning);
if (game == null)
{
await DisplayAlert("No game found", "No game found to resume. Please start a new game.", "OK");
return;
}
SelectMapManager.InitializeGame(game.UsedMap, game.CurrentPlayer);
await Shell.Current.GoToAsync(nameof(PageBoard));
}
} }
Loading…
Cancel
Save