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.
157 lines
5.1 KiB
157 lines
5.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using TheGameExtreme.model.effect;
|
|
using TheGameExtreme.model.@event;
|
|
|
|
namespace TheGameExtreme.model.manager
|
|
{
|
|
public class SoloGameManager : GameManager
|
|
{
|
|
|
|
public SoloGameManager(int nbPlayer, List<String> players)
|
|
: base(nbPlayer, players)
|
|
{
|
|
|
|
}
|
|
|
|
public override void endTurn()
|
|
{
|
|
pioche();
|
|
|
|
currentIndexPlayer += 1;
|
|
if (currentIndexPlayer == playerList.Count)
|
|
{
|
|
currentIndexPlayer = 0;
|
|
}
|
|
CurrentHand = playerList[currentIndexPlayer].getCardList();
|
|
OnPlayerChanged(new PlayerChangedEventArgs(CurrentHand));
|
|
|
|
if (isEndGame()) // Ajouter le score en calculant les cartes restantes dans la pile et dans les mains des joueurs
|
|
{
|
|
if (win)
|
|
{
|
|
Console.WriteLine("Le jeu est terminé!\n Bravo vous avez gagné!");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Le jeu est terminé!\n Désolé, vous avez perdu... Essayez encore!");
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void pioche()
|
|
{
|
|
int nbPickedCard = nbMaxCard - CurrentHand.Count;
|
|
for (int i = 0; i < nbPickedCard; i++)
|
|
{
|
|
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;
|
|
|
|
|
|
|
|
|
|
//playerList.ForEach(player =>
|
|
//{
|
|
// if (player.getCardList().Count != 0)
|
|
// {
|
|
// List<Card> playableCard = new List<Card>();
|
|
// List<Card> cardList = new List<Card>(player.getCardList());
|
|
// cardList.ForEach(card =>
|
|
// {
|
|
// if (card.Value < descendingCardListOrder1.Peek().Value || card.Value < descendingCardListOrder2.Peek().Value || card.Value > ascendingCardListOrder1.Peek().Value || card.Value > ascendingCardListOrder2.Peek().Value)
|
|
// {
|
|
// playableCard.Add(card);
|
|
// }
|
|
// });
|
|
// if (playableCard.Count < 3 && playableCard.Count >= 2)
|
|
// {
|
|
// foreach (Card c in playableCard)
|
|
// {
|
|
// // Tester si c'est une classe ThreeCard
|
|
// // Si oui:
|
|
// if (currentPlayer == playerList.IndexOf(player))
|
|
// {
|
|
// win = false;
|
|
// endGame = true;
|
|
// return;
|
|
// }
|
|
// }
|
|
// }
|
|
// else if (playableCard.Count < 2)
|
|
// {
|
|
// if (currentPlayer == playerList.IndexOf(player))
|
|
// {
|
|
// win = false;
|
|
// endGame = true;
|
|
// return;
|
|
// }
|
|
// }
|
|
// }
|
|
//});
|
|
}
|
|
|
|
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 < 3 && playableCard.Count >= 2)
|
|
{
|
|
foreach (Card c in playableCard)
|
|
{
|
|
if (c.Equals(typeof(ThreeCard)))
|
|
{
|
|
win = false;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
else if (playableCard.Count < 2)
|
|
{
|
|
win = false;
|
|
return true;
|
|
}
|
|
else if (effectLose())
|
|
{
|
|
win = false;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
protected override bool effectLose()
|
|
{
|
|
foreach (Stack<Card> orderedStack in ListOrderedStacks)
|
|
{
|
|
if (orderedStack.Peek().GetType() == typeof(EndGame))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|