Jump to content

Making a text adventure in PHP-very basic/beginner


DeadlyAzn

Recommended Posts

Is this possible? I have around 2 weeks for a computer science project and I want to do this in PHP. However, I have just started learning PHP, and since I'm so short on time I'm going to see if I can learn how to code this while learning basics of PHP.

So basically, can anyone give me a simple and good way of starting this? I have no idea where to begin. I was thinking of doing rooms in a coordinate system with North, South, East, West buttons and a pick up item button and an attack button.

So can you guys help? I would also like to know how to make buttons in HTML or anything that goes with Apache 2, I have no idea how that works.

 

Right now I have PHP set up with Apache 2, so I can navigate to the file with the code in the browser and run the code.

Link to comment
Share on other sites

Users should not "bump" topics that are still on the first page of the forums. If you bump' date=' you must provide additional information. If you resort to bumping, chances are your question needs to be re-thought and re-described (see Eric Raymond's "How To Ask Questions The Smart Way").[/quote']

 

We're not going to write it for you. Do you have a specific question or are you stuck on something in particular?

Link to comment
Share on other sites

Yes.

 

We're not going to design it for you, however.  That's beyond the scope of what we do here.  What we do is provide help for specific problems that our members have at least made a token effort to address on their own.

 

Do you have a PHP-specific question?  Any code for us to see?

Link to comment
Share on other sites

sort of just an idea that might work for what you are doing...

 

could create a rooms db table with fields...  if you want your building to be like 20x20 rooms, it could be pretty simple...

 

could have a database with 400 rows for example... then you just kind of visualize that the northern row is 0-19, second would be 20-39, etc

 

moving south 1 could be something like nextRoom = currentRoom + 20;

moving north 1 could be something like nextRoom = currentRoom - 20;

moving west 1 could be something like nextRoom = currentRoom - 1;

moving east 1 could be something like nextRoom = currentRoom + 1;

 

you could have fields within the rooms table (or bridged tables) that specify whether a room is accessible, or which sides its accessible from, or what items are in it, etc

 

and obviously you'd have to check for edges.. like if a person is in room 0, 20, 30, etc.. they wouldn't be able to move west...

 

this give you any idea on how you might want to start?

Link to comment
Share on other sites

Or you could organize your database as "room references" where each row references a room file. That way you don't need coordinates and don't have to organize the rooms in a static field; i.e., you can build and connect rooms dynamically.

 

I'm confused. How do you do this?

 

Do you have any more information on these tables?

huh? mysql? not sure i understand the question

 

How do I make db tables?  Or what you mentioned?

Link to comment
Share on other sites

Oh man. How does that work? I was thinking about giving variables to every room and assigning values to them, and those variables would be items or people or bits of string that contain the story. For example, the "inspect" button would echo out "The surrounds are dim and gloomy." And the "take items" button would be "You take $string and $paper." And the attack button would check if the value of the npc in the area was 1 or 0, 1 for alive and 0 for dead, and would be like if $life = 1 then echo "You attack the dogs, and they run away." If 0, then "You don't see anyone to attack!". And if $life was still 1, then it would echo "You can't move in any direction, you are trapped here!".

 

Also, do you guys have any idea on how you can have the player variable or something contain variables within itself? Like items, etc. Like, maybe contain $string, and the value of $string would be either "working" or "broken". Wow ok, this went really detailed, but its pretty specific, could you respond to these things? Thanks!

Link to comment
Share on other sites

Exactly.  Attempting to create something that works with this many moving parts (how should a room be represented?  its items?  its exits?  player position?) when you don't know the bare bones basics of the language, and with a two week deadline, is just going to end in tears.

 

Do something simple.  Create a small guestbook or something that addresses the basics of form handling, database insertion/retrieval, and user registration/logins.

Link to comment
Share on other sites

Alright so right now I'm just thinking about making 100 files, each name 1, 2, 3, 4, 5 etc and so forth, and giving each file code to move to which file depending on which action. This is lots of manual work but only way I can think of doing it.

 

Also, is there some way I can check for what I entered in a text box and then run a code with an if statement depending on what word was inside it?

Link to comment
Share on other sites

Did you actually follow along with the tutorials, or just read them? The reason I ask is, some of the questions you are asking are VERY basic and would easily have been covered in any number of beginning PHP tutorials. The gurus are here to help people along with specific tasks regarding PHP programming, but rarely (if ever) write code for someone. Usually it is understood that someone has done due diligence to find out as much as they can, try it out for themselves, and post their problem code here for everyone to look at. If you're saying that you have read through many tutorials and still don't understand the extreme basics, you may want to look into another programming language that more fits your thinking processes.

 

I'm just thinking about making 100 files, each name 1, 2, 3, 4, 5 etc and so forth, and giving each file code to move to which file depending on which action. This is lots of manual work but only way I can think of doing it.

 

This tells many of the regulars here that you don't understand the key components of PHP programming. It's a web-based language, and it goes hand-in-hand with databases (usually MySQL). Most tutorials on beginning PHP should eventually start including database implementation. I'm not an expert when it comes to databases (or PHP, for that matter), but I had to learn the database thing in order to make anything useful with PHP. The quote above also states that you probably don't know a whole lot about arrays, which is also a must-know thing in any programming language. (OK, you don't HAVE to know it, but most things won't be possible to program if you don't.)

 

This is like walking into a garage and asking a mechanic how to start a car and adjust the seats, then casually asking him to rebuild the engine for you.

 

OK. That being said, I will now step off my soapbox and give you some design advice (though I'm not going to teach you how to build database tables, implement a database, or build arrays; this would take WAY too long).

 

I have built at least three of the types of game you want to make. I will tell you right now that you don't need to implement a database unless you want the player to be able to save their game mid-play. You can build everything you need with arrays, though it's not as fun. Technically, you could save player location  and information in a flat file, but that's beyond the scope of my rant as well. Continued in the next post.

Link to comment
Share on other sites

Build a couple of multidimensional arrays (you can either hand-code them or pull the data from a database). One array is for locations on the map (I call them 'squares'), and another array for inventory (items). The first index of each array is a square number, so on a 10X10 grid, you would have 0 - 99 for square numbers. I actually print out a grid with the numbers in them, 0 - 99, upper-let to lower-right. So now every location has a number which is associated with the first index of the two-dimensional array. So $square[0][0] would refer to the upper-left-most square, and $square[99][0] would refer to the bottom-right-most square.

 

The second dimension of the array is for meta information. I use [zero] for the square name ("City Hall"), [1] for the description ("You are standing in the center of City Hall. There is a pathway to the east and more of the city to the south"), [2],[3],[4],[5] are all used for North, South, East, and West, respectively. So $square[0][3] would be the square number you would get to if you went SOUTH of that square, so $square[0][3] = 10, and if the player went south, it would load up $square[10][0] (think of the squares on a 10X10 grid, starting at zero, the square to the south of square zero would be square 10. If you can't go that direction from a particular square, you just have zero as its index. So in the City Hall example, City Hall would be $square[0][2] = 0 (can't go north), $square[0][3] = 10 (you can go south, and it will take you to square 10), $square[0][4] = 1, $square[0][5] = 0 (can't go west either).

 

Use this information as a starting point. If I have time in the future, I'll tell you how to implement the inventory and items array. But I'm going to assume, for now, that this information may be a little beyond where you are right now. Take heed of the others and DO (not just read) some more PHP tutorials.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.