SubKorea > CYBER JAVA GAME > º®µ¹±ú±â2 (Javanoid v1.45) > ¼Ò½º #1

 

// ## JAVANOID : THE MAIN CLASS ###########################
// Here are the thread, the events and the paint method ...

// ## IMPORTS ###############################################
import java.lang.*;
import java.applet.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.peer.*;  //JDK Version 1.0.2
import java.net.*;

public class javanoid extends Applet implements Runnable {

 static String title = "Javanoid V1.45";

 // idle time during the run loop
 protected int animationDelay = 10;

 // width & height for the game & the control panel
 final static int gameWidth  = 320;
 final static int gameHeight = 300;
 final static int panelWidth = 100;
 
 // References
 Dimension     minSize;
 jnimageserver imgServer;
 jnsoundserver sndServer;
 jngame        game;
 Thread        myThread;
 
 // User interface
 Panel    panel;
 Checkbox soundCheck;
 Choice   speedChoice;
 
 public void init() {   // ÀÚ¹Ù³ëÀ̵å ÃʱâÈ­
 
  // Game construction (image server, sound server & the game itself)
  imgServer = new jnimageserver(this); imgServer.init();
  sndServer = new jnsoundserver(this); sndServer.init();
  game = new jngame(this, imgServer, sndServer, gameWidth, gameHeight);

  // User interface construction
  panel = new Panel();
 
  panel.setBackground(Color.lightGray);
  panel.resize(panelWidth, gameHeight);
  panel.setLayout(new GridLayout(0, 1));

  panel.add(new Button("START"));
  panel.add(new Button("DEMO"));
  panel.add(new Button("PAUSE"));
  panel.add(new Button("RESUME"));
 
  panel.add(soundCheck = new Checkbox("SOUND"));

  panel.add(new Label("SPEED", Label.CENTER));
  panel.add(speedChoice = new Choice());
  speedChoice.addItem("MAXIMUM");
  speedChoice.addItem("FAST");
  speedChoice.addItem("AVERAGE");
  speedChoice.addItem("SLOW");
  speedChoice.addItem("MINIMUM");
  speedChoice.select(2);

  panel.add(new Label("SPECIAL", Label.CENTER));
  panel.add(new Button("UNLOCK"));
  panel.add(new Button("NEXT"));
 
  setBackground(Color.lightGray);
  setLayout(new BorderLayout());
  add("West", game);
  add("East", panel);

  // Game init & Demo initialization
  game.startGame(true);
 
  // Thread launch
  start();
 
  } // À§·Î

 public void stop() {
 
  if (myThread!=null) myThread.stop();
  myThread=null;
 
  } // À§·Î
 
 public void start() {
 
  if (myThread == null) {
   myThread = new Thread(this);
   myThread.setPriority(Thread.MIN_PRIORITY);
   myThread.start();
   }
 
  } // À§·Î

 public synchronized void run() {

  while (Thread.currentThread()==myThread) {

   try {
    if (game!=null) { game.live(); game.repaint(); }
    if (sndServer!=null) sndServer.iterate();
    Thread.sleep(animationDelay);
    } catch (InterruptedException e) { break; }

   }
  } // À§·Î

 // Event handler (panel)
 public boolean action(Event evt, Object arg) {
 
  if (evt.target==speedChoice) { // °ÔÀÓ¼Óµµ
   animationDelay = 5 * speedChoice.getSelectedIndex();
   }
  else if (evt.target==soundCheck) {
   if (sndServer!=null) sndServer.toggle();
   }
  else if ("START".equals(arg)) {
   if (game!=null) { game.stopGame(); game.startGame(false); }
   }
  else if ("DEMO".equals(arg)) {
   if (game!=null) { game.stopGame(); game.startGame(true); }
   }
  else if ("PAUSE".equals(arg)) stop();
  else if ("RESUME".equals(arg)) start();
  else if ("UNLOCK".equals(arg)) {
   if (game!=null) game.unlock();
   }
  else if ("NEXT".equals(arg)) {
   if (game!=null) game.jumpNext();
   }
 
  return true;
 
  } // À§·Î

 // Applet information methods
 public String getAppletInfo() { return "Applet " + title + " by Remi FAITOUT"; }
 
 } // À§·Î