using System; using System.Collections.Generic; using TheGameExtreme.IO; using Xamarin.Forms; namespace TheGameExtreme.view { public partial class GamePreparationPage : ContentPage { public List listNbPlayer = new List { 1, 2, 3, 4, 5 }; public List listGameMode = new List { "entières", "relatives", "décimales", "dizaine", "centaine", "millième", "fractionnées" }; public List listNbStack = new List { 4, 6, 8 }; public GamePreparationPage() { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); PlayerSelecter.ItemsSource = listNbPlayer; LoadParameterNbPlayerGamePreparation(); SelectMode.ItemsSource = listGameMode; LoadParameterGameModeValueGamePreparation(); SelectNbStack.ItemsSource = listNbStack; LoadParameterNbStacksGamePreparation(); } private async void Back(object sender, EventArgs e) { IOGamePreparation.SaveParamaterGamePreparationNbPlayers(PlayerSelecter.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex); await Navigation.PopAsync(); } protected override bool OnBackButtonPressed() { IOGamePreparation.SaveParamaterGamePreparationNbPlayers(PlayerSelecter.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex); return base.OnBackButtonPressed(); } private async void Play(object sender, EventArgs args) { List playersNames = new List(); for (int i = 1; i < NameList.Children.Count; i++) { playersNames.Add(((Entry)NameList.Children[i]).Text); if (string.IsNullOrWhiteSpace(playersNames[playersNames.Count - 1])) { await DisplayAlert("Erreur pseudo", AppRessource.StrEnterPseudo, "OK"); return; } } IOGamePreparation.SaveParamaterGamePreparationNbPlayers(PlayerSelecter.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex); IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex); await Navigation.PushAsync(new MainPage(playersNames, (int)SelectNbStack.SelectedItem, (int)SelectMode.SelectedIndex)); } private void ChangedPseudo(object sender, EventArgs args) { while (NameList.Children.Count - 1 != (int)PlayerSelecter.SelectedItem) { if (NameList.Children.Count - 1 < (int)PlayerSelecter.SelectedItem) { Entry e = new Entry { Placeholder = "Pseudo", BackgroundColor = (Color)Application.Current.Resources["SkyBlueColor"], WidthRequest = 200, MinimumWidthRequest = 50, HorizontalOptions = LayoutOptions.Center }; NameList.Children.Add(e); } else { NameList.Children.RemoveAt(NameList.Children.Count - 1); } } } public void LoadParameterNbPlayerGamePreparation() { int nbJoueurs = IOGamePreparation.LoadParameterGamePreparationNbPlayers(); PlayerSelecter.SelectedIndex = nbJoueurs; } public void LoadParameterGameModeValueGamePreparation() { int gameModeValue = IOGamePreparation.LoadParameterGamePreparationGameModeValue(); SelectMode.SelectedIndex = gameModeValue; } public void LoadParameterNbStacksGamePreparation() { int nbStackSer = IOGamePreparation.LoadParamaterGamePreparationNbStacks(); SelectNbStack.SelectedIndex = nbStackSer; } } }