Package Project1.Game

Examples of Project1.Game.Game


    new Thread(this).start();
    }
   
  @Override
  public void run() {
    Game game = Game.getInstance();
   
    while (game.isRunning()) {
     
      // We get the current time at the beginning of the main loop
      long currentTime1 = Calendar.getInstance().getTimeInMillis() - initialTime;
     
      while(!commands.isEmpty()) {
        //This is the "defilage"
        synchronized(this) {
          Command command = commands.remove();
          command.doCommand();
        }
      }
     
     
      // The towers attack !!
      for(Tower tower: game.getTowerManager().getTowers()) {
        // we loop on each agent in the game
        for(GroupAgent agent: game.getAgentManager().getAgents()) {
          //if the agent is in the area of the tower
          if(tower.canShot(agent)) {
            // if the agent is attacking a base of the owner of the base
            if (tower.getOwner().equals(agent.getBaseDestination().getPlayer()) && !tower.getOwner().equals(agent.getBaseOrigin().getPlayer())) {
              long currentTime2 = Calendar.getInstance().getTimeInMillis() - initialTime;
              if (currentTime2 - tower.getMomentOfLastShot() >= tower.getCadence()) {
               
               
                System.out.println("Tower Attack !!!!");
                AttackAgent shotCommand = new AttackAgent(agent, tower.getMight());
                Engine.getInstance().getCommands().add(shotCommand);
               
                tower.setMomentOfLastShot(currentTime2);
              }
            }
          }
        }
      }
      // We get again the current time at the end of the defilage
      long currentTime3 = Calendar.getInstance().getTimeInMillis() - initialTime;
     
      // We run through all the Collection of Bases
      for(Base baseCurrent : game.getBaseManager().getBases()) {
        // We display the data for the agents for each base.
        baseCurrent.setForeground(new Color(255,255,255));
        baseCurrent.setText(""+baseCurrent.getNbAgents()+"");
        baseCurrent.setVerticalTextPosition(SwingConstants.CENTER);
        baseCurrent.setHorizontalTextPosition(SwingConstants.CENTER);
       
       
        //Test for generation
        float periodOfGeneration = 10000/(baseCurrent.getMight()); // on peut modifier, c'est empirique...
        if((currentTime3 - baseCurrent.getMomentOfTheLastGeneration()) < periodOfGeneration) {
          // if the elapsed time between the moment of the last generation and the current time is inferior
          // to the period of generation, we do nothing for the bases
        }
        else {
          // else we can generate agents
          if(baseCurrent.hasPlayer()) {
            // Neutral bases don't generate agents until they are taken
            baseCurrent.generateAgent();
            // We set the new moment of the last generation which is the current time now
            baseCurrent.setMomentOfTheLastGeneration(Calendar.getInstance().getTimeInMillis() - initialTime);
          } else {
           
          }
        }
      }
      // The Real Player die if he has 0 base.
      if(!Launcher.modeSpectateur) {
        try {
          if(Game.getInstance().getPlayerManager().getRealPlayer().getIsDead()) {
            System.out.println("La partie est terminée, vous êtes éliminé !");
            // Les autres joueurs ne continuent pas la partie tout seul.
            for(Player p : Game.getInstance().getPlayerManager().getPlayers()) {
              p.setIsDead(true);
            }
            Game.getInstance().setRunning(false);
          }
        } catch (RealPlayerException e1) {
          e1.printStackTrace();
        }
      }
     
      // Move and handle units
      for(Iterator<GroupAgent> it = game.getAgentManager().getAgents().iterator(); it.hasNext();) {
        GroupAgent groupAgent = it.next();
        groupAgent.moveOneStep();
      }
     
      // Players get progressively more money
      game.economicalEvolution(0.05F);
     
      // The game is updated with 30 fps
      long waiting = 1000/30 - ((Calendar.getInstance().getTimeInMillis()-initialTime) - currentTime1);
      if(waiting > 0) {
        try {
View Full Code Here


{
    // constructors -----------------------------------------------------------

    public Project2()
    {
        Project1 project = new Project1();
    }
View Full Code Here

{
    // constructors -----------------------------------------------------------

    public Project2()
    {
        Project1 project = new Project1();
    }
View Full Code Here

    // constructors -----------------------------------------------------------

    public Project2()
    {
        Project1 project = new Project1();
    }
View Full Code Here

     * Test of getGame method, of class Action.
     */
    @Test
    public void testGetGame() {
        System.out.println("getGame");
        Game result = actionTest.getGame();
        Game expResult = game;
        assertEquals(result, expResult);
    }
View Full Code Here

   
    @Before
    public void setUp() {
        player=new Player(5,5,5,false);
        game=new Game("username",001);
        instance=new Action(player,"action","value",game,session);
    }
View Full Code Here

     */
    @Test
    public void testGetGame() {
        System.out.println("getGame");

        Game result = instance.getGame();
        assertEquals(game, result);
    }
View Full Code Here

    public void testPerformAction() {
        System.out.println("performAction");
       
     
       Player  player=new Player(5,5,5,false);
       Game game=new Game("username",001);
       Action action=new Action(player,"action","value",game,session);
       
        ActionPerformerInterface instance = new ActionPerformerInterfaceImpl();
        instance.performAction(action);
View Full Code Here

       
       
        System.out.println("getGameMadeByCreator");
       
       String creatorUserName="wanting";
       Game result=instance.createNewGame("wanting");
       Game expect=instance.getGameMadeByCreator(creatorUserName);
       assertSame(expect,result)

    }
View Full Code Here

    @Test
    public void testGetGameWithUserInIt() {
       
        System.out.println("getGameWithUserInIt");
       
        Game result=instance.createNewGame("wanting");
        Game expResult=instance.getGameWithUserInIt("wanting");       
  
        assertEquals(expResult, result);

    }
View Full Code Here

TOP

Related Classes of Project1.Game.Game

Copyright © 2018 www.massapicom. 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.