开发者

How to design simple game "Labyrinth with robot"?

I am new in Object Orien开发者_运维百科ted Design. I am trying to write simple game where i can set labyrinth as array and add robot to this labyrinth. Robot can do simple actions: goahead(),turnRight(),turnLeft(). How to design this simple application in OOP style? Help me please


You could start by thinking about which objects you are going to need. A simple way to do this is decribe the game and check all the nouns in your description.

If I use your title as (very small) description, you will probably have a Game, Labyrinth and Robot object to start with.

Next, you should start thinking about how these objects communicate with eachother. For example, when a Game starts, a Labyrinth and a Robot will probably have to be created.

A robot should probably know about the Labyrinth, as would be in real life. So the goAhead() method should probably call some method of the Labyrinth to check if it is possible.

The robot should also know it's location, probably.


One of the common ways to make a game like that is to have a "game-loop" that simplified does something like:

  • check for user input
  • update objects
  • render

Usually the objects have a common base class to do something like update(timetick) and your left(), right(), straight() methods plus for example explode() or the like :)

Your labyrinth should also be an object - and you will probably need a method to check a robot object for collision before moving it.

If you need examples, you can checkout amazon with a search for "game programming" - many of the books have companion sites and sample chapters you can check out if you don't want to buy something right now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