G'Day....
I have been working on a text adventure game. You can follow my progress on my Blog (link in signature at bottom of post) Anyway, I have been chugging through the, frankly, tedious work of building my word lists and stuff as well as competing the 1st step in the phraser.. which is single command recognition and execution. The problem I am running into is how do I go about implementing area specific code and conditions, in my very generic and general purpose classes.
Class Structure As it is Now
(Obviously I have striped this list to make my problem clearer)
- Level Class - Contains a variable List<Area> Level [][]. This is a 2 dimensional array creating a X/Y reference values for any given spot on the array.
- Player Class - Contains a variable PosX and PosY... these are modified by movement and on .getPosition() returns the value of List<Area>[][]. This is how I am acessing the correct place in my game world based on the player position.
- Area Class - This contains a given area. These are placed inside the List<Area>[][].
- Item Class - This contains individual items sitting in the level to be interacted with.
So a Level -> Area -> Items.
The Problem
The problem I have having is I can not work out how to go about having unique things inside these Areas and Items. Like for example a Ball can not be opened but a box can. So they need a different variable. I can not use the same class for both Box and Sphere. An area might have nothing in it, but it also may have a table that needs a ball put on it and then something is activated.
What I am getting at here is that the structure is basically working using these generic classes but I am not sure how I can code exciting and interesting unique things in these areas or on these items with out fundamentally changing things, or adding a mass of variables to the cases that are only used in some cases.
Say I have a Box in the scene.
I want the players to see it, and then try to pick it up.. but they can't. So the examine it more closely and find that it is actually got a button on it. The press it and something happens.
The questions is where are the methods to do these unique things and edit the item parameters going to be put. If I put them in the Item or Area sections I need to basically have a unique class for everyone .. maybe that is what I am supposed to do. Thing is I wrote a really handy data txt file importer for areas and files that I do not want to scrap. That only really works on these generic ideas. To get really interesting events and natural language responses there needs to be a ton of unique things going on ... but I have kinda designed everything to be very generic.
Possible Solution
I know that a List<type> can contain classes as long as all the classes in the list are inherited form the same base class. So I was thinking of a new class that populates a simular kind of list to Level<area>[][]. This will be something like List<gameLogic>[][]. In here I put a all the methods for the individual areas. The Key values like the other list is pulled form the player positions. So if I need a unique method I could call it from Player.GetPostions().gameLogic.SetOpen();... this then would trigger bools and change description text and stuff in the more generic objects. The problem with this is I still need a series of generic method calls. So far example area.item[9] might be a Hat... if I type GETHAT it trigges a generic get() method on the hat, that ALL items have.. but it then actually dose a unique bit of logic in the logic class for that specific room.. so item.get(prams) triggers gameLogic.get(prams).. and those prams allow me to do specific "gets" per-object..
Is that making any sense?
So yeah.. I'm kinda stuck
Yeah.. so I am kinda stuck here about what to do. The crux of my issue is that I have a game loop and a series of objects.. level, areas in the level and items in the area. These are all generic so the I can be easily build the level during initiation of the game with out tons of unique code making editing and changes hard. So the exact way to continue these simple loops, but access unique code is confusing me. I mean as long as everything was very simple I could get wawya with it. but as I wanted to add more complex stuff I was finding the need for additional variables and checks.
Any thoughts? (sorry if I am not clear)
Quick demo of you... this shows the start screen and the first room. (pressing spacebar skips the text printout to finished)
So the very first time the game loops and finds you in a area it tests a variable in that area to see if you have ever been there before.. if not it prints a "cinematic".. witch is a long story focused text description, that you only see once. (it is also added to a log for reading latter). Then if you type the look command... it finds the area look description and adds it to the print buffer, then finds all the items (there are only two at the moment) and appends their descriptions and then prints out that look.
All pretty cool and I ma happy with it.
This is just to show something in the thread.. I seem to have noticed anything with a youtube video in it gets way more comments hahaah