Partage
  • Partager sur Facebook
  • Partager sur Twitter

Sokoban

    17 avril 2012 à 16:05:17

    Bonjour à tous,

    Je suis actuellement sur un projet important qui est développé un petit jeu video : le Sokoban.
    à l'heure d'aujourd'hui, je parviens à afficher l'interface graphique avec le personnage, la grille , les caisses, les boutons de déplacement .. etc
    En revanche je ne parviens à deplacer le sokoban donc je me trounes vers vous afin d'avoir un petit coup de pouce.

    Voici les classes qui selon moi pose problème ainsi que la javadoc( qui est le document sur lequel j'ai dû m'appuyer pour créer mes differentes classes).

    Javadoc

    http://igm.univ-mlv.fr/~masson//Teachi [...] -summary.html

    Game.java
    public class Game extends Object{
    
    	    private final Level level;
        private final List<SokobanGUI> listeners = new ArrayList<SokobanGUI>();
    	private SokobanGUI gui;
    
      	public Game(final Level l) {
    		 level = l;
    
    
    	}
    
    		public final Level getLevel() {
    		return level;
    	}
    
    	public void addSokobanGUI(SokobanGUI gui) {
    		listeners.add(gui);
    	}
    	
    	  private void notifyGUI()
    	    {
    	        SokobanGUI gui;
    	        for(Iterator<SokobanGUI> iterator = listeners.iterator(); iterator.hasNext(); gui.refreshAll())
    	            gui = iterator.next();
    
    	    }
    
    	    private void notifyGUI(List<Position> l)
    	    {
    	        if(l == null)
    	        {
    	            notifyGUI();
    	        } else
    	        {
    	            SokobanGUI gui;
    	            for(Iterator<SokobanGUI> iterator = listeners.iterator(); iterator.hasNext(); gui.refresh(l.toArray(new Position[0])))
    	                gui = iterator.next();
    
    	        }
    	    }
    
        public void playLevel() {
        	 notifyGUI();
             boolean end = false;
             do
             {
                 do
                 {
                     Command cmds[] = getFromGUIs();
                     Command acommand[];
                     int j = (acommand = cmds).length;
                     for(int i = 0; i < j; i++)
                     {
                         Command c = acommand[i];
                         if(end)
                         {
                            if(!EnumSet(SimpleCommand.HELP, SimpleCommand.EXIT, SimpleCommand.NEXT).contains(c.commande))
                             {
                                 printGUI("Le niveau est terminŽ ! Essayez 'Exit' ou 'Next'");
                                 continue;
                             }
                         } else
                         if(c.commande.equals(SimpleCommand.NEXT))
                         {
                             printGUI("Vous devez terminer le niveau !");
                             continue;
                         }
                         if(c.commande.equals(SimpleCommand.HELP))
                         {
                             printGUI("Les commandes sont : ");
                             notifyGUI();
                             continue;
                         }
                         if(c.commande.equals(SimpleCommand.UP))
                         {
                             printGUI("dŽplacement vers le haut !");
                             notifyGUI();
                             continue;
                         }
                         if(c.commande.equals(SimpleCommand.DOWN))
                         {
                             printGUI("dŽplacement vers le bas !");
                             notifyGUI();
                             continue;
                         }
                         if(c.commande.equals(SimpleCommand.LEFT))
                         {
                             printGUI("dŽplacement ˆ gauche !");
                             notifyGUI();
                             continue;
                         }
                         if(c.commande.equals(SimpleCommand.RIGHT))
                         {
                             printGUI("dŽplacement ˆ droite !");
                             
                             notifyGUI();
                             continue;
                         }
                         try
                         {
                             List<Position> l = c.changeModel(this);
                             if(/*end &&*/ l != null)
                             {
                                 end = false;
                                 notifyGUI(null);
                             } else
                             {
                                 notifyGUI(l);
                             }
                         }
                         catch(InvalidMoveException e)
                         {
                             printGUI((new StringBuilder("Mouvement impossible : ")).append(e.getMessage()).toString());
                         }
                     }
    
                 } while(end || !level.victory());
                 printGUI("Niveau terminŽ !");
                 end = true;
             } while(true);
         }
    	
    
    	private List<Position> EnumSet(fr.upe.pim.inf1.sokoban.controller.SimpleCommand HELP,
    			fr.upe.pim.inf1.sokoban.controller.SimpleCommand EXIT,
    			fr.upe.pim.inf1.sokoban.controller.SimpleCommand NEXT
    			) {
    		return null;
    	}
    
    	public void printGUI(String string) {
    		 SokobanGUI gui;
    	        for(Iterator<SokobanGUI> iterator = listeners.iterator(); iterator.hasNext(); gui.printMessage(string))
    	            gui = iterator.next();
    	}
    	
    	private Command[] getFromGUIs()
        {
            for(Iterator<SokobanGUI> iterator = listeners.iterator(); iterator.hasNext();)
            {
                SokobanGUI gui = (SokobanGUI) iterator.next();
                Command cmds[] = gui.getCommandsList();
                if(cmds != null)
                    return cmds;
            }
    		return null;
    
        }
    
    	public void getHelp() {
    		 StringBuilder sb = new StringBuilder();
    	        sb.append("Les commandes valides sont : ");
    	        String s;
    	        for(Iterator<String> iterator = Command.commandNames.keySet().iterator(); iterator.hasNext(); sb.append(s).append("/"))
    	            s = (String)iterator.next();
    
    	        return;
    	}
    
    	public SokobanGUI getGui() {
    		return gui;
    	}
    
    	public void setGui(SokobanGUI gui) {
    		this.gui = gui;
    	}
    
    }
    


    SimpleCommand.java

    public enum SimpleCommand implements Comparable<SimpleCommand> {
    
    
    
    	
    	        UP ("UP", 0) ,  
    	        DOWN ("DOWN", 1) ,  
    	        LEFT ("LEFT", 2) ,   
    	        RIGHT ("RIGHT", 3),
    	        EXIT ("EXIT", 4) ,
    	        HELP ("HELP", 5) ,
    	        RESET ("RESET", 6),
    	        NEXT ("NEXT", 7) ;   
    
    
    			protected String s;
    	        protected int i;
    		
    		   SimpleCommand(String s1, int i1)
    		    {
    		        this.s=s1;
    		        this.i=i1;
    		      
    		    }
    
    
    
    List<Position> changeModel(Game controller, int distance) throws InvalidMoveException {
    	equals(distance);
    	return null;
    } 
    
      /* public static SimpleCommand[] values()
        {
            SimpleCommand asimplecommand[];
            int i;
            SimpleCommand asimplecommand1[];
            System.arraycopy(asimplecommand = values(), 0, asimplecommand1 = new SimpleCommand[i = asimplecommand.length], 0, i);
            return asimplecommand1;
        }*/
    
       /* public static SimpleCommand valueOf(String s)
        {
            return (SimpleCommand)Enum.valueOf(null, SimpleCommand.s);
        }*/
        }
    






    • Partager sur Facebook
    • Partager sur Twitter

    Sokoban

    × 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