Blocage projet rpg !

anthonyhk Messages postés 1 Date d'inscription samedi 7 janvier 2006 Statut Membre Dernière intervention 18 mai 2007 - 18 mai 2007 à 09:50
rudybaka Messages postés 8 Date d'inscription vendredi 10 février 2006 Statut Membre Dernière intervention 24 mai 2007 - 21 mai 2007 à 08:54
voila g un probleme avecm on programme.
g deux classes, une classe Carte et une classe PersonnageJoueur extends Personnage
voila
en gros, ce que jarrive pas, c'est quand la carte est crée et
initialisé, je voudrais placer un personnageJoueur sur la carte afin
que après il puisse se déplacer sur la carte.mais je n'arrive pas a placer un perso sur la carte ( peut être à travers une private static final ?! genre un numero qui deésigne le joueur)

pouvez vous m'aider svp

merci d'avance


HeooO !   

g initialiser la class carte comme ceci ( pas encore fini) :

import java.util.*;
import java.io.*;
public class Carte
{
    public final static char MUR='#';
    public final static char CASE_VIDE =' ';
    private final static int LONGUEUR=24;
    private final static int LARGEUR=32;
   
    private char[][] tab;
    private String nomCarte;
   
    //Constructeurs
   
    public Carte()
    {
        this.tab=new char[Carte.LONGUEUR][Carte.LARGEUR];
        for(int i=0;i<Carte.LONGUEUR;i++)
        {
            for(int j=0;j<Carte.LARGEUR;j++)
            {
                this.tab[i][j]=Carte.CASE_VIDE;
            }
        }
       
        for(int i=0; i<Carte.LONGUEUR; i++)
        {
            this.tab[i][0]=Carte.MUR;
        }
        for(int j=0; j<Carte.LARGEUR; j++)
        {
            this.tab[0][j]=Carte.MUR;
        }
        for(int i=0; i<Carte.LONGUEUR; i++)
        {
            this.tab[i][Carte.LARGEUR-1]=Carte.MUR;
        }
        for(int j=0; j<Carte.LARGEUR; j++)
        {
            this.tab[Carte.LONGUEUR-1][j]=Carte.MUR;
        }
    }
   
    public Carte(Carte uneCarte)
    {
        this.nomCarte=new String(uneCarte.nomCarte);
        for(int i =0; i<Carte.LONGUEUR;i++)
        {
            for(int j=0; j<Carte.LARGEUR; j++)
            {
                this.tab[i][j] = uneCarte.getTab()[i][j];
            }
        }
    }
   
    //Methodes
   
    public char[][] getTab()
    {
        return this.tab;
    }
   
    public void setTab(char [][] tab)
    {
        this.tab=tab;
    }
   
    public String getNomCarte()
    {
        return this.nomCarte;
    }
   
    public void setNomCarte(String unNom)
    {
        this.nomCarte=unNom;
    }
   
    public void init()
    {
        int type = Clavier.readInt("\nQuelle carte choisissez vous ?\n\t1.Labyrinthe\n\t2.City\n\t3.Arena\n\t4.Aleatoire\n");
        switch(type)
        {
            case 1:
            {
                this.setNomCarte("Labyrinthe");
                for(int i=1; i<5; i++)
                {
                    this.getTab()[i][7]=Carte.MUR;
                }
                for(int i=1; i<5; i++)
                {
                    this.getTab()[i][Carte.LARGEUR-8]=Carte.MUR;
                }
                for(int j=1; j<11; j++)
                {
                    this.getTab()[Carte.LONGUEUR-4][j]=Carte.MUR;
                }
                for(int j=Carte.LARGEUR-1;j>Carte.LARGEUR-12; j--)
                {
                    this.getTab()[Carte.LONGUEUR-4][j]=Carte.MUR;
                }
                for(int j=5; j<15; j++)
                {
                    this.getTab()[Carte.LONGUEUR-7][j]=Carte.MUR;
                }
                for(int j=Carte.LARGEUR-6; j>Carte.LARGEUR-16; j--)
                {
                    this.getTab()[Carte.LONGUEUR-7][j]=Carte.MUR;
                }
                for(int i=Carte.LONGUEUR-8; i>Carte.LONGUEUR-14; i--)
                {
                    this.tab[i][5]=Carte.MUR;
                }
                for(int i=Carte.LONGUEUR-8; i>Carte.LONGUEUR-13; i--)
                {
                    this.getTab()[i][LARGEUR-6]=Carte.MUR;
                }
                for(int j=3; j<15; j++)
                {
                    this.getTab()[7][j]=Carte.MUR;
                }
                for(int j=Carte.LARGEUR-4; j>Carte.LARGEUR-15; j--)
                {
                    this.getTab()[7][j]=Carte.MUR;
                }
                break;
            }
            case 2:
            {
                this.setNomCarte("City");
                for(int j=5; j<Carte.LARGEUR-5; j++)
                {
                    this.getTab()[3][j]=Carte.MUR;
                }
                for(int j=5; j<11; j++)
                {
                    this.getTab()[6][j]=Carte.MUR;
                }
                for(int i=6; i<10; i++)
                {   
                    this.getTab()[i][11]=Carte.MUR;
                }
                for(int j=5; j<12 ; j++)
                {
                    this.getTab()[10][j]=Carte.MUR;
                }
                for(int j=5; j<11; j++)
                {
                    this.getTab()[13][j]=Carte.MUR;
                }
                for(int i=13; i<17; i++)
                {   
                    this.getTab()[i][11]=Carte.MUR;
                }
                for(int j=5; j<12; j++)
                {
                    this.getTab()[17][j]=Carte.MUR;
                }
                for(int j=21; j<Carte.LARGEUR-5; j++)
                {
                    this.getTab()[6][j]=Carte.MUR;
                }
                for(int i=7; i<17; i++)
                {
                    this.getTab()[i][21]=Carte.MUR;
                }
                for(int j=21; j<Carte.LARGEUR-5; j++)
                {
                    this.getTab()[17][j]=Carte.MUR;
                }
                for(int j=5; j<Carte.LARGEUR-5; j++)
                {
                    this.getTab()[Carte.LONGUEUR-4][j]=Carte.MUR;
                }
                break;
            }
            case 3:
            {
                this.setNomCarte("Arena");
                for(int i=5; i<Carte.LONGUEUR-5; i++)
                {
                    this.getTab()[i][7]=Carte.MUR;
                }
                for(int i=5; i<Carte.LONGUEUR-5; i++)
                {
                    this.getTab()[i][Carte.LARGEUR-8]=Carte.MUR;
                }
                for(int j=7; j<14; j++)
                {
                    this.getTab()[4][j]=Carte.MUR;
                }
                for(int j=Carte.LARGEUR-8; j>Carte.LARGEUR-15; j--)
                {
                    this.getTab()[4][j]=Carte.MUR;
                }
                for(int j=7; j<14; j++)
                {
                    this.getTab()[Carte.LONGUEUR-5][j]=Carte.MUR;
                }
                for(int j=Carte.LARGEUR-8; j>Carte.LARGEUR-15; j--)
                {
                    this.getTab()[Carte.LONGUEUR-5][j]=Carte.MUR;
                }
                this.getTab()[12][15]=Carte.MUR;
                this.getTab()[12][16]=Carte.MUR;
                this.getTab()[11][15]=Carte.MUR;
                this.getTab()[11][16]=Carte.MUR;
                break;
            }
        }
    }
       
    public String toString()
    {
        String s="";
        s=s+"Nom de la carte : "+this.getNomCarte()+"\n\n";
        for(int i=0; i<Carte.LONGUEUR; i++)
        {
            for(int j=0; j<Carte.LARGEUR; j++)
            {
                s=s+this.getTab()[i][j];
            }
            s=s+"\n";
        }
        this.getTab()[4][5]=1;
       
        return s;
    }
   
    public void sauverCarte (String nomFichier)
    {
        File accesFichier = new File (nomFichier);
        if (accesFichier.exists())
            System.err.println ("Ce fichier existe deja");
        else
        {FileOutputStream fOut;
        ObjectOutputStream sOut;
        try
        {
            fOut = new FileOutputStream (accesFichier);
            sOut = new ObjectOutputStream (fOut);
            sOut.writeObject (this);
            sOut.close();
            fOut.close();
        }
        catch (IOException e)
        {
            System.err.println (e);
            fOut = null;
            sOut = null;
        }
        }
    }

