import java.awt.*;
import java.applet.*;
import java.net.*;
import java.lang.System;

public class reikai extends java.applet.Applet {
  int		Ainit			= 1;
  int		Apaint			= 1;
  int		menuScreen		= 0;
  Image		bgImg;
  URL		file;
  int		mouseClicked		= 0;

  public void init() {
    if (Ainit == 1) {
      file = new URL(getCodeBase() + "loading.htm");
      menuScreen = 1;
      repaint();
      Ainit = 0;    
    }
  }

  public void paint(Graphics g) {
    if (Apaint == 1) {
      // Main Menu
      if (menuScreen == 1) {
        bgImg = getImage(getCodeBase(), "menu01.gif");
	g.drawImage(bgImg, 0, 0, this);
      }
      // Language Select
      if (menuScreen == 2) {
        bgImg = getImage(getCodeBase(), "menu02.gif");
	g.drawImage(bgImg, 0, 0, this);
      }
      // Load Game
      if (menuScreen == 3) {
        bgImg = getImage(getCodeBase(), "menu03.gif");
	g.drawImage(bgImg, 0, 0, this);
      }
      // Quit
      if (menuScreen == 5) {
        bgImg = getImage(getCodeBase(), "menu05.gif");
	g.drawImage(bgImg, 0, 0, this);
      }
      // Nihongo
      if (menuScreen == 7) {
        bgImg = getImage(getCodeBase(), "menu07.gif");
	g.drawImage(bgImg, 0, 0, this);
      }
    }
  }

  public boolean mouseDown(Event evt, int x, int y) {
    // Main Menu
    if (menuScreen == 1) {
      // User Selects "Start New Game"
      if (x > 16) {
        if (x < 152) {
          if (y > 84) {
            if (y < 110) {
              menuScreen = 2;
              repaint();
              return true;
            }
          }
        }
      }
      // User Selects "Continue Saved Game"
      if (x > 16) {
        if (x < 192) {
          if (y > 114) {
            if (y < 141) {
              menuScreen = 3;
              repaint();
              return true;
            }
          }
        }
      }
      // User Selects "Help"
      if (x > 16) {
        if (x < 51) {
          if (y > 144) {
            if (y < 170) {
              file = new URL(getCodeBase() + "readme.htm");
              getAppletContext().showDocument(file);
              return true;
            }
          }
        }
      }
      // User Selects "Exit"
      if (x > 16) {
        if (x < 51) {
          if (y > 174) {
            if (y < 192) {
              menuScreen = 5;
              repaint();
              return true;
            }
          }
        }
      }
    }
    // Language Select
    if (menuScreen == 2) {
      // User Selects "English"
      if (x > 16) {
        if (x < 80) {
          if (y > 99) {
            if (y < 125) {
              file = new URL(getCodeBase() + "tsorgia.htm");
              getAppletContext().showDocument(file);
              return true;
            }
          }
        }
      }
      // User Selects "Nihongo"
      if (x > 16) {
        if (x < 80) {
          if (y > 129) {
            if (y < 156) {
              menuScreen = 7;
              repaint();
              return true;
            }
          }
        }
      }
    }
    // Load Saved Game
    // Exit Confirmation
    if (menuScreen == 5) {
      // User Selects "Yes"
      if (x > 16) {
        if (x < 80) {
          if (y > 79) {
            if (y < 90) {
              return true;
            }
          }
        }
      }
      // User Selects "No"
      if (x > 16) {
        if (x < 80) {
          if (y > 94) {
            if (y < 105) {
              menuScreen = 1;
              repaint();
              return true;
            }
          }
        }
      }
    }
    // Nihongo Beta Screen
  }

  public boolean keyDown(Event evt, int key) {
    // Nihongo Beta Screen
    if (menuScreen == 7) {
      file = new URL(getCodeBase() + "tsorgib.htm");
      getAppletContext().showDocument(file);
      return true;
    }
  }
}
}