import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Image;
import Iridium;

public class Help
{
 static Font  infoFont = new Font("TimesRoman", 0, 11);
 static Font  linkFont = new Font("TimesRoman", 1, 11);
 static Color infoColor = Color.white;
 static Color linkColor = new Color(0xaaaaff);
 public boolean visible;
 Image   infoImg;
 Iridium game;
 int     page;
 int     aWidth;
 int     aHeight;
 int     lastpage;

 public Help(int gameWidth, int gameHeight, Image infoImage, Iridium iridium)
 {
  aWidth  = gameWidth;
  aHeight = gameHeight;
  infoImg = infoImage;
  game    = iridium;
  page    = 0;
 }

 public void show(int showpage)
 {
  lastpage = page;
  page     = showpage;
  visible  = true;
 }

 public void hide()
 {
  visible = false;
 }

 public void paint(Graphics g)
 {
  if(visible)
  {
   String infoTS;
   FontMetrics infoFontM;
   g.setColor(Color.darkGray);
   g.fillRect(25, 25, aWidth - 50, aHeight - 50);
   g.setColor(Color.gray);
   g.drawRect(25, 25, aWidth - 50, aHeight - 50);
   g.clipRect(27, 27, aWidth - 54, aHeight - 54);
   g.drawImage(infoImg, 27, 27, game);
   g.setFont(infoFont);
   infoFontM = g.getFontMetrics();
   if(page == 0)
   {
    g.setColor(Color.green);
    infoTS = "(Click mouse to continue)";
    g.drawString(infoTS,
     (aWidth-infoFontM.stringWidth(infoTS))/2, aHeight - 30);

    g.setColor(infoColor);
    infoTS = "I R I D I U M";
    g.drawString(infoTS,
     (aWidth-infoFontM.stringWidth(infoTS))/2, 50);

   //===========================================================/
    g.drawString("Author: Daniel Ramsköld, Sweden", 30, 50 + 12);
    g.drawString("Last Modified: 18 August 2000", 30, 50 + 12*2);
   //===========================================================/

    g.drawString("Keys:", 30, 50 + 12*4);
    g.drawString("4 or A:", 35, 50 + 12*5);
    g.drawString("Move ship left", 120, 50 + 12*5);
    g.drawString("5 or S:", 35, 50 + 12*6);
    g.drawString("Move ship down", 120, 50 + 12*6);
    g.drawString("6 or D:", 35, 50 + 12*7);
    g.drawString("Move ship right", 120, 50 + 12*7);
    g.drawString("8 or W:", 35, 50 + 12*8);
    g.drawString("Move ship up", 120, 50 + 12*8);
    g.drawString("Mouse-Move:", 35, 50 + 12*9);
    g.drawString("Move crosshair", 120, 50 + 12*9);
    g.drawString("Left Mouse-Click", 35, 50 + 12*10);
    g.drawString("or SPACE:", 35, 50 + 12*11);
    g.drawString("Fire lasers", 120, 50 + 12*11);
    g.drawString("P:", 35, 50 + 12*12);
    g.drawString("Pause/Resume game", 120, 50 + 12*12);
    g.drawString("M:", 35, 50 + 12*13);
    g.drawString("Mute/Play Sounds", 120, 50 + 12*13);
    g.drawString("B:", 35, 50 + 12*14);
    g.drawString("Show/Hide Shield-Bars", 120, 50 + 12*14);
    g.drawString("F2:", 35, 50 + 12*15);
    g.drawString("Restart game", 120, 50 + 12*15);
    g.drawString("F12:", 35, 50 + 12*16);
    g.drawString("Go to next level (cheat)", 120, 50 + 12*16);

    g.drawString("Further Help:", 60, 50 + 12*18);
    g.setColor(linkColor);
    g.setFont(linkFont);
    g.drawString("The Mission", 60, 50 + 12*19);
    g.drawString("Scoring", 60, 50 + 12*20);
    g.drawString("Enemies", 60, 50 + 12*21);

    g.setFont(infoFont);
    g.setColor(infoColor);
    g.drawString("Click on a blue link to go to another topic", 30, 50 + 12*24);
   }
   else
   {
    g.setColor(linkColor);
    g.setFont(linkFont);
    g.drawString("Back", 30, 62);
    if(page == 1)
    {
     g.setFont(infoFont);
     g.setColor(infoColor);
     infoTS = "SCORING";
     g.drawString(infoTS,
      (aWidth-infoFontM.stringWidth(infoTS))/2, 50);
     g.drawString("Scores:", 30, 50 + 12*2);
     g.drawString("Asteroids:", 35, 50 + 12*3);
     g.drawString("Shot at asteroid:", 40, 50 + 12*4);
     g.drawString("4 points", Math.max(aWidth/2, 150), 50 + 12*4);
     g.drawString("Crashing an asteroid:", 40, 50 + 12*5);
     g.drawString("50 points", Math.max(aWidth/2, 150), 50 + 12*5);
     g.drawString("Enemy vessels:", 35, 50 + 12*6);
     g.drawString("Shot at enemy:", 40, 50 + 12*7);
     g.drawString("4 points", Math.max(aWidth/2, 150), 50 + 12*7);
     g.drawString("Crashing an interceptor:", 40, 50 + 12*8);
     g.drawString("100 points", Math.max(aWidth/2, 150), 50 + 12*8);
     g.drawString("Crashing a heavy fighter:", 40, 50 + 12*9);
     g.drawString("350 points", Math.max(aWidth/2, 150), 50 + 12*9);
     g.drawString("Crashing a zephi:", 40, 50 + 12*10);
     g.drawString("50 points", Math.max(aWidth/2, 150), 50 + 12*10);
     g.drawString("Bonuses:", 35, 50 + 12*11);
     g.drawString("Completing a level:", 40, 50 + 12*12);
     g.drawString("100 - 300 points", Math.max(aWidth/2, 150), 50 + 12*12);
     g.drawString("Saving Irue:", 40, 50 + 12*13);
     g.drawString("1000 - 7000 points", Math.max(aWidth/2, 150), 50 + 12*13);
     g.drawString("Costs:", 30, 50 + 12*14);
     g.drawString("Fire lasers:", 40, 50 + 12*15);
     g.drawString("1 point", Math.max(aWidth/2, 150), 50 + 12*15);
    }
    else if(page == 2)
    {
     g.setFont(infoFont);
     g.setColor(infoColor);
     infoTS = "TABLE OF ENEMIES";
     g.drawString(infoTS,
      (aWidth-infoFontM.stringWidth(infoTS))/2, 50);
     g.drawString("Enemies:", 30, 50 + 12*2);
     g.drawString("Level first seen at:", Math.max(aWidth/2, 150), 50 + 12*2);
     g.setColor(linkColor);
     g.setFont(linkFont);
     g.drawString("Asteroid", 35, 50 + 12*3);
     g.setFont(infoFont);
     g.setColor(infoColor);
     g.drawString("Level 1", Math.max(aWidth/2, 150)+5, 50 + 12*3);
     g.setColor(linkColor);
     g.setFont(linkFont);
     g.drawString("Interceptor", 35, 50 + 12*4);
     g.setFont(infoFont);
     g.setColor(infoColor);
     g.drawString("Level 2", Math.max(aWidth/2, 150)+5, 50 + 12*4);
     g.setColor(linkColor);
     g.setFont(linkFont);
     g.drawString("Heavy Fighter", 35, 50 + 12*5);
     g.setFont(infoFont);
     g.setColor(infoColor);
     g.drawString("Level 6", Math.max(aWidth/2, 150)+5, 50 + 12*5);
     g.setColor(linkColor);
     g.setFont(linkFont);
     g.drawString("Zephi", 35, 50 + 12*6);
     g.setFont(infoFont);
     g.setColor(infoColor);
     g.drawString("Level 10 (Irue)", Math.max(aWidth/2, 150)+5, 50 + 12*6);
    }
    else if(page == 10)
    {
     g.setFont(infoFont);
     g.setColor(Color.green);
     infoTS = "(Click mouse to continue)";
     g.drawString(infoTS,
     (aWidth-infoFontM.stringWidth(infoTS))/2, aHeight - 30);
     g.setColor(infoColor);
     infoTS = "THE MISSION";
     g.drawString(infoTS,
      (aWidth-infoFontM.stringWidth(infoTS))/2, 50);
     g.drawString("The planet Irue is situated far away from our bases.", 30, 50 + 12*2);
     g.drawString("But though, it is one of our most important trade partners.", 30, 50 + 12*3);
     g.drawString("Between Irue and us, there is an asteroid belt,", 30, 50 + 12*4);
     g.drawString("where enemies settled just a year ago.", 30, 50 + 12*5);
     g.drawString("Now trade can no longer be done.", 30, 50 + 12*6);

     g.drawString("Your mision is to weaken the enemy forces,", 30, 50 + 12*8);
     g.drawString("and determine wether the reports of a coming attack", 30, 50 + 12*9);
     g.drawString("on Irue are true.", 30, 50 + 12*10);
     g.drawString("We have long been afraid a Zephi attack would", 30, 50 + 12*11);
     g.drawString("entirely detroy Irue.", 30, 50 + 12*12);

     g.drawString("A Zephi is a type of unmanned kamakazie ship, ", 30, 50 + 12*14);
     g.drawString("with a light shield but else unarmed.", 30, 50 + 12*15);
     g.drawString("Even though, their numbers and large explosives", 30, 50 + 12*16);
     g.drawString("make them dangerous enough.", 30, 50 + 12*17);
    }
    else if(page == 101)
    {
     g.setFont(infoFont);
     g.setColor(infoColor);
     infoTS = "ASTEROID";
     g.drawString(infoTS,
      (aWidth-infoFontM.stringWidth(infoTS))/2, 50);
     g.drawString("General notes:", 30, 50 + 12*2);
     g.drawString("Asteroids are the large rocks floating in space.", 35, 50 + 12*3);
     g.drawString("Crashing into one would damage yor ship seriously.", 35, 50 + 12*4);
     g.drawString("Faraway asteroids aren\'t dangerous.", 35, 50 + 12*5);

     g.drawString("Score:", 30, 50 + 12*7);
     g.drawString("50 points", 80, 50 + 12*7);
     g.drawString("Shield:", 30, 50 + 12*8);
     g.drawString("3 hits", 80, 50 + 12*8);
     g.drawString("Weapons:", 30, 50 + 12*9);
     g.drawString("None", 80, 50 + 12*9);

     g.drawString("Hints:", 30, 50 + 12*11);
     g.drawString("An effective way to crash asteroids is to", 35, 50 + 12*12);
     g.drawString("place the crosshair some centimeters in front of", 35, 50 + 12*13);
     g.drawString("your victim and fire. The lasers take up to 1 second", 35, 50 + 12*14);
     g.drawString("before they hit their target.", 35, 50 + 12*15);
     g.drawString("This definition of  \' in front of \'  is the place where the object", 35, 50 + 12*16);
     g.drawString("soon will move to.", 35, 50 + 12*17);
    }
    else if(page == 102)
    {
     g.setFont(infoFont);
     g.setColor(infoColor);
     infoTS = "INTERCEPTOR";
     g.drawString(infoTS,
      (aWidth-infoFontM.stringWidth(infoTS))/2, 50);
     g.drawString("General notes:", 30, 50 + 12*2);
     g.drawString("Interceptors are light spaceships armed with a single laser", 35, 50 + 12*3);
     g.drawString("as their only weapon. But be aware, it can still cause you damage.", 35, 50 + 12*4);

     g.drawString("Score:", 30, 50 + 12*6);
     g.drawString("100 points", 80, 50 + 12*6);
     g.drawString("Shield:", 30, 50 + 12*7);
     g.drawString("1 hit", 80, 50 + 12*7);
     g.drawString("Weapons:", 30, 50 + 12*8);
     g.drawString("1 Laser", 80, 50 + 12*8);

     g.drawString("Hints:", 30, 50 + 12*10);
     g.drawString("Interceptors are too fast to shoot down in the same", 35, 50 + 12*11);
     g.drawString("way as asteroids. Luckely, they don\'t have any shield,", 35, 50 + 12*12);
     g.drawString("like later enemies will have.", 35, 50 + 12*13);
     g.drawString("Try to keep as far away from interceptors as possible,", 35, 50 + 12*14);
     g.drawString("then they won\'t shoot at you.", 35, 50 + 12*15);
    }
    else if(page == 103)
    {
     g.setFont(infoFont);
     g.setColor(infoColor);
     infoTS = "HEAVY FIGHTER";
     g.drawString(infoTS,
      (aWidth-infoFontM.stringWidth(infoTS))/2, 50);
     g.drawString("General notes:", 30, 50 + 12*2);
     g.drawString("Heavy Fighters are quite slow spaceships armed", 35, 50 + 12*3);
     g.drawString("with multiple lasers, and a missile.", 35, 50 + 12*4);
     g.drawString("Keep a close eye on these, or they will quickly shoot you down.", 35, 50 + 12*5);

     g.drawString("Score:", 30, 50 + 12*7);
     g.drawString("350 points", 80, 50 + 12*7);
     g.drawString("Shield:", 30, 50 + 12*8);
     g.drawString("4 hits", 80, 50 + 12*8);
     g.drawString("Weapons:", 30, 50 + 12*9);
     g.drawString("5 Lasers, 1 Missile", 80, 50 + 12*9);

     g.drawString("Hints:", 30, 50 + 12*11);
     g.drawString("Keep away from Heavy Fighters,", 35, 50 + 12*12);
     g.drawString("and especially their missiles.", 35, 50 + 12*13);
     g.drawString("Just don\'t forget to shoot at them, they\'re worth", 35, 50 + 12*14);
     g.drawString("a lot of points, and can quickly take you to the next level.", 35, 50 + 12*15);
    }
    else if(page == 104)
    {
     g.setFont(infoFont);
     g.setColor(infoColor);
     infoTS = "ZEPHI";
     g.drawString(infoTS,
      (aWidth-infoFontM.stringWidth(infoTS))/2, 50);
     g.drawString("General notes:", 30, 50 + 12*2);
     g.drawString("Zephis are kamakazie vessels, set on destructing Irue.", 35, 50 + 12*3);
     g.drawString("They can\'t attack you, but are trying to crash into Irue.", 35, 50 + 12*4);

     g.drawString("Score:", 30, 50 + 12*6);
     g.drawString("50 points", 80, 50 + 12*6);
     g.drawString("Shield:", 30, 50 + 12*7);
     g.drawString("2 hits", 80, 50 + 12*7);
     g.drawString("Weapons:", 30, 50 + 12*8);
     g.drawString("None", 80, 50 + 12*8);

     g.drawString("Hints:", 30, 50 + 12*10);
     g.drawString("Be quick, they are in large numbers,", 35, 50 + 12*11);
     g.drawString("and moves faster than they seem to do.", 35, 50 + 12*12);
    }
   }
  }
 }