    public static Carte chargerCarte (String nomFichier)
    {
        Carte c = null;
        File accesFichier = new File (nomFichier);
        if (!accesFichier.exists())
            System.err.println ("Ce fichier n'existe pas" );
        else
        {
            FileInputStream fIn;
            ObjectInputStream sIn;
            try
            {
                fIn = new FileInputStream (accesFichier);
                sIn = new ObjectInputStream (fIn);
                c = (Carte) sIn.readObject ();
                sIn.close();
                fIn.close();
            }
            catch (IOException e)
            {
                System.err.println (e);
                c = null;
            }
            catch (ClassNotFoundException e)
            {
                System.err.println (e);
            }
            finally
            {
                sIn = null;
                fIn = null;
            }   
        }
        return c;
    }
}
           
   et voici la class PersonnageJoueur ( non fini aussi lol ) :

import java.util.*;
import java.io.*;

public class PersonnageJoueur extends Personnage
{
    public static final char persoJoueur='1';
   
    private int niveauBlessure;
    private int force;
    private int adresse;
    private int resistance;
    private ArrayList inventaires;
    private Coordonnee placeInit;

//Constructeurs

    public PersonnageJoueur()
    {
    super();
    this.inventaires=new ArrayList();
    this.placeInit=new Coordonnee();
    }

    public PersonnageJoueur(String nom, int force, int adresse, int resistance, int initiative, int attaque, int esquive,
    int defense, int degats, int pv, int pa, int niveauBlessure,ArrayList inventaires, Coordonnee position)
    {
    super(nom,initiative,attaque,esquive,defense,degats,pv,pa,position);
    this.niveauBlessure=niveauBlessure;
    this.force=force;
    this.adresse=adresse;
    this.resistance=resistance;
    this.inventaires=inventaires;
    this.placeInit=new Coordonnee(1,1);
    }
   
    public PersonnageJoueur( PersonnageJoueur unJoueur)
    {
    super(unJoueur);
    this.niveauBlessure=unJoueur.getNiveauBlessure();
    this.force=unJoueur.getForce();
    this.adresse=unJoueur.getAdresse();
    this.resistance=unJoueur.getResistance();
    this.inventaires=new ArrayList(unJoueur.inventaires);
    //this.placeInit=new Coordonnee(unJoueur.placeInit);
    }
   
//Methodes

    public int getForce()
    {
    return this.force;
    }

    public void setForce(int force)
    {
    this.force=force;    
    }

    public int getAdresse()
    {
    return this.adresse;
    }
   
    public void setAdresse(int adresse)
    {
    this.adresse=adresse;    
    }

    public void setResistance(int resistance)
    {
    this.resistance=resistance;
    }

    public int getResistance()
    {
    return this.resistance;
    }
   
    public int getNiveauBlessure()
    {
        return this.niveauBlessure;
    }
   
    public void setNiveauBlessure(int niveauBlessure)
    {
        this.niveauBlessure=niveauBlessure;
    }
   
    public Coordonnee getPlaceInit()
    {
        return this.placeInit;
    }
   
    public void setPlaceInit(Coordonnee placeInit)
    {
        this.placeInit=placeInit;
    }
   
    public String caracteristiqueString()
    {
        String s="";
        s=s+"\nVos caracteristiques sont :\n\t- Force : "+this.getForce()+"\n\t- Adresse : "+this.getAdresse() +
   
    "\n\t- Resistance : "+this.getResistance()+"\n\t+ Initiative :
"+this.getInitiative()+"\n\t+ Attaque : "+this.getAttaque()+
        "\n\t+ Defense : "+this.getDefense()+"\n\t+ Degats : "+this.getDegats();
        if(this.getNiveauBlessure() == 30)
        {        
            s=s+"\nVotre niveaux de blessures est : en forme\nVotre nombre de points d action est : "+this.getPa();
        }
        if(this.getNiveauBlessure()<30 && this.getNiveauBlessure()>=25)
        {
   
        s=s+"\nVotre niveaux de blessures est : Blessures
superficielles\nVotre nombre de points d action est : "+this.getPa();
        }
        if(this.getNiveauBlessure()<25 && this.getNiveauBlessure()>=20)
        {
            s=s+"\nVotre niveaux de blessures est : Legerement blesse \nVotre nombre de points d action est : "+this.getPa();
        }
        if(this.getNiveauBlessure()<20 && this.getNiveauBlessure()>=15)
        {
            s=s+"\nVotre niveaux de blessures est : Blesse \nVotre nombre de points d action est : "+this.getPa();
        }
        if(this.getNiveauBlessure()<15 && this.getNiveauBlessure()>=8)
        {
            s=s+"\nVotre niveaux de blessures est : Gravement blesse \nVotre nombre de points d action est : "+this.getPa();
        }
        if(this.getNiveauBlessure()<8 && this.getNiveauBlessure()>=1)
        {
            s=s+"\nVotre niveaux de blessures est : Inconscient \nVotre nombre de points d action est : "+this.getPa();
        }
        if(this.getNiveauBlessure()==0)
        {
            s=s+"\nVotre niveaux de blessures est : MORT \nVotre nombre de points d action est : "+this.getPa();
        }
        return s;
    }
        
