Merge pull request 'v0.9 - Application MAUI' (#112) from dev into master
Reviewed-on: #112 Reviewed-by: Remi NEVEU <remi.neveu@etu.uca.fr>master v0.9
After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 228 B |
Before Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 846 KiB |
After Width: | Height: | Size: 978 KiB |
After Width: | Height: | Size: 39 MiB |
After Width: | Height: | Size: 972 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 1.9 MiB |
Before Width: | Height: | Size: 2.0 MiB |
After Width: | Height: | Size: 18 KiB |
@ -0,0 +1,173 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Trek_12.Views.PageBoard"
|
||||
Title="Board"
|
||||
BackgroundColor="Bisque">
|
||||
|
||||
<Grid RowDefinitions="*,auto" ColumnDefinitions="auto,*,auto">
|
||||
<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"
|
||||
BackgroundColor="Yellow"
|
||||
IsVisible="Hidden"
|
||||
x:Name="YellowDice">
|
||||
<Label Text="{Binding Dice1.Value}"
|
||||
FontSize="Large"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center"
|
||||
TextColor="Black"
|
||||
x:Name="Dice1"
|
||||
FontAttributes="Bold"/>
|
||||
</Frame>
|
||||
<Frame BorderColor="DarkGray"
|
||||
HeightRequest="50"
|
||||
WidthRequest="50"
|
||||
Grid.Column="0"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center"
|
||||
Padding="0"
|
||||
BackgroundColor="Red"
|
||||
IsVisible="Hidden"
|
||||
x:Name="RedDice">
|
||||
<Label Text="{Binding Dice2.Value}"
|
||||
FontSize="Large"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center"
|
||||
TextColor="Black"
|
||||
x:Name="Dice2"
|
||||
FontAttributes="Bold"/>
|
||||
</Frame>
|
||||
|
||||
</HorizontalStackLayout>
|
||||
<Button Text="Roll"
|
||||
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.Column="1"
|
||||
SelectionMode="Single"
|
||||
WidthRequest="350"
|
||||
HeightRequest="350"
|
||||
ItemsLayout="VerticalGrid,7"
|
||||
x:Name="Board"
|
||||
SelectionChanged="OnCellSelected">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate x:Name="Cellule">
|
||||
<Grid VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="50" WidthRequest="50">
|
||||
|
||||
<Frame
|
||||
IsVisible="{Binding Valid}"
|
||||
BorderColor="DarkGray"
|
||||
CornerRadius="25"
|
||||
HeightRequest="50"
|
||||
WidthRequest="50"
|
||||
BackgroundColor="White"
|
||||
Opacity="0.7"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center"
|
||||
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"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger TargetType="Frame" Binding="{Binding IsDangerous}" Value="False">
|
||||
<Setter Property="BorderColor" Value="Transparent"/>
|
||||
</DataTrigger>
|
||||
</Frame.Triggers>
|
||||
</Frame>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
|
||||
<!-- Operation Grid -->
|
||||
<Grid Grid.Row="0" Grid.Column="2"
|
||||
ColumnDefinitions="auto,*"
|
||||
RowDefinitions="auto,auto">
|
||||
<!--Images des operations -->
|
||||
<!--Grille de la partie-->
|
||||
<CollectionView Grid.Column="1"
|
||||
ItemsSource="{Binding UsedMap.OperationGrid}"
|
||||
WidthRequest="200"
|
||||
HeightRequest="250"
|
||||
BackgroundColor="Transparent"
|
||||
SelectionChanged="OnOperationCellSelected"
|
||||
Margin="50"
|
||||
ItemsLayout="VerticalGrid,4">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Frame HasShadow="True"
|
||||
BorderColor="Black"
|
||||
BackgroundColor="Transparent"
|
||||
CornerRadius="0"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center"
|
||||
HeightRequest="50"
|
||||
WidthRequest="50"
|
||||
Padding="0">
|
||||
<Image Source="checked.png"
|
||||
IsVisible="{Binding IsChecked}"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center"/>
|
||||
</Frame>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
<!--Les bouttons de selection d'operation-->
|
||||
<HorizontalStackLayout Grid.Row="1"
|
||||
Grid.ColumnSpan="2"
|
||||
VerticalOptions="Center">
|
||||
<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>
|
@ -0,0 +1,216 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
namespace Trek_12.Views;
|
||||
|
||||
using Models.Events;
|
||||
using Models.Game;
|
||||
|
||||
public partial class PageBoard : ContentPage
|
||||
{
|
||||
public Game GameManager => (App.Current as App).Manager;
|
||||
|
||||
public int Result { get; set; }
|
||||
|
||||
public Cell ChoosenCell { get; set; }
|
||||
|
||||
public PageBoard()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = GameManager;
|
||||
GameManager.CurrentPlayer.UpdateLastPlayed();
|
||||
|
||||
GameManager.DiceRolled += TheGame_DiceRolled;
|
||||
GameManager.DiceRolled += ResultAddition;
|
||||
GameManager.DiceRolled += ResultLower;
|
||||
GameManager.DiceRolled += ResultHigher;
|
||||
GameManager.DiceRolled += ResultSubstraction;
|
||||
GameManager.DiceRolled += ResultMultiplication;
|
||||
GameManager.PlayerOption += GameManager_PlayerOption;
|
||||
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 =
|
||||
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;
|
||||
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)
|
||||
{
|
||||
YellowDice.IsVisible = true;
|
||||
RedDice.IsVisible = true;
|
||||
Dice1.Text = $"{e.Dice1Value}";
|
||||
Dice2.Text = $"{e.Dice2Value}";
|
||||
RollButton.IsEnabled = false;
|
||||
}
|
||||
|
||||
private void OnOperationCellSelected(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.CurrentSelection.Count > 0) // Si un élément est sélectionné
|
||||
{
|
||||
var selectedCell = (OperationCell)e.CurrentSelection[0];
|
||||
if (selectedCell != null && !selectedCell.IsChecked)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
private void HigherClicked(object sender, EventArgs e)
|
||||
{
|
||||
GameManager.PlayerOperation = Operation.HIGHER;
|
||||
SetOperationButtonState((Button)sender);
|
||||
Result = GameManager.ResultOperation(Operation.HIGHER);
|
||||
GameManager.HandlePlayerOperation(Operation.HIGHER);
|
||||
}
|
||||
|
||||
private void LowerClicked(object sender, EventArgs e)
|
||||
{
|
||||
GameManager.PlayerOperation = Operation.LOWER;
|
||||
SetOperationButtonState((Button)sender);
|
||||
Result = GameManager.ResultOperation(Operation.LOWER);
|
||||
GameManager.HandlePlayerOperation(Operation.LOWER);
|
||||
}
|
||||
|
||||
private void AdditionClicked(object sender, EventArgs e)
|
||||
{
|
||||
GameManager.PlayerOperation = Operation.ADDITION;
|
||||
SetOperationButtonState((Button)sender);
|
||||
Result = GameManager.ResultOperation(Operation.ADDITION);
|
||||
GameManager.HandlePlayerOperation(Operation.ADDITION);
|
||||
}
|
||||
|
||||
private void SubstractionClicked(object sender, EventArgs e)
|
||||
{
|
||||
GameManager.PlayerOperation = Operation.SUBTRACTION;
|
||||
SetOperationButtonState((Button)sender);
|
||||
Result = GameManager.ResultOperation(Operation.SUBTRACTION);
|
||||
GameManager.HandlePlayerOperation(Operation.SUBTRACTION);
|
||||
}
|
||||
|
||||
private void MultiplicationClicked(object sender, EventArgs e)
|
||||
{
|
||||
GameManager.PlayerOperation = Operation.MULTIPLICATION;
|
||||
SetOperationButtonState((Button)sender);
|
||||
Result = GameManager.ResultOperation(Operation.MULTIPLICATION);
|
||||
GameManager.HandlePlayerOperation(Operation.MULTIPLICATION);
|
||||
}
|
||||
|
||||
private void DiceButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
GameManager.RollAllDice();
|
||||
}
|
||||
|
||||
private async void OnCellSelected(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:views="clr-namespace:Trek_12.Views.Components"
|
||||
x:Class="Trek_12.Views.PageLeaderBoard"
|
||||
Title="PageLeaderBoard">
|
||||
<Grid BackgroundColor="BlanchedAlmond"
|
||||
RowDefinitions="auto,6*,*">
|
||||
<VerticalStackLayout>
|
||||
<Label
|
||||
Text="Leader board"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center"
|
||||
FontSize="Title"/>
|
||||
<BoxView
|
||||
Color="DarkSalmon"
|
||||
HeightRequest="1"
|
||||
WidthRequest="125"/>
|
||||
</VerticalStackLayout>
|
||||
<ScrollView Grid.Row="1"
|
||||
VerticalOptions="FillAndExpand"
|
||||
VerticalScrollBarVisibility="Never"
|
||||
Margin="0,10">
|
||||
<VerticalStackLayout>
|
||||
<views:ContentLeaderBoard/>
|
||||
<views:ContentLeaderBoard/>
|
||||
<views:ContentLeaderBoard/>
|
||||
<views:ContentLeaderBoard/>
|
||||
<views:ContentLeaderBoard/>
|
||||
<views:ContentLeaderBoard/>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
<Button Text="Back"
|
||||
BackgroundColor="OliveDrab"
|
||||
FontSize="Title"
|
||||
Grid.Row="2"
|
||||
HorizontalOptions="Start"
|
||||
CornerRadius="20"
|
||||
WidthRequest="150"
|
||||
HeightRequest="75"
|
||||
Margin="10"/>
|
||||
</Grid>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:views="clr-namespace:Trek_12.Views.Components"
|
||||
x:Class="Trek_12.Views.PageLeaderBoard"
|
||||
Title="PageLeaderBoard">
|
||||
|
||||
<ContentPage.Content>
|
||||
<Grid BackgroundColor="BlanchedAlmond"
|
||||
RowDefinitions="auto,6*,*">
|
||||
|
||||
<Frame Grid.Row="0" BackgroundColor="Transparent" BorderColor="Transparent" Padding="0" Margin="15">
|
||||
<Image Source="back_arrow.png"
|
||||
Margin="0"
|
||||
HeightRequest="50"
|
||||
WidthRequest="50"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Start"/>
|
||||
<Frame.GestureRecognizers>
|
||||
<TapGestureRecognizer Tapped="OnBackArrow_Tapped"/>
|
||||
</Frame.GestureRecognizers>
|
||||
</Frame>
|
||||
|
||||
|
||||
<VerticalStackLayout VerticalOptions="Center" HorizontalOptions="Center">
|
||||
<Label
|
||||
Text="Leaderboard"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center"
|
||||
FontSize="Title"/>
|
||||
<BoxView
|
||||
Color="DarkSalmon"
|
||||
HeightRequest="1"
|
||||
WidthRequest="125"/>
|
||||
</VerticalStackLayout>
|
||||
<ScrollView Grid.Row="1"
|
||||
VerticalOptions="FillAndExpand"
|
||||
VerticalScrollBarVisibility="Never"
|
||||
Margin="0,10">
|
||||
<VerticalStackLayout HorizontalOptions="Center">
|
||||
<CollectionView ItemsSource="{Binding BestScores}"
|
||||
ItemsLayout="VerticalList"
|
||||
VerticalOptions="Center">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<views:ContentLeaderBoard
|
||||
Pseudo="{Binding ThePlayer.Pseudo}"
|
||||
ProfilePicture="{Binding ThePlayer.ProfilePicture}"
|
||||
NbGames="{Binding GamesPlayed}"
|
||||
BestScore="{Binding Score}"
|
||||
Map="{Binding MapName}"
|
||||
/>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
</Grid>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
@ -1,9 +1,20 @@
|
||||
namespace Trek_12.Views;
|
||||
|
||||
public partial class PageLeaderBoard : ContentPage
|
||||
{
|
||||
public PageLeaderBoard()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
using Models.Game;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Trek_12.Views;
|
||||
|
||||
public partial class PageLeaderBoard : ContentPage
|
||||
{
|
||||
public Game LeaderboardManager => (App.Current as App).Manager;
|
||||
|
||||
public PageLeaderBoard()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = LeaderboardManager;
|
||||
}
|
||||
|
||||
private async void OnBackArrow_Tapped(object sender, EventArgs e)
|
||||
{
|
||||
await Shell.Current.GoToAsync("..");
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Trek_12.Views.PageSelectMap"
|
||||
Title="PageSelectMap">
|
||||
|
||||
|
||||
<Grid RowDefinitions="auto,auto,auto">
|
||||
<Label Grid.Row="0" Text="Sélection de la Carte" HorizontalOptions="Center" FontSize="Header"/>
|
||||
|
||||
<CollectionView Grid.Row="1"
|
||||
ItemsSource="{Binding Maps}"
|
||||
ItemsLayout="HorizontalList"
|
||||
HorizontalOptions="Center"
|
||||
SelectionMode="Single"
|
||||
SelectionChanged="OnSelectionChanged">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Frame HasShadow="True"
|
||||
BorderColor="DarkGray"
|
||||
CornerRadius="5"
|
||||
Margin="20"
|
||||
HeightRequest="300"
|
||||
WidthRequest="200"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="CenterAndExpand"
|
||||
x:Name="Frame">
|
||||
<Grid RowDefinitions="auto,*">
|
||||
<Label Text="{Binding Name}"
|
||||
FontAttributes="Bold"
|
||||
FontSize="18"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center"/>
|
||||
<Image Source="{Binding Background}"
|
||||
Aspect="AspectFill"
|
||||
HeightRequest="150"
|
||||
WidthRequest="150"
|
||||
HorizontalOptions="Center"
|
||||
Grid.Row="1"/>
|
||||
</Grid>
|
||||
</Frame>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</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"
|
||||
FontAttributes="Bold"
|
||||
FontSize="Large"
|
||||
Grid.Row="2"
|
||||
HorizontalOptions="Start"
|
||||
Margin="100"
|
||||
Clicked="BackButton_Clicked"/>
|
||||
<Button Text="Jouer"
|
||||
FontAttributes="Bold"
|
||||
FontSize="Large"
|
||||
Grid.Row="2"
|
||||
HorizontalOptions="End"
|
||||
Margin="100"
|
||||
Clicked="PlayButton_Clicked"/>
|
||||
</Grid>
|
||||
</ContentPage>
|
@ -0,0 +1,114 @@
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Trek_12.Views;
|
||||
using Stub;
|
||||
using Models.Game;
|
||||
|
||||
public partial class PageSelectMap : ContentPage
|
||||
{
|
||||
public Game SelectMapManager => (App.Current as App).Manager;
|
||||
private Map? _selectedMap;
|
||||
|
||||
private bool isVisibleContinueButton = false;
|
||||
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
if (SelectMapManager.Games.Any(g => g.IsRunning))
|
||||
{
|
||||
isVisibleContinueButton = 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");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public PageSelectMap()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = SelectMapManager;
|
||||
|
||||
}
|
||||
|
||||
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
_selectedMap = e.CurrentSelection.FirstOrDefault() as Map;
|
||||
}
|
||||
|
||||
private async void BackButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
await Shell.Current.GoToAsync("..");
|
||||
}
|
||||
|
||||
private async void PlayButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
if (_selectedMap == null)
|
||||
{
|
||||
await DisplayAlert("Selection Required", "Please select a map you want to play to continue.", "OK");
|
||||
return;
|
||||
}
|
||||
if (SelectMapManager.Players.Count == 0)
|
||||
{
|
||||
await DisplayAlert("No player found", "Please add a player in the profile page.", "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
string[] profiles = GetProfiles().ToArray();
|
||||
string choosenPlayerName = await DisplayActionSheet("Choose a player", "Cancel", null, profiles);
|
||||
if (choosenPlayerName == null || choosenPlayerName == "Cancel") return;
|
||||
|
||||
Player chosenPlayer = GetProfileByName(choosenPlayerName);
|
||||
|
||||
var runningGames = SelectMapManager.Games.Where(g => g.IsRunning).ToList();
|
||||
|
||||
bool delete = false;
|
||||
foreach (var game in runningGames)
|
||||
{
|
||||
SelectMapManager.Games.Remove(game);
|
||||
delete = true;
|
||||
}
|
||||
|
||||
if (delete)
|
||||
{
|
||||
await DisplayAlert("Game deleted", "The previous game has been deleted because you started a new one.", "OK");
|
||||
SelectMapManager.OnPropertyChanged(nameof(SelectMapManager.Games));
|
||||
SelectMapManager.SaveData();
|
||||
}
|
||||
|
||||
|
||||
SelectMapManager.InitializeGame(_selectedMap.Clone(), chosenPlayer);
|
||||
|
||||
if (SelectMapManager.UsedMap != null && Equals(SelectMapManager.CurrentPlayer, chosenPlayer))
|
||||
{
|
||||
await Shell.Current.GoToAsync(nameof(PageBoard));
|
||||
}
|
||||
else
|
||||
{
|
||||
await DisplayAlert("Error", "An error occured while initializing the game. Please try again.", "OK");
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> GetProfiles()
|
||||
{
|
||||
return SelectMapManager.Players.Select(p => p.Pseudo).ToList();
|
||||
}
|
||||
|
||||
private Player GetProfileByName(string 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, false);
|
||||
await Shell.Current.GoToAsync(nameof(PageBoard));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Trek_12.Views.PageProfiles"
|
||||
xmlns:views="clr-namespace:Trek_12.Views.Components"
|
||||
Title="PageProfiles">
|
||||
|
||||
<ContentPage.Content>
|
||||
|
||||
<Grid RowDefinitions="auto,3*,*">
|
||||
<Image Source="bg_profils.jpg" Grid.RowSpan="3" Aspect="AspectFill"/>
|
||||
|
||||
<Frame Grid.Row="0" BackgroundColor="Transparent" BorderColor="Transparent" Padding="0" Margin="15">
|
||||
<Image Source="back_arrow.png"
|
||||
Margin="0"
|
||||
HeightRequest="50"
|
||||
WidthRequest="50"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Start"/>
|
||||
<Frame.GestureRecognizers>
|
||||
<TapGestureRecognizer Tapped="OnBackArrow_Tapped"/>
|
||||
</Frame.GestureRecognizers>
|
||||
</Frame>
|
||||
|
||||
<Frame BackgroundColor="WhiteSmoke" Opacity="0.5" Grid.Row="1" />
|
||||
|
||||
<Label Grid.Row="0" Text="Profils" TextColor="black" HorizontalTextAlignment="Center" FontSize="Header" Margin="30"/>
|
||||
|
||||
<Grid Grid.Row="1" ColumnDefinitions="*,*,*">
|
||||
<Label Text="Pseudo" TextColor="black" FontSize="Large" HorizontalTextAlignment="Center" Grid.Column="1"/>
|
||||
<Label Text="Date de Création" TextColor="black" FontSize="Large" HorizontalTextAlignment="Center" Grid.Column="2"/>
|
||||
</Grid>
|
||||
<CollectionView Grid.Row="1" ItemsSource="{Binding Players}"
|
||||
ItemsLayout="VerticalList"
|
||||
VerticalOptions="Center">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<views:viewsProfils
|
||||
Pseudo="{Binding Pseudo}"
|
||||
ProfilePicture="{Binding ProfilePicture}"
|
||||
CreationDate="{Binding CreationDate}"/>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
|
||||
<HorizontalStackLayout Grid.Row="2" HorizontalOptions="Center" Spacing="50">
|
||||
<Button Text="Modifier" WidthRequest="300" HeightRequest="60" CornerRadius="4" Clicked="Button_ClickedModify"/>
|
||||
<Button Text="Créer" WidthRequest="300" HeightRequest="60" CornerRadius="4" Clicked="Button_ClickedAdd"/>
|
||||
<Button Text="Supprimer" WidthRequest="300" HeightRequest="60" CornerRadius="4" Clicked="Button_ClickedPop"/>
|
||||
</HorizontalStackLayout>
|
||||
</Grid>
|
||||
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
@ -0,0 +1,113 @@
|
||||
using Models.Game;
|
||||
using Stub;
|
||||
using System.Diagnostics;
|
||||
using CommunityToolkit.Maui.Alerts;
|
||||
using CommunityToolkit.Maui.Core;
|
||||
using Models.Interfaces;
|
||||
|
||||
namespace Trek_12.Views;
|
||||
|
||||
public partial class PageProfiles : ContentPage
|
||||
{
|
||||
public Game ProfileManager => (App.Current as App).Manager;
|
||||
|
||||
public PageProfiles()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = ProfileManager;
|
||||
}
|
||||
|
||||
private async void OnBackArrow_Tapped(object sender, EventArgs e)
|
||||
{
|
||||
await Shell.Current.GoToAsync("..");
|
||||
}
|
||||
|
||||
async void Button_ClickedAdd(System.Object sender, System.EventArgs e)
|
||||
{
|
||||
string pseudo = await DisplayPromptAsync("Info", $"Choose a name : ", "Ok");
|
||||
char[] trim = { ' ', '\n', '\t' };
|
||||
pseudo = pseudo.TrimEnd(trim);
|
||||
pseudo = pseudo.TrimStart(trim);
|
||||
if (pseudo == null) return;
|
||||
if (ProfileManager.Players.Any(p => p.Pseudo == pseudo))
|
||||
{
|
||||
await DisplayAlert("Info", "This name is already taken", "Ok");
|
||||
return;
|
||||
}
|
||||
|
||||
var profilePicture = await MediaPicker.PickPhotoAsync();
|
||||
if (profilePicture == null) return;
|
||||
|
||||
IImageConverter converter = new Base64Converter();
|
||||
|
||||
string convertedProfilePicture = converter.ConvertImage(profilePicture.FullPath);
|
||||
|
||||
Player player = new Player(pseudo, convertedProfilePicture);
|
||||
ProfileManager.AddPlayer(player);
|
||||
Debug.WriteLine("Player " + pseudo + " added with profile picture " + convertedProfilePicture);
|
||||
Debug.WriteLine("It's the number" + ProfileManager.Players.Count + " player");
|
||||
|
||||
ProfileManager.OnPropertyChanged(nameof(ProfileManager.Players));
|
||||
ProfileManager.SaveData();
|
||||
}
|
||||
|
||||
async void Button_ClickedPop(System.Object sender, System.EventArgs e)
|
||||
{
|
||||
if (ProfileManager.Players.Count == 0)
|
||||
{
|
||||
await DisplayAlert("Info", "There is no player actually\nPlease add one", "Ok");
|
||||
return;
|
||||
}
|
||||
|
||||
string result = await DisplayPromptAsync("Info", $"Choose a pseudo to delete : ", "Ok");
|
||||
if (result == null) return;
|
||||
Debug.WriteLine("Answer: " + result);
|
||||
if (ProfileManager.RemovePlayer(result))
|
||||
{
|
||||
Debug.WriteLine("bam, deleted");
|
||||
OnPropertyChanged(nameof(ProfileManager));
|
||||
}
|
||||
else
|
||||
{
|
||||
await DisplayAlert("Info", "This name do not exist", "Ok");
|
||||
Debug.WriteLine("Player not found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
async void Button_ClickedModify(System.Object sender, System.EventArgs e)
|
||||
{
|
||||
if (ProfileManager.Players.Count == 0)
|
||||
{
|
||||
await DisplayAlert("Info", "There is no player actually\nPlease add one", "Ok");
|
||||
return;
|
||||
}
|
||||
|
||||
string result = await DisplayPromptAsync("Info", $"Choose a name to modify : ", "Ok");
|
||||
Debug.WriteLine("Answer: " + result);
|
||||
if (result == null)
|
||||
{
|
||||
Debug.WriteLine("Did not found");
|
||||
return;
|
||||
}
|
||||
string tomodify = await DisplayPromptAsync("Info", $"How will you rename it ?: ", "Ok");
|
||||
Debug.WriteLine("Answer: " + tomodify);
|
||||
if (tomodify == null)
|
||||
{
|
||||
Debug.WriteLine("Did not found");
|
||||
return;
|
||||
}
|
||||
Debug.WriteLine("bam, modified");
|
||||
bool ismodified = ProfileManager.ModifyPlayer(result, tomodify);
|
||||
|
||||
if (ismodified)
|
||||
{
|
||||
Debug.WriteLine("Modified");
|
||||
ProfileManager.SaveData();
|
||||
}
|
||||
else Debug.WriteLine("Player not found");
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Trek_12.Views.PageProfils"
|
||||
xmlns:views="clr-namespace:Trek_12.Views.Components"
|
||||
Title="pageProfils">
|
||||
|
||||
<ContentPage.Content>
|
||||
|
||||
|
||||
<Grid RowDefinitions="2*,3*,*">
|
||||
<Image Source="bg_profils.jpg" Grid.RowSpan="3" Aspect="AspectFill"/>
|
||||
|
||||
|
||||
<Label Text="Profils" TextColor="black" HorizontalTextAlignment="Center" FontSize="Header" Margin="30"/>
|
||||
|
||||
<ScrollView Grid.Row="1">
|
||||
<Grid RowDefinitions="*,*,*,*,*,*">
|
||||
<views:viewsProfils />
|
||||
<views:viewsProfils Grid.Row="1" />
|
||||
<views:viewsProfils Grid.Row="2"/>
|
||||
<views:viewsProfils Grid.Row="3"/>
|
||||
<views:viewsProfils Grid.Row="4"/>
|
||||
<views:viewsProfils Grid.Row="5"/>
|
||||
|
||||
</Grid>
|
||||
</ScrollView>
|
||||
|
||||
<HorizontalStackLayout Grid.Row="2" HorizontalOptions="Center" Spacing="50">
|
||||
<Button Text="Modifier" WidthRequest="300" HeightRequest="60" CornerRadius="4"/>
|
||||
<Button Text="Créer" WidthRequest="300" HeightRequest="60" CornerRadius="4"/>
|
||||
<Button Text="Supprimer" WidthRequest="300" HeightRequest="60" CornerRadius="4"/>
|
||||
</HorizontalStackLayout>
|
||||
</Grid>
|
||||
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
@ -1,9 +0,0 @@
|
||||
namespace Trek_12.Views;
|
||||
|
||||
public partial class PageProfils : ContentPage
|
||||
{
|
||||
public PageProfils()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|