Skip to content

Commit

Permalink
Merge pull request #13 from Sch-Tomi/phpDev
Browse files Browse the repository at this point in the history
Php dev
  • Loading branch information
Sch-Tomi authored May 15, 2017
2 parents 799b5b3 + d8dec71 commit a9634cc
Show file tree
Hide file tree
Showing 64 changed files with 2,509 additions and 241 deletions.
2 changes: 1 addition & 1 deletion dev_js/blocks/blocker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Blocker extends MasterBlock {
constructor(heading, x, y, moving, rotating) {
super("img/blokkolo.png", heading, x, y, moving, rotating)
super("/img/blocks/blokkolo.png", heading, x, y, moving, rotating)
}

get_newDir(dir) {
Expand Down
2 changes: 1 addition & 1 deletion dev_js/blocks/checkpoint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CheckPoint extends MasterBlock {
constructor(heading, x, y, moving, rotating) {
super("img/ellenorzo.png", heading, x, y, moving, rotating)
super("/img/blocks/ellenorzo.png", heading, x, y, moving, rotating)

this._hit = false
}
Expand Down
2 changes: 1 addition & 1 deletion dev_js/blocks/doublemirror.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class DoubleMirror extends MasterBlock {
constructor(heading, x, y, moving, rotating) {
super("img/dupla.png", heading, x, y, moving, rotating)
super("/img/blocks/dupla.png", heading, x, y, moving, rotating)
}

get_newDir(laserDirection) {
Expand Down
2 changes: 1 addition & 1 deletion dev_js/blocks/halfmirror.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class HalfMirror extends MasterBlock {
constructor(heading, x, y, moving, rotating) {
super("img/felig.png", heading, x, y, moving, rotating)
super("/img/blocks/felig.png", heading, x, y, moving, rotating)
}

get_newDir(dir) {
Expand Down
2 changes: 1 addition & 1 deletion dev_js/blocks/laser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Laser extends MasterBlock {
constructor(heading, x, y, moving, rotating) {
super("img/lezer.png", heading, x, y, moving, rotating)
super("/img/blocks/lezer.png", heading, x, y, moving, rotating)
}
}
2 changes: 1 addition & 1 deletion dev_js/blocks/mirror.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Mirror extends MasterBlock {
constructor(heading, x, y, moving, rotating, imgsrc = null) {
if (imgsrc === null) {
super("img/tukor.png", heading, x, y, moving, rotating)
super("/img/blocks/tukor.png", heading, x, y, moving, rotating)
} else {
super(imgsrc, heading, x, y, moving, rotating)
}
Expand Down
2 changes: 1 addition & 1 deletion dev_js/blocks/target.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Target extends Mirror {
constructor(heading, x, y, moving, rotating) {
super(heading, x, y, moving, rotating, "img/cel.png")
super(heading, x, y, moving, rotating, "/img/blocks/cel.png")

this._hit = false

Expand Down
152 changes: 96 additions & 56 deletions dev_js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,28 @@ class Game {
this.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || window.mozRequestAnimationFrame;

this._setInteface()
this._precentRightClick()
this._preventRightClick()

this._minHit = 0

this._lvl_data = ""

}

setLvl(data) {
this._lvl_data = data;
}

run() {
// Let's play this game!
this._parseLvl();
this._main();
}

_setInteface() {

this._modal = new Modal()

this.selector = document.createElement("select")
this.selector.id = "lvlSelect"
this.selector.innerHTML += "<option disabled selected value> -- válassz egy pályát -- </option>"
this.selector.innerHTML += "<option value='1'>Level 1</option>"
this.selector.innerHTML += "<option value='2'>Level 2</option>"
this.selector.innerHTML += "<option value='3'>Level 3</option>"

document.body.querySelector("#lightBreaker-lvlSelector").appendChild(this.selector)
this.selector.onchange = () => {
this._levelSelect()
}

this.fireButton = document.createElement('button')
this.fireButton.textContent = 'Tűz!'
this.fireButton.className = 'fireBtn'
Expand All @@ -42,71 +37,75 @@ class Game {
}
}

_precentRightClick() {
_preventRightClick() {
document.body.oncontextmenu = () => {
return false
}
}

_levelSelect() {
this.canvas.clear()
switch (parseInt(this.selector.options[this.selector.selectedIndex].value)) {
case 1:
this._level1()
break;
case 2:
this._level2()
break;
case 3:
this._level3()
break;
default:
_parseLvl() {
let lvl = this._lvl_data[0]
this._parseField(lvl.field)
this._parseParking(lvl.parking)

}
this._minHit = lvl.hits
this.canvas.setLimit(this._minHit)
}

_level1() {
this.canvas.addBlock(new Laser(180, 1, 1, false, false))
this.canvas.addBlock(new Target(0, 3, 3, false, true))
this.canvas.addParkingBlock(new DoubleMirror(0, 0, 0, true, true))
_parseField(field) {

for (let block of field) {
this.canvas.addBlock(this._createNewBlock(block))
}

this._minHit = 1
this.canvas.setLimit(this._minHit)
}

_level2() {
this.canvas.addBlock(new Laser(270, 0, 0, false, true))
this.canvas.addBlock(new Target(90, 4, 0, false, true))
this.canvas.addBlock(new DoubleMirror(90, 3, 1, false, false))
_parseParking(parking) {

this.canvas.addParkingBlock(new Target(0, 0, 0, true, true))
this.canvas.addParkingBlock(new HalfMirror(0, 0, 0, true, true))
for (var block of parking) {
this.canvas.addParkingBlock(this._createNewBlock(block))
}

this._minHit = 2
this.canvas.setLimit(this._minHit)
}

_level3() {
this.canvas.addBlock(new Laser(90, 1, 2, false, true))
this.canvas.addBlock(new Mirror(270, 2, 0, false, true))
this.canvas.addBlock(new Mirror(270, 4, 0, false, true))
this.canvas.addBlock(new Mirror(0, 3, 2, false, false))
this.canvas.addBlock(new DoubleMirror(90, 0, 4, false, false))
this.canvas.addBlock(new CheckPoint(0, 4, 3, false, false))

this.canvas.addParkingBlock(new Mirror(0, 0, 0, true, true))
this.canvas.addParkingBlock(new Mirror(0, 0, 0, true, true))
this.canvas.addParkingBlock(new HalfMirror(0, 0, 0, true, true))
_createNewBlock(block) {
switch (block.type) {
case "HalfMirror":
return new HalfMirror(block.heading, block.col, block.row, block.moving, block.rotating)
break;
case "Mirror":
return new Mirror(block.heading, block.col, block.row, block.moving, block.rotating)
break;
case "DoubleMirror":
return new DoubleMirror(block.heading, block.col, block.row, block.moving, block.rotating)
break;
case "Target":
return new Target(block.heading, block.col, block.row, block.moving, block.rotating)
break;
case "CheckPoint":
return new CheckPoint(block.heading, block.col, block.row, block.moving, block.rotating)
break;
case "Blcoker":
return new Blocker(block.heading, block.col, block.row, block.moving, block.rotating)
break;
case "Laser":
return new Laser(block.heading, block.col, block.row, block.moving, block.rotating)
break;
}

this._minHit = 2
this.canvas.setLimit(this._minHit)
}

_fire() {
if (this.canvas.isParkingEmpty()) {
var result = new LaserPathCalculator(this.canvas.get_board(), this._minHit)
if (result.valid) {
this._modal.setUp("Gratulálok", ["Sikeresen teljesítetted a pályát!"])
this._ajax({
mod: 'post',
url: '/game/report',
postadat: 'status=success&id='+window.location.pathname.split("/")[2],
siker: (xhr, txt) => {this._modal.setUp("Gratulálok", ["Ők is megoldották már: \n\n", txt]); this._modal.show()}
})
} else {
let missNumber = parseInt(this._minHit) - parseInt(result.hits)
if (missNumber == 0) {
Expand All @@ -118,13 +117,54 @@ class Game {
}
}
this.canvas.drawResult(result.paths)
}else {
} else {
this._modal.setUp("Hiba!", ["Minden tükröt kötelezően fel kell használnod!"])
}

this._modal.show()
}

_ajax(opts) {
var mod = opts.mod || 'GET',
url = opts.url || '',
getadat = opts.getadat || '',
postadat = opts.postadat || '',
siker = opts.siker || function() {},
hiba = opts.hiba || function() {};

mod = mod.toUpperCase();

if(this._endsWithPhp(url)){
url = url + '?' + getadat;
}

var xhr = new XMLHttpRequest(); // ujXHR();
xhr.open(mod, url, true);
if (mod === 'POST') {
xhr.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
}
xhr.addEventListener('readystatechange', function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
siker(xhr, xhr.responseText);
} else {
hiba(xhr);
}
}
}, false);
xhr.send(mod == 'POST' ? postadat : null);
return xhr;
}

_endsWithPhp(url){

return url[url.length-1] == "p" &&
url[url.length-2] == "h" &&
url[url.length-3] == "p"

}

_main() {
this.canvas.render();

Expand Down
2 changes: 1 addition & 1 deletion dev_js/gui/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Canvas {


this._lock = new Image()
this._lock.src = "img/lock.png"
this._lock.src = "/img/blocks/lock.png"

this._gameBoard = new GameBoard(this._context, this._cellDimension, this._boardWidth, this._tablePadding)
this._hitCounter = new HitCounter(this._context, this._cellDimension, this._boardWidth, this._tablePadding)
Expand Down
1 change: 0 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ BROWSER = firefox

all:
compafy
$(BROWSER) site/index.html
18 changes: 18 additions & 0 deletions site/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
35 changes: 35 additions & 0 deletions site/config/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* Specials:
* (:any)
* (:string)
* (:num)
*/


$this->route['GET']['/'] = 'Main';
$this->route['GET']['404'] = 'Errors/show_404';
$this->route['GET']['/error/(:num)'] = 'Errors/show';

$this->route['GET']['/game'] = "Game/show_games";
$this->route['GET']['/game/(:num)'] = "Game/start";
$this->route['POST']['/game/report'] = "Game/report";

$this->route['GET']['/login'] = "Auth/login";
$this->route['POST']['/login'] = "Auth/do_login";
$this->route['GET']['/logout'] = "Auth/logout";

$this->route['GET']['/register'] = "Auth/register";
$this->route['POST']['/register'] = "Auth/do_register";

$this->route['GET']['/admin'] = "Admin/adminDash";
$this->route['POST']['/admin/add'] = "Admin/add";
$this->route['GET']['/admin/delete/(:num)'] = "Admin/del";






?>
50 changes: 50 additions & 0 deletions site/controllers/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

class Admin extends LightController{

private $authLib;
private $gameModel;

function __construct(){
parent::__construct();

$this->authLib = $this->libMan->load_and_create("AuthenticationLib");
$this->gameModel = $this->modelMan->load_and_create("GameModel");
$this->view->set_template("basic");

$this->view->add_style("/css/style.css");

$this->view->add_section("menu", "sections/menu");
$this->view->add_section("footer", "sections/footer");

$this->authoritization();
}

public function adminDash(){
$this->view->add_style("/css/table.css");
$this->view->add_style("/css/adminDash.css");
$this->view->add_script("/js/adminHelper.js");
$this->view->show("admin/dash", array('games' => $this->gameModel->get_games() ));
}

public function add(){
$this->gameModel->add($_POST);
$this->redirect("/admin");
}

public function del($id){
$this->gameModel->del($id);
$this->redirect("/admin");
}

private function authoritization(){
if (!$this->authLib->is_admin()) {
$this->redirect("/error/403");
}
}

}



?>
Loading

0 comments on commit a9634cc

Please sign in to comment.