Continuer page
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
603c7eb8a3
commit
30bad619ad
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Shell
|
||||
x:Class="MauiSpark.AppShell"
|
||||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:local="clr-namespace:MauiSpark"
|
||||
xmlns:pages="clr-namespace:MauiSpark.Pages"
|
||||
Shell.NavBarIsVisible="False"
|
||||
Shell.FlyoutBehavior="Flyout"
|
||||
Title="Mastermind">
|
||||
|
||||
<ShellContent
|
||||
Title="Accueil"
|
||||
ContentTemplate="{DataTemplate pages:Accueil}" />
|
||||
|
||||
<ShellContent
|
||||
Title="Connexion"
|
||||
ContentTemplate="{DataTemplate pages:ConnexionPage}" />
|
||||
|
||||
<ShellContent
|
||||
Title="TableauScore"
|
||||
ContentTemplate="{DataTemplate pages:TableauScore}" />
|
||||
|
||||
<ShellContent
|
||||
Title="Regle"
|
||||
ContentTemplate="{DataTemplate pages:Regle}" />
|
||||
|
||||
<ShellContent
|
||||
Title="Victoire"
|
||||
ContentTemplate="{DataTemplate pages:Victoire}" />
|
||||
|
||||
<ShellContent
|
||||
Title="Defaite"
|
||||
ContentTemplate="{DataTemplate pages:Defaite}" />
|
||||
|
||||
<ShellContent
|
||||
Title="Egalite"
|
||||
ContentTemplate="{DataTemplate pages:Egalite}" />
|
||||
|
||||
<ShellContent
|
||||
Title="Plateau"
|
||||
ContentTemplate="{DataTemplate pages:Plateau}" />
|
||||
|
||||
|
||||
</Shell>
|
@ -1,9 +1,34 @@
|
||||
using CoreLibrary;
|
||||
using CoreLibrary.Events;
|
||||
using CoreLibrary.Joueurs;
|
||||
|
||||
namespace MauiSpark.Pages;
|
||||
|
||||
|
||||
public partial class ConnexionPage : ContentPage
|
||||
{
|
||||
public ConnexionPage()
|
||||
private readonly JoueurBuilder joueurBuilder;
|
||||
|
||||
public ConnexionPage(Partie partie, DemanderNomEventArgs e)
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeComponent();
|
||||
|
||||
joueurBuilder = e.JoueurBuilder;
|
||||
|
||||
if(partie.Regles.NbJoueurs + 1 == partie.Regles.NbJoueursMaximum)
|
||||
partie.NouveauTour += QuandNouveauTour;
|
||||
|
||||
BindingContext = $"Joueur {e.Indice}";
|
||||
}
|
||||
|
||||
private void QuandNouveauTour(object sender, NouveauTourEventArgs e)
|
||||
{
|
||||
if (sender != null && sender is Partie)
|
||||
Navigation.PushAsync(new Plateau(sender as Partie, e));
|
||||
}
|
||||
|
||||
private void QuandSeConnecterPresse(Object sender, EventArgs e)
|
||||
{
|
||||
joueurBuilder.Joueur(new Joueur(Nom.Text));
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?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.Mode"
|
||||
Title="Mode">
|
||||
<Grid ColumnDefinitions="*" RowDefinitions="*, *">
|
||||
<Label Text="Mode de jeu"/>
|
||||
<Button Grid.Row="1" Text="Règles classiques" Clicked="QuandReglesClassiques"/>
|
||||
</Grid>
|
||||
</ContentPage>
|
@ -0,0 +1,26 @@
|
||||
using CoreLibrary;
|
||||
using CoreLibrary.Events;
|
||||
using CoreLibrary.Regles;
|
||||
|
||||
namespace MauiSpark.Pages;
|
||||
|
||||
public partial class Mode : ContentPage
|
||||
{
|
||||
public Mode()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void QuandReglesClassiques(Object? sender, EventArgs e)
|
||||
{
|
||||
Partie partie = new Partie(new ReglesClassiques());
|
||||
partie.DemanderNom += QuandDemanderNom;
|
||||
partie.Jouer();
|
||||
}
|
||||
|
||||
private void QuandDemanderNom(Object? sender, DemanderNomEventArgs e)
|
||||
{
|
||||
if(sender != null && sender is Partie)
|
||||
Navigation.PushAsync(new ConnexionPage(sender as Partie, e));
|
||||
}
|
||||
}
|
@ -1,220 +1,15 @@
|
||||
using CoreLibrary.Events;
|
||||
using CoreLibrary.Manager;
|
||||
using CoreLibrary;
|
||||
using CoreLibrary.Regles;
|
||||
using CoreLibrary.Joueurs;
|
||||
using Microsoft.Maui.Controls;
|
||||
using CoreLibrary.Core;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.ObjectModel;
|
||||
using CoreLibrary.Exceptions;
|
||||
|
||||
namespace MauiSpark.Pages
|
||||
{
|
||||
public partial class Plateau : ContentPage, INotifyPropertyChanged
|
||||
{
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public void QuandPropertyChanged([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
private TaskCompletionSource<CouleurSelectionResult> CouleurSelectedTask;
|
||||
public Couleur? selectedColor;
|
||||
public Jeton selectedJeton;
|
||||
public List<string> Noms { get; set; }
|
||||
public string Nom { get; set; }
|
||||
public IRegles regles;
|
||||
public Partie partie;
|
||||
Joueur joueur;
|
||||
public int Tour { get; set; }
|
||||
public IEnumerable<IEnumerable<Jeton?>> Grille { get; set; }
|
||||
public IEnumerable<IEnumerable<Indicateur>> Indicateurs { get; set; }
|
||||
public ObservableCollection<Jeton?> Jetons { get; set; }
|
||||
|
||||
public Plateau()
|
||||
{
|
||||
InitializeComponent();
|
||||
regles = new ReglesClassiques();
|
||||
partie = new Partie(regles);
|
||||
partie.DemanderNom += DemanderNom;
|
||||
partie.DebutPartie += OnDebutPartie;
|
||||
partie.NouveauTour += NouveauTourAsync;
|
||||
partie.PartieTerminee += OnPartieTerminee;
|
||||
Jetons = new ObservableCollection<Jeton?>();
|
||||
BindingContext = this;
|
||||
}
|
||||
|
||||
private void OnSubmitClicked(object sender, EventArgs e)
|
||||
{
|
||||
Noms = new List<string> { PlayerNameEntry1.Text, PlayerNameEntry2.Text };
|
||||
partie.Jouer();
|
||||
}
|
||||
|
||||
private void DemanderNom(object sender, DemanderNomEventArgs e)
|
||||
{
|
||||
int joueurIndex = e.Indice - 1;
|
||||
if (joueurIndex >= 0 && joueurIndex < Noms.Count())
|
||||
{
|
||||
e.JoueurBuilder.Nom(Noms[joueurIndex]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnDebutPartie(object sender, DebutPartieEventArgs e)
|
||||
{
|
||||
DisplayAlert("Début de la partie", "La partie commence !", "OK");
|
||||
}
|
||||
|
||||
private void OnPartieTerminee(object sender, PartieTermineeEventArgs e)
|
||||
{
|
||||
DisplayAlert("Partie terminée", "La partie est terminée !", "OK");
|
||||
}
|
||||
|
||||
private void OnColorButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
Button button = (Button)sender;
|
||||
string colorText = button.Text;
|
||||
selectedColor = GetColorFromString(colorText);
|
||||
System.Diagnostics.Debug.WriteLine($"Couleur sélectionnée: {selectedColor}");
|
||||
}
|
||||
|
||||
private void OnValidateButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
if (selectedColor.HasValue)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Couleur validée: {selectedColor.Value}");
|
||||
OnJetonSelected(selectedColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSupprimmerButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
OnJetonSelected(null);
|
||||
}
|
||||
|
||||
public async void NouveauTourAsync(Object? sender, NouveauTourEventArgs e)
|
||||
{
|
||||
Code code = e.Code;
|
||||
Tour = e.Tour;
|
||||
Grille = e.Grille;
|
||||
Indicateurs = e.Indicateurs;
|
||||
joueur = regles.JoueurCourant().Item1;
|
||||
Nom = joueur.Nom;
|
||||
QuandPropertyChanged(nameof(joueur));
|
||||
QuandPropertyChanged(nameof(Tour));
|
||||
QuandPropertyChanged(nameof(Grille));
|
||||
QuandPropertyChanged(nameof(Indicateurs));
|
||||
QuandPropertyChanged(nameof(Nom));
|
||||
|
||||
while (!code.EstComplet())
|
||||
{
|
||||
await DisplayAlert("Cliquer sur une couleur", "Cliquer sur une couleur", "OK");
|
||||
System.Diagnostics.Debug.WriteLine("En attente de la sélection d'un jeton...");
|
||||
|
||||
CouleurSelectionResult result = await WaitForCouleurSelection();
|
||||
if (result.IsSuppression)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Supprimer le dernier jeton suite à une suppression");
|
||||
|
||||
try
|
||||
{
|
||||
code.SupprimerDernierJeton();
|
||||
}
|
||||
catch (CodeVideException)
|
||||
{
|
||||
await DisplayAlert("Le code est deja vide", "Vous ne pouvez pas supprimmer", "OK");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Jeton jetonSelectionne = new Jeton(result.Couleur.Value);
|
||||
System.Diagnostics.Debug.WriteLine($"Jeton sélectionné: {jetonSelectionne.Couleur}");
|
||||
code.AjouterJeton(jetonSelectionne);
|
||||
}
|
||||
|
||||
Jetons.Clear();
|
||||
foreach (Jeton? jeton in code.Jetons())
|
||||
{
|
||||
if (jeton.HasValue)
|
||||
{
|
||||
Jetons.Add(jeton.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
e.Joueur.Code(code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Task<CouleurSelectionResult> WaitForCouleurSelection()
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("WaitForJetonSelection appelé");
|
||||
CouleurSelectedTask = new TaskCompletionSource<CouleurSelectionResult>();
|
||||
return CouleurSelectedTask.Task;
|
||||
}
|
||||
|
||||
private void OnJetonSelected(Couleur? selectedColor)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("OnJetonSelected appelé");
|
||||
|
||||
if (CouleurSelectedTask != null && !CouleurSelectedTask.Task.IsCompleted)
|
||||
{
|
||||
if (selectedColor.HasValue)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"OnJetonSelected - complétion de la tâche avec: {selectedColor.Value}");
|
||||
CouleurSelectedTask.SetResult(CouleurSelectionResult.FromCouleur(selectedColor.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("OnJetonSelected - complétion de la tâche avec un jeton nul (suppression)");
|
||||
CouleurSelectedTask.SetResult(CouleurSelectionResult.Suppression());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("OnJetonSelected - tâche déjà complétée ou null");
|
||||
}
|
||||
}
|
||||
|
||||
private Couleur? GetColorFromString(string colorText)
|
||||
{
|
||||
return colorText.ToLower() switch
|
||||
{
|
||||
"rouge" => Couleur.ROUGE,
|
||||
"vert" => Couleur.VERT,
|
||||
"bleu" => Couleur.BLEU,
|
||||
"jaune" => Couleur.JAUNE,
|
||||
"blanc" => Couleur.BLANC,
|
||||
"noir" => Couleur.NOIR,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
public class CouleurSelectionResult
|
||||
{
|
||||
public Couleur? Couleur { get; }
|
||||
public bool IsSuppression { get; }
|
||||
|
||||
private CouleurSelectionResult(Couleur? couleur, bool isSuppression)
|
||||
{
|
||||
Couleur = couleur;
|
||||
IsSuppression = isSuppression;
|
||||
}
|
||||
|
||||
public static CouleurSelectionResult FromCouleur(Couleur couleur)
|
||||
{
|
||||
return new CouleurSelectionResult(couleur, false);
|
||||
}
|
||||
|
||||
public static CouleurSelectionResult Suppression()
|
||||
{
|
||||
return new CouleurSelectionResult(null, true);
|
||||
}
|
||||
}
|
||||
|
||||
using CoreLibrary;
|
||||
using CoreLibrary.Events;
|
||||
|
||||
namespace MauiSpark.Pages;
|
||||
|
||||
|
||||
public partial class Plateau : ContentPage
|
||||
{
|
||||
public Plateau(Partie p, NouveauTourEventArgs e)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = e;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?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:Class="MauiSpark.Views.UsernameEntryView">
|
||||
|
||||
<Grid
|
||||
Margin="0, 50"
|
||||
ColumnDefinitions="auto, *, 8*, *"
|
||||
RowDefinitions="auto">
|
||||
|
||||
<Label
|
||||
Text="Joueur X"
|
||||
FontSize="Large"
|
||||
Margin="50, 0, 0, 0"
|
||||
VerticalOptions="Center"
|
||||
HorizontalOptions="Center"/>
|
||||
|
||||
<Entry
|
||||
Grid.Column="2"
|
||||
FontSize="Medium"
|
||||
Margin="50, 0"/>
|
||||
</Grid>
|
||||
|
||||
</ContentView>
|
@ -1,9 +0,0 @@
|
||||
namespace MauiSpark.Views;
|
||||
|
||||
public partial class UsernameEntryView : ContentView
|
||||
{
|
||||
public UsernameEntryView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue