🚧 Ajout de la navigation entre les pages, utilisation de la persistance et interactions
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

pull/100/head
Rémi LAVERGNE 11 months ago
parent 0153fd24a7
commit 8e9bca4b9a

@ -14,7 +14,7 @@
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" VerticalOptions="Center"
Padding="0"> Padding="0">
<Label Text="{Binding ThePartie.Dice1.Value}" <Label Text="{Binding Dice1.Value}"
FontSize="16" FontSize="16"
VerticalOptions="Center" VerticalOptions="Center"
HorizontalOptions="Center" HorizontalOptions="Center"
@ -28,7 +28,7 @@
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" VerticalOptions="Center"
Padding="0"> Padding="0">
<Label Text="{Binding ThePartie.Dice1.Value}" <Label Text="{Binding Dice2.Value}"
FontSize="16" FontSize="16"
VerticalOptions="Center" VerticalOptions="Center"
HorizontalOptions="Center" HorizontalOptions="Center"
@ -38,11 +38,11 @@
<Button Text="Roll" <Button Text="Roll"
HeightRequest="200" HeightRequest="200"
WidthRequest="200" WidthRequest="200"
Clicked="Button_Clicked"/> Clicked="DiceButton_Clicked"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<Image Source="maptest.png" Aspect="AspectFit" Grid.ColumnSpan="2" Grid.RowSpan="3"/> <Image Source="maptest.png" Aspect="AspectFit" Grid.ColumnSpan="2" Grid.RowSpan="3"/>
<CollectionView ItemsSource="{Binding ListMap[0].Boards}" <CollectionView ItemsSource="{Binding UsedMap.Boards}"
Grid.Row="1" Grid.Row="1"
Grid.Column="1" Grid.Column="1"
SelectionMode="Single" SelectionMode="Single"
@ -81,7 +81,7 @@
<!-- Operation Grid --> <!-- Operation Grid -->
<CollectionView Grid.Row="0" Grid.Column="2" <CollectionView Grid.Row="0" Grid.Column="2"
ItemsSource="{Binding ListMap[0].OperationGrid}" ItemsSource="{Binding UsedMap.OperationGrid}"
ItemsLayout="VerticalGrid,4" ItemsLayout="VerticalGrid,4"
WidthRequest="200" WidthRequest="200"
HeightRequest="250" HeightRequest="250"

@ -1,24 +1,27 @@
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
namespace Trek_12.Views; namespace Trek_12.Views;
using Models.Game; using Models.Game;
using Stub;
public partial class PageBoard : ContentPage public partial class PageBoard : ContentPage
{ {
public Stub MyStub { get; set; } = new Stub(); public Game GameManager => (App.Current as App).Manager;
public PageBoard() public PageBoard()
{ {
InitializeComponent(); InitializeComponent();
MyStub.ThePartie.DiceRolled += ThePartie_DiceRolled; GameManager.DiceRolled += TheGame_DiceRolled;
BindingContext = MyStub; BindingContext = GameManager;
MyStub.ThePartie.InitializeGame(MyStub.ThePartie.UsedMap, MyStub.ListPlayer[0]);
// We add this game to the list of games
GameManager.AddGame(GameManager);
GameManager.OnPropertyChanged(nameof(GameManager.Games));
GameManager.SaveData();
} }
private void ThePartie_DiceRolled(object? sender, Models.Events.DiceRolledEventArgs e) private void TheGame_DiceRolled(object? sender, Models.Events.DiceRolledEventArgs e)
{ {
Dice1.Text = $"{e.Dice1Value}"; Dice1.Text = $"{e.Dice1Value}";
Dice2.Text = $"{e.Dice2Value}"; Dice2.Text = $"{e.Dice2Value}";
@ -39,8 +42,8 @@ public partial class PageBoard : ContentPage
} }
} }
private void Button_Clicked(object sender, EventArgs e) private void DiceButton_Clicked(object sender, EventArgs e)
{ {
MyStub.ThePartie.RollAllDice(); GameManager.RollAllDice();
} }
} }

@ -6,9 +6,23 @@
Title="PageLeaderBoard"> Title="PageLeaderBoard">
<Grid BackgroundColor="BlanchedAlmond" <Grid BackgroundColor="BlanchedAlmond"
RowDefinitions="auto,6*,*"> RowDefinitions="auto,6*,*">
<VerticalStackLayout>
<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 <Label
Text="Leader board" Text="Leaderboard"
VerticalOptions="Center" VerticalOptions="Center"
HorizontalOptions="Center" HorizontalOptions="Center"
FontSize="Title"/> FontSize="Title"/>
@ -21,7 +35,7 @@
VerticalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
VerticalScrollBarVisibility="Never" VerticalScrollBarVisibility="Never"
Margin="0,10"> Margin="0,10">
<VerticalStackLayout> <VerticalStackLayout HorizontalOptions="Center">
<views:ContentLeaderBoard/> <views:ContentLeaderBoard/>
<views:ContentLeaderBoard/> <views:ContentLeaderBoard/>
<views:ContentLeaderBoard/> <views:ContentLeaderBoard/>
@ -30,14 +44,5 @@
<views:ContentLeaderBoard/> <views:ContentLeaderBoard/>
</VerticalStackLayout> </VerticalStackLayout>
</ScrollView> </ScrollView>
<Button Text="Back"
BackgroundColor="OliveDrab"
FontSize="Title"
Grid.Row="2"
HorizontalOptions="Start"
CornerRadius="20"
WidthRequest="150"
HeightRequest="75"
Margin="10"/>
</Grid> </Grid>
</ContentPage> </ContentPage>

@ -6,4 +6,9 @@ public partial class PageLeaderBoard : ContentPage
{ {
InitializeComponent(); InitializeComponent();
} }
private async void OnBackArrow_Tapped(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("..");
}
} }

@ -18,10 +18,18 @@
MinimumHeightRequest="50" MinimumHeightRequest="50"
MaximumHeightRequest="150"/> MaximumHeightRequest="150"/>
<Frame Grid.Row="0" BackgroundColor="Transparent" BorderColor="Transparent" Padding="0" Margin="20" HorizontalOptions="End" VerticalOptions="Start">
<Image Source="user.png" HeightRequest="50" WidthRequest="50" Aspect="AspectFit" VerticalOptions="Center" HorizontalOptions="Center" Margin="0" />
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="OnProfilesButton_Tapped"/>
</Frame.GestureRecognizers>
</Frame>
<Grid Grid.Row="1" ColumnDefinitions="*,2*,*" RowDefinitions="*,*" HorizontalOptions="Fill" VerticalOptions="Center" ColumnSpacing="50" RowSpacing="25" Margin="50,0"> <Grid Grid.Row="1" ColumnDefinitions="*,2*,*" RowDefinitions="*,*" HorizontalOptions="Fill" VerticalOptions="Center" ColumnSpacing="50" RowSpacing="25" Margin="50,0">
<Button Grid.Column="0" Grid.Row="1" Text="Leaderboard" BackgroundColor="#936f49" Opacity="0.9" CornerRadius="6"/> <Button Grid.Column="0" Grid.Row="1" Text="Leaderboard" BackgroundColor="#936f49" Opacity="0.9" CornerRadius="6" Clicked="OnLeaderBoardButton_Clicked"/>
<Button Grid.Column="1" Grid.RowSpan="2" Text="JOUER" BackgroundColor="#936f49" Opacity="0.9" CornerRadius="6"/> <Button Grid.Column="1" Grid.RowSpan="2" Text="JOUER" BackgroundColor="#936f49" Opacity="0.9" CornerRadius="6" Clicked="OnPlayButton_Clicked"/>
<Button Grid.Column="2" Grid.Row="1" Text="Règles" BackgroundColor="#936f49" Opacity="0.9" CornerRadius="6"/> <Button Grid.Column="2" Grid.Row="1" Text="Règles" BackgroundColor="#936f49" Opacity="0.9" CornerRadius="6" Clicked="OnRulesButton_Clicked"/>
</Grid> </Grid>
</Grid> </Grid>
</ContentPage.Content> </ContentPage.Content>

@ -1,8 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;
using Font = Microsoft.Maui.Font;
namespace Trek_12.Views; namespace Trek_12.Views;
@ -12,4 +17,24 @@ public partial class PageMenuPrincipal : ContentPage
{ {
InitializeComponent(); InitializeComponent();
} }
private async void OnRulesButton_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync(nameof(PageRegles));
}
private async void OnLeaderBoardButton_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync(nameof(PageLeaderBoard));
}
private async void OnPlayButton_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync(nameof(PageSelectMap));
}
private async void OnProfilesButton_Tapped(object sender, EventArgs e)
{
await Shell.Current.GoToAsync(nameof(PageProfiles));
}
} }

