|
|
@ -1,6 +1,8 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using TheGameExtreme.model.card;
|
|
|
|
using TheGameExtreme.model.card;
|
|
|
|
|
|
|
|
using TheGameExtreme.model.deck;
|
|
|
|
|
|
|
|
using TheGameExtreme.model.@event;
|
|
|
|
using TheGameExtreme.model.gameActions;
|
|
|
|
using TheGameExtreme.model.gameActions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TheGameExtreme.model.gameActions.classic
|
|
|
|
namespace TheGameExtreme.model.gameActions.classic
|
|
|
@ -10,117 +12,213 @@ namespace TheGameExtreme.model.gameActions.classic
|
|
|
|
|
|
|
|
|
|
|
|
protected List<GameAction> gameActions;
|
|
|
|
protected List<GameAction> gameActions;
|
|
|
|
protected Piles piles;
|
|
|
|
protected Piles piles;
|
|
|
|
|
|
|
|
public event EventHandler<TopRangeChangedEventArgs> TopRangeChanged;
|
|
|
|
|
|
|
|
protected int nbCardAtBeginOfTurn = 7;
|
|
|
|
|
|
|
|
protected Deck deck;
|
|
|
|
|
|
|
|
private int nbMaxCard;
|
|
|
|
|
|
|
|
|
|
|
|
public GameMode()
|
|
|
|
public GameMode()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gameActions = new List<GameAction>();
|
|
|
|
gameActions = new List<GameAction>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void load(int nbPlayer, List<Player> players)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
piles = new Piles();
|
|
|
|
|
|
|
|
|
|
|
|
gameActions.Add(new Piocher(piles));
|
|
|
|
gameActions.Add(new Piocher(piles));
|
|
|
|
gameActions.Add(new JouerUneCarte(piles));
|
|
|
|
gameActions.Add(new JouerUneCarte(piles));
|
|
|
|
gameActions.Add(new TerminerSonTour(piles));
|
|
|
|
gameActions.Add(new TerminerSonTour(piles));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createDeck();
|
|
|
|
|
|
|
|
defineNbMaxCard(nbPlayer);
|
|
|
|
|
|
|
|
distribueCard(players);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void load()
|
|
|
|
protected void createDeck()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
piles = new Piles();
|
|
|
|
switch (true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case false:
|
|
|
|
|
|
|
|
deck = new ClassicDeck();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
deck = new ExtremeDeck();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void pioche()
|
|
|
|
protected void defineNbMaxCard(int nbPlayer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
((Piocher)gameActions[0]).pioche();
|
|
|
|
switch (nbPlayer)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
nbMaxCard = 8;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
nbMaxCard = 7;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
nbMaxCard = 6;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void distribueCard(List<Player> players)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < nbMaxCard; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
players.ForEach(player =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int r = new Random().Next(0, deck.size() - 1);
|
|
|
|
|
|
|
|
player.pioche(deck.getCard(r));
|
|
|
|
|
|
|
|
deck.removeAt(r);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void pioche(List<Card> CurrentHand, Player player)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
((Piocher)gameActions[0]).pioche(CurrentHand, deck, player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void playCard(int valueCard, List<Card> CurrentHand, int orderedStackSelected, Player player, List<Card> CurrentCardPlayed)
|
|
|
|
public void playCard(int valueCard, List<Card> CurrentHand, int orderedStackSelected, Player player, List<Card> CurrentCardPlayed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
((JouerUneCarte)gameActions[1]).play(valueCard, CurrentHand, orderedStackSelected, player, CurrentCardPlayed);
|
|
|
|
if (((JouerUneCarte)gameActions[1]).play(valueCard, CurrentHand, orderedStackSelected, player, CurrentCardPlayed))
|
|
|
|
if (CurrentHand.Count == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
endTurn(); // Presque bon, oublie juste d'afficher les nouvelles cartes
|
|
|
|
OnTopRangeChanged(new TopRangeChangedEventArgs(piles.getStack(orderedStackSelected).Peek(), ((JouerUneCarte)gameActions[1]).OldCard, orderedStackSelected));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void endTurn()
|
|
|
|
protected internal void OnTopRangeChanged(TopRangeChangedEventArgs args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
((TerminerSonTour)gameActions[2]).end();
|
|
|
|
TopRangeChanged?.Invoke(this, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool endTurn(List<Card> CurrentHand, List<Card> CurrentCardPlayed, Player player)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
((TerminerSonTour)gameActions[2]).end(CurrentHand, nbCardAtBeginOfTurn, CurrentCardPlayed);
|
|
|
|
|
|
|
|
pioche(CurrentHand, player);
|
|
|
|
|
|
|
|
//currentIndexPlayer += 1;
|
|
|
|
|
|
|
|
//if (currentIndexPlayer == playerList.Count)
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// currentIndexPlayer = 0;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//CurrentHand = playerList[currentIndexPlayer].getCardList();
|
|
|
|
|
|
|
|
//OnPlayerChanged(new PlayerChangedEventArgs(CurrentHand, playerList[currentIndexPlayer].Pseudo));
|
|
|
|
|
|
|
|
nbCardAtBeginOfTurn = CurrentHand.Count;
|
|
|
|
|
|
|
|
CurrentCardPlayed.Clear();
|
|
|
|
|
|
|
|
//if (isEndGame()) // Ajouter le score en calculant les cartes restantes dans la pile et dans les mains des joueurs
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// displayWinner();
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//else
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
return false; // Changer
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//protected void displayWinner()
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// if (win)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// EndMessage = "Le jeu est terminé!\n Bravo vous avez gagné!";
|
|
|
|
|
|
|
|
// EndMessage = AppRessource.StrWin;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// private List<Rule> playRule = new List<Rule>();
|
|
|
|
|
|
|
|
// private List<Rule> beforeEndTurnRule = new List<Rule>();
|
|
|
|
|
|
|
|
// private List<Rule> endTurnRule = new List<Rule>();
|
|
|
|
|
|
|
|
// private List<Rule> commonRule = new List<Rule>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public GameMode()
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public void addPlayRule(PlayRule rule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// playRule?.Add(rule);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public void addEndTurnRule(EndTurnRule rule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// endTurnRule?.Add(rule);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public void addBeforeEndTurnRule(BeforeEndTurnRule rule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// beforeEndTurnRule?.Add(rule);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public void addCommonRule(Rule rule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// // Vérifier que se ne soit ni une PlayRule, ni une EndTurnRule ?
|
|
|
|
|
|
|
|
// commonRule?.Add(rule);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public bool checkPlayRule(Card card, Stack<Card> orderedStack, bool bottomUp, List<Card> CurrentHand)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// foreach(PlayRule rule in playRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (rule.Test(card, orderedStack, bottomUp, CurrentHand)) // Gestion des messages pour savoir qu'elle règle n'est pas respecter.
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// foreach (Rule rule in commonRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public bool checkBeforeEndTurnRule(List<Card> CurrentCardPlayed, int nbCardAtBeginOfTurn, List<Card> CurrentHand)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// foreach (BeforeEndTurnRule rule in beforeEndTurnRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (!rule.Test(CurrentCardPlayed, nbCardAtBeginOfTurn, CurrentHand)) // Gestion des messages pour savoir qu'elle règle n'est pas respecter.
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// foreach (Rule rule in commonRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public bool checkEndTurnRule(List<Card> CurrentCardPlayed, int nbCardAtBeginOfTurn, List<Card> CurrentHand)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// foreach (EndTurnRule rule in endTurnRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (!rule.Test(CurrentCardPlayed, nbCardAtBeginOfTurn, CurrentHand)) // Gestion des messages pour savoir qu'elle règle n'est pas respecter.
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// foreach (Rule rule in commonRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
// private List<Rule> playRule = new List<Rule>();
|
|
|
|
// }
|
|
|
|
// private List<Rule> beforeEndTurnRule = new List<Rule>();
|
|
|
|
// return true;
|
|
|
|
// private List<Rule> endTurnRule = new List<Rule>();
|
|
|
|
// }
|
|
|
|
// private List<Rule> commonRule = new List<Rule>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public GameMode()
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public void addPlayRule(PlayRule rule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// playRule?.Add(rule);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public void addEndTurnRule(EndTurnRule rule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// endTurnRule?.Add(rule);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public void addBeforeEndTurnRule(BeforeEndTurnRule rule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// beforeEndTurnRule?.Add(rule);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public void addCommonRule(Rule rule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// // Vérifier que se ne soit ni une PlayRule, ni une EndTurnRule ?
|
|
|
|
|
|
|
|
// commonRule?.Add(rule);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public bool checkPlayRule(Card card, Stack<Card> orderedStack, bool bottomUp, List<Card> CurrentHand)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// foreach(PlayRule rule in playRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (rule.Test(card, orderedStack, bottomUp, CurrentHand)) // Gestion des messages pour savoir qu'elle règle n'est pas respecter.
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// foreach (Rule rule in commonRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public bool checkBeforeEndTurnRule(List<Card> CurrentCardPlayed, int nbCardAtBeginOfTurn, List<Card> CurrentHand)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// foreach (BeforeEndTurnRule rule in beforeEndTurnRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (!rule.Test(CurrentCardPlayed, nbCardAtBeginOfTurn, CurrentHand)) // Gestion des messages pour savoir qu'elle règle n'est pas respecter.
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// foreach (Rule rule in commonRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public bool checkEndTurnRule(List<Card> CurrentCardPlayed, int nbCardAtBeginOfTurn, List<Card> CurrentHand)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// foreach (EndTurnRule rule in endTurnRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if (!rule.Test(CurrentCardPlayed, nbCardAtBeginOfTurn, CurrentHand)) // Gestion des messages pour savoir qu'elle règle n'est pas respecter.
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// foreach (Rule rule in commonRule)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|