@Override public synchronized void onNewMessage(lab6_msgs.GUIPolyMsg msg) { List<Point2D.Double> vertices = new ArrayList<Point2D.Double>(); for (int i = 0; i < msg.getNumVertices(); i++) { Point2D.Double p = new Point2D.Double(msg.getX()[i], msg.getY()[i]); vertices.add(p); } boolean closed = msg.getClosed() == 1; boolean filled = msg.getFilled() == 1; Color c = new Color( (int) msg.getC().getR(), (int) msg.getC().getG(), (int) msg.getC().getB()); // gui.makeRandomColor(); gui.addPoly(vertices, closed, filled, c); }
/** * Constructor of the map. Create the MapGui and the BottomPannel. * * @param map The Map used to create the MapGUI. */ public MainFrame(Map map) { this.setTitle("Tapawaru"); GridBagLayout myGrid = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); this.setLayout(myGrid); MapGUI mapGui = new MapGUI(map); mapGui.setPreferredSize(new Dimension(mapGui.guiMapSize()[0], mapGui.guiMapSize()[1])); c.fill = GridBagConstraints.BOTH; c.ipady = 0; c.weightx = 0; c.gridwidth = 2; c.gridx = 0; c.gridy = 0; this.add(mapGui, c); BottomPanel botPanel = new BottomPanel(map); botPanel.setPreferredSize(new Dimension(mapGui.guiMapSize()[0], 200)); c.fill = GridBagConstraints.BOTH; c.ipady = 0; c.weightx = 0; c.gridwidth = 2; c.gridx = 0; c.gridy = 1; this.add(botPanel, c); mapGui.addBotPanel(botPanel); this.addKeyListener(botPanel); this.pack(); this.setVisible(true); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.setResizable(false); map.setMapGui(mapGui); }
public void run() { System.out.print("Your name is :"); try { synchronized (Main.gigi) { Main.gigi.wait(); } } catch (InterruptedException e1) { // TODO Auto-generated catch block } hero.setName(GUI.getStdin()); hero.setGold(300); System.out.println(hero.getName()); // SimplePlayer music = new SimplePlayer(); int mapLevel = 1; m = new Map(9, mapLevel); try { EventQueue.invokeAndWait( new Runnable() { public void run() { try { mapGUI = new MapGUI(m, hero); } catch (Exception e) { e.printStackTrace(); } } }); } catch (InvocationTargetException | InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } while (hero.getCurrentHitPoints() > 0) { mapGUI.update(); mapGUI.repaint(); // System.out // .println("You are at : X " + hero.getVerticalLocation() + " Y " + // hero.getHorizontalLocation()); try { m.movePlayer(hero); if (m.getRoom(hero.getVerticalLocation(), hero.getHorizontalLocation()) instanceof EmptyRoom) { System.out.println("This room is empty as f**k."); } if (m.getRoom(hero.getVerticalLocation(), hero.getHorizontalLocation()) instanceof MonsterRoom) { MonsterRoom temp = (MonsterRoom) (m.getRoom(hero.getVerticalLocation(), hero.getHorizontalLocation())); if (temp.getMonster().isAlive() == false) { System.out.println("Monster is dead."); } else { Battle b = new Battle(hero, temp.getMonster()); System.out.println("Current Gold : " + hero.getGold()); } } if (m.getRoom(hero.getVerticalLocation(), hero.getHorizontalLocation()) instanceof BossRoom) { BossRoom temp = (BossRoom) (m.getRoom(hero.getVerticalLocation(), hero.getHorizontalLocation())); Battle b = new Battle(hero, temp.getMonster()); if (!temp.getMonster().isAlive()) { System.out.println("Current Gold : " + hero.getGold()); System.out.println( temp.getMonster().getName() + " is dead,you delve deeper into the dungeon."); mapLevel++; m = new Map(9, mapLevel); mapGUI.hide(); mapGUI = new MapGUI(m, hero); hero.setCurrentHitPoints(hero.getMaxHitPoints()); } } if (m.getRoom(hero.getVerticalLocation(), hero.getHorizontalLocation()) instanceof CityRoom) { Trader t = new Trader(); Trade trade = new Trade(hero, t); } } catch (IOException e) { e.printStackTrace(); } } // SQL.recordHighScore(hero.getName(), hero.getGold()); System.out.println("YOU LOST!"); // SQL.getHighScores(); }