@ -9,10 +9,11 @@
<Label Grid.Row="0" Text="Sélection de la Carte" HorizontalOptions="Center" FontSize="Header"/> <Label Grid.Row="0" Text="Sélection de la Carte" HorizontalOptions="Center" FontSize="Header"/>
<CollectionView Grid.Row="1" <CollectionView Grid.Row="1"
ItemsSource="{Binding ListMap}" ItemsSource="{Binding Maps}"
ItemsLayout="HorizontalList" ItemsLayout="HorizontalList"
HorizontalOptions="Center" HorizontalOptions="Center"
SelectionMode="Single"> SelectionMode="Single"
SelectionChanged="OnSelectionChanged">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Frame HasShadow="True" <Frame HasShadow="True"
@ -46,12 +47,14 @@
FontSize="Large" FontSize="Large"
Grid.Row="2" Grid.Row="2"
HorizontalOptions="Start" HorizontalOptions="Start"
Margin="100"/> Margin="100"
Clicked="BackButton_Clicked"/>
<Button Text="Jouer" <Button Text="Jouer"
FontAttributes="Bold" FontAttributes="Bold"
FontSize="Large" FontSize="Large"
Grid.Row="2" Grid.Row="2"
HorizontalOptions="End" HorizontalOptions="End"
Margin="100"/> Margin="100"
Clicked="PlayButton_Clicked"/>
</Grid> </Grid>
</ContentPage> </ContentPage>

@ -1,16 +1,82 @@
using System.Diagnostics;
namespace Trek_12.Views; namespace Trek_12.Views;
using Stub; using Stub;
using Models.Game;
public partial class PageSelectMap : ContentPage public partial class PageSelectMap : ContentPage
{ {
public Game SelectMapManager => (App.Current as App).Manager;
private Map? _selectedMap;
protected override async void OnAppearing()
{
base.OnAppearing();
if (SelectMapManager.Games.Any(g => g.IsRunning))
{
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 Stub MyStub { get; set; } = new Stub(); }
}
public PageSelectMap() public PageSelectMap()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = MyStub; 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);
SelectMapManager.InitializeGame(_selectedMap, chosenPlayer);
if (SelectMapManager.UsedMap == _selectedMap && 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);
}
} }

@ -10,6 +10,18 @@
<Grid RowDefinitions="auto,3*,*"> <Grid RowDefinitions="auto,3*,*">
<Image Source="bg_profils.jpg" Grid.RowSpan="3" Aspect="AspectFill"/> <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" /> <Frame BackgroundColor="WhiteSmoke" Opacity="0.5" Grid.Row="1" />
<Label Grid.Row="0" Text="Profils" TextColor="black" HorizontalTextAlignment="Center" FontSize="Header" Margin="30"/> <Label Grid.Row="0" Text="Profils" TextColor="black" HorizontalTextAlignment="Center" FontSize="Header" Margin="30"/>

@ -17,11 +17,20 @@ public partial class PageProfiles : ContentPage
BindingContext = ProfileManager; 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) async void Button_ClickedAdd(System.Object sender, System.EventArgs e)
{ {
string pseudo = await DisplayPromptAsync("Info", $"Choose a name : ", "Ok"); string pseudo = await DisplayPromptAsync("Info", $"Choose a name : ", "Ok");
if (pseudo == null) return; 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(); var profilePicture = await MediaPicker.PickPhotoAsync();
if (profilePicture == null) return; if (profilePicture == null) return;

@ -74,7 +74,7 @@
</ScrollView> </ScrollView>
<HorizontalStackLayout Grid.Row="2" HorizontalOptions="Center" Spacing="50"> <HorizontalStackLayout Grid.Row="2" HorizontalOptions="Center" Spacing="50">
<Button Text="Retour" WidthRequest="300" HeightRequest="60" CornerRadius="4"/> <Button Text="Retour" WidthRequest="300" HeightRequest="60" CornerRadius="4" Clicked="BackButton_Clicked"/>
<Button Text="Acheter" WidthRequest="300" HeightRequest="60" CornerRadius="4" Clicked="BrowserOpen_Clicked"/> <Button Text="Acheter" WidthRequest="300" HeightRequest="60" CornerRadius="4" Clicked="BrowserOpen_Clicked"/>
</HorizontalStackLayout> </HorizontalStackLayout>
</Grid> </Grid>

@ -9,6 +9,10 @@ public partial class PageRegles : ContentPage
InitializeComponent(); InitializeComponent();
} }
private async void BackButton_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("..");
}
private async void BrowserOpen_Clicked(System.Object sender, System.EventArgs e) private async void BrowserOpen_Clicked(System.Object sender, System.EventArgs e)
{ {

Loading…
Cancel
Save