import java.awt.*; import java.applet.*; import java.net.*; import java.awt.image.*; import java.util.*; public class JavaGame extends Applet { GameWindow javagame; Image image; public void init() { Button button = new Button("Load Puzzles of the Earth Java Game"); add(button); validate(); image=getImage(getCodeBase(),"earth.gif"); setJavaGame(); } public void setJavaGame() { javagame = new GameWindow(this); javagame.setTitle("Puzzles of The Earth Java Game"); javagame.resize(600, 480); javagame.setResizable(false); } public void reset() { javagame.hide(); javagame=null; setJavaGame(); } public void destroy() { javagame.hide(); javagame = null; } public boolean action(Event event, Object o) { javagame.show(); javagame.toFront(); return true; } } class GameWindow extends Frame { leftPanel left; rightPanel right; JavaGame applet; Question question; GameWindow here; public class Question extends Observable { public Point pt; public void Question() { // this.super(); pt = new Point(); } public void notifyCustom() { System.out.println("notifyCustom"); System.out.println(countObservers()); setChanged(); notifyObservers(pt); } } public boolean handleEvent(Event event) { if (event.id == Event.WINDOW_DESTROY) dispose(); return super.handleEvent(event); } public GameWindow(JavaGame applet) { here=this; this.applet=applet; // this.setBackground(new Color(50,25,20)); this.setLayout(new BorderLayout(0,0)); question = new Question(); System.out.println("Constructor debug"); left = new leftPanel(); right = new rightPanel(); question.addObserver(right); left.reshape(0,0,376,460); right.reshape(377,0,83,460); right.setBackground(Color.white); add("West", left); add("East", right); } public void paint(Graphics g) { } public class leftPanel extends Panel { leftCanvas canv; public leftPanel() { this.setLayout(new BorderLayout(0,0)); canv = new leftCanvas(new Dimension(348,393)); canv.setBackground(new Color(33,33,33)); this.setBackground(new Color(100,100,100)); this.setLayout(new BorderLayout(0,0)); System.out.println("new leftCanvas"); add("Center", canv); } class leftCanvas extends Canvas { Dimension size; Image image; Rectangle rect[]; public boolean handleEvent(Event event) { if (event.id == Event.MOUSE_DOWN) { question.pt = new Point(event.x,event.y); question.notifyCustom(); } return super.handleEvent(event); } public Dimension minimumSize() { return new Dimension(376,370); } public Dimension preferredSize() { return minimumSize(); } public leftCanvas(Dimension dim) { this.size = dim; image=applet.getImage(applet.getCodeBase(),"globe3.gif"); if(image!=null) System.out.println("getImage OK"); else System.out.println("getImage NULL!"); } public void paint(Graphics g) { System.out.println("drawImage"); g.drawImage(image, 0, 0, this); } } } class rightPanel extends Panel implements Observer { rightTopPanel rightTop; rightBottomPanel rightBottom; Rectangle[] area; aQuestion[] thequestions; class questionPanel extends Panel { public questionPanel() { setLayout(new CardLayout()); thequestions=new aQuestion[16]; thequestions[0]=new aQuestion("What happens when two continental plates collide?\n1)The plate moving with lesser force subducts under the one moving with greater force.\n2)The two plates will both subduct under each other.\n3)One of the plates will be forced under the other slightly, but no subduction takes place.", 0, 0, TextArea.SCROLLBARS_NONE); thequestions[0].setCorrect("three"); thequestions[1]=new aQuestion("How are plates moved?\n1)By convection currents in the Mantle\n2)By compressional forces\n3)By the eruptions of lava from volcanos.",0, 0, TextArea.SCROLLBARS_NONE); thequestions[1].setCorrect("one"); thequestions[2]=new aQuestion("What happens at divergent boundaries?\n1)Sea floor spreads and magma rises up to fill the gap, forming oceanic ridges and submarine volcanoes.\n2)Magma rises up and heat up the surrounding water to form tsunamis.\n3)A gap is formed and surrounding water rushes in to cool the magma into a lower layer of crust.",0,0,TextArea.SCROLLBARS_NONE); thequestions[2].setCorrect("one"); thequestions[3]=new aQuestion("What happens when volcanoes erupt?\n1)Pyroclastic and mud flows, tsunamis, release of poisonous gases, smoke, lava and ash.\n2)Prolonged thunder and lightning, and destructive thunderstorms.\n3)More plate movements, causing earthquakes.",0,0,TextArea.SCROLLBARS_NONE); thequestions[3].setCorrect("one"); thequestions[4]=new aQuestion("Why are settlements still found near volcanoes?\n1)To facilitate the study of volcanoes, and to send out immediate warnings to others in the near vicinity when the volcano show any signs of erupting.\n2)To reap the benefits of volcanos, like the fertile soil from pyroclastic flows and lava for rich harvest, and minerals for mining.\n3)People are unaware of the dangers of living near volcanoes.",0,0,TextArea.SCROLLBARS_NONE); thequestions[4].setCorrect("two"); thequestions[5]=new aQuestion("What are the effects of an earthquake measuring 7 on the richter scale?\n1)Wide cracks appear on the ground, damages buildings and landslides.\n2)Concrete structures destruyed, complete destruction of a settlement.\n3)Objects drop and vibration is felt by most.",0,0,TextArea.SCROLLBARS_NONE); thequestions[5].setCorrect("one"); thequestions[6]=new aQuestion("How do we reduce the effects of earthquakes?\n1)Build settlements on softer ground and high areas such as mountains.\n2)Proper planning and siting of settlement, construct flexible steel structures that sway with ground movement, install automatic shutoff systems and conduct earthquake drills.\n3)Build settlements of complete steel structures.",0,0,TextArea.SCROLLBARS_NONE); thequestions[6].setCorrect("two"); thequestions[7]=new aQuestion("Are fold mountains still forming on Earth?\n1)Yes, as long as there are plate movements, fold mountains will form from the compressional forces.\n2)No, the current plate movements are too insignificant to form fold mountains.\n3)No, the plates are moving in the wrong way.",0,0,TextArea.SCROLLBARS_NONE); thequestions[7].setCorrect("one"); thequestions[8]=new aQuestion("What is a shield volcano made of?\n1)Basic lava\n2)Acidic lava\n3)Ash and cinders",0,0,TextArea.SCROLLBARS_NONE); thequestions[8].setCorrect("one"); thequestions[9]=new aQuestion("What can be form at a convergent boundary?\n1)Acid lava volcano\n2)Shield volcano\n3)New crust",0,0,TextArea.SCROLLBARS_NONE); thequestions[9].setCorrect("one"); thequestions[10]=new aQuestion("Where is the mantle found?\n1)Between the crust and the core.\n2)The innermost part of the Earth.\n3)The outermost part of the Earth.",0,0,TextArea.SCROLLBARS_NONE); thequestions[10].setCorrect("one"); thequestions[11]=new aQuestion("Which is the hottest part of the Earth?\n1)The mantle\n2)The core\n3)The crust",0,0,TextArea.SCROLLBARS_NONE); thequestions[11].setCorrect("two"); thequestions[12]=new aQuestion("What is the structure of the earth most like?\n1)a watermelon\n2)an orange\n3)an apple",0,0,TextArea.SCROLLBARS_NONE); thequestions[12].setCorrect("three"); thequestions[13]=new aQuestion("The surface of the earth will:\n1)keep changing as plates keep moving\n2)remain the same until the end of the world\n3)slowly sink beneath the water surface",0,0,TextArea.SCROLLBARS_NONE); thequestions[13].setCorrect("one"); thequestions[14]=new aQuestion("Where can coal only be formed?\n1)warm and humid places\n2)cold places like Antarctica\n3)underwater",0,0,TextArea.SCROLLBARS_NONE); thequestions[14].setCorrect("one"); thequestions[15]=new aQuestion("Instructions:\nThe earth you see to your left contains clickable spots denoted by the circular graphics. Click on these spots and answer all the questions. You can reclick on a spot to change your answers. Once you're done, just click on the 'Done' button below. Have fun!",0,0,TextArea.SCROLLBARS_NONE); add("one",thequestions[0]); add("two",thequestions[1]); add("three",thequestions[2]); add("four",thequestions[3]); add("five",thequestions[4]); add("six",thequestions[5]); add("seven",thequestions[6]); add("eight",thequestions[7]); add("nine",thequestions[8]); add("ten",thequestions[9]); add("eleven",thequestions[10]); add("twelve",thequestions[11]); add("thirteen",thequestions[12]); add("fourteen",thequestions[13]); add("fifteen",thequestions[14]); add("sixteen",thequestions[15]); changeCard("sixteen"); } public void changeCard(String str) { ((CardLayout)getLayout()).show(this,str); } public int getCorrect() { int count=0; for(int x=0; x<15;x++) { if(thequestions[x].cbg.getCurrent()!=null) { String choice=(thequestions[x].cbg.getCurrent()).getLabel(); String actual=thequestions[x].correct; if(choice.compareTo(actual)==0) { System.out.println("here"); count++; } } } return count; } } class aQuestion extends Panel { boolean answered; questionText theText; String correct; CheckboxGroup cbg; Checkbox one, two, three; Panel checkboxes; public aQuestion(String str, int x, int y, int z) { answered=false; theText=new questionText(str, x, y, z); theText.setEditable(false); cbg=new CheckboxGroup(); checkboxes=new Panel(); checkboxes.setLayout(new FlowLayout()); one=new Checkbox("one", cbg, false); two=new Checkbox("two", cbg, false); three=new Checkbox("three", cbg, false); checkboxes.add(one); checkboxes.add(two); checkboxes.add(three); setLayout(new BorderLayout()); add("North",theText); add("South",checkboxes); } public void setCorrect(String str) { correct=str; } public void setAnswered(boolean ans) { answered=ans; } class questionText extends TextArea { public questionText(String str, int x, int y, int z) { super(str, x, y, z); } public Dimension minimumSize() { return new Dimension(192,170); } public Dimension preferredSize() { return minimumSize(); } } } questionPanel theQuestions; class rightTopPanel extends Panel { public rightTopPanel() { System.out.println("rightTopPanel created"); theQuestions=new questionPanel(); add(theQuestions); } public Dimension minimumSize() { return new Dimension(202,200); } public Dimension preferredSize() { return minimumSize(); } } class rightBottomPanel extends Panel { Button instructions,done; Label score; ScrollDiag diag; Frame fm; int correcto=15; public rightBottomPanel() { fm=new Frame(); System.out.println("rightBottomPanel created"); add(instructions=new Button("Instructions")); add(done=new Button("I'm done!")); // add("South",score=new Label("Click to see you're score..")); diag=new ScrollDiag(fm, "Score", true); diag.resize(200,200); } class ScrollDiag extends Dialog { Button diagExit; public Label howMany; public ScrollDiag(Frame f, String s, boolean b) { super(f,s,b); add("North", new Label("You got...")); Font origFont=applet.getFont(); Font newFont=new Font(origFont.getName(), Font.PLAIN, 20); setFont(newFont); add(howMany=new Label(correcto + " out of 10 correct.")); add("South", diagExit=new Button("Exit")); } public boolean handleEvent(Event event) { if(event.target==diagExit && event.id==Event.ACTION_EVENT) { fm.dispose(); applet.reset(); } return super.handleEvent(event); } } public Dimension minimumSize() { return new Dimension(192,170); } public Dimension preferredSize() { return minimumSize(); } public boolean handleEvent(Event event) { if (event.target == instructions && event.id==Event.ACTION_EVENT) theQuestions.changeCard("sixteen"); else if(event.target==done && event.id==Event.ACTION_EVENT) { correcto=theQuestions.getCorrect(); System.out.println("correcto=" + correcto); diag.howMany.setText(correcto + " out of 10 correct."); // score.setText("You got " + correct + " out of 10 correct."); diag.show(); } return super.handleEvent(event); } } public void update(Observable o, Object arg) { Point tmp = (Point)arg; System.out.println("rightPanel.update"); System.out.println(tmp.x); System.out.println(tmp.y); if((new Rectangle(46,70,40,40)).inside(tmp.x,tmp.y)) { // pangaea theory #1 theQuestions.changeCard("fourteen"); } else if((new Rectangle(120,35,40,40)).inside(tmp.x,tmp.y)) { // plate tect #1 theQuestions.changeCard("one"); } else if((new Rectangle(255,34,40,40)).inside(tmp.x,tmp.y)) { // effects on humans #1 theQuestions.changeCard("four"); } else if((new Rectangle(108,112,40,40)).inside(tmp.x,tmp.y)) { // effects on humans #2 theQuestions.changeCard("five"); } else if((new Rectangle(180,94,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("eight"); } else if((new Rectangle(100,180,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("eleven"); } else if((new Rectangle(232,172,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("twelve"); } else if((new Rectangle(285,134,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("thirteen"); } else if((new Rectangle(30,226,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("nine"); } else if((new Rectangle(73,275,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("six"); } else if((new Rectangle(102,313,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("two"); } else if((new Rectangle(152,282,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("fifteen"); } else if((new Rectangle(234,250,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("ten"); } else if((new Rectangle(252,288,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("seven"); } else if((new Rectangle(305,244,40,40)).inside(tmp.x,tmp.y)) { theQuestions.changeCard("three"); } } public rightPanel() { this.setLayout(new BorderLayout()); this.setBackground(new Color(0,0,0)); rightTop = new rightTopPanel(); rightTop.setBackground(new Color(255,255,255)); rightBottom = new rightBottomPanel(); rightBottom.setBackground(new Color(100,100,100)); add("North", rightTop); add("South", rightBottom); } } }