[Picross-commit] SF.net SVN: picross: [61] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2008-04-23 12:05:23
|
Revision: 61 http://picross.svn.sourceforge.net/picross/?rev=61&view=rev Author: yvan_norsa Date: 2008-04-23 05:05:30 -0700 (Wed, 23 Apr 2008) Log Message: ----------- size-based level selection ; dynamic game modes Modified Paths: -------------- trunk/build.xml trunk/data/contents.txt trunk/lib/mmvcs.jar trunk/src/picross/Picross.java trunk/src/picross/PicrossMediator.java trunk/src/picross/game/GameMediator.java trunk/src/picross/game/random/RandomGameMediator.java trunk/src/picross/game/simple/SimpleGameMediator.java trunk/src/picross/menus/GameMenuMediator.java trunk/src/picross/menus/GameMenuUI.java trunk/src/picross/menus/LevelMenuMediator.java trunk/src/picross/menus/LevelMenuModel.java trunk/src/picross/menus/LevelMenuUI.java trunk/src/picross/menus/MenuController.java trunk/src/picross/menus/MenuMediator.java trunk/src/picross/menus/MenuUI.java Added Paths: ----------- trunk/list_contents.sh trunk/services/ trunk/services/picross.game.GameMode trunk/src/picross/game/GameCommand.java trunk/src/picross/game/GameMode.java trunk/src/picross/game/random/RandomGameMode.java trunk/src/picross/game/simple/FileInfo.java trunk/src/picross/game/simple/LevelInfo.java trunk/src/picross/game/simple/SimpleGameMode.java trunk/src/picross/menus/GameMenuModel.java trunk/src/picross/menus/LevelMenuController.java trunk/src/picross/menus/LevelsListCommand.java trunk/src/picross/menus/MenuCommand.java trunk/src/picross/menus/SelectSizeCommand.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/build.xml 2008-04-23 12:05:30 UTC (rev 61) @@ -95,6 +95,10 @@ <fileset dir="data" /> </copy> + <copy todir="${build.dir}/META-INF/services"> + <fileset dir="services" /> + </copy> + <jar destfile="${jar.name}" basedir="${build.dir}" /> </target> Modified: trunk/data/contents.txt =================================================================== --- trunk/data/contents.txt 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/data/contents.txt 2008-04-23 12:05:30 UTC (rev 61) @@ -1,5 +1,5 @@ -audio.xbm -batman2.xbm -bunny.xbm -halloween.xbm -squares.xbm +audio.xbm : 32x32 +batman2.xbm : 32x32 +bunny.xbm : 16x16 +halloween.xbm : 16x16 +squares.xbm : 16x16 Modified: trunk/lib/mmvcs.jar =================================================================== (Binary files differ) Added: trunk/list_contents.sh =================================================================== --- trunk/list_contents.sh (rev 0) +++ trunk/list_contents.sh 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,10 @@ +#!/bin/tcsh + +set dest = data/contents.txt +rm $dest + +foreach file (`ls data/*.xbm`) + set width = `awk '/width/ {print $3}' $file` + set height = `awk '/height/ {print $3}' $file` + echo "$file:t : $width"x"$height" >> $dest +end Property changes on: trunk/list_contents.sh ___________________________________________________________________ Name: svn:executable + * Added: trunk/services/picross.game.GameMode =================================================================== --- trunk/services/picross.game.GameMode (rev 0) +++ trunk/services/picross.game.GameMode 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,2 @@ +picross.game.random.RandomGameMode +picross.game.simple.SimpleGameMode Modified: trunk/src/picross/Picross.java =================================================================== --- trunk/src/picross/Picross.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/Picross.java 2008-04-23 12:05:30 UTC (rev 61) @@ -49,6 +49,9 @@ import org.apache.log4j.Logger; +import picross.game.simple.FileInfo; +import picross.game.simple.LevelInfo; + /** * Helper class. * @@ -168,8 +171,10 @@ return Picross.getFile(Picross.DATA_DIR + name).openStream(); } - public static List<String> listDataFiles() throws IOException { - List<String> list = new ArrayList<String>(); + //public static List<String> listDataFiles() throws IOException { + public static List<LevelInfo> listDataFiles() throws IOException { + //List<String> list = new ArrayList<String>(); + List<LevelInfo> list = new ArrayList<LevelInfo>(); BufferedReader in = null; @@ -179,7 +184,11 @@ String line = null; while ((line = in.readLine()) != null) { - list.add(line); + //list.add(line); + String[] lineData = line.split(":"); + String[] sizeData = lineData[1].trim().split("x"); + + list.add(new FileInfo(lineData[0].trim(), Integer.parseInt(sizeData[0]), Integer.parseInt(sizeData[1]))); } } catch (IOException ioEx) { throw ioEx; Modified: trunk/src/picross/PicrossMediator.java =================================================================== --- trunk/src/picross/PicrossMediator.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/PicrossMediator.java 2008-04-23 12:05:30 UTC (rev 61) @@ -44,6 +44,7 @@ import org.apache.log4j.Logger; +import picross.game.GameCommand; import picross.game.GameMediator; import picross.game.random.RandomGameMediator; @@ -55,6 +56,7 @@ import picross.menus.GameMenuMediator; import picross.menus.LevelMenuMediator; import picross.menus.MainMenuMediator; +import picross.menus.MenuCommand; import picross.menus.MenuMediator; import picross.menus.WaitMenuMediator; @@ -106,11 +108,13 @@ return; } + /* if (cmd.equals(PicrossController.RANDOM_GAME_CMD)) { this.displayWaitScreen(); this.startRandomGame(); return; } + */ if (cmd.equals(PicrossController.NEXT_RANDOM_GAME_CMD)) { this.startRandomGame(); @@ -122,12 +126,30 @@ return; } + /* if (cmd.equals(PicrossController.LEVEL_CMD)) { this.displayWaitScreen(); this.startGame(e.getComment()); return; } + */ + if (cmd.equals("MENU_CMD")) { + MenuCommand command = (MenuCommand) e.getCommand(); + this.displayMenu(command.getMenuClass()); + + return; + } + + if (cmd.equals(GameCommand.GAME_CMD)) { + this.displayWaitScreen(); + + GameCommand command = (GameCommand) e.getCommand(); + this.startGame(command.getGame()); + + return; + } + if (cmd.equals(PicrossController.EXIT_CMD)) { this.exit(); return; @@ -196,6 +218,24 @@ this.view.setContent(menu.getView()); } + private void startGame(final GameMediator game) { + Thread worker = new Thread() { + public void run() { + try { + //game = new RandomGameMediator(); + game.start(); + PicrossMediator.this.gameLoaded(game); + } catch (PicrossException picrossEx) { + PicrossMediator.this.view + .displayError(picrossEx.getMessage()); + return; + } + } + }; + + worker.start(); + } + /** Starts a random game. */ private void startRandomGame() { Thread worker = new Thread() { @@ -204,6 +244,7 @@ try { game = new RandomGameMediator(); + game.start(); PicrossMediator.this.gameLoaded(game); } catch (PicrossException picrossEx) { PicrossMediator.this.view @@ -217,6 +258,7 @@ } /** Starts a new game. */ + /* private void startGame(final String level) { PicrossMediator.log.debug("startGame(" + level + ")"); @@ -241,6 +283,7 @@ worker.start(); } + */ /** * Callback used to display the game view. Added: trunk/src/picross/game/GameCommand.java =================================================================== --- trunk/src/picross/game/GameCommand.java (rev 0) +++ trunk/src/picross/game/GameCommand.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,69 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game; + +import fr.cle.mmvcs.NamedCommand; + +/** + * @author Y. Norsa + */ +public class GameCommand extends NamedCommand { + /*** Constante ***/ + + public static final String GAME_CMD = "GAME_CMD"; + + /*** Champ statique ***/ + + /*** Champ ***/ + + private GameMediator game; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + public GameCommand(GameMediator gameMediator) { + super(GameCommand.GAME_CMD); + + this.game = gameMediator; + } + + /*** M\xE9thode ***/ + + public GameMediator getGame() { + return this.game; + } +} + Property changes on: trunk/src/picross/game/GameCommand.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/game/GameMediator.java =================================================================== --- trunk/src/picross/game/GameMediator.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/game/GameMediator.java 2008-04-23 12:05:30 UTC (rev 61) @@ -113,6 +113,10 @@ */ protected abstract PicrossGrid initModel() throws PicrossException; + public void start() throws PicrossException { + this.init(); + } + /*** Method overloaded from the class Mediator ***/ /** {@inheritDoc} */ Added: trunk/src/picross/game/GameMode.java =================================================================== --- trunk/src/picross/game/GameMode.java (rev 0) +++ trunk/src/picross/game/GameMode.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,46 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game; + +import fr.cle.core.gui.SimpleButton; + +import javax.swing.JButton; + +/** + * @author Y. Norsa + */ +public interface GameMode { + SimpleButton<JButton> getButton(); +} + Property changes on: trunk/src/picross/game/GameMode.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/game/random/RandomGameMediator.java =================================================================== --- trunk/src/picross/game/random/RandomGameMediator.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/game/random/RandomGameMediator.java 2008-04-23 12:05:30 UTC (rev 61) @@ -65,9 +65,9 @@ * @throws PicrossException if there is a problem loading the grid model * or building the view */ - public RandomGameMediator() throws PicrossException { + public RandomGameMediator() {//throws PicrossException { //super(); - this.init(); + //this.init(); } /*** Methods overloaded from the class GameMediator ***/ Added: trunk/src/picross/game/random/RandomGameMode.java =================================================================== --- trunk/src/picross/game/random/RandomGameMode.java (rev 0) +++ trunk/src/picross/game/random/RandomGameMode.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,86 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.random; + +import fr.cle.core.gui.SimpleButton; + +import fr.cle.mmvcs.SimpleEvent; + +import javax.swing.ImageIcon; +import javax.swing.JButton; + +import picross.Picross; + +import picross.game.GameMode; + +/** + * @author Y. Norsa + */ +public class RandomGameMode implements GameMode { + /*** Constante ***/ + + /** Image for the "random" button. */ + private static final String RANDOM_BUTTON_IMAGE = "button-random.png"; + + /** "Random" button X coordinate. */ + private static final int RANDOM_BUTTON_X = 150; + + /** "Random" button Y coordinate. */ + private static final int RANDOM_BUTTON_Y = 175; + + /*** Champ statique ***/ + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + RandomGameMode() { + } + */ + /*** M\xE9thode ***/ + + public SimpleButton<JButton> getButton() { + ImageIcon icon = Picross.getLocalizedImage(RandomGameMode.RANDOM_BUTTON_IMAGE); + SimpleEvent event = new SimpleEvent(new picross.game.GameCommand(new RandomGameMediator())); + SimpleButton<JButton> button = new SimpleButton<JButton>(null, event) { }; + button.getButton().setIcon(icon); + + return button; + } +} + Property changes on: trunk/src/picross/game/random/RandomGameMode.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/simple/FileInfo.java =================================================================== --- trunk/src/picross/game/simple/FileInfo.java (rev 0) +++ trunk/src/picross/game/simple/FileInfo.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,71 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.simple; + +import java.awt.Dimension; + +/** + * @author Y. Norsa + */ +public class FileInfo implements LevelInfo { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + private String name; + private Dimension dimension; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + public FileInfo(String levelName, int width, int height) { + this.name = levelName; + this.dimension = new Dimension(width, height); + } + + /*** M\xE9thode ***/ + + public String getName() { + return this.name; + } + + public Dimension getDimension() { + return this.dimension; + } +} + Property changes on: trunk/src/picross/game/simple/FileInfo.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/game/simple/LevelInfo.java =================================================================== --- trunk/src/picross/game/simple/LevelInfo.java (rev 0) +++ trunk/src/picross/game/simple/LevelInfo.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,45 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.simple; + +import java.awt.Dimension; + +/** + * @author Y. Norsa + */ +public interface LevelInfo { + String getName(); + Dimension getDimension(); +} + Property changes on: trunk/src/picross/game/simple/LevelInfo.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/game/simple/SimpleGameMediator.java =================================================================== --- trunk/src/picross/game/simple/SimpleGameMediator.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/game/simple/SimpleGameMediator.java 2008-04-23 12:05:30 UTC (rev 61) @@ -57,11 +57,11 @@ * @throws PicrossException if there is a problem loading the grid model * or building the view */ - public SimpleGameMediator(String levelName) throws PicrossException { + public SimpleGameMediator(String levelName) {//throws PicrossException { //super(); this.level = levelName; - this.init(); + //this.init(); } /*** Method overloaded from the class GameMediator ***/ Added: trunk/src/picross/game/simple/SimpleGameMode.java =================================================================== --- trunk/src/picross/game/simple/SimpleGameMode.java (rev 0) +++ trunk/src/picross/game/simple/SimpleGameMode.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,88 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.simple; + +import fr.cle.core.gui.SimpleButton; + +import fr.cle.mmvcs.SimpleEvent; + +import picross.Picross; + +import picross.game.GameMode; + +import javax.swing.ImageIcon; +import javax.swing.JButton; + +/** + * @author Y. Norsa + */ +public class SimpleGameMode implements GameMode { + /*** Constante ***/ + + /** Image for the "select" button. */ + private static final String SELECT_BUTTON_IMAGE = "button-select.png"; + + /** "Select" button X coordinate. */ + private static final int SELECT_BUTTON_X = 150; + + /** "Select" button Y coordinate. */ + private static final int SELECT_BUTTON_Y = 250; + + /*** Champ statique ***/ + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + SimpleGameMode() { + } + */ + + /*** M\xE9thode ***/ + + public SimpleButton<JButton> getButton() { + ImageIcon icon = + Picross.getLocalizedImage(SimpleGameMode.SELECT_BUTTON_IMAGE); + SimpleEvent event = new SimpleEvent(new picross.menus.MenuCommand(picross.menus.LevelMenuMediator.class)); + SimpleButton<JButton> button = new SimpleButton<JButton>("", event) { }; + button.getButton().setIcon(icon); + + return button; + } +} + Property changes on: trunk/src/picross/game/simple/SimpleGameMode.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/menus/GameMenuMediator.java =================================================================== --- trunk/src/picross/menus/GameMenuMediator.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/menus/GameMenuMediator.java 2008-04-23 12:05:30 UTC (rev 61) @@ -66,7 +66,7 @@ protected MenuUI initView(PicrossUI ui, MenuController controller) throws PicrossException { - return new GameMenuUI(controller); + return new GameMenuUI(controller, new GameMenuModel().getGameModes()); } } Added: trunk/src/picross/menus/GameMenuModel.java =================================================================== --- trunk/src/picross/menus/GameMenuModel.java (rev 0) +++ trunk/src/picross/menus/GameMenuModel.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,67 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.menus; + +import java.util.Iterator; +import java.util.ServiceLoader; + +import picross.game.GameMode; + +/** + * @author Y. Norsa + */ +class GameMenuModel { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + GameMenuModel() { + } + */ + + /*** M\xE9thode ***/ + + /*Iterator*/ServiceLoader<GameMode> getGameModes() { + return ServiceLoader.load(GameMode.class);//.iterator(); + } +} + Property changes on: trunk/src/picross/menus/GameMenuModel.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/menus/GameMenuUI.java =================================================================== --- trunk/src/picross/menus/GameMenuUI.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/menus/GameMenuUI.java 2008-04-23 12:05:30 UTC (rev 61) @@ -37,8 +37,14 @@ import java.io.FileNotFoundException; +import java.util.Iterator; + +import org.apache.log4j.Logger; + import picross.PicrossController; +import picross.game.GameMode; + /** * UI for the game menu. * @@ -51,23 +57,25 @@ private static final long serialVersionUID = 4472277675596865332L; /** Image for the "random" button. */ - private static final String RANDOM_BUTTON_IMAGE = "button-random.png"; + //private static final String RANDOM_BUTTON_IMAGE = "button-random.png"; /** "Random" button X coordinate. */ - private static final int RANDOM_BUTTON_X = 150; + //private static final int RANDOM_BUTTON_X = 150; /** "Random" button Y coordinate. */ - private static final int RANDOM_BUTTON_Y = 175; + //private static final int RANDOM_BUTTON_Y = 175; /** Image for the "select" button. */ - private static final String SELECT_BUTTON_IMAGE = "button-select.png"; + //private static final String SELECT_BUTTON_IMAGE = "button-select.png"; /** "Select" button X coordinate. */ - private static final int SELECT_BUTTON_X = 150; + //private static final int SELECT_BUTTON_X = 150; /** "Select" button Y coordinate. */ - private static final int SELECT_BUTTON_Y = 250; + //private static final int SELECT_BUTTON_Y = 250; + private static Logger log = Logger.getLogger(GameMenuUI.class); + /*** Constructor ***/ /** @@ -76,9 +84,10 @@ * @param listener listener for the buttons * @throws MissingImageException if a button image can't be found */ - GameMenuUI(ActionListener listener) { + GameMenuUI(MenuController listener, /*Iterator*/java.util.ServiceLoader<GameMode> modes) { super(); + /* this.addButton(GameMenuUI.RANDOM_BUTTON_IMAGE, PicrossController.RANDOM_GAME_CMD, listener, @@ -87,6 +96,21 @@ PicrossController.SELECT_LEVEL_CMD, listener, GameMenuUI.SELECT_BUTTON_X, GameMenuUI.SELECT_BUTTON_Y); + */ + + int x = 150; + int y = 175; + + //while (modes.hasNext()) { + + GameMenuUI.log.debug("listing des modes..."); + + for (GameMode mode : modes) { + GameMenuUI.log.debug("mode : " + mode); + this.addButton(mode/*s.next()*/.getButton(), listener, x, y); + + y += 75; + } } } Added: trunk/src/picross/menus/LevelMenuController.java =================================================================== --- trunk/src/picross/menus/LevelMenuController.java (rev 0) +++ trunk/src/picross/menus/LevelMenuController.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,87 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.menus; + +import fr.cle.mmvcs.SimpleEvent; + +import org.apache.log4j.Logger; + +/** + * @author Y. Norsa + */ +class LevelMenuController extends MenuController { + /*** Constante ***/ + + static final String SIZE_CMD = "SIZE_CMD"; + + static final String LEVELS_LIST_CMD = "LEVELS_LIST_CMD"; + + /*** Champ statique ***/ + + private static Logger log = Logger.getLogger(LevelMenuController.class); + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + LevelMenuController() { + } + */ + + /*** M\xE9thode ***/ + + public void eventPerformed(SimpleEvent e) { + LevelMenuController.log.debug("eventPerformed(" + e + ")"); + + String cmd = e.getCommandName(); + + if (cmd.equals(picross.game.GameCommand.GAME_CMD)) { + return; + } + + if (cmd.equals(LevelMenuController.LEVELS_LIST_CMD)) { + LevelsListCommand command = (LevelsListCommand) e.getCommand(); + ((LevelMenuUI) this.getView()).displayLevels(this, command.getList()); + + return; + } + + super.eventPerformed(e); + } +} + Property changes on: trunk/src/picross/menus/LevelMenuController.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/menus/LevelMenuMediator.java =================================================================== --- trunk/src/picross/menus/LevelMenuMediator.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/menus/LevelMenuMediator.java 2008-04-23 12:05:30 UTC (rev 61) @@ -33,6 +33,12 @@ package picross.menus; +import fr.cle.mmvcs.SimpleEvent; + +import java.util.List; + +import org.apache.log4j.Logger; + import picross.PicrossException; import picross.PicrossUI; @@ -42,6 +48,10 @@ * @author Y. Norsa */ public class LevelMenuMediator extends MenuMediator { + private static Logger log = Logger.getLogger(LevelMenuMediator.class); + + private LevelMenuModel model; + /*** Constructor ***/ /** @@ -56,13 +66,45 @@ /*** Method overloaded from the class MenuMediator ***/ + protected MenuController initController() { + MenuController controller = new LevelMenuController(); + this.addSimpleListener(controller); + + return controller; + } + /** {@inheritDoc} */ @Override protected MenuUI initView(PicrossUI ui, MenuController controller) throws PicrossException { - LevelMenuModel model = new LevelMenuModel(); - return new LevelMenuUI(controller, model.getLevelsList()); + this.model = new LevelMenuModel(); + //return new LevelMenuUI(controller, model.getLevelsList()); + return new LevelMenuUI(controller, this.model.getSizesList()); } + + public void eventPerformed(SimpleEvent e) { + LevelMenuMediator.log.debug("eventPerformed(" + e + ")"); + + String cmd = e.getCommandName(); + + if (cmd.equals(LevelMenuController.SIZE_CMD)) { + SelectSizeCommand command = (SelectSizeCommand) e.getCommand(); + this.displayLevels(this.model.getLevels(command.getSize())); + + return; + } + + if (cmd.equals(picross.PicrossController.LEVEL_CMD)) { + this.fireEventPerformed(new picross.game.GameCommand(new picross.game.simple.SimpleGameMediator(e.getComment()))); + return; + } + + super.eventPerformed(e); + } + + private void displayLevels(List<String> levels) { + this.fireEventPerformed(new LevelsListCommand(levels)); + } } Modified: trunk/src/picross/menus/LevelMenuModel.java =================================================================== --- trunk/src/picross/menus/LevelMenuModel.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/menus/LevelMenuModel.java 2008-04-23 12:05:30 UTC (rev 61) @@ -33,13 +33,20 @@ package picross.menus; +import java.awt.Dimension; + import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import picross.Picross; import picross.PicrossException; +import picross.game.simple.LevelInfo; + /** * Model for the level selection menu. * @@ -49,8 +56,10 @@ /*** Field ***/ /** Level list. */ - private List<String> levels; + //private List<String> levels; + private Map<Dimension, List<String>> levels; + /*** Constructor ***/ /** @@ -59,11 +68,28 @@ * @throws PicrossException if an error arises during the levels listing */ LevelMenuModel() throws PicrossException { + this.levels = new HashMap<Dimension, List<String>>(); + + List<LevelInfo> infos = null; + try { - this.levels = Picross.listDataFiles(); + //this.levels = Picross.listDataFiles(); + infos = Picross.listDataFiles(); } catch (IOException ioEx) { throw new PicrossException(ioEx); } + + for (LevelInfo info : infos) { + Dimension levelSize = info.getDimension(); + List<String> levelsList = this.levels.get(levelSize); + + if (levelsList == null) { + levelsList = new ArrayList<String>(); + this.levels.put(levelSize, levelsList); + } + + levelsList.add(info.getName()); + } } /*** Method ***/ @@ -73,8 +99,12 @@ * * @return list of the level files */ - List<String> getLevelsList() { - return this.levels; + List<String> getLevels(Dimension size) { + return this.levels.get(size); } + + List<Dimension> getSizesList() { + return new ArrayList<Dimension>(this.levels.keySet()); + } } Modified: trunk/src/picross/menus/LevelMenuUI.java =================================================================== --- trunk/src/picross/menus/LevelMenuUI.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/menus/LevelMenuUI.java 2008-04-23 12:05:30 UTC (rev 61) @@ -36,6 +36,8 @@ import fr.cle.mmvcs.SimpleEvent; import fr.cle.mmvcs.SimpleListener; +import java.awt.Dimension; + import java.util.List; import picross.PicrossController; @@ -59,15 +61,40 @@ * @param listener listener for the buttons * @param levels levels list */ - LevelMenuUI(SimpleListener listener, List<String> levels) { + //LevelMenuUI(SimpleListener listener, List<String> levels) { + LevelMenuUI(SimpleListener listener, List<Dimension> sizes) { super(); - int x = 50; + int x = 150; int y = 150; + int nbSizes = sizes.size(); + + for (int i = 0; i < nbSizes; i++) { + Dimension currentDim = sizes.get(i); + String size = (int) currentDim.getWidth() + "x" + + (int) currentDim.getHeight(); + + SimpleEvent event = new SimpleEvent(new SelectSizeCommand(currentDim)); + this.addSimpleButton(size, event, listener, x, y); + + y += 75; + + if (y == 375) { + x = 250; + y = 150; + } + } + } + + void displayLevels(SimpleListener listener, List<String> levels) { + this.removeAll(); + + int x = 150; + int y = 150; + for (String level : levels) { - SimpleEvent event = new SimpleEvent(PicrossController.LEVEL_CMD, - level); + SimpleEvent event = new SimpleEvent(PicrossController.LEVEL_CMD, level); this.addSimpleButton(level, event, listener, x, y); y += 75; @@ -77,6 +104,8 @@ y = 150; } } + + this.repaint(); } } Added: trunk/src/picross/menus/LevelsListCommand.java =================================================================== --- trunk/src/picross/menus/LevelsListCommand.java (rev 0) +++ trunk/src/picross/menus/LevelsListCommand.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,69 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.menus; + +import fr.cle.mmvcs.NamedCommand; + +import java.util.List; + +/** + * @author Y. Norsa + */ +class LevelsListCommand extends NamedCommand { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + private List<String> list; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + LevelsListCommand(List<String> levels) { + super(LevelMenuController.LEVELS_LIST_CMD); + + this.list = levels; + } + + /*** M\xE9thode ***/ + + List<String> getList() { + return this.list; + } +} + Property changes on: trunk/src/picross/menus/LevelsListCommand.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/menus/MenuCommand.java =================================================================== --- trunk/src/picross/menus/MenuCommand.java (rev 0) +++ trunk/src/picross/menus/MenuCommand.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,67 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.menus; + +import fr.cle.mmvcs.NamedCommand; + +/** + * @author Y. Norsa + */ +public class MenuCommand extends NamedCommand { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + private Class<? extends MenuMediator> menuClass; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + public MenuCommand(Class<? extends MenuMediator> mediatorClass) { + super("MENU_CMD"); + + this.menuClass = mediatorClass; + } + + /*** M\xE9thode ***/ + + public Class<? extends MenuMediator> getMenuClass() { + return this.menuClass; + } +} + Property changes on: trunk/src/picross/menus/MenuCommand.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/menus/MenuController.java =================================================================== --- trunk/src/picross/menus/MenuController.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/menus/MenuController.java 2008-04-23 12:05:30 UTC (rev 61) @@ -39,15 +39,23 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import org.apache.log4j.Logger; + /** * @author Y. Norsa */ class MenuController extends Controller implements ActionListener { + private static Logger log = Logger.getLogger(MenuController.class); + + private MenuUI view; + /*** Method overloaded from the class Controller ***/ /** {@inheritDoc} */ @Override public void eventPerformed(SimpleEvent e) { + MenuController.log.debug("eventPerformed(" + e + ")"); + this.fireEventPerformed(e); } @@ -58,5 +66,13 @@ String cmd = e.getActionCommand(); this.fireEventPerformed(cmd); } + + void setView(MenuUI ui) { + this.view = ui; + } + + protected MenuUI getView() { + return this.view; + } } Modified: trunk/src/picross/menus/MenuMediator.java =================================================================== --- trunk/src/picross/menus/MenuMediator.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/menus/MenuMediator.java 2008-04-23 12:05:30 UTC (rev 61) @@ -66,12 +66,20 @@ * @throws PicrossException if the instantiation of the view fails */ MenuMediator(PicrossUI ui) throws PicrossException { - MenuController controller = new MenuController(); + //MenuController controller = new MenuController(); + MenuController controller = this.initController(); controller.addSimpleListener(this); this.view = this.initView(ui, controller); + + MenuMediator.log.debug("controller.setView()"); + controller.setView(this.view); } + protected MenuController initController() { + return new MenuController(); + } + /*** Abstract method ***/ /** Modified: trunk/src/picross/menus/MenuUI.java =================================================================== --- trunk/src/picross/menus/MenuUI.java 2008-04-22 12:46:19 UTC (rev 60) +++ trunk/src/picross/menus/MenuUI.java 2008-04-23 12:05:30 UTC (rev 61) @@ -151,6 +151,13 @@ this.putButton(button.getButton(), x, y, 150, 50); } + protected void addButton(SimpleButton<JButton> button, SimpleListener listener, + int x, int y) { + button.addSimpleListener(listener); + button.getButton().setBorder(null); + this.putButton(button.getButton(), x, y, button.getButton().getIcon().getIconWidth(), button.getButton().getIcon().getIconHeight()); + } + private void putButton(JButton button, int x, int y, int width, int height) { button.setBounds(x, y, width, height); this.add(button); Added: trunk/src/picross/menus/SelectSizeCommand.java =================================================================== --- trunk/src/picross/menus/SelectSizeCommand.java (rev 0) +++ trunk/src/picross/menus/SelectSizeCommand.java 2008-04-23 12:05:30 UTC (rev 61) @@ -0,0 +1,69 @@ +/* + * $Id$ + * + * Copyright (c) 2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.menus; + +import fr.cle.mmvcs.NamedCommand; + +import java.awt.Dimension; + +/** + * @author Y. Norsa + */ +class SelectSizeCommand extends NamedCommand { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + private Dimension size; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + SelectSizeCommand(Dimension dim) { + super(LevelMenuController.SIZE_CMD); + + this.size = dim; + } + + /*** M\xE9thode ***/ + + Dimension getSize() { + return this.size; + } +} + Property changes on: trunk/src/picross/menus/SelectSizeCommand.java ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |