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

📄 gameframe.java

📁 SIMULATION FOURMILIERE -3D-ISOMETRIQUE
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * @param component    the componant where we add the listener
	 * @param listener     the listener to add
	 */
	public void addActionListener(final MnuControls component, final ActionListener listener) {
		if (component == null || listener == null)
			throw new IllegalArgumentException();
		tabMnu.get(component).addActionListener(listener);
	}

	
	/**
	 * Add a MouseListener to a specific button of the frame 
	 * @param component    the componant where we add the listener
	 * @param listener     the listener to add
	 */
	public void addButtonListener(final BtnControls component, final MouseListener listener) {
		if (component == null || listener == null)
			throw new IllegalArgumentException();
		tabBtn.get(component).addMouseListener(listener);
	}

	
	/**
	 * Add a MouseListener to a specific GameButton of the frame 
	 * @param component    the button in witch we put the listener
	 * @param listener     the listener to add
	 */
	public void addGameButtonListener(final GameControls component, final MouseListener listener) {
		if (component == null || listener == null)
			throw new IllegalArgumentException();
		tabAction.get(component).updateMouseListener(listener);
	}
	
	
	/**
	 * Update the state of a game button
	 * @param control	the current button to modify
	 * @param state		true=enabled, else disabled
	 */
	public void updateGameButton(final GameControls control, final boolean state) {
		final GameButton btn = tabAction.get(control);
		btn.setEnabled(state);
	}
	
	/**
	 * Update the tooptip text of a game button when disabled
	 * @param control	the current button to modify
	 * @param tooltip	the new tooltip to show
	 * @param isForEnabled	to know if the text is applied for enbled or disabled button
	 */
	public void updateToolTip(final GameControls control, final String tooltip, final boolean isForEnabled) {
		final GameButton btn = tabAction.get(control);
		if(isForEnabled)
			btn.setEnabledTooltip(tooltip);
		else
		btn.setDisabledTooltip(tooltip);
	}
	
    /**
     * Add a ChangeListener to a slider of the frame.
     * @param component the JSlider component to use
     * @param listener the new Listener
     */
    public void addSliderListener(final SlideControls component, final ChangeListener listener) {
    	final JSlider slider = tabSlide.get(component);
        slider.addChangeListener(listener);
    }
    
    
	/**
	 * Add an InputListener to the game Grid panel
	 * @param listener     the listener to add
	 */
	public void addGridPaneListener(final InputListener listener) {
		if (listener == null)
			throw new IllegalArgumentException();
		gridPane.addInputListener(listener);
	}

	/**
	 * Remove an InputListener from the game Grid panel
	 * @param listener     the listener to remove
	 */
	public void removeInputListener(final InputListener listener) {
		if (listener == null)
			throw new IllegalArgumentException();
		gridPane.removeInputListener(listener);
	}


	/**
	 * Give the quantity of rocks in the game (in percents)
	 * @return the quantity
	 */
	public int getQtyOfRocks() {
		return tabScroll.get(ScrollControls.SCR_Rock).getValue();
	}

	
	/**
	 * Give the quantity of food in the game (in percents)
	 * @return the quantity
	 */
	public int getQtyOfFood() {
		return tabScroll.get(ScrollControls.SCR_Food).getValue();
	}

	
	/**
	 * Give the quantity of sand in the game (in percents)
	 * @return the quantity
	 */
	public int getQtyOfSand() {
		return tabSlide.get(SlideControls.SLI_DESERT).getValue();
	}
	
	
	/**
	 * Give the quantity of water in the game (in percents)
	 * @return the quantity
	 */
	public int getQtyOfWater() {
		return tabScroll.get(ScrollControls.SCR_Water).getValue();
	}
	
	
	/**
	 * Give the difficulty of the game (selected in the 'Difficulty' menu)
	 * @return the difficulty
	 */
	public Game.Difficulty getDifficulty() {
		return gameDifficulty;
	}

	
	/**
	 * Give the world associated at this frame.
	 * @return  the World element
	 */
	public World getWorld() {
		return world;
	}

	
	/**
	 * Give the game speed
	 * @return  the game speed
	 */
	public int getGameSpeed() {
		return gameSpeed;
	}
	
	/**
	 * Assign the new game speed
	 * @param newSpeed the new speed
	 */
	void setGameSpeed(int newSpeed) {
		gameSpeed = newSpeed;
	}
	
	
	/**
	 * Assign the new game difficulty
	 * @param newDifficulty the new difficulty
	 */
	void setGameDifficulty(Difficulty newDifficulty) {
		gameDifficulty = newDifficulty;
	}
	
	
	/**
	 * Assign a new world to the frame
	 * @param newWorld     the new world to assign
	 */
	public void assignNewWorld(final World newWorld) {
		world = newWorld;
		gridPane = createGridPane(newWorld);
		gamePane = new JScrollPane(gridPane);
		splitPane.setRightComponent(gamePane);
		setZoom(gameZoom);
		resizeMenu();
	}

	
	/**
	 * Create a new GridPane of the given world
	 * @param newWorld  the word to use as model
	 * @return the new GridPane
	 */
	private GridPane<Values> createGridPane(final World newWorld) {
		gridPane = new GridPane<Values>(newWorld.getModel(), imageProvider, widthTiles, heightTiles);
		return gridPane;
	}
	
	
	/**
	 * Give the title of the window
	 * @return the title
	 */
	public String getTitle() {
		return frame.getTitle();
	}

	/**
	 * Get the willing size of the map. If the coords are invalid, we inform the
	 * user and we return null.
	 * @return the maximal's coord point if it is valid, else null
	 */
	public WorldPoint getAndValidSizeMap() {
		int x = 0;
		int y = 0;
		String errorMessage = null;
		try {
			x = Integer.parseInt(tabTxtField.get(TextControls.TXT_SIZE_X_GAME).getText());
			y = Integer.parseInt(tabTxtField.get(TextControls.TXT_SIZE_Y_GAME).getText());
			if (x < MIN_PLAY_X || x > MAX_PLAY_X || y < MIN_PLAY_Y || y > MAX_PLAY_Y)
				errorMessage = "Incorrect dimensions. Accepted sizes are ("
					+ MIN_PLAY_X + "," + MIN_PLAY_Y + ") to (" + MAX_PLAY_X
					+ "," + MAX_PLAY_Y + ").";
		} catch (NumberFormatException nfe) {
			errorMessage = "The 'size' fields are incorrects.";
		}

		if (errorMessage != null) {
			SelectBuilder.showMessageAlert(getTitle(), errorMessage);
			return null;
		}
		return new WorldPoint(x, y);
	}
    
    
    /**
     * Change the left panel during the game, to show informations about the player's antHill
     */
    public void setLeftPanelAntHill() {
        setLeftPanelGame(panelGameAntHill);
    }

    
    /**
     * Change the left panel during the game, to show informations about the player's Samantha
     */
    public void setLeftPanelSamantha() {
        setLeftPanelGame(panelGameSamantha);
    }
    
    
    /**
     * Change the left panel during the game, to show that the player's samantha is dead
     */
    public void setLeftPanelSamanthaDead() {
        setLeftPanelGame(panelGameSamanthaDead);
    }
    
    
    /**
     * Change the left panel during the game, to show informations about selected insects
     */
    public void setLeftPanelGroup(final List<Insect> insGroup) {
    	FactoryPanelGroup.createMenu(panelGameGroup, insGroup);
        setLeftPanelGame(panelGameGroup);
    }

    
    /**
     * Update the left menu for the game
     * @param panel the panel to show
     */
    private void setLeftPanelGame(final JPanel panel) {
        leftComponentGame.removeAll();
        leftComponentGame.add(panel);
        resizeMenu();
        leftComponentGame.validate();
        leftComponentGame.repaint();
    }

    
    /**
     * Update the label giving the stock of food for the player's team
     * @param quantity the new quantity to show
     */
    public void updateFoodStock(final int quantity) {
    	tabLbl.get(LblControls.LBL_Food).setText(Integer.toString(quantity));
    }
    
    
    /**
     * Update the label giving the knowledges of the player's team
     * @param quantity the new quantity to show
     */
    public void updateKnowledges(final int quantity) {
    	tabLbl.get(LblControls.LBL_Knowledge).setText(Integer.toString(quantity));
    }
    
    
    /**
     * Update the lable giving the actual energy of Samantha, the ant controled by the player
     * @param energy the energy to show
     */
    public void updateEnergySamantha(final int energy) {
    	tabLbl.get(LblControls.LBL_SamanthaEnergy).setText(Integer.toString(energy));
    }
    

    /**
     * Add a listener to the GridPane (game or level editor)
     * @param listener the listener to add
     */
    public void addGridPaneListener(final MouseListener listener) {
    	gridPane.addMouseListener(listener);
    }
    
    
    /**
     * Remove a listener from the GridPane (game or level editor)
     * @param listener the listener to remove
     */
    public void removeGridPaneListener(final MouseListener listener) {
    	gridPane.removeMouseListener(listener);
    }
    
    
    /**
     * Add a listener indicating when the size of the frame change.
     * @param listener the listener to add
     */
    public void addResizeFrameListener(final ComponentListener listener) {
    	frame.addComponentListener(listener);
    }
    
  
    /**
     * Scroll the gamePane so that the specified point become visible
     * @param p the point to show
     */
    public void centerGamePaneAroundCoords(final WorldPoint p) {
    	final int x = p.getX() * widthTiles;
    	final int y = p.getY() * heightTiles;
    	final int decalX = 8 * widthTiles;
    	final int decalY = 8 * heightTiles;
    	final JViewport viewport = gamePane.getViewport();
        viewport.scrollRectToVisible(new Rectangle(x - decalX, y - decalY, widthTiles, heightTiles));
    }
    

    /**
     * Show the 'about' window
     */
    public void showAbout() {
    	AboutFrame.showAbout(frame, frame.getTitle());
    }
}

⌨️ 快捷键说明

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