• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Snake Game asking for feedback and improvements

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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.

Game class



GameObjects Class



Board Class



Food Class





Class QuitG_Listener



RestartBt_ActionListener



Score class


Snake Class


[/img]
 
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ion Ciorici
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 285
14
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 5562
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ion Ciorici
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 17700
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Junilu Lacar
Sheriff
Posts: 17700
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic