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.
175 lines
5.5 KiB
175 lines
5.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TheGameExtreme.model;
|
|
using TheGameExtreme.model.manager;
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Xaml;
|
|
using TheGameExtreme.model.@event;
|
|
using TheGameExtreme.viewmodel;
|
|
|
|
namespace TheGameExtreme
|
|
{
|
|
// Learn more about making custom code visible in the Xamarin.Forms previewer
|
|
// by visiting https://aka.ms/xamarinforms-previewer
|
|
[DesignTimeVisible(false)]
|
|
public partial class MainPage : ContentPage
|
|
{
|
|
private bool isFirst = true;
|
|
private Main viewmodel;
|
|
private List<CheckBox> stacks = new List<CheckBox>();
|
|
Button button = new Button();
|
|
|
|
|
|
public MainPage()
|
|
{
|
|
InitializeComponent();
|
|
|
|
stacks.Add(checkbox0);
|
|
stacks.Add(checkbox1);
|
|
stacks.Add(checkbox2);
|
|
stacks.Add(checkbox3);
|
|
button.Text = "Retry";
|
|
button.Clicked += retry;
|
|
|
|
viewmodel = new Main();
|
|
|
|
viewmodel.BindingChanged += OnBindingChanged;
|
|
|
|
Alert.SetBinding(Label.TextProperty, new Binding("Alert", source: viewmodel));
|
|
|
|
inflateHand();
|
|
|
|
//pile0.SetBinding(Label.TextProperty, new Binding("Stack0", source: viewmodel));
|
|
//pile1.SetBinding(Label.TextProperty, new Binding("Stack1", source: viewmodel));
|
|
//pile2.SetBinding(Label.TextProperty, new Binding("Stack2", source: viewmodel));
|
|
//pile3.SetBinding(Label.TextProperty, new Binding("Stack3", source: viewmodel));
|
|
//card1.SetBinding(Button.TextProperty, new Binding("ValueCard1", source: viewmodel));
|
|
//card2.SetBinding(Button.TextProperty, new Binding("ValueCard2", source: viewmodel));
|
|
//card3.SetBinding(Button.TextProperty, new Binding("ValueCard3", source: viewmodel));
|
|
//card4.SetBinding(Button.TextProperty, new Binding("ValueCard4", source: viewmodel));
|
|
//card5.SetBinding(Button.TextProperty, new Binding("ValueCard5", source: viewmodel));
|
|
//card6.SetBinding(Button.TextProperty, new Binding("ValueCard6", source: viewmodel));
|
|
//card7.SetBinding(Button.TextProperty, new Binding("ValueCard7", source: viewmodel));
|
|
}
|
|
|
|
private void inflateHand()
|
|
{
|
|
Hand.Children.Clear();
|
|
for (int i = 0; i < viewmodel.CurrentHand.Count; i++)
|
|
{
|
|
Button card = new Button();
|
|
card.Text = viewmodel.CurrentHand[i].Value.ToString();
|
|
card.Clicked += played;
|
|
Hand.Children.Add(card);
|
|
}
|
|
}
|
|
|
|
private void OnBindingChanged(object sender, TopRangeChangedEventArgs args)
|
|
{
|
|
switch (args.NumStackChanged)
|
|
{
|
|
case 0:
|
|
pile0.Text = args.NewTopRangeCard.Value.ToString();
|
|
break;
|
|
case 1:
|
|
pile1.Text = args.NewTopRangeCard.Value.ToString();
|
|
break;
|
|
case 2:
|
|
pile2.Text = args.NewTopRangeCard.Value.ToString();
|
|
break;
|
|
case 3:
|
|
pile3.Text = args.NewTopRangeCard.Value.ToString();
|
|
break;
|
|
}
|
|
|
|
for (int i = 0; i < Hand.Children.Count; i++)
|
|
{
|
|
Button b = Hand.Children[i] as Button;
|
|
if (String.Equals(b.Text,args.NewTopRangeCard.Value.ToString()))
|
|
{
|
|
Hand.Children.RemoveAt(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void played(object sender, EventArgs args)
|
|
{
|
|
viewmodel.Alert = "";
|
|
|
|
int numStack = 0;
|
|
bool hasFind = false;
|
|
stacks.ForEach(checkbox =>
|
|
{
|
|
if (checkbox.IsChecked)
|
|
{
|
|
hasFind = true;
|
|
if (viewmodel.played(numStack, Convert.ToInt32((sender as Button).Text)))
|
|
{
|
|
botPanel.Children.Add(button);
|
|
}
|
|
}
|
|
numStack += 1;
|
|
});
|
|
|
|
if (!hasFind)
|
|
{
|
|
viewmodel.Alert = "Aucune pile selectionné! Veuillez séléctionner une pile.";
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void radioButton(object sender, EventArgs args)
|
|
{
|
|
if (isFirst)
|
|
{
|
|
isFirst = false;
|
|
|
|
stacks.ForEach(checkbox =>
|
|
{
|
|
if (!checkbox.Equals(sender))
|
|
{
|
|
checkbox.IsChecked = false;
|
|
}
|
|
});
|
|
|
|
isFirst = true;
|
|
}
|
|
}
|
|
|
|
private void retry(object sender, EventArgs args)
|
|
{
|
|
viewmodel = new Main();
|
|
|
|
viewmodel.BindingChanged += OnBindingChanged;
|
|
|
|
Alert.SetBinding(Label.TextProperty, new Binding("Alert", source: viewmodel));
|
|
|
|
inflateHand();
|
|
|
|
pile0.Text = "1";
|
|
pile1.Text = "1";
|
|
pile2.Text = "100";
|
|
pile3.Text = "100";
|
|
|
|
botPanel.Children.Remove(button);
|
|
}
|
|
|
|
private void endTurn(object sender, EventArgs args)
|
|
{
|
|
if (viewmodel.endTurn())
|
|
{
|
|
botPanel.Children.Add(button);
|
|
}
|
|
else
|
|
{
|
|
inflateHand();
|
|
}
|
|
}
|
|
}
|
|
}
|