[img]I am not allowed to to use additional APIs (application programming interfaces), libraries other than what is available in the Java SDK API classes / interfaces.
As a general rule, I don't like extending display classes. It is however a good idea to extend JPanel to override its paintComponent(Graphics) method.
I also think it is usually a bad idea to make a display class implement ActionListener.
What about storing objects in a collection? What are the usages and did I make it properly?
Also, for the images that I want to use in the game is there a better way to use images because it is only bounded to the file path of my computer at the moment
you need to make a package and store the images as resources in the package, then you can load them from there, and it means you can distribute the program.
What use does the GameObject have? It exists of two GameObjects, Snake and Food, but what use is the posX and posY fields? For Snake these are unnecessary, and a Food has its own x and y.
Then it could be a Collection of GameObjects, but the Board draws a Snake and a Food literally, so it doesn't use a GameObject as Collection.
Why does the Food class have a field: Snake snake? I did not see any code using this field.
So, at a glance I'd say get rid of the GameObject class, make an interface Drawable, that has a method 'draw' and let Snake and Food implement this interface.
Lastly (for now) don't let the 'draw' method load an image. Load these images at startup.
But I like the idea and it certainly would work. As soon as I have created some images, I'll have a go playing the game. The last time I played Snakes, was it in the 80's or 90's?
There are three kinds of actuaries: those who can count, and those who can't.
Can you advise me how can I make use of the GameObject
I need to have an abstract class that is used for Snake and Food to inherit its methods related to how the game
objects are displayed and manipulated and suitably overridden
What's the point of lines 11-13 in this constructor?
gameobj is declared and assigned a new ArrayList<GameObject> instance. However, this is a local variable and it is not assigned to any instance variable so when the constructor exits, it will simply vanish without a trace. It's quite pointless from what I can tell.
Referring to Line 6 of the Food class, why would a Food object have a Snake object as one of its attributes/fields? Can you explain your reasons for doing that?
Message for you sir! I think it is a tiny ad:
Gift giving made easy with the permaculture playing cards