public void explode() { /* * For some reason I have to repeat this code 10 times * for it to get all of the drones * F**k the world */ for (int i = 0; i < 10; i++) { for (Actor a : getStage().getActors()) { if (a instanceof Drone) { Drone d = (Drone) a; if (getDistanceFrom(d) < RADIUS) { d.takeDamage(DAMAGE); } } else if (a instanceof Queen) { Queen q = (Queen) a; if (getDistanceFrom(q) < RADIUS) { q.takeDamage(DAMAGE); } } } } destroy(); }
@Test public void testMove() { q_w.move(4, 0); assertTrue(q_w.getX() == 4 && q_w.getY() == 0); p1_b.move(6, 3); assertFalse(p1_b.getX() == 6 && p1_b.getY() == 3); board.print(); }
public PromotionDialog(Square location) { // Creating promotion dialog if (Board.getBoard().isWhiteMove()) { setTitle( "Promotion for " + Board.getBoard().getWhitePlayer().getName() + " - Choose a figure"); } else { setTitle( "Promotion for " + Board.getBoard().getBlackPlayer().getName() + " - Choose a figure"); } this.location = location; JPanel pane = (JPanel) getContentPane(); pane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); pane.setLayout(new GridLayout(1, 4, 10, 10)); JButton rookButton = new JButton(); rookButton.setIcon(rook.getFigureIcon()); rookButton.addActionListener(this); rookButton.setFocusPainted(false); pane.add(rookButton); JButton knightButton = new JButton(); knightButton.setIcon(knight.getFigureIcon()); knightButton.addActionListener(this); knightButton.setFocusPainted(false); pane.add(knightButton); JButton bishopButton = new JButton(); bishopButton.setIcon(bishop.getFigureIcon()); bishopButton.addActionListener(this); bishopButton.setFocusPainted(false); pane.add(bishopButton); JButton queenButton = new JButton(); queenButton.setIcon(queen.getFigureIcon()); queenButton.addActionListener(this); queenButton.setFocusPainted(false); pane.add(queenButton); // Has to choose setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); // Set to be always on top setAlwaysOnTop(true); // http://goo.gl/h3vnma // Makes dialog customizable setModal(true); // Disable resize setResizable(false); // Makes the dialog like an application (with swing components, etc.) setModalityType(ModalityType.APPLICATION_MODAL); // Size of dialog setMinimumSize(new Dimension(300, 100)); // Centering by default setLocationRelativeTo(null); pack(); setVisible(true); }
@Override public void actionPerformed(ActionEvent e) { // If figure icon matches the the button selected's icon - insert figure into board Icon icon = ((JButton) e.getSource()).getIcon(); if (icon.equals(rook.getFigureIcon())) { location.setFigure(rook); } else if (icon.equals(knight.getFigureIcon())) { location.setFigure(knight); } else if (icon.equals(bishop.getFigureIcon())) { location.setFigure(bishop); } else if (icon.equals(queen.getFigureIcon())) { location.setFigure(queen); } // Delete frame when clicked dispose(); }
@Test public void testCanEatAt() { assertTrue(q_w.canEatAt(4, 0)); assertFalse(p1_b.canEatAt(7, 2)); }
public Unit addUnit(String name) { HashMap<String, String> unit = new HashMap(); if (name.equals("Zergling")) { Zergling zergling = new Zergling(); unit.put("name", zergling.name()); unit.put("damage", String.valueOf(zergling.damage())); unit.put("damageVsStrong", String.valueOf(zergling.damageVsStrong())); unit.put("range", String.valueOf(zergling.range())); unit.put("hp", String.valueOf(zergling.hp())); unit.put("speed", String.valueOf(zergling.speed())); unit.put("armor", String.valueOf(zergling.armor())); unit.put("popcap", String.valueOf(zergling.popcap())); unit.put("type", zergling.type()); unit.put("strongVS", zergling.strongVS()); unit.put("weakVS", zergling.weakVS()); armyunits.add(unit); return zergling; } else if (name.equals("Hydralisk")) { Hydralisk hydralisk = new Hydralisk(); unit.put("name", hydralisk.name()); unit.put("damage", String.valueOf(hydralisk.damage())); unit.put("damageVsStrong", String.valueOf(hydralisk.damageVsStrong())); unit.put("range", String.valueOf(hydralisk.range())); unit.put("hp", String.valueOf(hydralisk.hp())); unit.put("speed", String.valueOf(hydralisk.speed())); unit.put("armor", String.valueOf(hydralisk.armor())); unit.put("popcap", String.valueOf(hydralisk.popcap())); unit.put("type", hydralisk.type()); unit.put("strongVS", hydralisk.strongVS()); unit.put("weakVS", hydralisk.weakVS()); armyunits.add(unit); return hydralisk; } else if (name.equals("Ultralisk")) { Ultralisk ultralisk = new Ultralisk(); unit.put("name", ultralisk.name()); unit.put("damage", String.valueOf(ultralisk.damage())); unit.put("damageVsStrong", String.valueOf(ultralisk.damageVsStrong())); unit.put("range", String.valueOf(ultralisk.range())); unit.put("hp", String.valueOf(ultralisk.hp())); unit.put("speed", String.valueOf(ultralisk.speed())); unit.put("armor", String.valueOf(ultralisk.armor())); unit.put("popcap", String.valueOf(ultralisk.popcap())); unit.put("type", ultralisk.type()); unit.put("strongVS", ultralisk.strongVS()); unit.put("weakVS", ultralisk.weakVS()); armyunits.add(unit); return ultralisk; } else if (name.equals("Mutalisk")) { Mutalisk mutalisk = new Mutalisk(); unit.put("name", mutalisk.name()); unit.put("damage", String.valueOf(mutalisk.damage())); unit.put("damageVsStrong", String.valueOf(mutalisk.damageVsStrong())); unit.put("range", String.valueOf(mutalisk.range())); unit.put("hp", String.valueOf(mutalisk.hp())); unit.put("speed", String.valueOf(mutalisk.speed())); unit.put("armor", String.valueOf(mutalisk.armor())); unit.put("popcap", String.valueOf(mutalisk.popcap())); unit.put("type", mutalisk.type()); unit.put("strongVS", mutalisk.strongVS()); unit.put("weakVS", mutalisk.weakVS()); armyunits.add(unit); return mutalisk; } else if (name.equals("Baneling")) { Baneling baneling = new Baneling(); unit.put("name", baneling.name()); unit.put("damage", String.valueOf(baneling.damage())); unit.put("damageVsStrong", String.valueOf(baneling.damageVsStrong())); unit.put("range", String.valueOf(baneling.range())); unit.put("hp", String.valueOf(baneling.hp())); unit.put("speed", String.valueOf(baneling.speed())); unit.put("armor", String.valueOf(baneling.armor())); unit.put("popcap", String.valueOf(baneling.popcap())); unit.put("type", baneling.type()); unit.put("strongVS", baneling.strongVS()); unit.put("weakVS", baneling.weakVS()); armyunits.add(unit); return baneling; } else if (name.equals("Broodlord")) { Broodlord broodlord = new Broodlord(); unit.put("name", broodlord.name()); unit.put("damage", String.valueOf(broodlord.damage())); unit.put("damageVsStrong", String.valueOf(broodlord.damageVsStrong())); unit.put("range", String.valueOf(broodlord.range())); unit.put("hp", String.valueOf(broodlord.hp())); unit.put("speed", String.valueOf(broodlord.speed())); unit.put("armor", String.valueOf(broodlord.armor())); unit.put("popcap", String.valueOf(broodlord.popcap())); unit.put("type", broodlord.type()); unit.put("strongVS", broodlord.strongVS()); unit.put("weakVS", broodlord.weakVS()); armyunits.add(unit); return broodlord; } else if (name.equals("Corruptor")) { Corruptor corruptor = new Corruptor(); unit.put("name", corruptor.name()); unit.put("damage", String.valueOf(corruptor.damage())); unit.put("damageVsStrong", String.valueOf(corruptor.damageVsStrong())); unit.put("range", String.valueOf(corruptor.range())); unit.put("hp", String.valueOf(corruptor.hp())); unit.put("speed", String.valueOf(corruptor.speed())); unit.put("armor", String.valueOf(corruptor.armor())); unit.put("popcap", String.valueOf(corruptor.popcap())); unit.put("type", corruptor.type()); unit.put("strongVS", corruptor.strongVS()); unit.put("weakVS", corruptor.weakVS()); armyunits.add(unit); return corruptor; } else if (name.equals("Infestor")) { Infestor infestor = new Infestor(); unit.put("name", infestor.name()); unit.put("damage", String.valueOf(infestor.damage())); unit.put("damageVsStrong", String.valueOf(infestor.damageVsStrong())); unit.put("range", String.valueOf(infestor.range())); unit.put("hp", String.valueOf(infestor.hp())); unit.put("speed", String.valueOf(infestor.speed())); unit.put("armor", String.valueOf(infestor.armor())); unit.put("popcap", String.valueOf(infestor.popcap())); unit.put("type", infestor.type()); unit.put("strongVS", infestor.strongVS()); unit.put("weakVS", infestor.weakVS()); armyunits.add(unit); return infestor; } else if (name.equals("Queen")) { Queen queen = new Queen(); unit.put("name", queen.name()); unit.put("damage", String.valueOf(queen.damage())); unit.put("damageVsStrong", String.valueOf(queen.damageVsStrong())); unit.put("range", String.valueOf(queen.range())); unit.put("hp", String.valueOf(queen.hp())); unit.put("speed", String.valueOf(queen.speed())); unit.put("armor", String.valueOf(queen.armor())); unit.put("popcap", String.valueOf(queen.popcap())); unit.put("type", queen.type()); unit.put("strongVS", queen.strongVS()); unit.put("weakVS", queen.weakVS()); armyunits.add(unit); return queen; } else if (name.equals("Roach")) { Roach roach = new Roach(); unit.put("name", roach.name()); unit.put("damage", String.valueOf(roach.damage())); unit.put("damageVsStrong", String.valueOf(roach.damageVsStrong())); unit.put("range", String.valueOf(roach.range())); unit.put("hp", String.valueOf(roach.hp())); unit.put("speed", String.valueOf(roach.speed())); unit.put("armor", String.valueOf(roach.armor())); unit.put("popcap", String.valueOf(roach.popcap())); unit.put("type", roach.type()); unit.put("strongVS", roach.strongVS()); unit.put("weakVS", roach.weakVS()); armyunits.add(unit); return roach; } else return null; }