In this three-part tutorial, I make up a dynamic story as I go along using a lot of the functions that I have taught about before. If you would like to see another way of applying variables and functions called array, count, date, echo, mktime, and rand: it is highly suggested you take your time and watch this tutorial.
Lets Make up a Story! Part 2
Here are the sources used in this tutorial:
tut020.php
<?php //PHP Tutorial 020 ?> Hello, adventurer, it was a dark and stormy <?php $x = rand(1,6); $save = mktime(0,0,0,2,$x,1995); echo date("l",$save); ?> night! You are with <?php $people = rand(2,40); echo $people; ?> other people, and you want to go and mow the grand lawn of the ages!<br /> One of your best friends, <?php $friends = array(); $friends[] = "Joe"; $friends[] = "James"; $friends[] = "John"; $friends[] = "Jacob"; $friend = $friends[rand(0,count($friends)-1)]; echo $friend; ?> wants to join you on your wonderful adventure! Now, you must decide to let him or not!<br /> <?php $yesorno = rand(0,1); if($yesorno){ echo " You said yes to $friend!"; }else{ echo " You said no to $friend!"; } ?> Because you said, <?php if($yesorno){ echo "yes"; }else{ echo "no"; } ?>, your friend is quite <?php if($yesorno){ echo "happy!"; }else{ echo "sad."; } ?> Now you and <?php if($yesorno){ echo $people + 1; }else{ echo $people; } ?> other people traveled over the Neatherlands!
November 12th, 2009 at 9:59 pm
[...] like a more elaborate sh or batch file in a command line interface. If you recall in the previous tutorial (020), I made up a story. Well, now we can introduce this to where it is somewhat like a game. It can be [...]