/// <summary> /// Clears the tile, sets all the variables for tile contents to null, sets isBlocked to false. /// </summary> public void clearTile() { creature = null; plant = null; remains = null; obstacle = null; isBlocked = false; }
/// <summary> /// Populates the world by adding plants and obstacles /// </summary> private void populateWorld() { for (int plantNum = 0; plantNum < Simulation.getPlantPopulation(); plantNum++) { int[] xy = getRandomClearTile(); if (xy[0] == -1 && xy[1] == -1) { throw new Exception("World is full, cannot add any further content"); } else { Tile t = getTile(xy[1], xy[0]); Plant p = new Plant(randomNumberGenerator); p.setLocation(xy[0], xy[1]); plantList.Add(p); t.addPlant(p); } } for (int obstNum = 0; obstNum < Simulation.getNumObstacles(); obstNum++) { int[] xy = getRandomClearTile(); if (xy[0] == -1 && xy[1] == -1) { throw new Exception("World is full, cannot add any further content"); } else { Tile t = getTile(xy[1], xy[0]); Obstacle o = new Obstacle(); o.setLocation(xy[0], xy[1]); t.addObstacle(o); } } }
/// <summary> /// Adds a plant to the tile, sets the plant variable to the specified plant and sets the tile to be blocked /// </summary> /// <param name="c">The plant to add to the tile</param> public void addPlant(Plant p) { plant = p; isBlocked = true; }
/// <summary> /// Views a plant, sets viewing to be true and sets up the information viewing commands /// </summary> /// <param name="c">The Plant to be viewed</param> private void viewPlant(Plant p) { viewing = true; maxInfo = plantMaxInfo; plantView = p; }
/// <summary> /// Cancels views, sets viewing to be false and all the viewing variables etc. to be null /// </summary> private void deView() { viewing = false; creatureView = null; plantView = null; remainsView = null; following = false; dataViewed = 0; buttons[3].setVisible(false); buttons[4].setVisible(false); buttons[5].setVisible(false); }
/// <summary> /// Gets an array of strings that contain information about the plant /// </summary> /// <param name="c">The plant to get information about</param> /// <returns>An array of strings containing a set of information about the plant</returns> public string[] getPlantInfo(Plant p) { string[] status = new string[1]; switch (DataViewed) { case 0: status = new string[] { "Food Units Remaining: " + p.getFoodRemaining(), "Food value: " + p.getFoodValue(), "Regrows in: " + p.getTicksRemainingBeforeAction() + " ticks" }; break; } return status; }
/// <summary> /// Draws the plant viewing window /// </summary> /// <param name="c">The plant to draw the viewing window for</param> private void drawPlantView(Plant p) { drawBack(); Simulation.getGraphicsDeviceManager().GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap; spriteBatch.Begin(0, null, SamplerState.PointWrap, null, null); Rectangle r = new Rectangle((Display.getWindowWidth() - 800) / 2 + 10, Display.getWindowHeight() - 130, 120, 120); Texture2D tex = null; if(p.isDepeleted()) { tex = depletedPlantTile; } else { tex = plantTile; } spriteBatch.Draw(tex, r, Color.White); spriteBatch.End(); string[] status = inputHandler.getPlantInfo(p); Vector2 topLeft = new Vector2((Display.getWindowWidth() - 800) / 2 + 10 + 120 + 10, Display.getWindowHeight() - 130); string title = "Plant"; if(p.isDepeleted()) { title += " (depleted)"; } drawStrings(topLeft, title, status, 4); }