I'm creating a haunted house text-based game in PHP for a school assignment. I have most of the stuff down, except that there has to be a way for the user to progress to another room. From my e-mail:
Code:
Can someone explain to me how parallel arrays work in PHP?
The refresh part lets me check for randomness.
The 'progress to another room' begins the necessity of storing the user's changing location, lives left, level of difficulty, location of exits, etc. as the user leaves a room.
Even though the user leaves the room, you, the programmer, will continue to use the game board that you have already made. All you will be doing is monitoring by which door the user leaves and keeping track of the 'winning' door.
The problem can be solved in many ways, one of which is using parallel arrays that keep track of doors in arrRoomFileNames[ ].
I hope this helps.
The 'progress to another room' begins the necessity of storing the user's changing location, lives left, level of difficulty, location of exits, etc. as the user leaves a room.
Even though the user leaves the room, you, the programmer, will continue to use the game board that you have already made. All you will be doing is monitoring by which door the user leaves and keeping track of the 'winning' door.
The problem can be solved in many ways, one of which is using parallel arrays that keep track of doors in arrRoomFileNames[ ].
I hope this helps.
<!-- Gameboard -->
<html>
<head>
<title>Layout for gameboard</TITLE>
<style>
body {background: #222244;
}
table {width: 800px;
height: 500px;
margin: 0px;
padding: 0px;
border: none;
}
</style>
</head>
<body>
<center>
<?php
$arrRoomFileNames=array("bathroom.JPG", "office.JPG", "cbed.JPG", "study.JPG", "kitchen.JPG", "sroom.JPG" , "foyer.JPG", "mbed.JPG", "froom.JPG");
$chosenroom=$arrRoomFileNames[rand(0,8)];
?>
<table>
<tr height="450px">
<td width="650px" background="echo '<img src='.$arrRoomFileNames[$chosenroom].'>; ?>">Playing board</td>
<td bgcolor=#cfc9a9></td>
</tr>
<tr>
<td bgcolor=#dfd9b9 colspan=2>Lives remaining: 3</td>
</tr>
</table>
</center>
</body>
</html>
<html>
<head>
<title>Layout for gameboard</TITLE>
<style>
body {background: #222244;
}
table {width: 800px;
height: 500px;
margin: 0px;
padding: 0px;
border: none;
}
</style>
</head>
<body>
<center>
<?php
$arrRoomFileNames=array("bathroom.JPG", "office.JPG", "cbed.JPG", "study.JPG", "kitchen.JPG", "sroom.JPG" , "foyer.JPG", "mbed.JPG", "froom.JPG");
$chosenroom=$arrRoomFileNames[rand(0,8)];
?>
<table>
<tr height="450px">
<td width="650px" background="echo '<img src='.$arrRoomFileNames[$chosenroom].'>; ?>">Playing board</td>
<td bgcolor=#cfc9a9></td>
</tr>
<tr>
<td bgcolor=#dfd9b9 colspan=2>Lives remaining: 3</td>
</tr>
</table>
</center>
</body>
</html>


Comment