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.
117 lines
3.0 KiB
117 lines
3.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using TheGameExtreme.model.card;
|
|
using TheGameExtreme.model.@event;
|
|
using TheGameExtreme.model.manager;
|
|
|
|
namespace TheGameExtreme.viewmodel
|
|
{
|
|
public class Main : INotifyPropertyChanged
|
|
{
|
|
|
|
public event EventHandler<TopRangeChangedEventArgs> BindingChanged;
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
private string alert = "";
|
|
public String Alert
|
|
{
|
|
get { return alert; }
|
|
set
|
|
{
|
|
alert = value;
|
|
OnPropertyChanged("Alert");
|
|
}
|
|
}
|
|
protected virtual void OnPropertyChanged(string info)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
|
|
}
|
|
|
|
private GameManager gameManager;
|
|
public List<Card> CurrentHand { get; set; }
|
|
private ObservableCollection<Stack<Card>> ListOrderedStacks;
|
|
|
|
|
|
public Main()
|
|
{
|
|
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 = new ObservableCollection<Stack<Card>>(gameManager.ListOrderedStacks);
|
|
}
|
|
|
|
protected internal void OnPlayerChanged(object source, PlayerChangedEventArgs args)
|
|
{
|
|
CurrentHand = args.NewCurrentHand;
|
|
}
|
|
|
|
public void OnTopRangeChanged(object source, TopRangeChangedEventArgs args)
|
|
{
|
|
BindingChanged?.Invoke(this, args);
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @return booléen de fin de jeu
|
|
*/
|
|
public bool played(int numStack, int valueCard)
|
|
{
|
|
if (gameManager.isCanPlay())
|
|
{
|
|
return playOneCard(numStack, valueCard);
|
|
}
|
|
else
|
|
{
|
|
Alert = "Le joueur n'a plus de carte dans sa main!";
|
|
// Faire un toast
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @return booléen de fin de jeu
|
|
*/
|
|
private bool playOneCard(int numStack, int valueCard)
|
|
{
|
|
try
|
|
{
|
|
gameManager.joue(valueCard, numStack);
|
|
if (gameManager.EndMessage != null)
|
|
{
|
|
Alert = gameManager.EndMessage;
|
|
return true;
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
// Faire un toast
|
|
Alert = e.Message;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool endTurn()
|
|
{
|
|
try
|
|
{
|
|
return gameManager.endTurn();
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
Alert = e.Message;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|