/// <summary> /// Collects moons /// </summary> /// <param name="moonFlower">The moon to collect from</param> /// <param name="moon">The moon to collect</param> public void CollectMoon(MoonFlower moonFlower, Moon moon) { //Collect it moonFlower.CollectMoon(moon); //Cascade the moons moonFlower.CascadeMoons(); }
/// <summary> /// Sets one of each type of plant /// </summary> private void SetPlants() { _plants[0] = new Tree(-1, -1, new Rectangle()); _plants[1] = new MoonFlower(-1, -1, new Rectangle()); _plants[2] = new PeaShooter(-1, -1, new Rectangle()); _plants[3] = new WallNut(-1, -1, new Rectangle()); _plants[4] = new SnowPea(-1, -1, new Rectangle()); _plants[5] = new PotatoMine(-1, -1, new Rectangle()); _plants[6] = new CherryBomb(-1, -1, new Rectangle()); }
/// <summary> /// Handles the user grabbing a moon /// </summary> /// <param name="moon"></param> /// <param name="moonflower"></param> public void GrabMoon(Moon moon, MoonFlower moonflower) { // If the mouse is down and the mouse location is within the bounds of the passed in moon. if (_isMouseDown && moon.Bounds.Contains(_mouseLocation)) { // Sets the moon's isCollected property to true. moon.IsCollected = true; // Calls the wrapper to collect the specified moon at the specified moonflower. _wrapper.CollectMoon(moonflower, moon); } }
/// <summary> /// Moves all of the moons /// </summary> /// <param name="row">Row</param> /// <param name="col">Column</param> private void MoveMoons(int row, int col) { //Check if its a moonflower if (_vars.board[row, col] is MoonFlower) { //Create the moonflower MoonFlower moonFlower = _vars.board[row, col] as MoonFlower; //Loop through all of the moons to draw foreach (Moon moon in moonFlower.GetMoonsToDraw()) { //Move it moon.Move(); } } }
/// <summary> /// Handles the drawing of moons on the board /// </summary> /// <param name="g"></param> public void DrawMoons(Graphics g) { // Loops through the rows from 0 until the constant row value. for (int row = 0; row < ROWS; row++) { // Loops through the cols from 0 until the constant col value. for (int col = 0; col < COLS; col++) { // If the plant at the specific board location is a moon flower. if (_wrapper.GetBoard()[row, col] is MoonFlower) { // Creates a moonflower to store the specific plant at the board location as a moonflower. MoonFlower moonflower = _wrapper.GetBoard()[row, col] as MoonFlower; // Creates a list of moons which are to be removed. List <Moon> moonsToBeRemoved = new List <Moon>(); // Loops through each moons in the wrapper's list of moons to be drawn. foreach (Moon moon in _wrapper.GetMoonsToDraw(moonflower)) { // Draws the moon at its bounds. g.DrawImage(Graphic.GetImage(moon), moon.Bounds); // Calls the method to handle the user's grabbing of a moon. GrabMoon(moon, moonflower); // Checks if the moon is expired and ready to be collected. if (moon.IsExpired) { // Adds that specific moon to the list of moons to be removed. moonsToBeRemoved.Add(moon); } } // Adds the amount of moons that need to be removed to the total amount of moons. _wrapper.AddMoons(moonsToBeRemoved.Count); // Loops through each moon in the list of moons to be removed. foreach (Moon moonToBeRemoved in moonsToBeRemoved) { // Removes the specific moon from the specific moonflower from the wrapper's list of moons to be drawn. _wrapper.GetMoonsToDraw(moonflower).Remove(moonToBeRemoved); } } } } }
/// <summary> /// Check if the player picked up any moons /// </summary> private void CheckMoonPickUp() { //Loop through all of the rows for (int rows = 0; rows < ROWS; rows++) { //Loop through all of the columns for (int cols = 0; cols < COLS; cols++) { //Check if the plant is a moonflower if (_wrapper.GetBoard()[rows, cols] is MoonFlower) { //Create the moonflower MoonFlower moonFlower = _wrapper.GetBoard()[rows, cols] as MoonFlower; //Create the moon to remove Moon toRemove = null; //Loop through all of the moons foreach (Moon moon in _wrapper.GetMoons(moonFlower)) { //If the mouse is over the moon if (StaticMethods.MouseIntersects(moon.X, moon.Y, moon.Width, moon.Height, _mouseX, _mouseY)) { //Collect the moon moon.IsCollected = true; //Update the moon to remove toRemove = moon; //Break out of the loop break; } } //Check if there is a moon to remove if (toRemove != null) { //Collect the moon _wrapper.CollectMoon(moonFlower, toRemove); } } } } }
/// <summary> /// Handles making moons /// </summary> /// <param name="endDest"></param> internal void MakeMoons(Point endDest) { // Creates a 2D array to store the board. Plant[,] board = _sharedVariables.board; // Loops from 0 to the length of the board's first dimension. for (int x = 0; x < board.GetLength(0); x++) { // Loops from 0 to the length of the board's second dimension. for (int y = 0; y < board.GetLength(1); y++) { // If the specific board location is a moon flower. if (board[x, y] is MoonFlower) { // Creates a moon flower to store the board location as a moon flower. MoonFlower moonFlower = board[x, y] as MoonFlower; // Calls said moon flower to make a moon passing in the end destination of the moon. moonFlower.MakeMoon(endDest); } } } }
/// <summary> /// Draw the moons /// </summary> /// <param name="g">Graphics to draw on</param> /// <param name="row">The row of the plant</param> /// <param name="col">The column of the plant</param> private void DrawGameMoons(Graphics g, int row, int col) { //If the plant is a moonflower if (_wrapper.GetBoard()[row, col] is MoonFlower) { //Create the moonflower MoonFlower moonFlower = _wrapper.GetBoard()[row, col] as MoonFlower; //Store all moons that should be removed List <Moon> toRemove = new List <Moon>(); //Loop through all of the moons for the moonflower foreach (Moon moon in _wrapper.GetMoonsToDraw(moonFlower)) { //Draw the moon g.DrawImage(Properties.Resources.moon, moon.Bounds); //Check if the moon is already collected if (moon.IsExpired) { //Add it to the remove list toRemove.Add(moon); } } //Add the amount of moons that have been collected _wrapper.AddMoons(toRemove.Count); //Loop through all of the moons that should be removed foreach (Moon moon in toRemove) { //Remove the moon _wrapper.GetMoonsToDraw(moonFlower).Remove(moon); } } }
/// <summary> /// Gets the moons to draw /// </summary> /// <param name="moonFlower">The moonflower in question</param> /// <returns>The moons to draw</returns> public List <Moon> GetMoonsToDraw(MoonFlower moonFlower) { return(moonFlower.GetMoonsToDraw()); }
/// <summary> /// Gets the moons for a moonflower /// </summary> /// <param name="moonFlower">The moonflower in question</param> /// <returns>The moons on it</returns> public List <Moon> GetMoons(MoonFlower moonFlower) { return(moonFlower.GetMoons()); }
/// <summary> /// Buy and place a plant /// </summary> /// <param name="row">The row to place</param> /// <param name="col">The column to place</param> /// <param name="bounds">The bounds of the tile</param> private void BuyAndPlace(int row, int col, Rectangle bounds) { //Check if the mouse is pressed and a plant is grabbed if (!_mouseDown && _plantGrabbed[_plantGrabbedIndex]) { //Get the grabbed plant Plant grabbedPlant = _wrapper.GetPlants()[_plantGrabbedIndex]; //Create a plant Plant plant = null; //Check if the grabbed plant is a tree if (grabbedPlant is Tree) { //Create the new plant plant = new Tree(row, col, bounds); } ////Check if the grabbed plant is a moonflower else if (grabbedPlant is MoonFlower) { //Create the new plant plant = new MoonFlower(row, col, bounds); } //Check if the grabbed plant is a cherrybomb else if (grabbedPlant is CherryBomb) { //Create the new plant plant = new CherryBomb(row, col, bounds); } //Check if the grabbed plant is a potatomine else if (grabbedPlant is PotatoMine) { //Create the new plant plant = new PotatoMine(row, col, bounds); } //Check if the grabbed plant is a peashooter else if (grabbedPlant is PeaShooter) { //Create the new plant plant = new PeaShooter(row, col, bounds); } //Check if the grabbed plant is a snowpea else if (grabbedPlant is SnowPea) { //Create the new plant plant = new SnowPea(row, col, bounds); } //Check if the grabbed plant is a wallnut else if (grabbedPlant is WallNut) { //Create the new plant plant = new WallNut(row, col, bounds); } //Store the reason that a player can either place or not place a plant ModelWrapper.Reason reason = _wrapper.GetReason(row, col, plant); //Check if the tile is occupied by a plant if (reason == ModelWrapper.Reason.Occupied) { //Set the note accordingly _note = OCCUPIED; } //Check if there is no trees in bounds else if (reason == ModelWrapper.Reason.NoTreesNearby) { //Set the note accordingly _note = NO_TREES_NEARBY; } //Check if the player doesnt have enough moons else if (reason == ModelWrapper.Reason.InsufficientMoons) { //Set the note accordingly _note = INSUFFICIENT_MOONS; } //Buy and place the plant _wrapper.BuyAndPlace(row, col, plant); //Release the plant _plantGrabbed[_plantGrabbedIndex] = false; } }