    public String toString()
    {
        String s="";
        s=s+"\nNom : "+this.getNom()+this.caracteristiqueString();
        return s;
    }
   
    public void init()
    {
        int degre=18;
        this.setNom(Clavier.readString("\nEntrez votre nom : "));
        this.setNiveauBlessure(30);
        this.setPa(4);
        while(degre > 0)
        {
            System.out.println("\n\nVous avez encore "+degre+" degres de caracteristique a placer.");
            int choix=Clavier.readInt("Choisir une caracteristiques a evoluer :\n\t1. Force("+this.getForce()+
            ")\n\t2. Adresse("+this.getAdresse()+")\n\t3. Resistance("+this.getResistance()+")\nVotre choix : ");
            switch (choix)
            {
                case 1:
                {
                    this.setForce(this.getForce()+1);
                    this.setDegats(this.getDegats()+1);
                    break;
                }
                case 2:
                {
                    this.setAdresse(this.getAdresse()+1);
                    this.setInitiative(this.getInitiative()+1);
                    this.setAttaque(this.getAttaque()+1);
                    this.setEsquive(this.getEsquive()+1);
                    break;
                }
                case 3:
                {
                    this.setResistance(this.getResistance()+1);
                    this.setDefense(this.getDefense()+1);
                    break;
                }                                    
            }
            degre--;
        }
        this.setPlaceInit(this.getPlaceInit());    
    }

    public void sauverPersoJ (String nomFichier)
    {
        File accesFichier = new File (nomFichier);
        if (accesFichier.exists())
            System.err.println ("Ce fichier existe deja");
        else
        {FileOutputStream fOut;
        ObjectOutputStream sOut;
        try
        {
            fOut = new FileOutputStream (accesFichier);
            sOut = new ObjectOutputStream (fOut);
            sOut.writeObject (this);
            sOut.close();
            fOut.close();
        }
        catch (IOException e)
        {
            System.err.println (e);
            fOut = null;
            sOut = null;
        }
        }
    }

    public static PersonnageJoueur chargerpersoJ (String nomFichier)
    {
        PersonnageJoueur pJ = null;
        File accesFichier = new File (nomFichier);
        if (!accesFichier.exists())
            System.err.println ("Ce fichier n'existe pas" );
        else
        {
            FileInputStream fIn;
            ObjectInputStream sIn;
            try
            {
                fIn = new FileInputStream (accesFichier);
                sIn = new ObjectInputStream (fIn);
                pJ = (PersonnageJoueur) sIn.readObject ();
                sIn.close();
                fIn.close();
            }
            catch (IOException e)
            {
                System.err.println (e);
                pJ = null;
            }
            catch (ClassNotFoundException e)
            {
                System.err.println (e);
            }
            finally
            {
                sIn = null;
                fIn = null;
            }    
        }
        return pJ;
    }

            
}
   
       
               

1 réponse

rudybaka Messages postés 8 Date d'inscription vendredi 10 février 2006 Statut Membre Dernière intervention 24 mai 2007
21 mai 2007 à 08:54
Si tu ve pouvoir deplacer ton objet sur la carte, je pense que le mieux est de crée un personnage dans ta carte. Donc à la contruction de ta carte tu lui passe un personnage et tu rajoute une methode te permettant de recupérer le personnage : getPersonnageJoueur()
Ensuite tu manipule ton personnage grace a cette methode :
getPersonnageJoueur().getForce()
...
0
Rejoignez-nous