Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- */
- class Stone
- {
- private $ring_colors;
- private $ring_sizes;
- function __construct($amountRings, $Original_colors)
- {
- $Original_sizes = array("big", "medium", "small");
- $this->ring_colors = array();
- $this->ring_sizes = array();
- for ($i=0; $i < $amountRings; $i++) {
- $this->ring_colors[$i] = $Original_colors[rand(0, count($Original_colors)-1)];
- $size = array_rand($Original_sizes);
- $this->ring_sizes[$i] = $Original_sizes[$size];
- unset($Original_sizes[$size]);
- }
- }
- public function Show(){
- foreach ($this->ring_colors as $key => $color){
- echo "<ring class='" . $color . " " . $this->ring_sizes[$key] . "'></ring>";
- }
- }
- public function CheckColor($color){
- $check = false;
- foreach ($this->ring_colors as $ringcolor){
- if ($ringcolor==$color){
- $check = true;
- }
- }
- if ($check){return true;}else{return false;}
- }
- public function GiveColors(){
- return $this->ring_colors;
- }
- public function Remove($kleur){
- foreach ($this->ring_colors as $key => $color) {
- if ($color==$kleur){
- unset($this->ring_sizes[$key]);
- unset($this->ring_colors[$key]);
- }
- }
- if (count($this->ring_colors)==0){
- return true;
- }else{
- return false;
- }
- }
- }
- /**
- *
- */
- class field
- {
- private $score;
- private $lvl;
- private $positions;
- function __construct()
- {
- $this->positions = array();
- for ($i=0; $i < 9; $i++) {
- $this->positions[$i] = "";
- }
- $this->score=0;
- $this->lvl=1;
- }
- public function Show(){
- echo "<score class='score'>". $this->score ."</score>";
- echo "<field>";
- for ($i=0; $i < 9; $i++) {
- echo "<box onclick='window.location.href=`index.php?click=" . $i . "`;'>";
- if($this->positions[$i] != ""){
- $this->positions[$i]->Show();
- }
- echo "</box>";
- }
- echo "</field>";
- }
- public function clicked($GET,$stone)
- {
- //Copy randomstone naar de clicked location
- if ($this->positions[$GET] == "") {
- $this->positions[$GET] = $stone;
- foreach ($this->positions[$GET]->GiveColors() as $kleur) {
- $this->CheckRow($GET,$kleur);
- }
- $this->Checklose();
- return true;
- }else{
- return false;
- }
- }
- private function Checklose(){
- $check = true;
- for ($i=0;$i < 9; $i++){
- if ($this->positions[$i]==""){$check=false;}
- }
- if ($check){
- echo "LOSER! Score = ";
- }
- }
- private function checkStones($GET,$color){
- if ($this->positions[$GET])
- if ($this->positions[$GET]!=""&&$this->positions[$GET]->CheckColor($color)){
- return true;
- }else{return false;}
- }
- private function CheckRow($GET,$color){
- switch ($GET){
- case 0:
- if ($this->checkStones(0,$color)&&
- $this->checkStones(1,$color)&&
- $this->checkStones(2,$color)){
- $this->removeStones(array(0,1,2),$color);
- }
- if ($this->checkStones(1,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(7,$color)){
- $this->removeStones(array(1,4,7),$color);
- }
- if ($this->checkStones(0,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(8,$color)){
- $this->removeStones(array(0,4,8),$color);
- }
- break;
- case 1:
- if ($this->checkStones(0,$color)&&
- $this->checkStones(1,$color)&&
- $this->checkStones(2,$color)){
- $this->removeStones(array(0,1,2),$color);
- }
- if ($this->checkStones(1,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(7,$color)){
- $this->removeStones(array(1,4,7),$color);
- }
- break;
- case 2:
- if ($this->checkStones(0,$color)&&
- $this->checkStones(1,$color)&&
- $this->checkStones(2,$color)){
- $this->removeStones(array(0,1,2),$color);
- }
- if ($this->checkStones(2,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(6,$color)){
- $this->removeStones(array(2,4,6),$color);
- }
- if ($this->checkStones(2,$color)&&
- $this->checkStones(5,$color)&&
- $this->checkStones(8,$color)){
- $this->removeStones(array(2,5,6),$color);
- }
- break;
- case 3:
- if ($this->checkStones(0,$color)&&
- $this->checkStones(3,$color)&&
- $this->checkStones(6,$color)){
- $this->removeStones(array(0,3,6),$color);
- }
- if ($this->checkStones(3,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(5,$color)){
- $this->removeStones(array(3,4,5),$color);
- }
- break;
- case 4:
- if ($this->checkStones(1,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(7,$color)){
- $this->removeStones(array(1,4,7),$color);
- }
- if ($this->checkStones(3,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(5,$color)){
- $this->removeStones(array(3,4,5),$color);
- }
- if ($this->checkStones(0,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(8,$color)){
- $this->removeStones(array(0,4,8),$color);
- }
- if ($this->checkStones(2,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(6,$color)){
- $this->removeStones(array(2,4,6),$color);
- }
- break;
- case 5:
- if ($this->checkStones(3,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(5,$color)){
- $this->removeStones(array(3,4,5),$color);
- }
- if ($this->checkStones(2,$color)&&
- $this->checkStones(5,$color)&&
- $this->checkStones(8,$color)){
- $this->removeStones(array(2,5,8),$color);
- }
- break;
- case 6:
- if ($this->checkStones(0,$color)&&
- $this->checkStones(3,$color)&&
- $this->checkStones(6,$color)){
- $this->removeStones(array(0,3,6),$color);
- }
- if ($this->checkStones(6,$color)&&
- $this->checkStones(7,$color)&&
- $this->checkStones(8,$color)){
- $this->removeStones(array(6,7,8),$color);
- }
- if ($this->checkStones(2,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(6,$color)){
- $this->removeStones(array(2,4,6),$color);
- }
- break;
- case 7:
- if ($this->checkStones(6,$color)&&
- $this->checkStones(7,$color)&&
- $this->checkStones(8,$color)){
- $this->removeStones(array(6,7,8),$color);
- }
- if ($this->checkStones(1,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(7,$color)){
- $this->removeStones(array(1,4,7),$color);
- }
- break;
- case 8:
- if ($this->checkStones(6,$color)&&
- $this->checkStones(7,$color)&&
- $this->checkStones(8,$color)){
- $this->removeStones(array(6,7,8),$color);
- }
- if ($this->checkStones(2,$color)&&
- $this->checkStones(5,$color)&&
- $this->checkStones(8,$color)){
- $this->removeStones(array(2,5,8),$color);
- }
- if ($this->checkStones(0,$color)&&
- $this->checkStones(4,$color)&&
- $this->checkStones(8,$color)){
- $this->removeStones(array(0,4,8),$color);
- }
- break;
- }
- }
- private function removeStones($stones,$color){
- foreach ($stones as $stone){
- $this->score++;
- if ($this->positions[$stone]->Remove($color)){
- $this->positions[$stone]="";
- }
- }
- }
- }
- class GameManager
- {
- public $lvl;
- public $score;
- public $colors;
- public $field;
- public $randomStone;
- function __construct()
- {
- $this->lvl = 1;
- $this->score = 0;
- $this->colors = array('blue', 'orange', 'silver', 'yellow');
- $this->field = new field();
- $this->randomStone = new Stone(1 ,$this->colors);
- }
- public function Show(){
- $this->field->Show();
- echo "<br/><randomstone><box>";
- $this->randomStone->Show();
- echo "</box></randomstone>";
- }
- public function Clicked($id){
- //op vakje nummer $id is gekliked
- }
- }
- //$colors = array("hotpink","tomato","lime","chocolate");
- //$colors = array('aqua', 'blue', 'fuchsia', 'lime', 'orange', 'red', 'silver', 'yellow');
- //$colors = array("tomato","tomato","tomato");
- session_start();
- if(isset($_SESSION['Game'])){$Game = $_SESSION['Game'];}else{$Game = new GameManager();}
- if(isset($_GET['reset'])){session_destroy();header("location:index.php");}
- if(isset($_GET['click'])){$Game->clicked($_GET['click']);}
- ?>
- <html lang="en" dir="ltr">
- <head>
- <meta charset="utf-8">
- <title>Make A Match</title>
- </head>
- <style type="text/css">
- field{margin: auto; position: inherit; display: block; border: 1px solid black; height: 306px; width: 306px;}
- box{position: relative; display: block; border: 1px solid black; height: 100px; width: 100px; float: left;}
- ring{position: absolute; display: block; border: 10px solid black; border-radius: 50%; width: calc(100% - 20px); height: calc(100% - 20px);}
- randomstone{display: block; margin: auto; width: 102px; height: 102px;}
- <?php for ($i=0; $i < count($Game->colors); $i++) {
- echo ".". $Game->colors[$i] . "{border: 10px solid " . $Game->colors[$i] . ";}";
- }
- ?>
- .big{width: calc(100% - 20px); height: calc(100% - 20px);}
- .medium{width: calc(66% - 20px); height: calc(66% - 20px); margin: 18px;}
- .small{width: calc(33% - 20px); height: calc(33% - 20px); margin: 35px;}
- </style>
- <body>
- <?php $Game->Show();?>
- <!--
- <php $field->Show();
- <br/>
- <randomstone>
- <box>
- <php $randomStone->Show(); ?>
- </box>
- </randomstone>
- <br/>
- -->
- <a href="index.php?reset=">Reset</a>
- </body>
- </html>
- <?php $_SESSION['Game'] = $Game;?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement