Then you don't have to initialize node to null in the declaration. In the method move(), your switch statement needs a default case where you set node to null. There's no reason to use this with fields unless you're disambiguating it from a parameter. This will do: private LinkedList body = new LinkedList() you don't need to repeat the generic type on the right-hand side. I this statement: private LinkedList body = new LinkedList() It's clearer and less likely to cause bugs when being maintained. This was a school project where we had to program a game of our choice in one week using BlueJ, so its not the best piece of code but maybe it can help you out. If fact, I put braces around all the clauses in an if statement. BlueJ-Tac-Toe is a java implementation of Tic-tac-toe with BlueJ. Never put the else clause on the same on the same line as else. Private Snake initSnake() else isCovered = false Public boolean isDirectionChanged = false Private Direction snakeDirection = Direction.LEFT // initial direction is LEFT Return Math.abs(head.getX() - food.getX()) + Math.abs(head.getY() - food.getY()) = 0
![bluej program to make a game bluej program to make a game](https://media.geeksforgeeks.org/wp-content/uploads/20200917110454/tictac.jpg)
Private LinkedList body = new LinkedList() Pretty much anything that will help me become a better programmer.Īlso, I have commented a few things out of pure guess, so if it appears as if I have gotten something wrong, please correct me!Īlso, any extra tips for my future projects would be much appreciated!
Bluej program to make a game how to#
I am asking those who are more advanced programmers to help me with implementing programming techniques, better organization, how to comment better, etc. I don't really want help on how to make the game better in visuals, levels, or anything like that. I am skeptical on how good of a programmer I am, and I code messy.
![bluej program to make a game bluej program to make a game](https://static.javatpoint.com/images/puzzle_output.png)
I have rearranged the program into separate classes & methods.
![bluej program to make a game bluej program to make a game](https://s1.manualzz.com/store/data/009486852_1-653d5dba278f814b5cd59c1a078cb7b4-360x466.png)
I have recently created a snake game in Java with the help of an online tutorial. I am a self-taught coder, and have been learning Java for the last 2 months.