// GameScreen.java import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.io.IOException; /** * A factory class for the game itself. * This class deals with all decisions and rendering for the game. * Primarily it allocates control between smaller more specific classes that * make up the game. It also initliases all resources required for game-play * and in-game menus. * * @author Jack Wootton * @version Last modified 10/03/05 **/ public class GameScreen { private static boolean isActive; private int defaultFontHeight; private static int width, height, halfScreenWidth, halfScreenHeight; private static boolean inWorld, inShop, inOptions, inQuestions, inInventory, inInn; public GameScreen() { } public static void setInWorld(boolean b) { inWorld = b; if (b) { inShop = false; inOptions = false; inQuestions = false; inInventory = false; inInn = false; } } public static void setInShop(boolean b) { inShop = b; if (b) { inWorld = false; inOptions = false; inQuestions = false; inInventory = false; inInn = false; } } public static void setInOptions(boolean b) { inOptions = b; if (b) { inWorld = false; inShop = false; inQuestions = false; inInventory = false; inInn = false; } } public static void setInQuestions(boolean b) { inQuestions = b; if (b) { inWorld = false; inShop = false; inOptions = false; inInventory = false; inInn = false; } } public static void setInInventory(boolean b) { inInventory = b; if (b) { inWorld = false; inShop = false; inOptions = false; inQuestions = false; inInn = false; } } public static void setInInn(boolean b) { inInn = b; if (b) { inWorld = false; inShop = false; inOptions = false; inQuestions = false; inInventory = false; } } public static boolean getInWorld() { return inWorld; } public static boolean getInShop() { return inShop; } public static boolean getInOptions() { return inOptions; } public static boolean getInQuestions() { return inQuestions; } public static boolean getInInventory() { return inInventory; } public static boolean getInInn() { return inInn; } public static void initGame(int w, int h) { width = w; height = h; halfScreenWidth = h / 2; halfScreenHeight = h / 2; TheOthers.init(); World.init(width, height); Player.init(halfScreenWidth, halfScreenHeight); // Calls Player.setup(); WeaponsShop.init(w, h); Options.init(w,h); TaskHut.init(w,h); Inventory.init(w,h); Inn.init(w,h); inWorld = false; inShop = false; } public static boolean isActive() { return isActive; } public static void destroy() { /* destroy and null things we don't need in memory */ } protected static void paint(Graphics graphics) { isActive = true; graphics.setColor(0x00000000); graphics.fillRect(0, 0, width, height); if (inWorld) { World.setView(Player.getCenterX() - halfScreenWidth, Player.getCenterY() - halfScreenHeight); // Paint the world and everything in it World.render(graphics); } else if (inShop) { // Draw shop menu WeaponsShop.paint(graphics); } else if (inOptions) { // Draw options menu Options.paint(graphics); } else if (inQuestions) { // Draw questions interface TaskHut.paint(graphics); } else if (inInventory) { // Draw the players inventory Inventory.paint(graphics); } else if (inInn) { // Draw the Inn interface Inn.paint(graphics); } } public static void processKey(int keyCode, int GameActionKey) { if (inWorld) { // The effect of keys in the world is to move the player if (GameActionKey == Canvas.UP) { Player.moveUp(); } else if (GameActionKey == Canvas.DOWN) { Player.moveDown(); } else if (GameActionKey == Canvas.RIGHT) { Player.moveRight(); } else if (GameActionKey == Canvas.LEFT) { Player.moveLeft(); } World.cycle(); } else if (inShop) { // The effect of keys in the shop is too highlight items to buy WeaponsShop.processKey(keyCode, GameActionKey); } else if (inOptions) { // The effect of keys in the options screen is too highlight options Options.processKey(keyCode, GameActionKey); } else if (inQuestions) { TaskHut.processKey(keyCode, GameActionKey); } else if (inInventory) { Inventory.processKey(keyCode, GameActionKey); } else if (inInn) { Inn.processKey(keyCode, GameActionKey); } } protected static void processKeyRepeated(int keyCode, int GameActionKey) { } public static void newGame() { // We don't bother creating a new player since initResources() does that, so just reset player data. Player.reset(); } }