Вопрос

I'm very new to Java and am not sure if I'm even allowed to ask questions of this nature here but I'll give it a shot. I want/need practice programming Java so I've decided on a rather large project that should be within my capabilities I've started building it and have created a player object with some properties like level,name,xp,health and items. The items are and array of 5 object objects (bear with me XD) now I'd like to know if I should create the rooms as objects as well or as seperate classes or functions?

The rooms will be only rooms in an abstract sense the game is fully text-based they will need to contain puzzles and objects a user can pick up or examine as well as enemies and such the narrative will also be contained in each one. The player will be able to "pick up" items in the room and add them to their inventory. As well as participate in textual comabt with enemies like : you hit monster for 2 damage, monster hits back for 3 etc.

Remember that this isn't going to be pretty it's for practice and I need to do it within Java. Thanks in advance.

Это было полезно?

Решение

Your problem is related to the OOP concepts not to being a beginner in java, you should know more about OOP to think correctly before starting coding to put the correct OOP design for your program. since you are building this program in java you can start here.

For what I've understand from you question, you may want to have a Room Class, Containing the Room Properties and Functions.

Другие советы

From a high level, a good idea would be having a "Room" class, this would contain the Room Title, Description and any other room specific information (such as terrain type etc).

You could then create a multidimensional array of Room objects. One dimension being your X coordinate while the other your Y coordinate.

This way to "move" around all you need to do is track your location and either increment/decrement your X or Y based on the direction you moved.

You could extend it further doing something like generating a map of your surroundings as well. Each terrain type could be displayed as a different symbol (@ for forest, ~ for water etc). It would be a simple approach to add something like this because all you need to do is get your top right/bottom left coordinate and loop through those coordinates building your map.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top