Package jpotter

Source Code of jpotter.Game

package jpotter;

import java.io.IOException;

import jpotter.spells.Accio;
import jpotter.spells.Aguamenti;
import jpotter.spells.Avis;
import jpotter.spells.Deprimo;
import jpotter.spells.Expelliarmus;
import jpotter.spells.Incendio;
import jpotter.spells.Spell;

public class Game {
  public static final int NB_ENEMIES = 4;
  private static int turn = 0;
  private static Game instance = new Game();
  public volatile boolean casting = false;
  public Enemy[] enemies = new Enemy[NB_ENEMIES];

  private Game() {
    //
  }

  public static Game getInstance() {
    return instance;
  }

  public void run() {
    // bluetooth settings
    System.setProperty("bluecove.stack.first", "widcomm");
    System.setProperty("bluecove.jsr82.psm_minimum_off", "true");

    try {
      enemies[0] = new Enemy(50, "img/lucius.jpg", 0);
      enemies[1] = new Enemy(50, "img/bellatrix.jpg", 1);
      enemies[2] = new Enemy(50, "img/drago.jpg", 2);
      enemies[3] = new Enemy(50, "img/voldemort.jpg", 3);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

   
    FusionManager.getInstance();

    IHM ihm = IHM.getInstance();
    for (int i = 0; i < enemies.length; i++) {
      ihm.createEnemy(enemies[i]);
    }

    // simulation
    Spell[] spells = new Spell[] { new Aguamenti(), new Avis(),
        new Deprimo(), new Incendio(), new Expelliarmus(), new Accio() };

    // for (int i = 0; i < spells.length; i++) {
    // System.out.println(spells[i].toString());
    // ihm.setEnemyTarget(i%4);
    // ihm.cast(spells[i]);
    // try {
    // Thread.sleep(2500);
    // } catch (InterruptedException ex) {
    // ex.printStackTrace();
    // }
    // }
    boolean allKo = false;
    Player[] ps = new Player[NB_ENEMIES + 1];
    ps[0] = ihm.harry;
    ps[1] = enemies[0];
    ps[2] = enemies[1];
    ps[3] = enemies[2];
    ps[4] = enemies[3];
    while (!allKo && !ihm.harry.isKo()) {
      casting = true;
      if(!ps[turn].isKo()){
        ps[turn].play();
        while (casting)
          ;
      }
     
      turn = (turn + 1) % ps.length;

      boolean ko = true;
      for (int i = 0; i < NB_ENEMIES; i++) {
        ko &= enemies[i].isKo();
      }
      allKo = ko;

    }
   
    if(allKo){
      //harry win
      IHM.getInstance().displayText("You win !!");
    }else{
      IHM.getInstance().displayText("You lose !!");
    }
   
  }

  public static void main(String[] args) {
    Game.getInstance().run();
  }

}
TOP

Related Classes of jpotter.Game

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.