From 1ff7e4f3e28cb537c379edc6d09b0b2fd9f3763b Mon Sep 17 00:00:00 2001 From: cldupland Date: Mon, 2 Dec 2019 16:04:19 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20fractions,=20reste=20un=20petit?= =?UTF-8?q?=20probl=C3=A8me=20de=20taille=20pour=20le=20dessin=20des=20chi?= =?UTF-8?q?ffres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TheGameExtreme/TheGameExtreme.csproj | 1 + .../gameActions/decimals/GameModeDecimal.cs | 4 +- .../decimals/TerminerSonTourDecimal.cs | 2 +- .../gameActions/fraction/GameModeFraction.cs | 78 +++++++++++++++++++ .../fraction/JouerUneCarteFraction.cs | 77 ++++++++++++++++++ .../fraction/TerminerSonTourFraction.cs | 65 ++++++++++++++++ TheGameExtreme/view/MainPage.xaml.cs | 35 +++++++-- TheGameExtreme/view/TouchManipulationCard.cs | 12 +-- TheGameExtreme/viewmodel/Main.cs | 3 +- 9 files changed, 260 insertions(+), 17 deletions(-) create mode 100644 TheGameExtreme/model/gameActions/fraction/GameModeFraction.cs create mode 100644 TheGameExtreme/model/gameActions/fraction/JouerUneCarteFraction.cs create mode 100644 TheGameExtreme/model/gameActions/fraction/TerminerSonTourFraction.cs diff --git a/TheGameExtreme/TheGameExtreme.csproj b/TheGameExtreme/TheGameExtreme.csproj index 4defd0c..9660b77 100644 --- a/TheGameExtreme/TheGameExtreme.csproj +++ b/TheGameExtreme/TheGameExtreme.csproj @@ -30,6 +30,7 @@ + diff --git a/TheGameExtreme/model/gameActions/decimals/GameModeDecimal.cs b/TheGameExtreme/model/gameActions/decimals/GameModeDecimal.cs index a9972a6..4bb0c7c 100644 --- a/TheGameExtreme/model/gameActions/decimals/GameModeDecimal.cs +++ b/TheGameExtreme/model/gameActions/decimals/GameModeDecimal.cs @@ -40,7 +40,7 @@ namespace TheGameExtreme.model.gameActions.decimals } else { - Message = ((JouerUneCarte)gameActions[1]).ErrorMessage; + Message = ((JouerUneCarteDecimal)gameActions[1]).ErrorMessage; return false; } } @@ -57,7 +57,7 @@ namespace TheGameExtreme.model.gameActions.decimals } else { - Message = ((TerminerSonTour)gameActions[2]).ErrorMessage; + Message = ((TerminerSonTourDecimal)gameActions[2]).ErrorMessage; return false; } } diff --git a/TheGameExtreme/model/gameActions/decimals/TerminerSonTourDecimal.cs b/TheGameExtreme/model/gameActions/decimals/TerminerSonTourDecimal.cs index 25e2f77..7322e75 100644 --- a/TheGameExtreme/model/gameActions/decimals/TerminerSonTourDecimal.cs +++ b/TheGameExtreme/model/gameActions/decimals/TerminerSonTourDecimal.cs @@ -19,7 +19,7 @@ namespace TheGameExtreme.model.gameActions.decimals { // Vérifier la fin du jeu return true; - } + } else { ErrorMessage = AppResources.StrCardPlayedLessThanTwo; diff --git a/TheGameExtreme/model/gameActions/fraction/GameModeFraction.cs b/TheGameExtreme/model/gameActions/fraction/GameModeFraction.cs new file mode 100644 index 0000000..aec63a3 --- /dev/null +++ b/TheGameExtreme/model/gameActions/fraction/GameModeFraction.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using TheGameExtreme.model.card; +using TheGameExtreme.model.deck; +using TheGameExtreme.model.gameActions.abstractRules; +using TheGameExtreme.model.gameActions.classic; +using TheGameExtreme.model.piles; + +namespace TheGameExtreme.model.gameActions.fraction +{ + public class GameModeFraction : GameMode + { + public GameModeFraction(Piles piles, Deck deck) : base(piles, deck) + { + } + + override public void load(int nbPlayer, List players) + { + gameActions.Add(new PiocherClassic(Piles)); + gameActions.Add(new JouerUneCarteFraction(Piles)); + gameActions.Add(new TerminerSonTourFraction(Piles)); + + defineNbMaxCard(nbPlayer); + distribueCard(players); + } + + override public void pioche(List currentHand, Player player) + { + Message = null; + ((PiocherClassic)gameActions[0]).pioche(currentHand, deck, player, nbMaxCard); + quickSort(currentHand, 0, currentHand.Count - 1); + } + + override public bool playCard(decimal valueCard, List currentHand, int orderedStackSelected, Player player, List CurrentCardPlayed) + { + Message = null; + if (((JouerUneCarteFraction)gameActions[1]).play(valueCard, currentHand, orderedStackSelected, player, CurrentCardPlayed)) + { + return true; + } + else + { + Message = ((JouerUneCarteFraction)gameActions[1]).ErrorMessage; + return false; + } + } + + override public bool endTurn(List currentHand, List CurrentCardPlayed, Player player) + { + Message = null; + if (((TerminerSonTourFraction)gameActions[2]).end(currentHand, CurrentCardPlayed)) + { + pioche(currentHand, player); + CurrentCardPlayed.Clear(); + OnPlayerChanged(null); + return end; + } + else + { + Message = ((TerminerSonTourFraction)gameActions[2]).ErrorMessage; + return false; + } + } + + override public void TestEndGame(List currentHand) + { + if (((TerminerSonTourFraction)gameActions[2]).Test(currentHand)) + { + end = false; + } + else + { + OnEndGame(new EventArgs()); + end = true; + } + } + } +} diff --git a/TheGameExtreme/model/gameActions/fraction/JouerUneCarteFraction.cs b/TheGameExtreme/model/gameActions/fraction/JouerUneCarteFraction.cs new file mode 100644 index 0000000..8355235 --- /dev/null +++ b/TheGameExtreme/model/gameActions/fraction/JouerUneCarteFraction.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using TheGameExtreme.model.card; +using TheGameExtreme.model.card.cardType; +using TheGameExtreme.model.gameActions.abstractRules; +using TheGameExtreme.model.piles; +using TheGameExtreme.Resx; + +namespace TheGameExtreme.model.gameActions.fraction +{ + public class JouerUneCarteFraction : JouerUneCarte + { + public JouerUneCarteFraction(Piles ListOrderedStacks) : base(ListOrderedStacks) + { + } + + override public bool play(decimal valueCard, List CurrentHand, int orderedStackSelected, Player player, List CurrentCardPlayed) + { + foreach (Card card in CurrentHand) + { + if (valueCard.CompareTo(card.Value) == 0) + { + if (orderedStackSelected >= 0 && orderedStackSelected < ListOrderedStacks.Size) + { + bool success; + if (orderedStackSelected < (ListOrderedStacks.Size * 0.5)) + { + ErrorMessage = null; + success = Rule(card, ListOrderedStacks.getStack(orderedStackSelected), true, player, CurrentCardPlayed); + } + else + { + ErrorMessage = null; + success = Rule(card, ListOrderedStacks.getStack(orderedStackSelected), false, player, CurrentCardPlayed); + } + if (success) + { + CurrentHand.Remove(card); + } + return success; + } + else + { + ErrorMessage = AppResources.StrCantGetStack; + } + } + } + ErrorMessage = AppResources.StrCardDoesntExist; + return false; + } + + override protected bool Rule(Card card, Stack stack, bool bottomUp, Player player, List CurrentCardPlayed) + { + if ((bottomUp && card.Value > stack.Peek().Value) || (!bottomUp && card.Value < stack.Peek().Value)) + { + OldCard = stack.Peek(); + player.joue(card); + CurrentCardPlayed.Add(card); + stack.Push(card); + return true; + } + else if (((FractionCard)card).Fraction.isMultiple(((FractionCard)stack.Peek()).Fraction)) + { + OldCard = stack.Peek(); + player.joue(card); + CurrentCardPlayed.Add(card); + stack.Push(card); + return true; + } + else + { + ErrorMessage = AppResources.StrWrongStack; + return false; + } + } + } +} diff --git a/TheGameExtreme/model/gameActions/fraction/TerminerSonTourFraction.cs b/TheGameExtreme/model/gameActions/fraction/TerminerSonTourFraction.cs new file mode 100644 index 0000000..d75dd26 --- /dev/null +++ b/TheGameExtreme/model/gameActions/fraction/TerminerSonTourFraction.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using TheGameExtreme.model.card; +using TheGameExtreme.model.card.cardType; +using TheGameExtreme.model.gameActions.abstractRules; +using TheGameExtreme.model.piles; +using TheGameExtreme.Resx; + +namespace TheGameExtreme.model.gameActions.fraction +{ + public class TerminerSonTourFraction : TerminerSonTour + { + public TerminerSonTourFraction(Piles ListOrderedStacks) : base(ListOrderedStacks) + { + } + + public override bool end(List CurrentHand, List CurrentCardPlayed) + { + if (CurrentHand.Count == 0 || CurrentCardPlayed.Count >= 2) + { + // Vérifier la fin du jeu + return true; + } + else + { + ErrorMessage = AppResources.StrCardPlayedLessThanTwo; + return false; + } + } + + protected override bool testEndGame(List playableCard) + { + if (playableCard.Count < 2) + { + return false; + } + return true; + } + + protected override void tryToFindSoluce(List playableCard, List CurrentHand) + { + CurrentHand.ForEach(card => + { + for (int i = 0; i < ListOrderedStacks.Size; i++) + { + if (i < (ListOrderedStacks.Size * 0.5)) + { + if (card.Value > ListOrderedStacks.getStack(i).Peek().Value) + { + playableCard.Add(card); + } + } + else if (card.Value < ListOrderedStacks.getStack(i).Peek().Value) + { + playableCard.Add(card); + } + else if (((FractionCard)card).Fraction.isMultiple(((FractionCard)ListOrderedStacks.getStack(i).Peek()).Fraction)) + { + playableCard.Add(card); + } + } + }); + } + } +} diff --git a/TheGameExtreme/view/MainPage.xaml.cs b/TheGameExtreme/view/MainPage.xaml.cs index 5543713..75eca93 100644 --- a/TheGameExtreme/view/MainPage.xaml.cs +++ b/TheGameExtreme/view/MainPage.xaml.cs @@ -232,8 +232,19 @@ namespace TheGameExtreme.view for (int i = 0; i < viewmodel.getListOrderedStacks().Count; i++) { textPaint = new SKPaint(); - textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("000"); - position.X -= textPaint.MeasureText(viewmodel.getListOrderedStacks()[i].Peek().Value.ToString()) * 0.5f; + float textWidth; + + if (indexMode == 5) + { + textWidth = textPaint.MeasureText("00"); + textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth; + } + else + { + textWidth = textPaint.MeasureText(viewmodel.getListOrderedStacks()[i].Peek().Value.ToString()); + textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth; + } + position.X -= textWidth * 0.5f; stackCollection.Add(new TouchManipulationCard(textPaint, viewmodel.getListOrderedStacks()[i].Peek(), inflateWidth) { @@ -242,7 +253,7 @@ namespace TheGameExtreme.view InitialPoint = position }); - position.X += (float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / viewmodel.getListOrderedStacks().Count); + position.X += (float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / viewmodel.getListOrderedStacks().Count) + textWidth * 0.5f; } } @@ -268,9 +279,19 @@ namespace TheGameExtreme.view for (int i = 0; i < viewmodel.CurrentHand.Count; i++) { textPaint = new SKPaint(); - float textWidth = textPaint.MeasureText(viewmodel.CurrentHand[i].Value.ToString()); - textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("000"); - position.X -= (float)(textWidth * 0.5); + float textWidth; + + if (indexMode == 5) + { + textWidth = textPaint.MeasureText("00"); + textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth; + } + else + { + textWidth = textPaint.MeasureText(viewmodel.CurrentHand[i].Value.ToString()); + textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth; + } + position.X -= textWidth * 0.5f; textCollection.Add(new TouchManipulationCard(textPaint, viewmodel.CurrentHand[i], inflateWidth) { @@ -279,7 +300,7 @@ namespace TheGameExtreme.view InitialPoint = position }); - position.X += (float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / viewmodel.CurrentHand.Count); + position.X += (float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / viewmodel.CurrentHand.Count) + textWidth * 0.5f; } } diff --git a/TheGameExtreme/view/TouchManipulationCard.cs b/TheGameExtreme/view/TouchManipulationCard.cs index 6d07f0f..d517613 100644 --- a/TheGameExtreme/view/TouchManipulationCard.cs +++ b/TheGameExtreme/view/TouchManipulationCard.cs @@ -32,6 +32,8 @@ namespace TheGameExtreme.view { this.textPaint = textPaint; Value = value; + this.width = width; + height = 2f * this.width; if (Value.View.GetType() == typeof(FractionCard)) { @@ -43,9 +45,6 @@ namespace TheGameExtreme.view display = Value.ToString(); - this.width = width; - height = 2f * width; - if (!display.Contains(",") && !display.Contains(".") && !display.Contains("/")) { if (Value.Value.CompareTo(-10m) <= 0) @@ -58,6 +57,7 @@ namespace TheGameExtreme.view } } + Matrix = SKMatrix.MakeIdentity(); Mode = TouchManipulationMode.PanOnly; @@ -106,7 +106,7 @@ namespace TheGameExtreme.view if (Value.View.GetType() == typeof(FractionCard)) { canvas.DrawRect(card, textPaint1); - if (((FractionCard)Value.View).Fraction.Numerateur < 10 && ((FractionCard)Value.View).Fraction.Numerateur > 0) // Gros prob + if (((FractionCard)Value.View).Fraction.Numerateur < 10 && ((FractionCard)Value.View).Fraction.Numerateur > 0) { canvas.DrawText(((FractionCard)Value.View).Fraction.Numerateur.ToString(), textPaint.MeasureText(((FractionCard)Value.View).Fraction.Numerateur.ToString()) * 0.5f, -50, textPaint); } @@ -114,7 +114,7 @@ namespace TheGameExtreme.view { canvas.DrawText(((FractionCard)Value.View).Fraction.Numerateur.ToString(), 0, -50, textPaint); } - canvas.DrawText("__", 0, -textPaint.TextSize * 0.5f, textPaint1); + canvas.DrawText("__", 0, -textPaint.TextSize * 0.4f, textPaint1); if (((FractionCard)Value.View).Fraction.Denominateur < 10 && ((FractionCard)Value.View).Fraction.Denominateur > 0) { canvas.DrawText(((FractionCard)Value.View).Fraction.Denominateur.ToString(), textPaint.MeasureText(((FractionCard)Value.View).Fraction.Denominateur.ToString()) * 0.5f, 50, textPaint2); @@ -159,7 +159,7 @@ namespace TheGameExtreme.view SKPoint transformedPoint = inverseMatrix.MapPoint(location); // Check if it's in the untransformed bitmap rectangle - SKRect rect = new SKRect(-width, -height - textPaint.TextSize + 10, width + textPaint.MeasureText(display), height + 10); + SKRect rect = new SKRect(-width, -height - textPaint.TextSize, width + textPaint.MeasureText(display), height); return rect.Contains(transformedPoint); } return false; diff --git a/TheGameExtreme/viewmodel/Main.cs b/TheGameExtreme/viewmodel/Main.cs index aeb03b3..6c264b6 100644 --- a/TheGameExtreme/viewmodel/Main.cs +++ b/TheGameExtreme/viewmodel/Main.cs @@ -8,6 +8,7 @@ using TheGameExtreme.model.@event; using TheGameExtreme.model.gameActions.abstractRules; using TheGameExtreme.model.gameActions.classic; using TheGameExtreme.model.gameActions.decimals; +using TheGameExtreme.model.gameActions.fraction; using TheGameExtreme.model.manager; using TheGameExtreme.model.piles; @@ -75,7 +76,7 @@ namespace TheGameExtreme.viewmodel gameMode = new GameModeDecimal(new PilesMoins5To5(nbPile), new MilliemeDeck(nbCard, -4.999m, 4.999m)); break; case 5: - gameMode = new GameModeDecimal(new FractionPiles(nbPile), new FractionDeck(nbCard, 0m, 51m)); + gameMode = new GameModeFraction(new FractionPiles(nbPile), new FractionDeck(nbCard, 0m, 51m)); break; default: gameMode = new GameModeClassic(new ClassicPiles(nbPile), new ClassicDeck(nbCard, 1, 99));