Exemple #1
0
function killedBy($who)
{
    narrate([sprintf("You have been killed by %s!", $who)]);
    gameOver();
}
Exemple #2
0
    if (is_a($bee, 'Queen')) {
        if ($bee->isAlive == 0) {
            // if the queen bee has life 0 then game over.
            gameOver();
        }
    }
    // if any bee in the array has isAlive true then break from loop, else all bees are dead and game ends
    if ($bee->isAlive == 1) {
        $GLOBALS['allBeesDead'] = false;
        break;
    } elseif ($bee->isAlive == 0) {
        $GLOBALS['allBeesDead'] = true;
    }
}
if ($GLOBALS['allBeesDead'] == 1) {
    gameOver();
}
?>

        <br>
        <br>
        <?php 
//print out the UI, if game is over then display reset, otherwise display attack button
if ($_SESSION["gameOver"] == 0) {
    echo '<form action="BeeGame.php" method="get">
                            Attack: <input type="submit">
                        </form>';
} elseif ($_SESSION["gameOver"] == 1) {
    echo "Game Over<br>\r\n                <form action='test.php' method='get'>\r\n                    Restart: <input type='submit'>\r\n                </form>";
}
function gameOver()
Exemple #3
0
			echo $playersMove.$board."waiting";	
			mysqli_close($mysqli);			
			exit();
		}
		else //already exists
		{
			$res = mysqli_fetch_assoc($result);
			if (strcmp(substr($res['move'],0,1),$player) != 0) //other player made previous move $res[$playerCol] != "" && $res[$oppPlayerCol] != "")
			{
				$q="INSERT INTO $game (move) VALUES($m)"; //record move, waiting for other player
				mysqli_query($mysqli,$q);
				//update board
				$q = "UPDATE $gameBoard SET state ='$board'";
				mysqli_query($mysqli,$q);
				
				if (gameOver($board,$player)) 
				{
					echo $playersMove.$board."won".$player; //won1 or won2
					mysqli_close($mysqli);
					exit();
				}
				echo $playersMove.$board."waiting";	
				mysqli_close($mysqli);				
				exit();
			}
			echo $oldBoard."invalidwaiting";
			mysqli_close($mysqli);
			exit();			
		}
		break;
	}
function displayGame($userid, $gameid = 0)
{
    $gameData = new mysqli(MYSQLHOST, MYSQLUSER, MYSQLPASSWORD);
    if ($session_check->connect_error) {
        printf("Connection to DB failed", $mysqli->connect - error);
        die;
    }
    $gameData->select_db("dontburnthepig_hangman");
    $query = "select * from games where user_id = ? and finished is NULL limit 1";
    $stmt = $gameData->prepare($query);
    $stmt->bind_param("s", $userid);
    $stmt->execute();
    $result = $stmt->get_result();
    while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
        $rows[] = $row;
    }
    $test = $rows[0]['guesses'];
    $replaced = preg_replace('/\\s/', "\n", $rows[0]['word']);
    if ($rows[0]['wrong_count'] < 6) {
        $rtstr = "Topic : " . $rows[0]['topic'] . "\n\n";
        $replaced = preg_replace('/[^' . $test . '\\s0-9\\&\\(\\)\\^\'\\#\\@\\"\\:\\,]/i', "_ ", $replaced);
        if (strpos($replaced, "_") === FALSE) {
            gameOver($userid);
            $rtstr .= "Congrats You Won!!!\n";
        }
        $rtstr .= preg_replace('/([a-zA-Z])/', "\$1 ", $replaced) . "\n---------------------------------------------\n";
        foreach (str_split($rows[0]['guesses']) as $letter) {
            if (strpos(strtolower($rows[0]['word']), $letter) === FALSE) {
                $rtstr .= "[" . $letter . "]";
            }
        }
    } else {
        gameOver($userid);
        $rtstr .= "GAME OVER!!!\n\n";
        $rtstr .= $replaced . "\n---------------------------------------------\n";
        foreach (str_split($rows[0]['guesses']) as $letter) {
            if (strpos(strtolower($rows[0]['word']), $letter) === FALSE) {
                $rtstr .= "[" . $letter . "]";
            }
        }
    }
    return $rtstr;
}