Jump to content

Creating A Text Based Game


Infiltration
 Share

Recommended Posts

I've noticed a lot of pre made scripts are .php files, so when I try to open them, it's just a huge thing of code, note I'm still on the basics of HTML and I'll build up to PHP, but I was just wondering.. What exactly do you do with this? For example: It was a script for "attacking a player" how would I actually use that?However of course, this post is mainly because I would like to know the steps to creating a web based multi player online text based game similar to Outwar and Torn City. I understand HTML and PHP are very important languages to help, but what else would I need?

Edited by Infiltration
Link to comment
Share on other sites

and chances are just plugging in their code won't work right off the bat. You might need to learn javascript too. Also, try to actually learn what the code is doing rather than just copy/pasting.

Link to comment
Share on other sites

Don't get me wrong, I'm not planning on using someone else's stuff and just paste it together and yay my game.I'm just asking as an example, because I had no idea what to do with it. It wasn't that I was going to actually use it, I just wanted to know after I write my own stuff, what do I do with it?and I am focusing all my time into learning all possible languages. I've been working on html for about a week now 10 hours each day. I just need to know what are the steps, as in what languages, what language does what, programs, etc. I just want to know the steps that will lead me into that direction. I am planning on taking this very seriously, I started the tutorials here and I'm starting college in January.

Link to comment
Share on other sites

Well, HTML formats your information into pieces the browser can understand, CSS tells the browser how to display the HTML, JS does stuff with the HTML, and PHP generates the HTML to be sent to the browser.Everyone has different methods of coding; there is no way you could utilize all libraries using a single method. The best way is to read the documentation.

Link to comment
Share on other sites

Like Synook said, HTML is the language you use to create the structure that the browser shows. CSS is the language where you define how the structure gets displayed, things like colors and borders and fonts etc. Javascript is for most things that happen interactively on a page, without the page getting refreshed. If you can use one page to create or move or save things without the page getting refreshed, it's Javascript that makes that possible. Things like Gmail and Google Maps use Javascript so that you can interact with the page without needing to refresh every time you click. PHP is the language that you use on the server, PHP is what you use to read and write to a database or files on the server, or what you use to send email or process a login form or anything that needs to happen on the server. You can also use languages like ASP, ColdFusion, or Python to run on the server in place of something like PHP. In addition to those, SQL is the language that you actually use to communicate with a database, commands sent to a database are in the SQL language. Any server language like PHP or ASP can send SQL commands to a database, but SQL is still another language. You'll find tutorials for those languages on this site or elsewhere through Google, but it's usually more effective to learn from some books or something else a little deeper than what you can find online.

Link to comment
Share on other sites

To set up a basic text based games you dont need to know alot actually, many great text based games are made with just the basics of PHP programming and HTML/CSS, To use a script like "Attacking player" you need following scripts;login.php - The login script with php based loginregistrer.php - Registrer scriptindex.php - Script with menu to attacking player - And etc a frame to show player_attacking.phpplayer_attacking.php - Sricpt that sends a mysql_query('function') to MySQL database A little player_attacking.php example:

<?phpinclude "config.php"; //File with mysql_connect etc.$username = $_COOKIE['user']; //Username was registrerd as a cookie in login.php  //If someone clicks the button attack_random_player in player_attack.phpif(isset($_POST['attack_random_player'])){   // Now we will find the target in the mysql_database	 $select_target = mysql_num_rows(mysql_query("SELECT * FROM `$mysql_data`.`user_Table` WHERE attackable='yes' and money !='0'"));   //Target selected randomly as an "id" $target 		= rand(0,$select_target);   // Now we bring out the money of the user (can output username and password to) $select_money 	= mysql_fetch_object(mysql_query("SELECT * FROM `$mysql_data`.`users_Table` WHERE id=$target"));  //Fint out randomly how much money the user gets from attack based on the targets money $money_out 	= rand(0, $select_money->money);   // If number of variable true_success is 23 attack is a success $success		= 23;   //Varible true_success $true_success	= rand(21,25);  		// If the true_success is 23	if($success === $true_success){ 			//Creating the targets remaining money		$money_ut	= $select_money->money-$money_out; 				//Now we bring out the money our user allready has		$money_in	= mysql_fetch_object(mysql_query("SELECT * FROM `$mysql_data`.`user_Table` WHERE username='$username'"));				//And we add the new ammout from target onto users money		$money_inn	= $money_in->money+$money_out; 				//Here we insert remaining money to target		mysql_query("UPDATE `$mysql_data`.`user_Table` SET money='$money_out' WHERE id=$target"); 				//Here we insert new moeny to our user		mysql_query("UPDATE `$mysql_data`.`user_Table` SET money='$money_inn' WHERE username='$username'"); 				//Here we say our success message			echo "Attack sucess, you got $money_out from the attack."; 					//And exit the "page"			exit(); 	}	else //Here we say if true_success is other than 23 execute failiure message	{		// Here is our failiure message		echo "Attack failed"; 				//Then we exit page		exit(); 	}}?>

