Voilà, j'ai commencer un projet sur la conception d'un jeu de société et la POO est un peu nouveau pour moi.
Je voulais vous présenter ma "structure" des classes, du moins le tout début, afin d'avoir votre avis à savoir si je pars complètement à l'opposé des "best practices" ou simplement si j'ai rien compris à la POO bref voici .
Tout d'abords j'ai créé une classe pour les joueurs (l'âge du joueur est simple pour déterminer si il joue en premier ^^) :
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Players {
public string PlayerName { get; set; }
public int PlayerOrder { get; set; }
public int PlayerScore { get; set; }
public int PlayerId { get; set; }
public int PlayerAge { get; set; }
public string playerName;
public int playerOrder;
public int playerScore;
public int playerId;
public int playerAge;
public Players(string playerName,int playerOrder,int playerScore,int playerId,int playerAge)
{
this.PlayerName = playerName;
this.PlayerOrder = playerOrder;
this.PlayerScore = playerScore;
this.PlayerId = playerId;
this.PlayerAge = playerAge;
}
}
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cartes {
public string CarteName { get; set; }
public string CarteType { get; set; }
public Cartes(string carteName,string carteType)
{
this.CarteName = carteName;
this.CarteType = carteType;
}
}
public class MainCarte
{
public Cartes[] Main { get; set; }
public int NombreMax { get; set; }
public int NombreActuel { get; set; }
public MainCarte(Cartes[] main,int nombreMax)
{
this.Main = main;
this.NombreMax = nombreMax;
this.NombreActuel = main.Length;
}
}
public class PotCarte
{
public List<Cartes> Pot { get; set; }
public int NombreCarte { get; set; }
public PotCarte(int count,List<Cartes> Listcartes)
{
int i;
this.Pot = new List<Cartes>();
for (i=0;i<count; i++)
{
this.Pot.Add(Listcartes[i]);
}
this.NombreCarte = this.Pot.Count;
}
}
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Partie {
public int NombreJoueurs { get; set; }
public List<Players> ListeJoueurs { get; set; }
public PotCarte pot { get; set; }
public int AgeActuel { get; set; }
public int JoueurActif { get; set; }
public int Phase { get; set; }
public Partie(int nbJoueurs,List<Players> listJoueurs)
{
this.NombreJoueurs = nbJoueurs;
this.ListeJoueurs = listJoueurs;
}
private int PremierJoueur(List<Players> listjoueurs)
{
int id=0,ageMin=0;
for (int i=0;i<listjoueurs.Count;i++)
{
if (ageMin != 0 && (ageMin < listjoueurs[i].PlayerAge))
{
id = listjoueurs[i].PlayerId;
}
ageMin = listjoueurs[i].PlayerAge;
}
return id;
}
public void Init()
{
//Initisalisation des Cartes
List<Cartes> listeCartes = new List<Cartes>();
Cartes c1 = new Cartes("Pouvoir Supreme", "Feu");
Cartes c2 = new Cartes("Pouvoir tout pourri", "Eau");
Cartes c3 = new Cartes("Double coup", "Terre");
Cartes c4 = new Cartes("Triple coup", "Feu");
listeCartes.Add(c1);
listeCartes.Add(c2);
listeCartes.Add(c3);
listeCartes.Add(c4);
//Création du pot de X cartes parmis toutes les cartes
pot = new PotCarte(4, listeCartes);
for (int i = 0; i < pot.NombreCarte; i++)
{
Debug.Log("Cartes du pot : " + pot.Pot[i].CarteName);
}
Debug.Log("Paramètres de la partie :");
Debug.Log("Nombre de joueurs :" + this.NombreJoueurs);
for(int i=0;i<this.ListeJoueurs.Count;i++)
{
Debug.Log("Joueur numéro :" + (i + 1));
Debug.Log("Nom du joueur : " + this.ListeJoueurs[i].PlayerName);
Debug.Log("Score du joueur : " + this.ListeJoueurs[i].PlayerScore);
Debug.Log("Ordre du joueur : " + this.ListeJoueurs[i].PlayerOrder);
Debug.Log("Age du joueur : " + this.ListeJoueurs[i].PlayerAge);
Debug.Log("ID du joueur : " + this.ListeJoueurs[i].PlayerId);
}
//Détermination du premier joueur
this.JoueurActif = PremierJoueur(this.ListeJoueurs);
Debug.Log("Le premier joueur est : " + this.ListeJoueurs[this.JoueurActif].PlayerName);
}
}
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Gamemanager : MonoBehaviour {
#region public
public const int nombreMaxPot = 4;
public int nombreJoueurs = 4;
public int age = 3;
public int phase;
public int joueurActif;
public string joueur1, joueur2, joueur3, joueur4;
public int ageJoueur1, ageJoueur2, ageJoueur3, ageJoueur4;
#endregion public
#region private
private Players player1, player2;
private List<Players> listplayer;
private Partie partie;
#endregion private
void Start () {
#region Initialisation
//Création des joueurs
listplayer = new List<Players>();
player1 = new Players(joueur1, 1, 0, 0, ageJoueur1);
player2 = new Players(joueur2, 2, 0, 1, ageJoueur2);
listplayer.Add(player1);
listplayer.Add(player2);
//Initialisation de la partie
partie = new Partie(2, listplayer);
partie.Init();
#endregion Initialisation
}
}
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GUICartes {
public Cartes carte ;
public image icon;
public GameObject graphics;
etc...
}
Voilà, est-ce que vous voyez des trucs, d'un point de vue organisationnel ou structurel complètement à l'ouest? Est-ce que je pars dans une bonne direction?