From 1e11b435b2548ccc7b7a417c0ddfe521bdb2dd45 Mon Sep 17 00:00:00 2001 From: cldupland Date: Mon, 9 Dec 2019 12:05:51 +0100 Subject: [PATCH] Gestion du design des fractions --- TheGameExtreme/model/Fraction.cs | 4 +- TheGameExtreme/model/deck/CentaineDeck.cs | 2 +- TheGameExtreme/model/deck/DizaineDeck.cs | 2 +- TheGameExtreme/model/deck/FractionDeck.cs | 4 +- TheGameExtreme/model/deck/MilliemeDeck.cs | 2 +- TheGameExtreme/model/piles/FractionPiles.cs | 2 +- TheGameExtreme/view/MainPage.xaml.cs | 45 +++++++--------- TheGameExtreme/view/TouchManipulationCard.cs | 56 ++++++++++++++++---- 8 files changed, 74 insertions(+), 43 deletions(-) diff --git a/TheGameExtreme/model/Fraction.cs b/TheGameExtreme/model/Fraction.cs index 16d1de3..9bb2a10 100644 --- a/TheGameExtreme/model/Fraction.cs +++ b/TheGameExtreme/model/Fraction.cs @@ -6,11 +6,13 @@ namespace TheGameExtreme.model { public int Numerateur; public int Denominateur; + public int SizeMax; - public Fraction(int numerateur, int denominateur) + public Fraction(int numerateur, int denominateur, int sizeMax) { Numerateur = numerateur; Denominateur = denominateur; + SizeMax = sizeMax; } public bool isMultiple(Fraction fraction) diff --git a/TheGameExtreme/model/deck/CentaineDeck.cs b/TheGameExtreme/model/deck/CentaineDeck.cs index 09a629a..5be6439 100644 --- a/TheGameExtreme/model/deck/CentaineDeck.cs +++ b/TheGameExtreme/model/deck/CentaineDeck.cs @@ -14,7 +14,7 @@ namespace TheGameExtreme.model.deck while (deck.Count < nbCard && deck.Count < (borneMaxRandom - borneMinRandom)) { int value = random.Next(borneMinRandom, borneMaxRandom); - InsertionDichotomique(deck, 0, deck.Count-1, new FractionCard(new Fraction(value, 100))); + InsertionDichotomique(deck, 0, deck.Count-1, new FractionCard(new Fraction(value, 100, 3))); } } } diff --git a/TheGameExtreme/model/deck/DizaineDeck.cs b/TheGameExtreme/model/deck/DizaineDeck.cs index c7ef670..82740a6 100644 --- a/TheGameExtreme/model/deck/DizaineDeck.cs +++ b/TheGameExtreme/model/deck/DizaineDeck.cs @@ -13,7 +13,7 @@ namespace TheGameExtreme.model.deck while (deck.Count < nbCard && deck.Count < (borneMaxRandom - borneMinRandom)) { int value = random.Next(borneMinRandom, borneMaxRandom); - InsertionDichotomique(deck, 0, deck.Count-1, new FractionCard(new Fraction(value, 10))); + InsertionDichotomique(deck, 0, deck.Count-1, new FractionCard(new Fraction(value, 10, 2))); } } } diff --git a/TheGameExtreme/model/deck/FractionDeck.cs b/TheGameExtreme/model/deck/FractionDeck.cs index 1b1d361..1b04eb4 100644 --- a/TheGameExtreme/model/deck/FractionDeck.cs +++ b/TheGameExtreme/model/deck/FractionDeck.cs @@ -19,7 +19,7 @@ namespace TheGameExtreme.model.deck { if (deck.Count < nbCard) { - InsertionDichotomique(deck, 0, deck.Count - 1, new FractionCard(new Fraction(i, j))); + InsertionDichotomique(deck, 0, deck.Count - 1, new FractionCard(new Fraction(i, j, 1))); } else { @@ -43,7 +43,7 @@ namespace TheGameExtreme.model.deck denominateur /= pgcd; pgcd = PGCD(numerateur, denominateur); } - InsertionDichotomique(deck, 0, deck.Count - 1, new FractionCard(new Fraction(numerateur, denominateur))); + InsertionDichotomique(deck, 0, deck.Count - 1, new FractionCard(new Fraction(numerateur, denominateur, 2))); } } } diff --git a/TheGameExtreme/model/deck/MilliemeDeck.cs b/TheGameExtreme/model/deck/MilliemeDeck.cs index ce60de8..56c264d 100644 --- a/TheGameExtreme/model/deck/MilliemeDeck.cs +++ b/TheGameExtreme/model/deck/MilliemeDeck.cs @@ -14,7 +14,7 @@ namespace TheGameExtreme.model.deck while (deck.Count < nbCard && deck.Count < (borneMaxRandom - borneMinRandom)) { int value = random.Next(borneMinRandom, borneMaxRandom); - InsertionDichotomique(deck, 0, deck.Count-1, new FractionCard(new Fraction(value, 1000))); + InsertionDichotomique(deck, 0, deck.Count-1, new FractionCard(new Fraction(value, 1000, 4))); } } } diff --git a/TheGameExtreme/model/piles/FractionPiles.cs b/TheGameExtreme/model/piles/FractionPiles.cs index 2b318b4..7dbfefb 100644 --- a/TheGameExtreme/model/piles/FractionPiles.cs +++ b/TheGameExtreme/model/piles/FractionPiles.cs @@ -15,7 +15,7 @@ namespace TheGameExtreme.model.piles } else { - ListOrderedStacks[i].Push(new ClassicCard(100m)); + ListOrderedStacks[i].Push(new ClassicCard(25m)); } } } diff --git a/TheGameExtreme/view/MainPage.xaml.cs b/TheGameExtreme/view/MainPage.xaml.cs index 51b35b6..f34e99f 100644 --- a/TheGameExtreme/view/MainPage.xaml.cs +++ b/TheGameExtreme/view/MainPage.xaml.cs @@ -8,6 +8,7 @@ using SkiaSharp.Views.Forms; using TouchTracking; using Xamarin.Essentials; using TheGameExtreme.Resx; +using TheGameExtreme.model.card.cardType; namespace TheGameExtreme.view { @@ -195,16 +196,16 @@ namespace TheGameExtreme.view stackCollection.Clear(); SKPaint textPaint = new SKPaint(); - SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width) / (viewmodel.getListOrderedStacks().Count * 2)), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.1) + (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.01 + 2 * (0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("001")))); + SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width - 20) / (viewmodel.getListOrderedStacks().Count * 2)) + 10f, (float)((DeviceDisplay.MainDisplayInfo.Height * 0.1) + (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.01 + 2 * (0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("001")))); float inflateWidth; if (indexMode == 4 || indexMode == 3) { - inflateWidth = 0.03f * (float)DeviceDisplay.MainDisplayInfo.Width; + inflateWidth = 0.03f * (float)(DeviceDisplay.MainDisplayInfo.Width - 20); } else { - inflateWidth = 0.02f * (float)DeviceDisplay.MainDisplayInfo.Width; + inflateWidth = 0.02f * (float)(DeviceDisplay.MainDisplayInfo.Width - 20); } position.X -= inflateWidth; @@ -214,20 +215,16 @@ namespace TheGameExtreme.view textPaint = new SKPaint(); float textWidth; - if (indexMode == 3) + if (viewmodel.getListOrderedStacks()[i].Peek().View.GetType() == typeof(FractionCard)) { - textWidth = textPaint.MeasureText("000"); - textPaint.TextSize = 0.04f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("000"); - } - else if (indexMode == 4) - { - textWidth = textPaint.MeasureText("0000"); - textPaint.TextSize = 0.04f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("0000"); + string displayMax = Math.Pow(10, ((FractionCard)(viewmodel.getListOrderedStacks()[i].Peek().View)).Fraction.SizeMax-1).ToString(); + textWidth = textPaint.MeasureText(displayMax); + textPaint.TextSize = 0.048f * (float)(DeviceDisplay.MainDisplayInfo.Width - 20) * textPaint.TextSize / textPaint.MeasureText(displayMax); } else { textWidth = textPaint.MeasureText("00"); - textPaint.TextSize = 0.04f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("00"); + textPaint.TextSize = 0.04f * (float)(DeviceDisplay.MainDisplayInfo.Width - 20) * textPaint.TextSize / textPaint.MeasureText("00"); } position.X -= textWidth * 0.5f; @@ -238,7 +235,7 @@ namespace TheGameExtreme.view InitialPoint = position }); - position.X += (float)((DeviceDisplay.MainDisplayInfo.Width) / viewmodel.getListOrderedStacks().Count); + position.X += (float)((DeviceDisplay.MainDisplayInfo.Width - 20) / viewmodel.getListOrderedStacks().Count) + textWidth * 0.5f; } } @@ -249,16 +246,16 @@ namespace TheGameExtreme.view private void InflateHand() { SKPaint textPaint = new SKPaint(); - SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width) / (viewmodel.CurrentHand.Count * 2)), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.1 - 2 * (0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("001")))); + SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width - 20) / (viewmodel.CurrentHand.Count * 2)) + 10f, (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.1 - 2 * (0.05f * (float)(DeviceDisplay.MainDisplayInfo.Width - 20) * textPaint.TextSize / textPaint.MeasureText("001")))); float inflateWidth; if (indexMode == 4 || indexMode == 3) { - inflateWidth = 0.03f * (float)DeviceDisplay.MainDisplayInfo.Width; + inflateWidth = 0.03f * (float)(DeviceDisplay.MainDisplayInfo.Width - 20); } else { - inflateWidth = 0.015f * (float)DeviceDisplay.MainDisplayInfo.Width; + inflateWidth = 0.015f * (float)(DeviceDisplay.MainDisplayInfo.Width - 20); } position.X -= inflateWidth; @@ -268,20 +265,16 @@ namespace TheGameExtreme.view textPaint = new SKPaint(); float textWidth; - if (indexMode == 3) - { - textWidth = textPaint.MeasureText("000"); - textPaint.TextSize = 0.048f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("000"); - } - else if (indexMode == 4) + if (viewmodel.CurrentHand[i].View.GetType() == typeof(FractionCard)) { - textWidth = textPaint.MeasureText("0000"); - textPaint.TextSize = 0.04f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("0000"); + string displayMax = Math.Pow(10, ((FractionCard)(viewmodel.CurrentHand[i].View)).Fraction.SizeMax-1).ToString(); + textWidth = textPaint.MeasureText(displayMax); + textPaint.TextSize = 0.048f * (float)(DeviceDisplay.MainDisplayInfo.Width - 20) * textPaint.TextSize / textPaint.MeasureText(displayMax); } else { textWidth = textPaint.MeasureText("00"); - textPaint.TextSize = 0.048f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textPaint.MeasureText("00"); + textPaint.TextSize = 0.048f * (float)(DeviceDisplay.MainDisplayInfo.Width - 20) * textPaint.TextSize / textPaint.MeasureText("00"); } position.X -= textWidth * 0.5f; @@ -292,7 +285,7 @@ namespace TheGameExtreme.view InitialPoint = position }); - position.X += (float)((DeviceDisplay.MainDisplayInfo.Width) / viewmodel.CurrentHand.Count); + position.X += (float)((DeviceDisplay.MainDisplayInfo.Width - 20) / viewmodel.CurrentHand.Count) + textWidth * 0.5f; } } diff --git a/TheGameExtreme/view/TouchManipulationCard.cs b/TheGameExtreme/view/TouchManipulationCard.cs index e31b1c8..eb38e4e 100644 --- a/TheGameExtreme/view/TouchManipulationCard.cs +++ b/TheGameExtreme/view/TouchManipulationCard.cs @@ -44,8 +44,8 @@ namespace TheGameExtreme.view textPaint1.TextSize = textPaint.TextSize; textPaint2.TextSize = textPaint.TextSize; } - //else - //{ + else + { if (!display.Contains(",") && !display.Contains(".") && !display.Contains("/")) { if (Value.Value.CompareTo(-10m) <= 0) @@ -57,7 +57,7 @@ namespace TheGameExtreme.view this.width += textPaint.MeasureText("0") * 0.5f; } } - //} + } Matrix = SKMatrix.MakeIdentity(); @@ -86,13 +86,11 @@ namespace TheGameExtreme.view textPaint.StrokeWidth = 5; textPaint.Style = SKPaintStyle.Stroke; - //SKRect card = new SKRect(0, 0, 100, 100); - SKRect card; if (Value.View.GetType() == typeof(FractionCard)) { - card = new SKRect(-width, -height - textPaint.TextSize, width + textPaint.MeasureText("00"), height); + card = new SKRect(-width, -height - textPaint.TextSize, width + textPaint.MeasureText(Math.Pow(10, ((FractionCard)(Value.View)).Fraction.SizeMax-1).ToString()), height); textPaint1.Color = color; textPaint1.StrokeWidth = 5; textPaint1.Style = SKPaintStyle.Stroke; @@ -107,10 +105,40 @@ namespace TheGameExtreme.view if (Value.View.GetType() == typeof(FractionCard)) { + float xNum = 0; + float xDen = 0; + int sizeMax = ((FractionCard)(Value.View)).Fraction.SizeMax; + int tailleNum = Math.Abs(((FractionCard)(Value.View)).Fraction.Numerateur); + int tailleDen = Math.Abs(((FractionCard)(Value.View)).Fraction.Denominateur); + + if (tailleNum == 0) + { + tailleNum += 1; + } + if (tailleDen == 0) + { + tailleDen += 1; + } + + string fractionBarre = "__"; + for (int i = 2; i < sizeMax; i++){ + fractionBarre += "_"; + } + while (tailleNum < Math.Pow(10, (int)(sizeMax * 0.5))) + { + xNum += textPaint.MeasureText("0"); + tailleNum *= 10; + } + while (tailleDen < Math.Pow(10, sizeMax * 0.5)) + { + xDen += textPaint2.MeasureText("0"); + tailleDen *= 10; + } + canvas.DrawRect(card, textPaint1); - canvas.DrawText(((FractionCard)Value.View).Fraction.Numerateur.ToString(), width * 0.5f - textPaint.MeasureText(((FractionCard)Value.View).Fraction.Numerateur.ToString()) * 0.5f, - textPaint.TextSize * 0.5f - height * 0.5f, textPaint); - canvas.DrawText("___", width * 0.5f - textPaint1.MeasureText("___") * 0.5f, -textPaint1.TextSize * 0.6f, textPaint1); - canvas.DrawText(((FractionCard)Value.View).Fraction.Denominateur.ToString(), width * 0.5f - textPaint2.MeasureText(((FractionCard)Value.View).Fraction.Numerateur.ToString()) * 0.5f, height * 0.5f, textPaint2); + canvas.DrawText(((FractionCard)Value.View).Fraction.Numerateur.ToString(), xNum, -height * 0.5f, textPaint); + canvas.DrawText(fractionBarre, 0, -textPaint1.TextSize * 0.6f, textPaint1); + canvas.DrawText(((FractionCard)Value.View).Fraction.Denominateur.ToString(), xDen, height * 0.5f, textPaint2); } else { @@ -147,7 +175,15 @@ 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, width + textPaint.MeasureText(display), height); + SKRect rect; + if (Value.View.GetType() == typeof(FractionCard)) + { + rect = new SKRect(-width, -height - textPaint.TextSize, width + textPaint.MeasureText(Math.Pow(10, ((FractionCard)(Value.View)).Fraction.SizeMax - 1).ToString()), height); + } + else + { + rect = new SKRect(-width, -height - textPaint.TextSize, width + textPaint.MeasureText(display), height); + } return rect.Contains(transformedPoint); } return false;