You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.0 KiB

using System;
using System.Collections.Generic;
using TheGameExtreme.IO;
using Xamarin.Forms;
namespace TheGameExtreme.view
{
public partial class GamePreparationPage : ContentPage
{
public List<int> listNbPlayer = new List<int> { 1, 2, 3, 4, 5 };
public List<string> listGameMode = new List<string> { "entières", "relatives", "décimales", "dizaines", "centaines", "millièmes", "fractionnées" };
public List<int> listNbStack = new List<int> { 4, 6, 8 };
public List<int> listNbCard = new List<int> { 100, 80, 60, 40 };
public GamePreparationPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
PlayerSelecter.ItemsSource = listNbPlayer;
LoadParameterNbPlayerGamePreparation();
SelectMode.ItemsSource = listGameMode;
LoadParameterGameModeValueGamePreparation();
SelectNbStack.ItemsSource = listNbStack;
LoadParameterNbStacksGamePreparation();
SelectNbCard.ItemsSource = listNbCard;
LoadParameterNbCardsGamePreparation();
}
private async void Back(object sender, EventArgs e)
{
IOGamePreparation.SaveParamaterGamePreparationNbPlayers(PlayerSelecter.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbCards(SelectNbCard.SelectedIndex);
await Navigation.PopAsync();
}
protected override bool OnBackButtonPressed()
{
IOGamePreparation.SaveParamaterGamePreparationNbPlayers(PlayerSelecter.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationGameModeValue(SelectMode.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbStacks(SelectNbStack.SelectedIndex);
IOGamePreparation.SaveParameterGamePreparationNbCards(SelectNbCard.SelectedIndex);
return base.OnBackButtonPressed();
}
private async void Play(object sender, EventArgs args)
{
List<string> playersNames = new List<string>();
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);
IOGamePreparation.SaveParameterGamePreparationNbCards(SelectNbCard.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;
}
public void LoadParameterNbCardsGamePreparation()
{
int nbCards = IOGamePreparation.LoadParameterGamePreparationNbCards();
SelectNbCard.SelectedIndex = nbCards;
}
}
}