Gestion du design des fractions

master
cldupland 5 years ago
parent f0c5aed372
commit 1e11b435b2

@ -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)

@ -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)));
}
}
}

@ -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)));
}
}
}

@ -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)));
}
}
}

@ -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)));
}
}
}

@ -15,7 +15,7 @@ namespace TheGameExtreme.model.piles
}
else
{
ListOrderedStacks[i].Push(new ClassicCard(100m));
ListOrderedStacks[i].Push(new ClassicCard(25m));
}
}
}

@ -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;
}
}

@ -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;

Loading…
Cancel
Save