Debut reprise d'une partie
continuous-integration/drone/push Build is failing Details

master
Céleste BARBOSA 11 months ago
parent 1baca9f63a
commit 10dae20440

@ -1,10 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -1,25 +0,0 @@
using System;
using System.IO;
class Program
{
static void Main()
{
// Récupérer le chemin du dossier AppData de l'utilisateur
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
// Définir le chemin du dossier "mastermind" dans AppData
string mastermindPath = Path.Combine(appDataPath, "Mastermind");
// Vérifier si le dossier existe, et s'il n'existe pas, le créer
if (!Directory.Exists(mastermindPath))
{
Directory.CreateDirectory(mastermindPath);
Console.WriteLine("Le dossier 'mastermind' a été créé dans AppData.");
}
else
{
Console.WriteLine("Le dossier 'mastermind' existe déjà dans AppData.");
}
}
}

@ -20,7 +20,6 @@ namespace CoreLibrary.Joueurs
[DataMember] [DataMember]
public string Nom { get; private set; } = ""; public string Nom { get; private set; } = "";
[DataMember]
public bool EstConnecte { get; private set; } = false; public bool EstConnecte { get; private set; } = false;
public Joueur() public Joueur()

@ -13,6 +13,7 @@ namespace CoreLibrary.Manageurs
public IReadOnlyList<Joueur> Joueurs => joueurs; public IReadOnlyList<Joueur> Joueurs => joueurs;
public IReadOnlyList<Partie> Parties => parties; public IReadOnlyList<Partie> Parties => parties;
public IReadOnlyList<Partie> PartiesNonTerminees => parties.Where(partie => !partie.Termine).ToList();
public Manageur(IPersistance persistance) public Manageur(IPersistance persistance)
{ {
@ -54,6 +55,8 @@ namespace CoreLibrary.Manageurs
{ {
perdant.IncrementerStatistique(regles, Statistique.PartiePerdue); perdant.IncrementerStatistique(regles, Statistique.PartiePerdue);
} }
Sauvegarder();
}; };
return partie; return partie;

