/** * makes this jump * * @param pressed true if jump button is down * @param sound true if should play sound */ public void jump(boolean pressed, boolean sound) { if (dead) return; if (pressed) jumpDown = true; else jumpDown = false; if (cape) { if (pressed) { movingUp = true; acc.y = Wuigi.GRAVITY; jumping = true; } else { movingUp = false; jumping = false; acc.y = 0; } return; } if (pressed) { if (vel.y == 0) { vel.y = JUMP_VEL + Wuigi.GRAVITY; jumping = true; jumpAdd = Wuigi.COMPLETE_JUMP_TIME; if (sound) JUMP.start(); } } else { jumpAdd = -Wuigi.COMPLETE_JUMP_TIME; } }
/** shoots the AWP */ public void shootAWP(int x, int y) { if (numBullets > 0) { numBullets--; AWP.start(); shotTime = System.currentTimeMillis(); ammo.setText("" + numBullets); double awpx = pos.x + width / 2; double awpy = pos.y + height / 2; double mousex = x + this.pos.x - (Wuigi.screenWidth / 2.0 + xOffset()); double mousey = Wuigi.screenHeight + pos.y + 32 - (ScreenManager.mouse.y + yOffset()); addSpawn(new AWPBullet(awpx, awpy, mousex, mousey)); } }
void newGame() { ptm = null; NewGame ngd = new NewGame(this); ngd.setVisible(true); if (ngd.gst == null) { if (firstrun) { bst = new BoardSettings(); gst = new GameSettings(); bst.setOrder(13); gst.setType(0); gst.swap = false; firstrun = false; } else return; } else { bst = ngd.bst; gst = ngd.gst; firstrun = false; } bst.findScale(getSize()); x0 = bst.scale * r3 * (bst.getOrder() + 4) / 2; y0 = bst.scale * r3 * 2 + 50; data = new GameData(bst.getOrder()); getCoordinates(); /*if(gst.ai!=null) { gst.ai.flush(); gst.ai.start(); }*/ gameActive = true; count = 0; lmv = null; AIMethods.init(bst.getOrder()); if (gst.getType() == GameSettings.HUMAN_VS_AI) { if (gst.ai == null) gst.ai = new MiniMax(bst.getOrder(), (cst == 1) ? 2 : 1); gst.ai.init(this); userMove = true; } AePlayWave.q.clear(); if (gst.audio) AePlayWave.play(AePlayWave.START); repaint(); }
void exit() { int n = JOptionPane.showConfirmDialog( this, "Are you sure you want to exit this game?", "Confirm Exit", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { if (gst.audio) { AePlayWave.play(AePlayWave.EXIT); try { Thread.sleep(2000); } catch (Exception e) { } } dispose(); System.exit(0); } }
void place(int mx, int my) { if (drme) { drme = false; return; } int n = data.a.length; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (((mx - data.a[i][j].x) * (mx - data.a[i][j].x) + (my - data.a[i][j].y) * (my - data.a[i][j].y) < bst.scale * bst.scale * .75) && data.a[i][j].getState() == 0) { if (count == 1 && gst.swap) { int ch = JOptionPane.showConfirmDialog( this, "Swap moves?", "Swap", JOptionPane.YES_NO_OPTION); if (ch == JOptionPane.YES_OPTION) { lmv.setState(cst); switch (cst) { case 1: data.a[i][j].setState(2); break; case 2: data.a[i][j].setState(1); break; } repaint( (int) (lmv.x - 0.8 * bst.scale), (int) (lmv.y - 0.8 * bst.scale), (int) (1.6 * bst.scale), (int) (1.6 * bst.scale)); if (AIMethods.gameOver(this, lmv.i, lmv.j, count)) { newGame(); } if (gst.ai != null) gst.ai.updateAI(lmv.i, lmv.j, lmv.getState(), count); } else data.a[i][j].setState(cst); } else data.a[i][j].setState(cst); lmv = data.a[i][j]; repaint( (int) (data.a[i][j].x - 0.8 * bst.scale), (int) (data.a[i][j].y - 0.8 * bst.scale), (int) (1.6 * bst.scale), (int) (1.6 * bst.scale)); switch (cst) { case 1: cst = 2; break; case 2: cst = 1; break; } if (AIMethods.gameOver(this, lmv.i, lmv.j, count)) { System.out.println("Game Over"); firstrun = true; String win = ""; if (lmv.getState() == Block.RED_BEAD) { switch (gst.theme) { case 0: win = "Red"; break; case 1: win = "Black"; break; case 2: win = "Gold"; break; } } else { switch (gst.theme) { case 0: win = "Blue"; break; case 1: win = "Green"; break; case 2: win = "Silver"; break; } } if (gst.audio) AePlayWave.play(AePlayWave.END); JOptionPane.showMessageDialog( this, win + " wins", "Game Over", JOptionPane.INFORMATION_MESSAGE); newGame(); return; } if (gst.audio) { if (gst.ai == null) AePlayWave.play(AePlayWave.PLACE); else if (userMove) AePlayWave.play(AePlayWave.AIMOVE); } count++; if (gst.ai != null && userMove) { userMove = false; gst.ai.nextMove(lmv.i, lmv.j, lmv.getState(), count); } else userMove = true; return; } } } if (gst.audio) AePlayWave.play(AePlayWave.BLOCK); }
// 构造函数 public MyPanel(String flag) { apw.start(); // 恢复记录 Recorder.getRecord(); // bombs.add(new Bomb(0,0)); // 括号里的是初始位置 myTank = new MyTank(100, 100); if (flag.equals("newGame")) { // 初始化敌方坦克 for (int i = 0; i < enemySize; i++) { // 创建一辆敌人的坦克 EnemyTank et = new EnemyTank((i + 1) * 50, 0); et.setColor(1); et.setDirect(2); // 將MyPanel的敵人坦克向量交給該敵人坦克 et.setEts(enemyTanks); // 启动敌人的坦克 Thread t = new Thread(et); t.start(); // 给敌人坦克添加一颗子弹 Bullet b = new Bullet(et.x + 10, et.y + 30, 2); // 加入敌人坦克 et.bb.add(b); Thread t2 = new Thread(b); t2.start(); // 加入 enemyTanks.add(et); } } else { nodes = new Recorder().getNodesAndEnNums(); // 初始化敌方坦克 for (int i = 0; i < nodes.size(); i++) { Node node = nodes.get(i); // 创建一辆敌人的坦克 EnemyTank et = new EnemyTank(node.x, node.y); et.setColor(1); et.setDirect(node.direct); // 將MyPanel的敵人坦克向量交給該敵人坦克 et.setEts(enemyTanks); // 启动敌人的坦克 Thread t = new Thread(et); t.start(); // 给敌人坦克添加一颗子弹 Bullet b = new Bullet(et.x + 10, et.y + 30, 2); // 加入敌人坦克 et.bb.add(b); Thread t2 = new Thread(b); t2.start(); // 加入 enemyTanks.add(et); } } // 初始化爆炸图片 // try { // image1= ImageIO.read(new File("/3.png")); // image2= ImageIO.read(new File("/2.png")); // image3= ImageIO.read(new File("/1.png")); // } catch (IOException e) { // e.printStackTrace(); // } image1 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/3.png")); image2 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/2.png")); image3 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/1.png")); bombs.add(new Bomb(0, 0)); }