简体   繁体   中英

New to eclipse and need guidance

So I am writing a game code in eclipse and I was just wondering if I could split up my work in different tabs. An example is that I have all my if statements in one tab and in the next I have another class that I could work with. Because at the moment my code is getting way too long and I would like to be more organized. Sorry for my bad English.

If you want to make a simple game on a canvas, you could use the following tabs (classes):

MainThread - this class updates the canvas (let's say) at 60 fps, it calls update() and draw(Canvas canvas) in the GamePanel class.

GamePanel - this class has a GameplayScene field, the GameplayScene instance is the scene that is currently being displayed on the canvas. In the GamePanel class, you have (at least) two methods: update() and draw(Canvas canvas) , which call the same methods in the GameplayScene instance.

GameplayScene - you could make this an interface, so you could have multiple classes implementing it. You could also have just one GameplayScene , it doesn't have to be an interface then.

You could have multiple classes that implement GameplayScene , so you have multiple scenes, for example, an item shop, the main menu, or a level.

In each scene you have, again, the update() and draw(Canvas canvas) methods, which call the same methods in instances of GameObject . A scene class is responsible for keeping track of the player's score, when the player dies, or that the game restarts when the player dies.

GameObject - I would make this an interface, so you could have multiple objects implementing the interface.

A game object could be the player, an obstacle, a button, an enemy, whatever is drawn onto the canvas.

In the game object's update() method, you (for example) set the object's position based on some calculations, or you test if an enemy collides with the player.
In the game object's draw(Canvas canvas) method, the only thing you do is drawing the object onto the canvas . You do the calculations in the update() method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM