Ajout des fractions, reste un petit problème de taille pour le dessin des chiffres

master
cldupland 5 years ago
parent f302da9ef4
commit 1ff7e4f3e2

@ -30,6 +30,7 @@
<Folder Include="model\piles\" /> <Folder Include="model\piles\" />
<Folder Include="model\gameActions\decimals\" /> <Folder Include="model\gameActions\decimals\" />
<Folder Include="model\gameActions\abstractRules\" /> <Folder Include="model\gameActions\abstractRules\" />
<Folder Include="model\gameActions\fraction\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="model\effect\StopColm.cs" /> <Compile Remove="model\effect\StopColm.cs" />

@ -40,7 +40,7 @@ namespace TheGameExtreme.model.gameActions.decimals
} }
else else
{ {
Message = ((JouerUneCarte)gameActions[1]).ErrorMessage; Message = ((JouerUneCarteDecimal)gameActions[1]).ErrorMessage;
return false; return false;
} }
} }
@ -57,7 +57,7 @@ namespace TheGameExtreme.model.gameActions.decimals
} }
else else
{ {
Message = ((TerminerSonTour)gameActions[2]).ErrorMessage; Message = ((TerminerSonTourDecimal)gameActions[2]).ErrorMessage;
return false; return false;
} }
} }

@ -19,7 +19,7 @@ namespace TheGameExtreme.model.gameActions.decimals
{ {
// Vérifier la fin du jeu // Vérifier la fin du jeu
return true; return true;
} }
else else
{ {
ErrorMessage = AppResources.StrCardPlayedLessThanTwo; ErrorMessage = AppResources.StrCardPlayedLessThanTwo;

@ -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<Player> 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<Card> 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<Card> currentHand, int orderedStackSelected, Player player, List<Card> 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<Card> currentHand, List<Card> 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<Card> currentHand)
{
if (((TerminerSonTourFraction)gameActions[2]).Test(currentHand))
{
end = false;
}
else
{
OnEndGame(new EventArgs());
end = true;
}
}
}
}

@ -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<Card> CurrentHand, int orderedStackSelected, Player player, List<Card> 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<Card> stack, bool bottomUp, Player player, List<Card> 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;
}
}
}
}

@ -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<Card> CurrentHand, List<Card> 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<Card> playableCard)
{
if (playableCard.Count < 2)
{
return false;
}
return true;
}
protected override void tryToFindSoluce(List<Card> playableCard, List<Card> 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);
}
}
});
}
}
}

@ -232,8 +232,19 @@ namespace TheGameExtreme.view
for (int i = 0; i < viewmodel.getListOrderedStacks().Count; i++) for (int i = 0; i < viewmodel.getListOrderedStacks().Count; i++)
{ {
textPaint = new SKPaint(); textPaint = new SKPaint();
textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("000"); float textWidth;
position.X -= textPaint.MeasureText(viewmodel.getListOrderedStacks()[i].Peek().Value.ToString()) * 0.5f;
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) stackCollection.Add(new TouchManipulationCard(textPaint, viewmodel.getListOrderedStacks()[i].Peek(), inflateWidth)
{ {
@ -242,7 +253,7 @@ namespace TheGameExtreme.view
InitialPoint = position 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++) for (int i = 0; i < viewmodel.CurrentHand.Count; i++)
{ {
textPaint = new SKPaint(); textPaint = new SKPaint();
float textWidth = textPaint.MeasureText(viewmodel.CurrentHand[i].Value.ToString()); float textWidth;
textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("000");
position.X -= (float)(textWidth * 0.5); 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) textCollection.Add(new TouchManipulationCard(textPaint, viewmodel.CurrentHand[i], inflateWidth)
{ {
@ -279,7 +300,7 @@ namespace TheGameExtreme.view
InitialPoint = position 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;
} }
} }

@ -32,6 +32,8 @@ namespace TheGameExtreme.view
{ {
this.textPaint = textPaint; this.textPaint = textPaint;
Value = value; Value = value;
this.width = width;
height = 2f * this.width;
if (Value.View.GetType() == typeof(FractionCard)) if (Value.View.GetType() == typeof(FractionCard))
{ {
@ -43,9 +45,6 @@ namespace TheGameExtreme.view
display = Value.ToString(); display = Value.ToString();
this.width = width;
height = 2f * width;
if (!display.Contains(",") && !display.Contains(".") && !display.Contains("/")) if (!display.Contains(",") && !display.Contains(".") && !display.Contains("/"))
{ {
if (Value.Value.CompareTo(-10m) <= 0) if (Value.Value.CompareTo(-10m) <= 0)
@ -58,6 +57,7 @@ namespace TheGameExtreme.view
} }
} }
Matrix = SKMatrix.MakeIdentity(); Matrix = SKMatrix.MakeIdentity();
Mode = TouchManipulationMode.PanOnly; Mode = TouchManipulationMode.PanOnly;
@ -106,7 +106,7 @@ namespace TheGameExtreme.view
if (Value.View.GetType() == typeof(FractionCard)) if (Value.View.GetType() == typeof(FractionCard))
{ {
canvas.DrawRect(card, textPaint1); 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); 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(((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) 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); 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); SKPoint transformedPoint = inverseMatrix.MapPoint(location);
// Check if it's in the untransformed bitmap rectangle // 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 rect.Contains(transformedPoint);
} }
return false; return false;

@ -8,6 +8,7 @@ using TheGameExtreme.model.@event;
using TheGameExtreme.model.gameActions.abstractRules; using TheGameExtreme.model.gameActions.abstractRules;
using TheGameExtreme.model.gameActions.classic; using TheGameExtreme.model.gameActions.classic;
using TheGameExtreme.model.gameActions.decimals; using TheGameExtreme.model.gameActions.decimals;
using TheGameExtreme.model.gameActions.fraction;
using TheGameExtreme.model.manager; using TheGameExtreme.model.manager;
using TheGameExtreme.model.piles; using TheGameExtreme.model.piles;
@ -75,7 +76,7 @@ namespace TheGameExtreme.viewmodel
gameMode = new GameModeDecimal(new PilesMoins5To5(nbPile), new MilliemeDeck(nbCard, -4.999m, 4.999m)); gameMode = new GameModeDecimal(new PilesMoins5To5(nbPile), new MilliemeDeck(nbCard, -4.999m, 4.999m));
break; break;
case 5: 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; break;
default: default:
gameMode = new GameModeClassic(new ClassicPiles(nbPile), new ClassicDeck(nbCard, 1, 99)); gameMode = new GameModeClassic(new ClassicPiles(nbPile), new ClassicDeck(nbCard, 1, 99));

Loading…
Cancel
Save