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.

96 lines
2.5 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using TheGameExtreme.model;
using TheGameExtreme.model.@event;
using TheGameExtreme.model.manager;
using Xamarin.Forms;
namespace TheGameExtreme.viewmodel
{
public class Main : INotifyPropertyChanged
{
Label alert;
private GameManager gameManager;
public List<Card> CurrentHand { get; set; }
public List<Stack<Card>> listOrderedStacks;
public List<Stack<Card>> ListOrderedStacks
{
get { return listOrderedStacks; }
set
{
listOrderedStacks = value;
OnPropertyChanged("Stack change");
}
}
private void OnPropertyChanged(string info)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
}
public event EventHandler<TopRangeChangedEventArgs> BindingChanged;
public event PropertyChangedEventHandler PropertyChanged;
public Main(Label alert)
{
this.alert = alert;
gameManager = new SoloGameManager(2, new List<String> { "Clément", "Baptiste" }) ; // Donner le nom des joueurs
gameManager.TopRangeChanged += OnTopRangeChanged;
gameManager.PlayerChanged += OnPlayerChanged;
CurrentHand = gameManager.CurrentHand;
ListOrderedStacks = gameManager.ListOrderedStacks;
}
public Main()
{
}
protected internal void OnPlayerChanged(object source, PlayerChangedEventArgs args)
{
CurrentHand = args.NewCurrentHand;
}
public void OnTopRangeChanged(object source, TopRangeChangedEventArgs args)
{
BindingChanged?.Invoke(this, args);
}
public void played(int numStack, int valueCard)
{
if (gameManager.isCanPlay())
{
playOneCard(numStack, valueCard);
}
else
{
alert.Text = "Le joueur n'a plus de carte dans sa main!";
// Faire un toast
}
}
private void playOneCard(int numStack, int valueCard)
{
try
{
gameManager.joue(valueCard, numStack);
}
catch(Exception e)
{
// Faire un toast
alert.Text = e.Message;
}
}
public void endTurn()
{
gameManager.endTurn();
}
}
}