Partage
  • Partager sur Facebook
  • Partager sur Twitter

Jeu du Pendu mise en place

    1 mai 2008 à 16:37:02

    bonjour ,

    je souhaiterai réaliser le jeu du pendu en définissant tout d abord les différents objets.
    Voila ceux que j ai identifier :

    Les classes :
    Dictionnaire
    Mot
    Joeur (je pensais a 2 types de joueur Humain et ordinateur)
    Partie

    Alors voici les classes que j ' ai implémenté :

    import java.util.ArrayList;
    
    
    public class Dictionnaire {
    	private ArrayList<Mot> mots;
    
    
    	public Mot getMotAtPosition(int position){
    		return mots.get(position);
    	}
    
    	public void deleteMotAtPosition(int position){
    		mots.remove(position);
    	}
    	
    	public void addMot(Mot mot){	
    		this.mots.add(mot);
    	}
    
    	public void deleteMot(Mot mot){	
    		this.mots.remove(mot);
    	}
    	
    	public ArrayList<Mot> getMots() {
    		return mots;
    	}
    
    	public void setMots(ArrayList<Mot> mots) {
    		this.mots = mots;
    	}
    	
    	public String toString(){
    		return this.mots.toString();
    	}
    	
    	public void afficher(){
    		System.out.println(this.toString()+"\n");
    	}
    }
    

    public class Mot {
    	private String chaineCarracteres;
    
    
    	public Mot() {
    		this.chaineCarracteres = "";
    	}
    	
    	public Mot(String chaine) {
    		super();
    		this.chaineCarracteres = chaine;
    	}
    
    	public String getChaineCarracteres() {
    		return chaineCarracteres;
    	}
    
    	public void setMot(String chaine) {
    		this.chaineCarracteres = chaine;
    	}
    	
    	public int getNbLettres(){
    		return this.chaineCarracteres.length();
    	}
    	
    	public boolean compare(Mot motAutre){
    		return motAutre.getChaineCarracteres().toLowerCase().equals(motAutre.getChaineCarracteres().toLowerCase());
    	}
    	
    	public boolean carracterePresent(char carr){
    		String str = new String(carr+"");
    		return this.chaineCarracteres.contains(str.toUpperCase()) || this.chaineCarracteres.contains(str.toLowerCase());
    	}	
    	public boolean carracterePresentAtPosition(char carr, int position){
    		String str = new String(carr+"").toLowerCase();
    		String str2 = (this.chaineCarracteres.toCharArray()[position]+"").toLowerCase();
    		
    		return str.equals(str2);
    	}
    	
    	public ArrayList nbOccurencesLettre(char carr){
    		ArrayList listeOccurences = new ArrayList();
    		
    		int position = 0;
    		
    		char[] tabChar = this.chaineCarracteres.toCharArray();
    		
    		while(position<tabChar.length){
    			if(this.carracterePresentAtPosition(carr,position)){
    				listeOccurences.add(new Integer(position));
    			}
    			
    			position++;
    		}
    		return listeOccurences;
    	}
    	
    	public String toString(){
    		return this.chaineCarracteres;
    	}
    	
    	public void afficher(){
    		System.out.println(this+"\n");
    	}
    }
    


    Ca m' a pris énormément de temps et de galère :-°
    merci



    • Partager sur Facebook
    • Partager sur Twitter
      1 mai 2008 à 18:25:23

      Ok, c'est cool!
      Mias qu'est ce que tu veux savoir? :D
      • Partager sur Facebook
      • Partager sur Twitter

      Jeu du Pendu mise en place

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown