What is happening now is that your Model and View are linked in the same class - this makes it hard to follow the logic behind everything. To progress with the project, consider making it an exercise in the MVC framework. To answer your postscript, set a background color or make a JPanel behind everything else with a painted color. P.S When I put this same exact code in Eclipse on my Mac, the background of my frame is black, but on Windows it's light gray. Private static ArrayList mySnake = new ArrayList() įtDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) Private static JFrame frame = new JFrame("Snake") Public void actionPerformed(ActionEvent e) Public class Snake extends JPanel implements KeyListener, ActionListener I'm looking for some ideas as to how I can progress with this project - please don't give me the full answer, because I'd like to figure out most of it on my own I just need some direction. At the moment, I've created an ArrayList with just one Snake object inside, if I add a second Snake object to the list and add it to the frame(with the first), only one Snake object is visible and the keys to move it don't function. My goal is to use an ArrayList to hold the squares that make up the snake. You don't need to hold down the key or keep pressing it it changes direction when you press any of the other keys that are set(Right, Up, Down). When you press LEFT once, the square begins to move left using a timer. At the moment, I have a square that the user can move around the screen using the arrow keys. I decided to re-create Snake using Java, but I'm sort of stuck.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |