Ajout des fractions en cours et traitement des chevauchements de cartes

master
cldupland 5 years ago
parent 9130f01be5
commit 5d0be44a68

@ -3,10 +3,8 @@ using System.ComponentModel;
namespace TheGameExtreme.model.card
{
public abstract class Card // : INotifyPropertyChanged
public abstract class Card
{
//public event PropertyChangedEventHandler PropertyChanged;
private decimal value;
public decimal Value
{
@ -14,20 +12,19 @@ namespace TheGameExtreme.model.card
set
{
this.value = value;
//OnPropertyChange("Value");
}
}
//private void OnPropertyChange(string v)
//{
// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(v));
//}
public Card(decimal value)
{
Value = value;
}
public override string ToString()
{
return Value.ToString();
}
public abstract String getName();
public abstract bool rapidEffect();

@ -0,0 +1,30 @@
using System;
namespace TheGameExtreme.model.card.cardType
{
public class FractionCard : Card
{
public static readonly String CARD_FRACTION = "FractionCard";
private Fraction fraction;
public FractionCard(Fraction value) : base(value.Result())
{
fraction = value;
}
public override bool rapidEffect()
{
return false;
}
override public String getName()
{
return CARD_FRACTION;
}
public override string ToString()
{
return fraction.ToString();
}
}
}

@ -0,0 +1,61 @@

using System;
namespace TheGameExtreme.model
{
public class Fraction
{
public int Numerateur;
public int Denominateur;
public Fraction(int numerateur, int denominateur)
{
Numerateur = numerateur;
Denominateur = denominateur;
}
//public int CompareTo(Fraction fraction)
//{
// decimal d = (Numerateur / Denominateur) - (fraction.Numerateur / fraction.Denominateur);
// if (d > 0)
// {
// return 1;
// }
// else if (d < 0)
// {
// return -1;
// }
// else
// {
// return 0;
// }
//}
public bool testDiviseurCommun(Fraction fraction)
{
if (PGCD(Numerateur, fraction.Numerateur) == Numerateur || PGCD(Denominateur, fraction.Denominateur) == Denominateur)
{
return true;
}
return false;
}
private int PGCD(int a, int b)
{
int temp = a % b;
if (temp == 0)
return b;
return PGCD(b, temp);
}
public decimal Result()
{
decimal result = (decimal)Numerateur / (decimal)Denominateur;
return result;
}
override public string ToString()
{
return Numerateur.ToString() + "/" + Denominateur.ToString();
}
}
}

@ -0,0 +1,37 @@
using System;
using TheGameExtreme.model.card.cardType;
namespace TheGameExtreme.model.deck
{
public class FractionDeck : Deck
{
public FractionDeck()
{
Random random = new Random();
for (int i = 1; i < 100; i ++)
{
int entier = random.Next(0, 100);
int deci = random.Next(0,100);
decimal d = (decimal)entier + (decimal)deci * 0.001m;
int numerateur = (int)(d * 1000m);
int denominateur = 1000;
int pgcd = PGCD(numerateur, denominateur);
while (pgcd != 1)
{
numerateur = numerateur / pgcd;
denominateur = denominateur / pgcd;
pgcd = PGCD(numerateur, denominateur);
}
deck.Add(new FractionCard(new Fraction(numerateur, denominateur)));
}
}
private int PGCD(int a, int b)
{
int temp = a % b;
if (temp == 0)
return b;
return PGCD(b, temp);
}
}
}

@ -0,0 +1,23 @@
using System;
using TheGameExtreme.model.card.cardType;
namespace TheGameExtreme.model.piles
{
public class FractionPiles : Piles
{
public FractionPiles(int nbPile) : base(nbPile)
{
for (int i = 0; i < nbPile; i++)
{
if (i < (nbPile * 0.5))
{
ListOrderedStacks[i].Push(new ClassicCard(0));
}
else
{
ListOrderedStacks[i].Push(new ClassicCard(100));
}
}
}
}
}

@ -8,7 +8,7 @@ namespace TheGameExtreme.view
public partial class GamePreparationPage : ContentPage
{
public List<int> listNbPlayer = new List<int> { 1, 2, 3, 4, 5 };
public List<string> listGameMode = new List<string> { "entières", "relatives", "décimales", "dizaines", "centaines", "millièmes" }; // , "fractionnées"
public List<string> listGameMode = new List<string> { "entières", "relatives", "décimales", "dizaines", "centaines", "millièmes", "fractionnées" };
public List<int> listNbStack = new List<int> { 4, 6, 8 };

@ -143,7 +143,7 @@ namespace TheGameExtreme.view
if (stack.HitTest(point) || stack.HitTest(pointVisuCard))
{
int indexPile = stackCollection.IndexOf(stack);
if (played(indexPile, decimal.Parse(bitmap.Value)))
if (played(indexPile, bitmap.Value.Value))
{
bitmap.ProcessTouchEvent(args.Id, TouchActionType.Moved, stack.InitialPoint);
bitmap.InitialPoint = stackCollection[stackCollection.IndexOf(stack)].InitialPoint;
@ -183,14 +183,14 @@ namespace TheGameExtreme.view
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText("001");
float textSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / (viewmodel.getListOrderedStacks().Count * 2)) - textPaint.MeasureText("01"), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.1) + (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.01 + 2 * textSize));
SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / (viewmodel.getListOrderedStacks().Count * 2)) - textPaint.MeasureText("01") * 0.5f, (float)((DeviceDisplay.MainDisplayInfo.Height * 0.1) + (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.01 + 2 * textSize));
for (int i = 0; i < viewmodel.getListOrderedStacks().Count; i++)
{
textPaint = new SKPaint();
textPaint.TextSize = textSize;
stackCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.getListOrderedStacks()[i].Peek().Value)
stackCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.getListOrderedStacks()[i].Peek())
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialMatrix = SKMatrix.MakeTranslation(position.X, position.Y),
@ -206,7 +206,7 @@ namespace TheGameExtreme.view
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText("001");
float textSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / (viewmodel.CurrentHand.Count * 2)) - textPaint.MeasureText("01"), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.2 - textSize));
SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / (viewmodel.CurrentHand.Count * 2)) - textPaint.MeasureText("01") * 0.5f + (float)(DeviceDisplay.MainDisplayInfo.Width * 0.01), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.1 - 2 * textSize));
for (int i = 0; i < viewmodel.CurrentHand.Count; i++)
{
@ -214,7 +214,7 @@ namespace TheGameExtreme.view
textPaint.TextSize = textSize;
position.X -= (float)(textWidth * 0.5);
textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i].Value)
textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i])
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialMatrix = SKMatrix.MakeTranslation(position.X, position.Y),

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using SkiaSharp;
using TheGameExtreme.viewmodel;
using TouchTracking;
using Xamarin.Essentials;
namespace TheGameExtreme.view
{
@ -10,26 +12,24 @@ namespace TheGameExtreme.view
public SKPoint InitialPoint { get; set; }
SKPaint textPaint;
Dictionary<long, TouchManipulationInfo> touchDictionary = new Dictionary<long, TouchManipulationInfo>();
public string Value;
public CardVM Value;
public string display;
public TouchManipulationBitmap(SKPaint textPaint, decimal value)
public TouchManipulationBitmap(SKPaint textPaint, CardVM value)
{
this.textPaint = textPaint;
Value = value.ToString();
Value = value;
display = Value.ToString();
if (!Value.Contains(",") && !Value.Contains("."))
if (!display.Contains(",") && !display.Contains(".") && !display.Contains("/"))
{
if (value < 0 && value > -10)
if (decimal.Parse(display) < 0 && decimal.Parse(display) > -10)
{
Value = "-0" + Math.Abs(value).ToString();
display = "-0" + Math.Abs(decimal.Parse(display)).ToString();
}
else if (value >= 0 && value < 10)
else if (decimal.Parse(display) >= 0 && decimal.Parse(display) < 10)
{
Value = "0" + value.ToString();
}
else
{
Value = value.ToString();
display = "0" + display;
}
}
@ -56,14 +56,13 @@ namespace TheGameExtreme.view
textPaint.Style = SKPaintStyle.Stroke;
SKRect textBounds = new SKRect();
textPaint.MeasureText(Value, ref textBounds);
textPaint.MeasureText(display, ref textBounds);
SKRoundRect card = new SKRoundRect(textBounds, 1f, 1f);
card.Inflate(35, 55);
card.Inflate(0.01f * (float)DeviceDisplay.MainDisplayInfo.Width, 0.01f * (float)DeviceDisplay.MainDisplayInfo.Width * 5f);
canvas.DrawRoundRect(card, textPaint);
canvas.DrawText(Value, 0, 0, textPaint);
canvas.DrawText(display, 0, 0, textPaint);
canvas.Restore();
@ -85,7 +84,7 @@ namespace TheGameExtreme.view
SKPoint transformedPoint = inverseMatrix.MapPoint(location);
// Check if it's in the untransformed bitmap rectangle
SKRect rect = new SKRect(-70, -110, textPaint.MeasureText(Value) + 35, textPaint.TextSize);
SKRect rect = new SKRect(-70, -110, textPaint.MeasureText(display) + 35, textPaint.TextSize);
return rect.Contains(transformedPoint);
}
return false;

@ -36,7 +36,9 @@ namespace TheGameExtreme.viewmodel
Value = view.Value;
}
public override string ToString()
{
return View.ToString();
}
}
}

@ -76,9 +76,9 @@ namespace TheGameExtreme.viewmodel
case 5:
gameMode = new GameMode(new PilesMoins5To5(nbPile), new MilliemeDeck());
break;
//case 6:
// // Fraction
// break;
case 6:
gameMode = new GameMode(new FractionPiles(nbPile), new FractionDeck());
break;
default:
gameMode = new GameMode(new ClassicPiles(nbPile), new ClassicDeck());
break;

Loading…
Cancel
Save