 public boolean click(int x, int y)
 {
  if(visible)
  {
   if(x < 25 || y < 25 || x > aWidth - 25 || y > aHeight - 25)
   {
    hide();
    return true;
   }
   if(page == 0)
   {
    if(y < 50 + 12*19 && y > 50 + 12*18 && x < 160)
    {
     show(10);
     return true;
    }
    if(y < 50 + 12*20 && y > 50 + 12*19 && x < 160)
    {
     show(1);
     return true;
    }
    if(y < 50 + 12*21 && y > 50 + 12*20 && x < 160)
    {
     show(2);
     return true;
    }
    hide();
    return true;
   }
   if(y < 62 && y > 50)
   {
    show(lastpage);
    lastpage = 0;
    return true;
   }
   if(page == 1)
   {
   }
   if(page == 2)
   {
    if(y < 50 + 12*3 && y > 50 + 12*2)
    {
     if(x < Math.max(aWidth/2, 150))
     {
      show(101);
      return true;
     }
     return false;
    }
    if(y < 50 + 12*4 && y > 50 + 12*3)
    {
     if(x < Math.max(aWidth/2, 150))
     {
      show(102);
      return true;
     }
     return false;
    }
    if(y < 50 + 12*5 && y >  50 + 12*4)
    {
     if(x < Math.max(aWidth/2, 150))
     {
      show(103);
      return true;
     }
     return false;
    }
    if(y < 50 + 12*6 && y >  50 + 12*5)
    {
     if(x < Math.max(aWidth/2, 150))
     {
      show(104);
      return true;
     }
     return false;
    }
   }
   if(page == 10)
   {
    hide();
    return true;
   }
  }
  return false;
 }

}