⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game.java

📁 SIMULATION FOURMILIERE -3D-ISOMETRIQUE
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					 */
					
					LinkedList<Insect> lst = team.getTabInsect();
					if (lst != null) {
						Insect[] ins = new Insect[lst.size()];
						ins = lst.toArray(ins);
						for (int i = 0; i < ins.length; ++i)
							if (ins[i] != null)
								ins[i].getAction();
					}
				}
				world.refresh();
            	
	            // We do some more actions, like "refresh the food stock information"
	            Team playerTeam = world.getTeams().get(0);
				int energySamantha = samantha.getEnergy();
	            int foodStock = playerTeam.getFoodStock();
	            int knowledge = playerTeam.getKnowledges();
	            if (ancFoodStock != foodStock) {
	                gameFrame.updateFoodStock(foodStock);
	                ancFoodStock = foodStock;
	            }
	            if (ancKnowledge != knowledge) {
	                gameFrame.updateKnowledges(knowledge);
	                ancKnowledge = knowledge;
	            }
	            if (ancEnergySamantha != energySamantha) {
	                gameFrame.updateEnergySamantha(energySamantha);
	                ancEnergySamantha = energySamantha;
	            }

	            // We activate gameButtons when we have enough knowledges in the player's team
	            if (knowledge >= Team.KNOWLEDGE_FOR_BUGS &&  playerTeam.getFoodStock() >= Team.FOOD_NEEDED_FOR_A_BUG && !isBugsActivated) {
	            	gameFrame.updateGameButton(GameFrame.GameControls.GAM_Bug, true);
	            	isBugsActivated = true;
	            }
	            if (knowledge >= Team.KNOWLEDGE_FOR_KAMIKAZES  && playerTeam.getFoodStock() >= Team.FOOD_NEEDED_FOR_A_KAMIKAZE && !isKamikazesActivated) {
	            	gameFrame.updateGameButton(GameFrame.GameControls.GAM_Kamikaze, true);
	            	isKamikazesActivated = true;
	            }
	            if (knowledge >= Team.KNOWLEDGE_FOR_SHIELDS && !isShieldActivated) {
	            	gameFrame.updateGameButton(GameFrame.GameControls.GAM_Shield, true);
	            	gameFrame.updateToolTip(GameFrame.GameControls.GAM_Shield, "You have already developped shields", false);
	            	isShieldActivated = true;
	            }
	            if (knowledge >= nextKnowledgeVeteran && playerTeam.getFoodStock() >= Team.FOOD_NEEDED_FOR_VETERANS && !isVeteransActivated) {
	            	isVeteransActivated = true;
	            	switch(playerTeam.getRank()) {
	            		case PRIVATE:	nextKnowledgeVeteran = Team.KNOWLEDGE_FOR_CAPTAINS;	break;
		            	case SERGEANT:	nextKnowledgeVeteran = Team.KNOWLEDGE_FOR_MAJORS;	break;
		            	case CAPTAIN:	nextKnowledgeVeteran = Team.KNOWLEDGE_FOR_COLONELS; break;
		            	case MAJOR:		nextKnowledgeVeteran = Team.KNOWLEDGE_FOR_GENERALS;	break;
		            	case COLONEL:	nextKnowledgeVeteran = Integer.MAX_VALUE;			break;
		            	case GENERAL:	nextKnowledgeVeteran = Integer.MAX_VALUE;			break;
	            	}
	           		gameFrame.updateGameButton(GameFrame.GameControls.GAM_Veteran, true);
	            }
	            
	            // And we desactivate them if the food sudently disapeared :)
	            if (isBugsActivated && playerTeam.getFoodStock() < Team.FOOD_NEEDED_FOR_A_BUG) {
	            	gameFrame.updateGameButton(GameFrame.GameControls.GAM_Bug, false);
	            	isBugsActivated = false;
	            }
	            if (!isShieldActivated && playerTeam.getFoodStock() < Team.FOOD_NEEDED_FOR_SHIELD) {
	            	gameFrame.updateGameButton(GameFrame.GameControls.GAM_Shield, false);
	            }
	            if (isKamikazesActivated && playerTeam.getFoodStock() < Team.FOOD_NEEDED_FOR_A_KAMIKAZE) {
	            	gameFrame.updateGameButton(GameFrame.GameControls.GAM_Kamikaze, false);
	            	isKamikazesActivated = false;
	            }
	            if (isVeteransActivated && playerTeam.getFoodStock() < Team.FOOD_NEEDED_FOR_VETERANS) {
	            	gameFrame.updateGameButton(GameFrame.GameControls.GAM_Veteran, false);
	            	isVeteransActivated = false;
	            }
	            	            
				wait(gameFrame.getGameSpeed());
			}
        }
	}

	/**
	 * Wait for tps miliseconds
	 * @param tps  delay to wait
	 */
	private void wait(final int tps) {
		if (startTime == 0) {
			this.startTime = System.currentTimeMillis();
		} else {
			try {
				final long timeToWait = tps - (System.currentTimeMillis() - startTime);
				if (timeToWait > 0) {
					Thread.sleep(timeToWait);
				}
			} catch (InterruptedException ex) {/* NOTHING */}
			this.startTime = System.currentTimeMillis();
		}
	}

	/**
	 * Give the current difficulty of the game
	 * @return the difficulty
	 */
	public Difficulty getDifficulty() {
		return gameFrame.getDifficulty();
	}


	/**
	 * Create a new Samantha Religiosa ant. This capacities are determined by
	 * the difficulty of the game
	 * @param isDeadBefore if true, we print a dialog box indicating that we are dead.
	 */
	public void createSamantha(final boolean isDeadBefore) {
		if (isDeadBefore) {
			gameFrame.setLeftPanelSamanthaDead();
			countDeath++;
		}
			final Team curTeam = world.getTeams().get(0);
		samantha = curTeam.getMaster().addSamantha();
	}

	/**
	 * Notify the Game when a master of a team is dead. If it is the player's
	 * team, he lose. Otherwise, if he killed all others masters, he win
	 * @param insect   the master that have just died.
	 */
	public void informDeadMasterOfTeam(final Insect insect) {
		if (!insect.equals(insect.getTeam().getMaster()) || gameBreak)
			return;
		if (insect.getTeam().getColor() == 0) {
			SelectBuilder.showMessageAlert(gameFrame.getTitle(), getEndGameMessage("Your queen is dead. You lose, sorry !"));
			gameBreak = true;
		} else {
			nbOpponents--;
			if (nbOpponents == 0) {
				SelectBuilder.showMessageInfo(gameFrame.getTitle(), getEndGameMessage("All the other queens are dead. You won !"));
				gameBreak = true;
			}
		}
	}

	
	/**
	 * Give some information on the game
	 * @param caption	the main message to return
	 * @return the end message
	 */
	private String getEndGameMessage(String caption) {
		return new StringBuilder(caption)
			.append(" For information, you have been killed ")
			.append(countDeath).append(countDeath <= 1 ? " time" : " times")
			.toString();
	}
	
	
	/**
	 * Show a confirm dialog box, asking the user if he really wants to
	 * continue, knowing that if he does, he lose the modifications he made on a level
	 * @return true if he agreed, else false
	 */
	boolean confirmLostModifications() {
		if (levelModified && !SelectBuilder.showMessageConfirm(gameFrame.getTitle(), "All change made will be lost. Continue anyway ?"))
			return false;
		return true;
	}
	
	
	/**
	 * Give the current World element
	 * @return  the World element
	 */
	World getWorld() {
		return world;
	}
	
	/**
	 * Give the player's antHill position
	 * @return  the position
	 */
	WorldPoint getAntHill() {
		return antHill;
	}
	
	/**
	 * Give the opponents' antHill positions
	 * @return the list of positions
	 */
	ArrayList<WorldPoint> getAntHillOpp() {
		return antHillOpp;
	}
	
	/**
	 * Give a reference to Samantha
	 * @return  Samantha
	 */
	Insect getSamantha() {
		return samantha;
	}

	/**
	 * Indicate if the game is paused or not
	 * @return  true if the game is paused
	 */
	boolean getGamePaused() {
		return gamePaused;
	}
	
	/**
	 * Pause / 'unpause' the game
	 */
	void setGamePaused(final boolean state) {
		gamePaused = state;
	}
	
	/**
	 * Indicate if a level has been modified or not
	 * @param state   if 'true' the the level has been modified
	 */
	void setLevelModified(final boolean state) {
		levelModified = state;
	}

	/**
	 * Indicate when the initialisation part of the game is over
	 * @return  true when it is over
	 */
	boolean getInitBreak() {
		return initBreak;
	}
	
	/**
	 * Indicate the end of the level editor 
	 * @param state  if 'true', the the level editor just finished
	 */
	void setInitBreak(final boolean state) {
		initBreak = state;
	}

	/**
	 * Indicate when the game is over
	 * @return  true when the game is over
	 */
	boolean getGameBreak() {
		return gameBreak;
	}

	/**
	 * Indicate the end of the current game
	 * @param state  if 'true' the the game just finished
	 */
	void setGameBreak(final boolean state) {
		gameBreak = state;
	}
	
	/** 
	 * Determine if the game to launch is a new or a saved one
	 * @param state  if 'true' then it is a new game. Else it is a saved one
	 */
	void setNewGame(final boolean state) {
		newGame = state;
	}

    public void setAntHill(final WorldPoint antHill) {
        this.antHill = antHill;
    }

    
    /**
     * Desactivate the 'developp veterans' button
     */
	void desactivateVeteranButton() {
		this.isVeteransActivated = false;
	}
 
	
	/**
     * Desactivate the 'developp a bug' button
     */
	void desactivateBugButton() {
		this.isBugsActivated = false;
	}
	
	
	/**
     * Desactivate the 'developp a kamikaze' button
     */
	void desactivateKamikazeButton() {
		this.isKamikazesActivated = false;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -