For some reason, my code is only outputting 'p3' and 'p4' twice. I was wondering if anyone could point out why it's repeating, and it'd be appreciated. Here's an example of what is wrong (this only is on p3 and p4 as stated above, p1 and p2 work fine)
http://i.imgur.com/glNXwr7.png
Here's my code:
index.php -
<?php
session_start();
if (!isset($_SESSION['p']))
{
$_SESSION['p'] = 'p1';
}
include('core.php');
include('core2.php');
$story = new Story;
$action = new Action;
$part = $_SESSION['p'];
?>
<!DOCTYPE HTML>
<html>
<head>
<title>MacBeth Console</title>
<style>
body{
background:black;
color:#2ecc71;
font-family: "Courier New", Courier, monospace
}
.txt{
border:0px;
background-color:black;
color:#2ecc71;
font-family: "Courier New", Courier, monospace
}
input:focus {outline: none; }
</style>
</head>
<body>
<?php
echo 'DEBUG: P_'.$part.' <br />';
if ($_SESSION['p'] == 'p1')
$story->p1();
else
$action->continueStory($part, '');
if (isset($_POST['submit']))
{
$action->ContinueStory($part, $_POST['yourAction']);
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="p" value="<?php echo $part; ?>" style="vertical-align:middle;">
<img src="cmd.png"><input type="text" id="input" name="yourAction" class="txt">
<input type="submit" name="submit" value="continue">
</form>
</body>
</html>
core.php -
<?php
class Story
{
public function p1()
{
print '<b>Witch 1</b>: When shall we all meet again? <br />
<b>Witch 2</b>: When the hurly-burly is done, and the battle\'s lost and won. <br />
<b>Witch 3</b>: That will be ere the set of sun. <br />
<b>Witch 1</b>: Where\'s the place? <br />
<b>Witch 2</b>: Upon the heath, is this location to thou satisfaction? <br />';
}
public function p2($action)
{
$action = strtolower($action);
if ($action == 'yes')
{
$_SESSION['p'] = 'p3';
print '** The meeting shall be held upon the heath to meet with MacBeth. ** -- PRESS ENTER';
}
else if ($action == 'no')
{
$_SESSION['p'] = 'p3';
print '** Despite your opinion, the other witches decide the best place to meet would be at the heath. **';
}
else
{
print 'Unknown action "'.$action.'".';
}
}
public function p3($action)
{
echo 'test ';
$_SESSION['p'] = 'p4';
/*return '<b><i>Scene II</i></b> <br />
<b>Duncan</b>: What bloody man is that? He can report, as seemeth by his plight, of the revolt the newest state. <br /> <br />
<b>Sergent</b>: Doubtful it stood; As two spent swimmers, that do cling together, and choke their art. The merciless Macdonwald-- Worthy to be a rebel, for to that
The multiplying villanies of nature. Do swarm upon him--from the western isles of kerns and gallowglasses is supplied; and fortune, on his damned quarrel smiling,
Show\'d like a rebel\'s whore: but all\'s too weak: For brave Macbeth--well he deserves that name-- Disdaining fortune, with his brandish\'d steel,
which smoked with bloody execution like valour\'s minion carved out his passage till he faced the slave; Which ne\'er shook hands, nor bade farewell to him
till he unseam\'d him from the nave to the chaps and fix\'d his head upon our battlements.
<b>Duncan</b>: O valiant cousin! worthy gentleman! <br /> <br />
** Please press enter ** <br />';*/
}
public function p4($action)
{
$_SESSION['p'] = 'p1';
echo 'test 2';
}
}
?>
core2.php -
<?php
class Action
{
public function ContinueStory($p, $action)
{
$story = new Story;
if ($p == "p1")
{
$story->p2($action);
}
else if ($p == "p3")
{
$story->p3($action);
}
else if ($p == "p4")
{
$story->p4($action);
}
}
}
?>