Question

I need help getting my game to select a random plant to paint here is the code for Actor and the two plants and the paintComponent that paints the objects. If you need anything else please comment and I can add it. The comments in paintComponent is where and what I think I need to change.

package ale import java.awt.geom. Point2D public class Plant extends Actor e public Plant ( Point 2D . Double startingPositio

1 public Example) super); // TODO Auto-generated constructor stub 4 // Define some quantities of the scene numRows - 5; numCo

7 IAdd them to the list of actors actors.add (death);// make random actors.add (blast):// make random actors.add (yoda); acto

package ale import java.awt.geom. Point2D public class Plant extends Actor e public Plant ( Point 2D . Double startingPosition, Point2D·Double initHit box, Buffered Image img, int health, int cooLDown, int super(startingPosition, initHitbox, img, health, cooLDown,0, attackDamage) An attack means the two hotboxes are overlapping and the Actor is ready to attack again (based on its cooldown) *Plants only attack Zombies * @param other e Override public void attack(Actor other) if (other instanceof Zombie) super.attack(other)
1 public Example) super); // TODO Auto-generated constructor stub 4 // Define some quantities of the scene numRows - 5; numCols- 7; cellSize-75; setPreferredSize(new Dimension (50 numCols cellSize, 50 numRows * cellSize)) rand-new Random); ranPicturenew Random(); // Store all the plants and zombies in here. actorsnew ArrayList
0 0
Add a comment Improve this question Transcribed image text
Answer #1
public void paintComponent(Graphics g) {
        
        super.paintComponent(g);
        
        ArrayList<Actor> plants = new ArrayList<>();
        
        for(Actor actor: actors) {
                if(!(actor instanceof Zombie)) {
                        plants.add(actor);
                }
        }
        
        // now you have only plants.
        int index = (int)(Math.random() * (plants.size()));
        
        Actor p = plants.get(index);
        p.draw(g, 0);
        p.drawHealthBar(g);
}
Add a comment
Know the answer?
Add Answer to:
I need help getting my game to select a random plant to paint here is the code for Actor and the ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is my code that i need to finish. In BoxRegion.java I have no idea how...

    This is my code that i need to finish. In BoxRegion.java I have no idea how to create the constructor. I tried to use super(x,y) but It is hard to apply. And Also In BoxRegionHashTable, I don't know how to create displayAnnotation BoxRegion.java ------------------------------------------------ public final class BoxRegion { final Point2D p1; final Point2D p2; /** * Create a new 3D point with given x, y and z values * * @param x1, y1 are the x,y coordinates for point...

  • I need help with my java code i am having a hard time compiling it //...

    I need help with my java code i am having a hard time compiling it // Cristian Benitez import java.awt.Color; import java.awt.Graphics; import java.util.ArrayList; import javax.swing.JPanel; Face class public class FaceDraw{ int width; int height; int x; int y; String smileStatus; //default constructor public FaceDraw(){ } // Getters and Setters for width,height,x,y public int getWidth(){ return width; } public void setWidth(int width){ this.width=width; } public int getHeight(){ return height; } public void setHeight(int height){ this.height=height; } public int getX(){ return...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • Please I need your help I have the code below but I need to add one...

    Please I need your help I have the code below but I need to add one thing, after player choose "No" to not play the game again, Add a HELP button or page that displays your name, the rules of the game and the month/day/year when you finished the implementation. import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.event.*; import java.util.Random; public class TicTacToe extends JFrame implements ChangeListener, ActionListener { private JSlider slider; private JButton oButton, xButton; private Board...

  • In java language here is my code so far! i only need help with the extra...

    In java language here is my code so far! i only need help with the extra credit part For this project, you will create a Rock, Paper, Scissors game. Write a GUI program that allows a user to play Rock, Paper, Scissors against the computer. If you’re not familiar with Rock, Paper, Scissors, check out the Wikipedia page: http://en.wikipedia.org/wiki/Rock-paper-scissors This is how the program works: The user clicks a button to make their move (rock, paper, or scissors). The program...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java...

    I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT