@Test public void shouldStoneIsDestroyedByBullet2() { // Given givenFl("☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼"); // When diceNew(1); hero.recharge(); hero.act(); game.tick(); // Then assertE("☼ ☼" + "☼ ☼" + "☼ * ☼" + "☼ ☺ ☼" + "☼ ☼"); // When game.tick(); // Then assertE("☼ ☼" + "☼ * ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼"); // When game.tick(); // Then assertE("☼ x ☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼"); // When game.tick(); // Then assertE("☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼"); }
@Test public void shouldStoneDestroyHero2() { // given givenFl("☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼"); diceNew(2); game.tick(); game.tick(); game.tick(); game.tick(); // then assertE("☼ ☼" + "☼ 0 ☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼"); hero.up(); game.tick(); // then assertE("☼ ☼" + "☼ ☼" + "☼ 0 ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼"); hero.up(); game.tick(); // then assertE("☼ ☼" + "☼ ☼" + "☼ + ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); }
// я могу двигаться @Test public void shouldFieldICanMove() { // given givenFl("☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼"); // when diceNew(); // выключаем генерацию каменей и мин hero.up(); game.tick(); // then assertE("☼ ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); // When hero.right(); game.tick(); // Then assertE("☼ ☼" + "☼ ☺☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); // When hero.down(); game.tick(); // Then assertE("☼ ☼" + "☼ ☼" + "☼ ☺☼" + "☼ ☼" + "☼ ☼"); // When hero.left(); game.tick(); // Then assertE("☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼"); }
@Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub if (e.getKeyCode() == KeyEvent.VK_W) { this.hero.setDirection(0); hero.moveUp(); } else if (e.getKeyCode() == KeyEvent.VK_D) { this.hero.setDirection(1); hero.moveRight(); } else if (e.getKeyCode() == KeyEvent.VK_S) { this.hero.setDirection(2); hero.moveDown(); } else if (e.getKeyCode() == KeyEvent.VK_A) { this.hero.setDirection(3); hero.moveLeft(); } // 判断玩家是否按下J键 则开火 if (e.getKeyCode() == KeyEvent.VK_J) { if (this.hero.bombs.size() <= 40) { hero.fire(); } } this.repaint(); }
@Test public void shouldNewBulletPackAfterHeroGetOldBulletPack() { // given givenFl("☼ ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); diceNew(-1, -1, 0, 1); game.tick(); // then assertE("☼7 ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); hero.left(); game.tick(); // then assertE("☼7 ☼" + "☼☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); hero.up(); game.tick(); diceNew(-1, -1, 3, 0); game.tick(); // then assertE("☼☺ ☼" + "☼ 7☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); }
private void setupPlayer1() { listener1 = mock(EventListener.class); player1 = new Player(listener1, game); joystick1 = player1.getJoystick(); dice(hero1.getX(), hero1.getY()); game.newGame(player1); hero1.init(game); }
private void setupPlayer2() { listener2 = mock(EventListener.class); player2 = new Player(listener2, game); joystick2 = player2.getJoystick(); dice(hero2.getX(), hero2.getY()); game.newGame(player2); hero2.init(game); }
private void givenFl(String board) { LevelImpl level = new LevelImpl(board); Hero hero = level.getHero(charger).get(0); game = new Spacerace(level, dice, charger.getBulletsCount()); listener = mock(EventListener.class); player = new Player(listener); game.newGame(player); player.hero = hero; hero.init(game); this.hero = game.getHeroes().get(0); }
public void paint(Graphics g) { super.paint(g); // 画出我的坦克 g.fillRect(0, 0, 400, 300); // 确定区域为400 300 背景为黑色值 // 使用画坦克方法画出坦克 this.drawTank(hero.getX(), hero.getY(), g, hero.getDirect(), 0); // 画出敌人的坦克 for (int i = 0; i < ets.size(); i++) { this.drawTank(ets.get(i).getX(), ets.get(i).getY(), g, ets.get(i).getDirect(), 1); } }
public void nextLevel() { // if (!firstStage) this.getInfo().writeText("You moved to the next stage!"); // else // firstStage = false; // boolean check = false; Dungeon d; floorLevel++; if (floorLevel == 6) JOptionPane.showMessageDialog( null, "Great Job! You beat the game (as it is right now). If you want you can continue."); d = new Dungeon(60, 60); // creates a dungeon ArrayList<Room> roo = d.getRooms(); boolean reDo = d.checkRooms(); while (reDo == true) { d = new Dungeon(50, 50); reDo = d.checkRooms(); } land = d.getDungeon(); // / change to land openSpaces = openLocations(); // gets locations of the rooms/corridors hero.setLand(this.land); grid = new BoundedGrid<>(land.length, land[1].length); world = new ActorWorld(grid); int counter = 0; for (int i = 0; i < numEnemies * floorLevel; i++) { addEnemy(); counter++; } for (int i = 0; i < numItems + floorLevel; i++) { addItem(); } Location l = (openSpaces.get((int) (Math.random() * openSpaces.size()))); world.add(openSpaces.get((int) (Math.random() * openSpaces.size())), hero.main); hero.setGrid(grid); hero.setPanel(this); addStairs(); ArrayList<ArrayList<Location>> a = d.getCorridors(); for (ArrayList<Location> lo : a) { for (int i = 0; i < lo.size(); i++) { openSpaces.add(lo.get(i)); } } repaint(); }
public void startGame() { JOptionPane.showMessageDialog( null, "Welcome to Pokemon Mystery Dungeon! Reach the 6th stage to beat the game!"); // if (!firstStage) // this.getInfo().writeText("You moved to the next stage!"); // else // firstStage = false; // boolean check = false; Dungeon d; d = new Dungeon(60, 60); // creates a dungeon ArrayList<Room> roo = d.getRooms(); boolean reDo = d.checkRooms(); while (reDo == true) { d = new Dungeon(50, 50); reDo = d.checkRooms(); } land = d.getDungeon(); // / change to land openSpaces = openLocations(); // gets locations of the rooms/corridors grid = new BoundedGrid<>(land.length, land[1].length); world = new ActorWorld(grid); int counter = 0; for (int i = 0; i < numEnemies * floorLevel; i++) { addEnemy(); counter++; } for (int i = 0; i < numItems + floorLevel; i++) { addItem(); } PersonalityTest t = new PersonalityTest(land); Pokemon z = t.chooseCharacter(this); hero = new Hero(z, land, this); Location l = (openSpaces.get((int) (Math.random() * openSpaces.size()))); world.add(openSpaces.get((int) (Math.random() * openSpaces.size())), hero.main); hero.setGrid(grid); hero.setPanel(this); addStairs(); ArrayList<ArrayList<Location>> a = d.getCorridors(); for (ArrayList<Location> lo : a) { for (int i = 0; i < lo.size(); i++) { openSpaces.add(lo.get(i)); } } repaint(); }
@Test public void shouldHeroShoot() { // Given givenFl("☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼"); // When diceNew(); hero.recharge(); hero.act(); game.tick(); game.tick(); // Then assertE("☼ ☼" + "☼ * ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼"); }
public void keyPressed(KeyEvent arg0) { // TODO Auto-generated method stub int key =arg0.getKeyCode(); if(key ==KeyEvent.VK_UP){ hero1.moveUp(); } else if(key ==KeyEvent.VK_DOWN){ hero1.moveDown(); } else if(key ==KeyEvent.VK_LEFT){ hero1.moveLeft(); } else if(key ==KeyEvent.VK_RIGHT){ hero1.moveRight(); } repaint(); }
// 重写paint方法 public void paint(Graphics g) { super.paint(g); // float lineWidth = 3.0f; // ((Graphics2D)g).setStroke(new BasicStroke(lineWidth)); // 将坦克的活动区域填充为默认黑色 g.fillRect(0, 0, 800, 600); this.drawTank(hero.getX(), hero.getY(), g, hero.getDirection(), 1); for (int i = 0; i < hero.bombs.size(); i++) { Bomb myBomb = hero.bombs.get(i); // 画出一颗子弹 if (myBomb != null && myBomb.isLive == true) { // float lineWidth = 2.0f; // ((Graphics2D) g).setStroke(new BasicStroke(lineWidth));//设置线条为粗线 g.draw3DRect(myBomb.x, myBomb.y, 2, 2, true); } if (myBomb.isLive == false) { hero.bombs.remove(myBomb); } } // 画出爆炸 for (int i = 0; i < baozhas.size(); i++) { BaoZha bz = baozhas.get(i); System.out.println("baozhas.size()= " + baozhas.size()); if (bz.life > 5) { g.drawImage(image3, bz.x, bz.y, 30, 30, this); } else if (bz.life > 3) { g.drawImage(image2, bz.x, bz.y, 30, 30, this); } else { g.drawImage(image1, bz.x, bz.y, 30, 30, this); } bz.liftDown(); if (bz.life == 0) { baozhas.remove(bz); } } // 画出敌人的坦克 for (int i = 0; i < ets.size(); i++) { EnemyTank et = ets.get(i); if (et.isLive) { this.drawTank(et.getX(), et.getY(), g, et.getDirection(), 0); } } }
public void keyPressed(KeyEvent arg0) { int key = arg0.getKeyCode(); if (key == KeyEvent.VK_UP) { girl.moveUp(); } else { if (key == KeyEvent.VK_DOWN) { girl.moveDown(); } else { if (key == KeyEvent.VK_RIGHT) { girl.moveRight(); } else { if (key == KeyEvent.VK_LEFT) { girl.moveLeft(); } } } } repaint(); }
@Test public void shouldBombDestroyedByBullet() { // given givenFl("☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼"); diceNew(-1, 1); hero.recharge(); hero.act(); game.tick(); game.tick(); game.tick(); assertE("☼ ♣ ☼" + "☼ * ☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼"); game.tick(); assertE("☼xxx☼" + "☼xxx☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼"); }
@Test public void shouldHeroShootAfterRecharge() { // todo make it independent from starting conditions // Given givenFl("☼ ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); // when diceNew(-1, -1, 0, 0); game.tick(); // Given assertE("☼ ☼" + "☼7☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); // when hero.act(); game.tick(); // Given assertE( "☼ * ☼" + // у него в начале теста есть одна пуля, выплюнем ее "☼7☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); // when hero.act(); game.tick(); // Given assertE("☼ ☼" + "☼7☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); hero.left(); game.tick(); // Given assertE("☼ ☼" + "☼☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); // When hero.act(); game.tick(); // Then assertE("☼* ☼" + "☼☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); }
@Test public void shouldBulletOutOfTheBoard() { // Given givenFl("☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼"); // When diceNew(); hero.recharge(); hero.act(); game.tick(); // Then assertE("☼ ☼" + "☼ * ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼"); game.tick(); game.tick(); // Then assertE("☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼"); }
@Test public void shouldBombDestroyedByBulletNew() { // given givenFl("☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☺ ☼"); diceNew(0, 2); hero.recharge(); game.tick(); game.tick(); hero.act(); game.tick(); game.tick(); // then assertE("☼ ☼" + "☼0 ♣ ☼" + "☼ ☼" + "☼ * ☼" + "☼ ☼" + "☼ ☺ ☼"); game.tick(); // then assertE("☼ ☼" + "☼ xxx☼" + "☼0xxx☼" + "☼ xxx☼" + "☼ ☼" + "☼ ☺ ☼"); }
/** * Takes in Player class as a parameter. Fully restore current player's HP(MP if Ghost). * * @param affected */ @Override public void triggerEffect(Player affected) { Hero hero = affected.getCharacter(); if (hero.isGhost() == false) { hero.setCurrentHP(hero.getMaxHP()); } else if (hero.isGhost() == true) { hero.setCurrentMP(hero.getMaxMP()); } this.setMessage("You were kissed by a magic fairy. Restore HP to max."); }
/** Makes note of the picked hero objects from the Radiant Captain. */ public static void analyzeRadiantPicks() { carries = 0; mids = 0; offlaners = 0; supports = 0; junglers = 0; for (Hero pick : Hero.radiantPicks) { if (pick.getRole().equals("Carry")) { carries++; } if (pick.getRole().equals("Mid")) { mids++; } if (pick.getRole().equals("Offlaner")) { offlaners++; } if (pick.getRole().equals("Support")) { supports++; } if (pick.getRole().equals("Jungler")) { junglers++; } } analyzePicks(carries, mids, offlaners, supports, junglers); }
/** Makes note of the banned hero objects from the Dire Captain. */ public static void analyzeDireBans() { carries = 0; mids = 0; offlaners = 0; supports = 0; junglers = 0; for (Hero ban : Hero.direBans) { if (ban.getRole().equals("Carry")) { carries++; } if (ban.getRole().equals("Mid")) { mids++; } if (ban.getRole().equals("Offlaner")) { offlaners++; } if (ban.getRole().equals("Support")) { supports++; } if (ban.getRole().equals("Jungler")) { junglers++; } } analyzeBans(carries, mids, offlaners, supports, junglers); }
@Test public void shouldHeroPickUpBulletPack() { // given givenFl("☼ ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); diceNew(-1, -1, 1, 1); game.tick(); game.tick(); game.tick(); game.tick(); // then assertE("☼ 7 ☼" + "☼ ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); hero.up(); game.tick(); assertE("☼ 7 ☼" + "☼ ☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); hero.up(); game.tick(); assertE("☼ ☺ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼" + "☼ ☼"); }
@Test public void testPoorVictimWontHaveNegativeGold() { Hero thief = player1.getCharacter(); Hero victim = player2.getCharacter(); int initGold = thief.getGold(); victim.setGold(1); card.triggerEffect(player1, player2); assertEquals(initGold + 1, thief.getGold()); assertEquals(0, victim.getGold()); }
public void moveEnemies(ArrayList<Pokemon> friendly) { for (Pokemon p : enemies) { p.move(friendly); } for (int i = 0; i < enemies.size(); i++) { if (enemies.get(i).getHp() <= 0 && enemies.get(i).isEnemy() == true) { enemies.get(i).removeSelfFromGrid(); getInfo() .writeText(enemies.get(i).getName() + " has been defeated. You gained 5 XP points!"); System.out.println("removed " + enemies.get(i)); enemies.remove(enemies.get(i)); hero.increaseXP(); } } }
@Test public void testStealGold() { Hero thief = player1.getCharacter(); Hero victim = player2.getCharacter(); int thiefInitGold = thief.getGold(); int victimInitGold = victim.getGold(); card.triggerEffect(player1, player2); int diff = thief.getGold() - thiefInitGold; String msg = card.getMessage(); msg = msg.replace( "Victim has just invested in Thief's ponzi scheme. As a result, Thief steals ", ""); msg = msg.replace(" from Victim", ""); assertEquals(diff, Integer.parseInt(msg)); assertEquals(thiefInitGold + Integer.parseInt(msg), thief.getGold()); assertEquals(Integer.parseInt(msg), victimInitGold - victim.getGold()); }
public void paint(Graphics g) { // Graphics is a crayon box // Graphics2d is like an art kit // Random random = new Random(); BufferedImage image = new BufferedImage(width, length, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) g; /*g2.setColor(Color.white); g2.fillRect(0, 0, width, length); g2.setColor(Color.red); g2.fillOval(50, 100, 200, 100); g2.setColor(Color.blue); g2.drawOval(50, 100, 200, 100); //x, y, width, length, startDEG, lengthDEG g2.drawArc(50, 300, 200, 100, 0, 90); //string, x, y g2.drawString("String", 300, 300); //lines: startX, startY, endX, endY g2.drawLine(0, 0, width, length);*/ g2.setColor(new Color(0, 255, 255)); g2.fillRect(0, 0, width, length); // paintLandscape(g2); g2.drawImage(girl.getImage(), girl.getX(), girl.getY(), null); itemPickedUp = false; /*int ovalD = 50; int margin = 30; for(int x = 0; x < width; x+=ovalD+margin) { g2.setColor(Color.white); g2.fillOval(x, 50, ovalD, 20); } g2.setColor(new Color(255, 204, 0)); g2.fillRect(0, 150, width, length); for(int num = 0; num < 7; num++) { int x = random.nextInt(width - 0 + 1) + 0; int y = random.nextInt(length - 150) + 150; g2.setColor(Color.green); g2.fillRect(x,y, 50, 100); } /*g2.setColor(Color.blue); int squareD = 20; int margin = 2; for (int x = 0; x < width; x += squareD + margin) { for (int y = 0; y < length; y += squareD + margin) { c++; if(c > 255) { c = 0; g2.setColor(new Color(0, 0, c)); g2.fillRect(x, y, squareD, squareD); } else { g2.setColor(new Color(0, 0, c)); g2.fillRect(x, y, squareD, squareD); } } }*/ // draw the buffered image on the canvas /** * if (Math.abs(girl.getX()-potion.getX()) + Math.abs(girl.getY()-potion.getY()) <10){ * itemPickedUp=true; }* */ g.drawImage(image, 0, 0, null); if (itemPickedUp) {} }
public void CheckBonus(BattleCard opponent) { if (Archer.contains(opponent)) bonus = 4; else if (Hero.contains(opponent)) bonus = 4; else bonus = 0; }
public void paint(Graphics g){ //Graphics is a crayon box; Graphics2d is like an art kit BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D)image.getGraphics(); //Graphics2D g2 = (Graphics2D)g; g2.setColor(Color.white); g2.fillRect(0,0,width,height); g2.setColor(Color.pink); g2.drawOval(50, 50, width-100, height-100); g2.drawOval(175, 175, width-490, height-490); g2.drawOval(375, 175, width-490, height-490); g2.drawLine(0,10,height,0); g2.drawArc(175, 250, 250, 130, 200, 90); Hero hero2 = new Hero("Dorami", "/images/heroes/Dorami.jpg",100,100); if(Math.abs(hero1.getX()-hero2.getX()) + Math.abs(hero1.getY()-hero2.getY()) <20 ){ itemPickedUp=true; } if(!itemPickedUp){g2.drawImage(hero2.getImage(), hero2.getX(), hero2.getY(), null);} g2.drawImage(hero1.getImage(), hero1.getX(), hero1.getY(), null); //g2.fillOval(50,100,200,100); //g2.drawArc(50, 300, 200, 100,0,90); /* int c =0; int margin =2; int squareD =20; for(int x=0; x<width; x+= squareD +margin){ for(int y=0; y<height; y+= squareD+margin){ if(c<255) c++; else c=0; Color local = new Color((int) Math.floor(Math.random() * 256),(int) Math.floor(Math.random() * 256),c); g2.setColor(local); g2.fillRect(x,y,squareD,squareD); } }*/ g.drawImage(image, 0, 0, null); }
public int attack(Hero hero, int enemyDefense) { return hero.attack(enemyDefense); }