@ -30,6 +30,12 @@ namespace CoreLibrary
[DataMember] [DataMember]
private int courant = 0; private int courant = 0;
public IReadOnlyList<Joueur> Joueurs => joueurs;
[DataMember]
public bool Termine { get; private set; } = false;
[DataMember]
public int Tour { get; private set; } = 0;
[DataMember] [DataMember]
public IRegles Regles { get; private init; } public IRegles Regles { get; private init; }
@ -40,7 +46,10 @@ namespace CoreLibrary
public void Jouer() public void Jouer()
{ {
DemanderJoueur(); if (joueurs.Count != Regles.NbJoueurs)
DemanderJoueur();
else
DebutPartie();
} }
private void DemanderJoueur() private void DemanderJoueur()
@ -53,11 +62,8 @@ namespace CoreLibrary
private void JoueurConnecte(object? sender, JoueurSeConnecterEventArgs e) private void JoueurConnecte(object? sender, JoueurSeConnecterEventArgs e)
{ {
Plateau plateau = new Plateau(Regles.TailleCode, Regles.NbTour);
plateau.PlateauAjouterCode += PlateauAjouterCode;
joueurs.Add(e.JoueurConnecte); joueurs.Add(e.JoueurConnecte);
plateaux.Add(plateau); plateaux.Add(new Plateau(Regles.TailleCode, Regles.NbTour));
if (joueurs.Count < Regles.NbJoueurs) if (joueurs.Count < Regles.NbJoueurs)
{ {
@ -71,7 +77,15 @@ namespace CoreLibrary
private void DebutPartie() private void DebutPartie()
{ {
Tour = 1;
foreach (Plateau plateau in plateaux)
{
plateau.PlateauAjouterCode += PlateauAjouterCode;
}
QuandPartieDebutPartie(); QuandPartieDebutPartie();
NouveauTour(); NouveauTour();
} }
@ -91,7 +105,10 @@ namespace CoreLibrary
else else
{ {
if (courant + 1 == joueurs.Count) if (courant + 1 == joueurs.Count)
{
++Tour;
courant = 0; courant = 0;
}
else else
++courant; ++courant;
@ -101,6 +118,8 @@ namespace CoreLibrary
private void PartieTerminee() private void PartieTerminee()
{ {
Termine = true;
List<Joueur> gagnants = new List<Joueur>(); List<Joueur> gagnants = new List<Joueur>();
List<Joueur> perdants = new List<Joueur>(); List<Joueur> perdants = new List<Joueur>();
@ -114,5 +133,14 @@ namespace CoreLibrary
QuandPartiePartieTerminee(gagnants, perdants); QuandPartiePartieTerminee(gagnants, perdants);
} }
public void ReinitialiserEcouteEvenements()
{
PartieDemanderJoueur = null;
PartieDebutPartie = null;
PartieNouveauTour = null;
PartiePasserLaMain = null;
PartiePartieTerminee = null;
}
} }
} }

@ -6,8 +6,15 @@ namespace CoreLibrary.Persistance
{ {
public class PersistanceJSON : IPersistance public class PersistanceJSON : IPersistance
{ {
private readonly string dossier = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../..");
private readonly string nomDossier = "Fichiers"; private readonly string nomDossier = "Fichiers";
private readonly string nomRacine = "Sources";
private readonly string dossier = AppDomain.CurrentDomain.BaseDirectory;
public PersistanceJSON()
{
while (new DirectoryInfo(dossier).Name != nomRacine)
dossier = Path.GetFullPath(Path.Combine(dossier, @"../"));
}
public T[] Charger<T>() where T : IEstPersistant public T[] Charger<T>() where T : IEstPersistant
{ {

@ -1,50 +0,0 @@
[
{
"EstConnecte": false,
"Nom": "Céleste",
"statistiques": [
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 10
},
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 11
}
]
},
{
"EstConnecte": false,
"Nom": "Pauline",
"statistiques": [
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 10
},
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 10
}
]
}
]

File diff suppressed because it is too large Load Diff

@ -103,6 +103,9 @@
<MauiXaml Update="Pages\ReglesPage.xaml"> <MauiXaml Update="Pages\ReglesPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Pages\ReprendrePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\TableauScore.xaml"> <MauiXaml Update="Pages\TableauScore.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
@ -121,6 +124,9 @@
<MauiXaml Update="Vues\JetonVue.xaml"> <MauiXaml Update="Vues\JetonVue.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Vues\PartieCommenceeVue.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Vues\ReglesVue.xaml"> <MauiXaml Update="Vues\ReglesVue.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>

@ -6,7 +6,7 @@
<Grid <Grid
ColumnDefinitions="*" ColumnDefinitions="*"
RowDefinitions="*, *"> RowDefinitions="*, *, *">
<Grid <Grid
@ -21,10 +21,17 @@
</Grid> </Grid>
<Button <Button
Grid.Row="2" Grid.Row="1"
Text="Jouer" Text="Jouer"
VerticalOptions="Center" Margin="0,30"
Margin="0, 50" VerticalOptions="End"
Clicked="QuandJouerClique"/> Clicked="QuandJouerClique"/>
<Button
Grid.Row="2"
Text="Reprendre"
Margin="0,30"
VerticalOptions="Start"
Clicked="QuandReprendreClique"/>
</Grid> </Grid>
</ContentPage> </ContentPage>

@ -13,5 +13,10 @@ public partial class AccueilPage : ContentPage
private void QuandJouerClique(Object? sender, EventArgs e) private void QuandJouerClique(Object? sender, EventArgs e)
{ {
Navigation.PushAsync(new ModePage()); Navigation.PushAsync(new ModePage());
} }
private void QuandReprendreClique(Object? sender, EventArgs e)
{
Navigation.PushAsync(new ReprendrePage());
}
} }

@ -0,0 +1,22 @@
<?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="MauiSpark.Pages.ReprendrePage"
xmlns:vues="clr-namespace:MauiSpark.Vues"
x:Name="reprendrePage"
Title="ReprendrePage">
<ScrollView>
<StackLayout>
<vues:TitreVue Texte="Reprendre une partie"/>
<StackLayout BindableLayout.ItemsSource="{Binding .}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<vues:PartieCommenceeVue Partie="{Binding .}" Margin="20"/>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</StackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,13 @@
namespace MauiSpark.Pages;
public partial class ReprendrePage : ContentPage
{
public ReprendrePage()
{
NavigationPage.SetHasNavigationBar(this, false);
BindingContext = MauiProgram.Manageur.PartiesNonTerminees;
InitializeComponent();
}
}

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="partieCommenceeVue"
x:Class="MauiSpark.Vues.PartieCommenceeVue">
<Border
StrokeThickness="2"
StrokeShape="RoundRectangle 10">
<Grid RowDefinitions="*, *, *" ColumnDefinitions="*" Margin="20">
<Label Text="{Binding NomRegles, Source={x:Reference partieCommenceeVue}}" FontSize="Large" Margin="0, 0, 0, 20"/>
<Grid Grid.Row="1" RowDefinitions="*, *" Margin="0, 0, 0, 20">
<Label Grid.Row="0" Text="{Binding NombreJoueurs, Source={x:Reference partieCommenceeVue}}" FontSize="Medium"/>
<Label Grid.Row="1" Text="{Binding TourActuel, Source={x:Reference partieCommenceeVue}}" FontSize="Medium"/>
</Grid>
<StackLayout Grid.Row="3" BindableLayout.ItemsSource="{Binding Joueurs, Source={x:Reference partieCommenceeVue}}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Text="{Binding .}" FontSize="Medium"/>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="PartiePressee"/>
</Grid.GestureRecognizers>
</Grid>
</Border>
</ContentView>

@ -0,0 +1,60 @@
using CoreLibrary;
using CoreLibrary.Joueurs;
using MauiSpark.Pages;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace MauiSpark.Vues;
public partial class PartieCommenceeVue : ContentView, INotifyPropertyChanged
{
public static readonly BindableProperty PartieProperty = BindableProperty.Create(nameof(Partie), typeof(Partie), typeof(PartieCommenceeVue), null, propertyChanged: QuandPartieChangee);
public Partie Partie
{
get => (Partie)GetValue(PartieProperty);
set => SetValue(PartieProperty, value);
}
public string NomRegles
{
get => Partie != null ? Partie.Regles.Nom : "";
}
public string TourActuel
{
get => $"Tour : {(Partie != null ? Partie.Tour : 0)} / {(Partie != null ? Partie.Regles.NbTour : 0)}";
}
public Joueur[] Joueurs
{
get => Partie != null ? Partie.Joueurs.ToArray() : [];
}
public string NombreJoueurs => $"Joueurs : {Joueurs.Length} / {(Partie != null ? Partie.Regles.NbJoueurs : 0)}";
private static void QuandPartieChangee(BindableObject bindable, object ancienneValeur, object nouvelleValeur)
{
((PartieCommenceeVue)bindable).OnPropertyChanged(nameof(NomRegles));
((PartieCommenceeVue)bindable).OnPropertyChanged(nameof(TourActuel));
((PartieCommenceeVue)bindable).OnPropertyChanged(nameof(Joueurs));
((PartieCommenceeVue)bindable).OnPropertyChanged(nameof(NombreJoueurs));
}
private void PartiePressee(object? sender, EventArgs e)
{
if (Partie == null)
return;
Partie.PartieDemanderJoueur += new ConnexionPage().QuandDemanderNom;
Partie.PartieNouveauTour += new PlateauPage().QuandNouveauTour;
Partie.PartiePartieTerminee += new VictoirePage().QuandPartieTerminee;
Partie.Jouer();
}
public PartieCommenceeVue()
{
InitializeComponent();
}
}
Loading…
Cancel
Save