|
|
|
@ -2,21 +2,18 @@ using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using TheGameExtreme.model.@event;
|
|
|
|
|
using TheGameExtreme.viewmodel;
|
|
|
|
|
using SkiaSharp;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using SkiaSharp.Views.Forms;
|
|
|
|
|
using TouchTracking;
|
|
|
|
|
using Xamarin.Essentials;
|
|
|
|
|
using TheGameExtreme.model.card;
|
|
|
|
|
|
|
|
|
|
namespace TheGameExtreme.view
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Learn more about making custom code visible in the Xamarin.Forms previewer
|
|
|
|
|
// by visiting https://aka.ms/xamarinforms-previewer
|
|
|
|
|
/**
|
|
|
|
|
* Classe qui permet de gérer la vue du jeu
|
|
|
|
|
*/
|
|
|
|
|
[DesignTimeVisible(false)]
|
|
|
|
|
public partial class MainPage : ContentPage
|
|
|
|
|
{
|
|
|
|
@ -25,12 +22,17 @@ namespace TheGameExtreme.view
|
|
|
|
|
private List<string> playersNames;
|
|
|
|
|
private int nbPile;
|
|
|
|
|
private int indexMode;
|
|
|
|
|
List<TouchManipulationBitmap> textCollection = new List<TouchManipulationBitmap>();
|
|
|
|
|
List<TouchManipulationBitmap> stackCollection = new List<TouchManipulationBitmap>();
|
|
|
|
|
Dictionary<long, TouchManipulationBitmap> textDictionary = new Dictionary<long, TouchManipulationBitmap>();
|
|
|
|
|
List<TouchManipulationCard> textCollection = new List<TouchManipulationCard>();
|
|
|
|
|
List<TouchManipulationCard> stackCollection = new List<TouchManipulationCard>();
|
|
|
|
|
Dictionary<long, TouchManipulationCard> textDictionary = new Dictionary<long, TouchManipulationCard>();
|
|
|
|
|
private SKCanvas canvas;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <param name="playersNames">Liste des pseudos des joueurs</param>
|
|
|
|
|
* <param name="nbPile">Nombre de piles pour jouer</param>
|
|
|
|
|
* <param name="indexMode">Version du jeu joué</param>
|
|
|
|
|
*/
|
|
|
|
|
public MainPage(List<string> playersNames, int nbPile, int indexMode)
|
|
|
|
|
{
|
|
|
|
|
this.playersNames = playersNames;
|
|
|
|
@ -55,6 +57,11 @@ namespace TheGameExtreme.view
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Evénement permettant d'afficher les messages d'alertes générés dans le model
|
|
|
|
|
* <param name="sender">Instance qui envoi l'événement</param>
|
|
|
|
|
* <param name="args">Argument(s) de l'événement</param>
|
|
|
|
|
*/
|
|
|
|
|
private void OnAlertChanged(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (viewmodel.Alert != null)
|
|
|
|
@ -65,7 +72,11 @@ namespace TheGameExtreme.view
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Evénement permettant de peindre la surface du canvas
|
|
|
|
|
* <param name="sender">Instance qui envoi l'événement</param>
|
|
|
|
|
* <param name="args">Arguments de l'événement</param>
|
|
|
|
|
*/
|
|
|
|
|
public void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
canvas = args.Surface.Canvas;
|
|
|
|
@ -83,12 +94,19 @@ namespace TheGameExtreme.view
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (TouchManipulationBitmap textPaint in textCollection)
|
|
|
|
|
foreach (TouchManipulationCard textPaint in textCollection)
|
|
|
|
|
{
|
|
|
|
|
textPaint.Paint(canvas, SKColors.SkyBlue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Evénement qui permet de gérer le Drag and Drop.
|
|
|
|
|
* Il permet de traiter le clic, le mouvement, le relachement du clic et la fin de traitement d'un clic.
|
|
|
|
|
* <param name="sender">Instance qui envoi l'événement</param>
|
|
|
|
|
* <param name="args">Arguments de l'événement</param>
|
|
|
|
|
*/
|
|
|
|
|
public void OnTouchEffectAction(object sender, TouchActionEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
TouchTrackingPoint pt = args.Location;
|
|
|
|
@ -101,11 +119,11 @@ namespace TheGameExtreme.view
|
|
|
|
|
case TouchActionType.Pressed:
|
|
|
|
|
for (int i = textCollection.Count - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
TouchManipulationBitmap textPaint = textCollection[i];
|
|
|
|
|
TouchManipulationCard textPaint = textCollection[i];
|
|
|
|
|
|
|
|
|
|
if (textPaint.HitTest(point))
|
|
|
|
|
{
|
|
|
|
|
// Move bitmap to end of collection
|
|
|
|
|
// Move card to end of collection
|
|
|
|
|
textCollection.Remove(textPaint);
|
|
|
|
|
textCollection.Add(textPaint);
|
|
|
|
|
|
|
|
|
@ -121,10 +139,10 @@ namespace TheGameExtreme.view
|
|
|
|
|
case TouchActionType.Moved:
|
|
|
|
|
if (textDictionary.ContainsKey(args.Id))
|
|
|
|
|
{
|
|
|
|
|
TouchManipulationBitmap bitmap = textDictionary[args.Id];
|
|
|
|
|
TouchManipulationCard card = textDictionary[args.Id];
|
|
|
|
|
point.Y -= 120;
|
|
|
|
|
point.X -= 50;
|
|
|
|
|
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
|
|
|
|
|
card.ProcessTouchEvent(args.Id, args.Type, point);
|
|
|
|
|
canvasView.InvalidateSurface();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@ -135,19 +153,19 @@ namespace TheGameExtreme.view
|
|
|
|
|
case TouchActionType.Cancelled:
|
|
|
|
|
if (textDictionary.ContainsKey(args.Id))
|
|
|
|
|
{
|
|
|
|
|
TouchManipulationBitmap bitmap = textDictionary[args.Id];
|
|
|
|
|
TouchManipulationCard card = textDictionary[args.Id];
|
|
|
|
|
bool find = false;
|
|
|
|
|
foreach (TouchManipulationBitmap stack in stackCollection)
|
|
|
|
|
foreach (TouchManipulationCard stack in stackCollection)
|
|
|
|
|
{
|
|
|
|
|
SKPoint pointVisuCard = new SKPoint(point.X, point.Y - 120);
|
|
|
|
|
if (stack.HitTest(point) || stack.HitTest(pointVisuCard))
|
|
|
|
|
{
|
|
|
|
|
int indexPile = stackCollection.IndexOf(stack);
|
|
|
|
|
if (played(indexPile, bitmap.Value.Value))
|
|
|
|
|
if (Played(indexPile, card.Value.Value))
|
|
|
|
|
{
|
|
|
|
|
bitmap.ProcessTouchEvent(args.Id, TouchActionType.Moved, stack.InitialPoint);
|
|
|
|
|
bitmap.InitialPoint = stackCollection[stackCollection.IndexOf(stack)].InitialPoint;
|
|
|
|
|
stackCollection[stackCollection.IndexOf(stack)] = bitmap;
|
|
|
|
|
card.ProcessTouchEvent(args.Id, TouchActionType.Moved, stack.InitialPoint);
|
|
|
|
|
card.InitialPoint = stackCollection[stackCollection.IndexOf(stack)].InitialPoint;
|
|
|
|
|
stackCollection[stackCollection.IndexOf(stack)] = card;
|
|
|
|
|
textCollection.RemoveAt(textCollection.Count - 1);
|
|
|
|
|
find = true;
|
|
|
|
|
}
|
|
|
|
@ -156,9 +174,9 @@ namespace TheGameExtreme.view
|
|
|
|
|
}
|
|
|
|
|
if (!find)
|
|
|
|
|
{
|
|
|
|
|
bitmap.ProcessTouchEvent(args.Id, TouchActionType.Moved, bitmap.InitialPoint);
|
|
|
|
|
card.ProcessTouchEvent(args.Id, TouchActionType.Moved, card.InitialPoint);
|
|
|
|
|
}
|
|
|
|
|
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
|
|
|
|
|
card.ProcessTouchEvent(args.Id, args.Type, point);
|
|
|
|
|
textDictionary.Remove(args.Id);
|
|
|
|
|
canvasView.InvalidateSurface();
|
|
|
|
|
}
|
|
|
|
@ -166,16 +184,10 @@ namespace TheGameExtreme.view
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//public void OnTouchModePickerSelectedIndexChanged(object sender, EventArgs args)
|
|
|
|
|
//{
|
|
|
|
|
// if (textPaint != null)
|
|
|
|
|
// {
|
|
|
|
|
// Picker picker = (Picker)sender;
|
|
|
|
|
// textPaint.TouchManager.Mode = (TouchManipulationMode)picker.SelectedItem;
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fonction permettant de déployer visuellement les piles
|
|
|
|
|
*/
|
|
|
|
|
private void InflateStack()
|
|
|
|
|
{
|
|
|
|
|
stackCollection.Clear();
|
|
|
|
@ -190,7 +202,7 @@ namespace TheGameExtreme.view
|
|
|
|
|
textPaint = new SKPaint();
|
|
|
|
|
textPaint.TextSize = textSize;
|
|
|
|
|
|
|
|
|
|
stackCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.getListOrderedStacks()[i].Peek())
|
|
|
|
|
stackCollection.Add(new TouchManipulationCard(textPaint, viewmodel.getListOrderedStacks()[i].Peek())
|
|
|
|
|
{
|
|
|
|
|
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
|
|
|
|
|
InitialMatrix = SKMatrix.MakeTranslation(position.X, position.Y),
|
|
|
|
@ -201,6 +213,10 @@ namespace TheGameExtreme.view
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fonction permettant de déployer visuellement les cartes contenues dans la main du joueur actif
|
|
|
|
|
*/
|
|
|
|
|
private void InflateHand()
|
|
|
|
|
{
|
|
|
|
|
SKPaint textPaint = new SKPaint();
|
|
|
|
@ -214,7 +230,7 @@ namespace TheGameExtreme.view
|
|
|
|
|
textPaint.TextSize = textSize;
|
|
|
|
|
position.X -= (float)(textWidth * 0.5);
|
|
|
|
|
|
|
|
|
|
textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i])
|
|
|
|
|
textCollection.Add(new TouchManipulationCard(textPaint, viewmodel.CurrentHand[i])
|
|
|
|
|
{
|
|
|
|
|
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
|
|
|
|
|
InitialMatrix = SKMatrix.MakeTranslation(position.X, position.Y),
|
|
|
|
@ -225,18 +241,30 @@ namespace TheGameExtreme.view
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Evénement traitant la fin du jeu
|
|
|
|
|
* <param name="sender">Instance qui envoi l'événement</param>
|
|
|
|
|
* <param name="args">Argument(s) de l'événement</param>
|
|
|
|
|
*/
|
|
|
|
|
private void OnEndGame(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
button = (Button)gameOption.Children[0];
|
|
|
|
|
gameOption.Children.Clear();
|
|
|
|
|
Button retryButton = new Button();
|
|
|
|
|
retryButton.Text = "Retry";
|
|
|
|
|
retryButton.Clicked += retry;
|
|
|
|
|
retryButton.Clicked += Retry;
|
|
|
|
|
retryButton.BackgroundColor = (Color)Application.Current.Resources["SkyBlueColor"];
|
|
|
|
|
gameOption.Children.Add(retryButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool played(int numStack, decimal value)
|
|
|
|
|
/**
|
|
|
|
|
* Fonction permettant de lancer le déplacement d'une carte sur une pile
|
|
|
|
|
* <param name="numStack">Index de la pile joué</param>
|
|
|
|
|
* <param name="value">Valeur de la carte joué</param>
|
|
|
|
|
* <returns>Booléen qui indique si la carte a pu être joué</returns>
|
|
|
|
|
*/
|
|
|
|
|
private bool Played(int numStack, decimal value)
|
|
|
|
|
{
|
|
|
|
|
if (!viewmodel.played(numStack, value))
|
|
|
|
|
{
|
|
|
|
@ -245,7 +273,13 @@ namespace TheGameExtreme.view
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void retry(object sender, EventArgs args)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Evénement permettant de relancer le jeu avec les mêmes paramètres de jeu
|
|
|
|
|
* <param name="sender">Instance qui envoi l'événement</param>
|
|
|
|
|
* <param name="args">Argument de l'événement</param>
|
|
|
|
|
*/
|
|
|
|
|
private void Retry(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
viewmodel = new Main(playersNames, nbPile, indexMode);
|
|
|
|
|
|
|
|
|
@ -263,6 +297,12 @@ namespace TheGameExtreme.view
|
|
|
|
|
gameOption.Children.Add(button);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Evénement permettant de lancer la fin du tour d'un joueur
|
|
|
|
|
* <param name="sender">Instance qui envoi l'événement</param>
|
|
|
|
|
* <param name="args">Argument de l'événement</param>
|
|
|
|
|
*/
|
|
|
|
|
private void EndTurn(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (!viewmodel.endTurn())
|
|
|
|
@ -276,6 +316,12 @@ namespace TheGameExtreme.view
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Evénement permettant de naviguer entre les différentes pages de l'application
|
|
|
|
|
* <param name="sender">Instance qui envoi l'événement</param>
|
|
|
|
|
* <param name="args">Argument de l'événement</param>
|
|
|
|
|
*/
|
|
|
|
|
private async void PlayToHome(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
await Navigation.PopToRootAsync();
|
|
|
|
|