|
|
|
@ -1,164 +0,0 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using TheGameExtreme.model.card;
|
|
|
|
|
using TheGameExtreme.model.@event;
|
|
|
|
|
|
|
|
|
|
namespace TheGameExtreme.model.manager
|
|
|
|
|
{
|
|
|
|
|
public class SoloGameManager : GameManager
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public SoloGameManager(int nbPlayer, List<String> players)
|
|
|
|
|
: base(nbPlayer, players)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool endTurn()
|
|
|
|
|
{
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
verifyNbCardPlay();
|
|
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
// Vérifie que l'utilisateur a bien joué deux cartes
|
|
|
|
|
>>>>>>> c1e072686aecc6833e1faf062739820e55484d86
|
|
|
|
|
pioche();
|
|
|
|
|
|
|
|
|
|
currentIndexPlayer += 1;
|
|
|
|
|
if (currentIndexPlayer == playerList.Count)
|
|
|
|
|
{
|
|
|
|
|
currentIndexPlayer = 0;
|
|
|
|
|
}
|
|
|
|
|
CurrentHand = playerList[currentIndexPlayer].getCardList();
|
|
|
|
|
OnPlayerChanged(new PlayerChangedEventArgs(CurrentHand));
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void verifyNbCardPlay()
|
|
|
|
|
{
|
|
|
|
|
foreach (Card cardPlayed in CurrentCardPlayed)
|
|
|
|
|
{
|
|
|
|
|
if (cardPlayed.GetType() == typeof(ThreeCard))
|
|
|
|
|
{
|
|
|
|
|
if ((nbCardAtBeginOfTurn - CurrentHand.Count) < 3) // Penser à vérifier s'il a joué une ThreeCard pour regarder s'il a bien joué 3 cartes
|
|
|
|
|
{
|
|
|
|
|
testIsEndGame();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ((nbCardAtBeginOfTurn - CurrentHand.Count) < 2) // Penser à vérifier s'il a joué une ThreeCard pour regarder s'il a bien joué 3 cartes
|
|
|
|
|
{
|
|
|
|
|
testIsEndGame();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void testIsEndGame()
|
|
|
|
|
{
|
|
|
|
|
if (isEndGame())
|
|
|
|
|
{
|
|
|
|
|
displayWinner();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Vous n'avez pas joué assez de carte!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void displayWinner()
|
|
|
|
|
{
|
|
|
|
|
if (win)
|
|
|
|
|
{
|
|
|
|
|
EndMessage = "Le jeu est terminé!\n Bravo vous avez gagné!";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void pioche()
|
|
|
|
|
{
|
|
|
|
|
int nbPickedCard = nbMaxCard - CurrentHand.Count;
|
|
|
|
|
for (int i = 0; i < nbPickedCard; i++)
|
|
|
|
|
{
|
|
|
|
|
if (deck.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int random = new Random().Next(0, deck.Count - 1);
|
|
|
|
|
playerList[currentIndexPlayer].pioche(deck[random]);
|
|
|
|
|
deck.RemoveAt(random);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool isEndGame()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentHand.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
List<Card> playableCard = new List<Card>();
|
|
|
|
|
tryToFindSoluce(playableCard);
|
|
|
|
|
return testEndGame(playableCard);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void tryToFindSoluce(List<Card> playableCard)
|
|
|
|
|
{
|
|
|
|
|
CurrentHand.ForEach(card =>
|
|
|
|
|
{
|
|
|
|
|
if (card.Value > ListOrderedStacks[0].Peek().Value || card.Value > ListOrderedStacks[1].Peek().Value || card.Value < ListOrderedStacks[2].Peek().Value || card.Value < ListOrderedStacks[3].Peek().Value)
|
|
|
|
|
{
|
|
|
|
|
playableCard.Add(card);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool testEndGame(List<Card> playableCard)
|
|
|
|
|
{
|
|
|
|
|
if (playableCard.Count == 2)
|
|
|
|
|
{
|
|
|
|
|
foreach (Card c in playableCard)
|
|
|
|
|
{
|
|
|
|
|
if (c.Equals(typeof(ThreeCard)))
|
|
|
|
|
{
|
|
|
|
|
win = false;
|
|
|
|
|
EndMessage = "Le jeu est terminé!\n Désolé, vous avez perdu... Vous deviez jouer trois cartes à cause de l'effet \"Trois cartes joué\" hors votre jeu ne permet pas d'en jouer autant! Essayez encore!";
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (playableCard.Count < 2)
|
|
|
|
|
{
|
|
|
|
|
win = false;
|
|
|
|
|
EndMessage = "Le jeu est terminé!\n Désolé, vous avez perdu... Essayez encore!";
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (effectLose())
|
|
|
|
|
{
|
|
|
|
|
win = false;
|
|
|
|
|
EndMessage = "Désolé, vous n'avez pas recouvert la tête de mort... Réessayez ;)";
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool effectLose()
|
|
|
|
|
{
|
|
|
|
|
foreach (Stack<Card> orderedStack in ListOrderedStacks)
|
|
|
|
|
{
|
|
|
|
|
if (orderedStack.Peek().GetType() == typeof(EndGameCard))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|