config.php - Script with mysql_connect and other functions you want or need.and a MySQL database.A basic attacking player script uses following tables in database:table_UsersidusernamepasswordmoneyattackableThats it.Now you have a basic script to look at, w3schools tutorials have more descriptions of functions,and with the player_attacking script you should get a better understanding of how to connect functions together.Hope it was helpful :)norNerd

Link to comment
Share on other sites

Well, I'am also building a game using php as the backbone. I really recommend you to read some tutorials about making a Content Management System (CMS) in php take a look at some of the basic security problems using $_GET and $_POST also to prevent cheating etc. To learn stuff about this I also recommend you to use the free PHPnuke CMS (also a very popular CMS) as an example. Look at the filestructure etc. Details on phpnuke can be found on: phpnuke-nederland.nlAfter you have made your CMS you can add your game as a so called 'module'. Modules are parts of your CMS that can be deleted or added without changing the rest of the system. You can insert a playerpage, maps, etc. When you have done all of this (witch takes some time) you are ready to learn something about players/members attacking each other. It will also be much easier to find stuff about Online browsergames on Google when you get the basics.After you have succesfully made all of this and the game is able to run on its own, you can smoothen things up using javascript as quick interaction and CSS to make a nice layout etc.

Link to comment
Share on other sites

Wow thanks a lot, this is all the info I was needing.I was just a bit confused because I didn't really understand what to do with all this random jibberish '.'I'm hoping I'll understand it a lot more as I dig deep into it, any other tips would be happily accepted :)
You can send me a PM if you need any help with creating scripts or understanding the basics of it.Used to host several mafia games in the past so have no problem helping you with this :)Kris
Link to comment
Share on other sites

Funny I see this because I was looking for somthing else actually, but I'm also trying to make a browser game with php. I don't know everything about php, but I know where to find info on php and that is a valuable alternative. What I have done for my page is thinking out a concept, making a nice layout and I made some art. Also the log in and register codes are done, I'm now working on a message system. So if you'd need help with that I can help you as well.My game will also need a kind of attack system but with the crucial difference that the attack takes some time, lets say an hour, to reach the defender. But the defender can see this attack coming and decide on which tactic to use. For example he can remove all his treasure and army. Or he can move his whole army to the attacked spot.Is it possible with php to make something that calculates the outcome of a fight an hour after the attack has been launched? If not, is there a simple way how to do this or do I need to rethink my game and find something that is easier to code.

Link to comment
Share on other sites

Yea, you have to make some kind of map system with coordinates. for example:-Coordinate A [1:1] attacks B [30:50]-Calculate the number of steps from point A to point B (30 steps down + 50 steps to left = 80 steps)-Give each step a timevalue (1 step = 10 seconds)-Take the exact Unixtime in seconds-Calculate Unixtime + the total number of seconds-Store this new unixtime in a database-When the first user (attacker or defender) logs in check if there is an attack log of the sended attack-If there is no log, After the given Unixtime let the attack take place and store a log in the database-When the second user logs in, check if there is a log, else let the attack take place-Attack took place and a winner is known

Edited by Redroest
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...