00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 package org.classroomgaming.cgp;
00021
00022 import org.classroomgaming.cgp.*;
00023 import java.util.*;
00024 import java.awt.*;
00025 import java.applet.*;
00026 import java.awt.event.*;
00027
00028 public class ShopModule extends org.classroomgaming.cgp.GameModule implements org.classroomgaming.cgp.GameModule.Renderable, KeyListener {
00029
00030 private int shopItem;
00031 private boolean inShop;
00032 private Shop currentShop;
00033
00034
00035
00036 public ShopModule(GameModule m) {
00037 parent = m;
00038 enabled = false;
00039 }
00040
00041 public void init(GameObject g, Configurator a) {
00042
00043 shopItem = 0;
00044 inShop = false;
00045
00046
00047
00048 }
00049
00050 public void enable(boolean val) {
00051 enabled = val;
00052 }
00053
00054 public boolean isEnabled() {
00055 return enabled;
00056 }
00057
00058 public void ponder(float t) {
00059 }
00060
00061 public void handleEvent(EventObject e) {
00062 }
00063
00064 public void deinit() {
00065 }
00066
00067 public void render(Graphics g) {
00068 if (inShop) {
00069 shopItem = currentShop.purchase(g, shopItem);
00070 }
00071 }
00072
00073 public boolean followLink(String myURL) {
00074 try {
00075
00076
00077 return true;
00078 } catch (Exception exception4) {
00079 exception4.printStackTrace();
00080 return false;
00081 }
00082 }
00083
00084 public void keyReleased(KeyEvent e) {
00085 }
00086
00087 public void keyPressed(KeyEvent e) {
00088 }
00089
00090 public void keyTyped(KeyEvent e) {
00091 if (!enabled) {
00092 return;
00093 }
00094
00095 char i = e.getKeyChar();
00096 e.consume();
00097
00098 if ((char) i == 'p') {
00099 shopItem = shopItem - 1;
00100
00101
00102 return;
00103 }
00104 if ((char) i == 'n') {
00105 shopItem = shopItem + 1;
00106
00107
00108 return;
00109 }
00110 if ((char) i == 'b') {
00111 inShop = !followLink(currentShop.link(shopItem));
00112 return;
00113 }
00114 return;
00115 }
00116 }