Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Hackit test</title>
- <link rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.min.css">
- <link rel="stylesheet" href="http://prismjs.com/themes/prism.css">
- <link rel="stylesheet" href="https://bootswatch.com/slate/bootstrap.min.css">
- <link rel="stylesheet" href="http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css">
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
- <style>
- .red { color: #F33 }
- .green { color: #62C462 }
- .blue { color: #39C }
- </style>
- </head>
- <body>
- <div class="container theme-showcase" role="main">
- <div class="container-fluid text-center" style="min-height:300px;padding-top:10px;">
- <!-- :::::::::::::::::==== GAME STARTS HERE ====::::::::::::::::: -->
- <?php
- define("DS", DIRECTORY_SEPARATOR );
- define("ROOT", $_SERVER['DOCUMENT_ROOT']);
- session_start();
- /******** Submit below this line ********/
- // changed a bit for testing
- class HackitX {// implements Hackit
- //{
- private $level = '';
- public $author = ''; //You can enter your name here if you want
- public function __construct(){$this->level = basename(__FILE__, '.php');} //so you can use $this->level to get the level id
- public function getName() { return 'My test level'; } //The name will be displayed in the level table
- public function getDescription() { return 'A work in progress'; } //This will be displayed when the level is started
- public function getTags() { return 'PHP'; } //Describe what technology you used. Comma,seperated
- private function setTimeLimit($time) { //Add a time limit to the level, use with getTimeLimit for status
- //USAGE: $this->setTimeLimit(30); //null
- $_SESSION['levels'][$this->level]['starttime'] = time();
- $_SESSION['levels'][$this->level]['maxtime'] = $time;
- $_SESSION['levels'][$this->level]['timerset'] = true;
- }
- private function getTimeLimit() { //return the active state of the time limit, the expired state, and the max time
- //USAGE: $this->getTimeLimit()->isExpired //bool
- $isExpired = false;
- $isActive = false;
- $maxTime = 0;
- if (
- array_key_exists('timerset', $_SESSION['levels'][$this->level]) &&
- $_SESSION['levels'][$this->level]['timerset'] === true
- ) {
- $isActive = true;
- $maxTime = $_SESSION['levels'][$this->level]['maxtime'];
- if (time() - $_SESSION['levels'][$this->level]['starttime'] >= $maxTime)
- $isExpired = true;
- }
- return (object)[
- "isActive" => $isActive,
- "isExpired" => $isExpired,
- "maxTime" => $maxTime
- ];
- } //Remember to include the time limit information in your render() !
- //shortcuts to set and check the password
- // $this->setLevelPassword("tooeasy") //null
- // $this->getLevelPassword() //"tooeasy"
- private function setLevelPassword($password) {
- $_SESSION['levels'][$this->level]['password'] = $password;
- }
- private function getLevelPassword() {
- if (! array_key_exists('password', $_SESSION['levels'][$this->level]) ) return false;
- return $_SESSION['levels'][$this->level]['password'];
- }
- /******** Modify below this line ********/
- /**
- *
- * This method is called to check if the
- * level has been solved. if it returns
- * true, it's solved
- *
- * @return bool
- *
- */
- public function isSolved() {
- /*
- //EX: if the time limit is active
- //and has not expired
- //or is not active
- //and the password is correct
- // -> return true
- $timer = $this->getTimeLimit();
- if (
- (
- (
- $timer->isActive === true &&
- $timer->isExpired === false
- ) || (
- $timer->isActive === false
- )
- ) &&
- array_key_exists('pw', $_REQUEST) &&
- $_REQUEST['pw'] === $this->getLevelPassword()
- ) return true;
- return false;
- */
- }
- /**
- *
- * The prepare method is called before
- * rendering the level. You can define
- * the password for this level, start
- * timers.. everything you want!
- *
- * @return NULL
- *
- */
- public function prepare() {
- /*
- //EX: Make sure we have an array for this level's data in $_SESSION
- if (
- (!array_key_exists( $this->level, $_SESSION['levels'] )) ||
- gettype($_SESSION['levels'][$this->level]) != "array"
- ) $_SESSION['levels'][$this->level] = [];
- // If you want to set a time limit (ex 30 seconds):
- $timer = $this->getTimeLimit();
- if (
- $timer->isActive === false ||
- $timer->isExpired === true
- ) {
- $this->setTimeLimit(30);
- // ---=== do your randomizing stuff here ===--- //
- $secret = mt_rand(0, 100);
- $this->setLevelPassword("password" . $secret);
- }
- */
- }
- /**
- *
- * The render method is called last and
- * returns the HTML code that will be
- * displayed on the level. You can use
- * variables defined in the prepare
- * method since render is called last
- *
- * @return NULL
- *
- */
- public function render() {
- return '
- <div>Subtitle or description</div>
- <p>You have <span class="green">30 seconds</span> to solve this level</p>
- <!-- Your stuff here -->
- <input type="password" id="pw" />
- <input type="button" onclick="checkPW()" value="GO" />
- <script>
- function checkPW() {
- el = document.getElementById("pw");
- document.location.href = "?pw=" + el.value;
- }
- <!-- if the level time limit is active, print out some JS to refresh the page -->
- ' . ( $this->getTimeLimit()->isActive ? "setTimeout(checkPW, " . $this->getTimeLimit()->maxTime * 1000 . ");" : "" ). '
- </script>';
- }
- }
- /******** Modify above this line ********/
- /******** Submit above this line ********/
- $hackit = new HackitX();
- $hackit->prepare();
- if ($hackit->isSolved() === false) {
- if (array_key_exists('pw', $_REQUEST) && !empty($_REQUEST['pw']) ) echo '
- <div class="alert alert-dismissable alert-danger">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <p>Wrong password</p>
- </div>
- ';
- echo '<h1>Test level</h1>';
- if ( !empty($hackit->author) ) echo "By $hackit->author";
- echo "<br><br>";
- echo $hackit->render();
- } else echo '
- <div class="alert alert-dismissable alert-success">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <p>
- <h2>Test level solved!</h2>
- </p>
- </div>
- <a href="?">Replay this level</a>
- ';
- ?>
- <!-- ::::::::::::::::::==== GAME ENDS HERE ====:::::::::::::::::: -->
- </div>
- </div>
- <script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
- <script src="http://prismjs.com/prism.js"></script>
- <script>document.onkeydown=function(){if(window.event.keyCode=='13'){checkPW();}} //submit on enter </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement