import java.awt.*; import java.net.*; import java.util.*; /** * A panel that contains a background picture which is stretched to fill the entire panel. * @author Torbjörn Nilsson * @version 1.1 */ public class BkgPanel extends Panel { Image bkg = null; ClientThread ct = null; boolean aMap = false; boolean anEgg = false; boolean aSpellRoom = false; boolean aZoom = false; boolean aResearch = false; boolean aMain = false; Banner banner; Image cityPic; /** * Default contructor */ BkgPanel() { } /** * Use this contructor when you have a picture you want to show */ BkgPanel(Image pic) { bkg = pic; } /** * This is the most commonly used constructor. The last argument is a string naming the use of the BkgPanel. These are possible uses: "map", "egg", "spellroom", "research", "main" & "zoom". The second argument is used for various callback-function-calls. */ BkgPanel(Image pic, ClientThread c,String s) { ct = c; bkg = pic; if(s.equals("map")) { try { ImageLoader imlo = new ImageLoader(c.client.s.getInetAddress().getHostName()); cityPic = imlo.add("http://www.lysator.liu.se/~nexus/FOD/PICS/stad.gif"); imlo.loadAllImages(); } catch (Exception e) { System.out.println("Iconpic load error:"+e); } aMap = true; setLayout(null); try { banner = new Banner(this,c.client.s.getInetAddress().getHostName() ); banner.start(); banner.suspend(); } catch (Exception e) { System.out.println("No banner! :"+e); } } else if(s.equals("egg")) anEgg = true; else if (s.equals("spellRoom")) aSpellRoom = true; else if (s.equals("zoom")) aZoom = true; else if(s.equals("research")) aResearch = true; else if(s.equals("main")) aMain = true; else { System.out.println("Error making BkgPanel!"); System.exit(-1); } } /** * Callback to method "mapEvent" in Clienthread with args x and y. */ public boolean mouseDown(Event e, int x, int y) { if (aMap) { ct.mapEvent(x,y); return true; } else return false; } /** * Check if a button ha been pressed when the BkgPanel has a certain use. This causes different actions to take place in the ClientThread. */ public boolean action(Event evt, Object arg){ if(aMain){ if(arg.equals("Quit Game")); ct.gameOver = true; return true; } else if(anEgg){ if(arg.equals("New Egg")){ new Egg(ct); return true; } return false; } else if (aSpellRoom) { if (arg.equals("Cast Spell")) { ct.castSpell(); return true; } return false; } else{ return false; } } /** * If BkgPanel is used as a research room, this method creates a new ResearchSpell if a spell is chosen from the list. */ public boolean handleEvent(Event evt) { if(aResearch){ switch(evt.id) { case Event.LIST_SELECT: System.out.println("Forska på "+evt); // ct.spellSelect(event); new ResearchSpell(ct,evt); return true; } return false; } return super.handleEvent(evt); } /** * Remove flickering. */ public void update(Graphics g) { // override paint(g); } /** * Do different painting stuff depending on the the usage of the BkgPanel. */ public void paint(Graphics g) { // System.out.println(g); Dimension di = size(); if (aZoom && ct != null) { //do this before drawing bkg!!! Area a = ct.map[ct.zoomPos.x][ct.zoomPos.y]; bkg = ct.terrainPics[(int)a.terrain]; // System.out.println("TERRAIN="+a.terrain+" "+bkg); // System.out.println(ct.terrainPics[0]); } if (bkg != null) g.drawImage(bkg,0,0,di.width, di.height, this ); if (aZoom && ct != null) { Area a = ct.map[ct.zoomPos.x][ct.zoomPos.y]; if (a.hasCity()) { City c = (City)(ct.cities.get(a.getCity())); ct.setOwnerColor(g,c.getOwner()); g.fillOval(ct.FRAME_WIDTH-100,30,60,60); } Enumeration e = a.getDragons(); int dc = 0, dx = 80; while(e.hasMoreElements()) { Dragon d = (Dragon)ct.dragons.get(e.nextElement()); ct.setOwnerColor(g, d.getOwner()); g.fillRect(10 + dx*dc, 350, 70,70); Image dragIm = ct.getDragonImage(d); g.drawImage(dragIm, 10 + dx*dc, 350, 65,65, ct.dragonPanel); ct.wlDragonNames[dc].setText(d.name); ct.wlDragonNames[dc].resize(70,18); dc++; } } if (aMap && ct != null) { g.setColor(Color.white); //draw grid for(int i=1;i