Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.91 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. */
  5. class Stone
  6. {
  7. private $ring_colors;
  8. private $ring_sizes;
  9. function __construct($amountRings, $Original_colors)
  10. {
  11. $Original_sizes = array("big", "medium", "small");
  12. $this->ring_colors = array();
  13. $this->ring_sizes = array();
  14. for ($i=0; $i < $amountRings; $i++) {
  15. $this->ring_colors[$i] = $Original_colors[rand(0, count($Original_colors)-1)];
  16. $size = array_rand($Original_sizes);
  17. $this->ring_sizes[$i] = $Original_sizes[$size];
  18. unset($Original_sizes[$size]);
  19. }
  20. }
  21. public function Show(){
  22. foreach ($this->ring_colors as $key => $color){
  23. echo "<ring class='" . $color . " " . $this->ring_sizes[$key] . "'></ring>";
  24. }
  25. }
  26.  
  27. public function CheckColor($color){
  28. $check = false;
  29. foreach ($this->ring_colors as $ringcolor){
  30. if ($ringcolor==$color){
  31. $check = true;
  32. }
  33. }
  34. if ($check){return true;}else{return false;}
  35. }
  36.  
  37. public function GiveColors(){
  38. return $this->ring_colors;
  39. }
  40. public function Remove($kleur){
  41. foreach ($this->ring_colors as $key => $color) {
  42. if ($color==$kleur){
  43. unset($this->ring_sizes[$key]);
  44. unset($this->ring_colors[$key]);
  45. }
  46. }
  47. if (count($this->ring_colors)==0){
  48. return true;
  49. }else{
  50. return false;
  51. }
  52. }
  53. }
  54.  
  55. /**
  56. *
  57. */
  58. class field
  59. {
  60. private $score;
  61. private $lvl;
  62.  
  63.  
  64. private $positions;
  65. function __construct()
  66. {
  67. $this->positions = array();
  68. for ($i=0; $i < 9; $i++) {
  69. $this->positions[$i] = "";
  70. }
  71. $this->score=0;
  72. $this->lvl=1;
  73. }
  74. public function Show(){
  75. echo "<score class='score'>". $this->score ."</score>";
  76. echo "<field>";
  77. for ($i=0; $i < 9; $i++) {
  78. echo "<box onclick='window.location.href=`index.php?click=" . $i . "`;'>";
  79. if($this->positions[$i] != ""){
  80. $this->positions[$i]->Show();
  81. }
  82. echo "</box>";
  83. }
  84. echo "</field>";
  85. }
  86.  
  87. public function clicked($GET,$stone)
  88. {
  89. //Copy randomstone naar de clicked location
  90. if ($this->positions[$GET] == "") {
  91. $this->positions[$GET] = $stone;
  92. foreach ($this->positions[$GET]->GiveColors() as $kleur) {
  93. $this->CheckRow($GET,$kleur);
  94. }
  95. $this->Checklose();
  96. return true;
  97. }else{
  98. return false;
  99. }
  100. }
  101. private function Checklose(){
  102. $check = true;
  103. for ($i=0;$i < 9; $i++){
  104. if ($this->positions[$i]==""){$check=false;}
  105. }
  106. if ($check){
  107. echo "LOSER! Score = ";
  108. }
  109. }
  110. private function checkStones($GET,$color){
  111. if ($this->positions[$GET])
  112. if ($this->positions[$GET]!=""&&$this->positions[$GET]->CheckColor($color)){
  113. return true;
  114. }else{return false;}
  115. }
  116. private function CheckRow($GET,$color){
  117. switch ($GET){
  118. case 0:
  119. if ($this->checkStones(0,$color)&&
  120. $this->checkStones(1,$color)&&
  121. $this->checkStones(2,$color)){
  122. $this->removeStones(array(0,1,2),$color);
  123. }
  124. if ($this->checkStones(1,$color)&&
  125. $this->checkStones(4,$color)&&
  126. $this->checkStones(7,$color)){
  127. $this->removeStones(array(1,4,7),$color);
  128. }
  129. if ($this->checkStones(0,$color)&&
  130. $this->checkStones(4,$color)&&
  131. $this->checkStones(8,$color)){
  132. $this->removeStones(array(0,4,8),$color);
  133. }
  134. break;
  135. case 1:
  136. if ($this->checkStones(0,$color)&&
  137. $this->checkStones(1,$color)&&
  138. $this->checkStones(2,$color)){
  139. $this->removeStones(array(0,1,2),$color);
  140. }
  141. if ($this->checkStones(1,$color)&&
  142. $this->checkStones(4,$color)&&
  143. $this->checkStones(7,$color)){
  144. $this->removeStones(array(1,4,7),$color);
  145. }
  146. break;
  147. case 2:
  148. if ($this->checkStones(0,$color)&&
  149. $this->checkStones(1,$color)&&
  150. $this->checkStones(2,$color)){
  151. $this->removeStones(array(0,1,2),$color);
  152. }
  153. if ($this->checkStones(2,$color)&&
  154. $this->checkStones(4,$color)&&
  155. $this->checkStones(6,$color)){
  156. $this->removeStones(array(2,4,6),$color);
  157. }
  158. if ($this->checkStones(2,$color)&&
  159. $this->checkStones(5,$color)&&
  160. $this->checkStones(8,$color)){
  161. $this->removeStones(array(2,5,6),$color);
  162. }
  163. break;
  164. case 3:
  165. if ($this->checkStones(0,$color)&&
  166. $this->checkStones(3,$color)&&
  167. $this->checkStones(6,$color)){
  168. $this->removeStones(array(0,3,6),$color);
  169. }
  170. if ($this->checkStones(3,$color)&&
  171. $this->checkStones(4,$color)&&
  172. $this->checkStones(5,$color)){
  173. $this->removeStones(array(3,4,5),$color);
  174. }
  175. break;
  176. case 4:
  177. if ($this->checkStones(1,$color)&&
  178. $this->checkStones(4,$color)&&
  179. $this->checkStones(7,$color)){
  180. $this->removeStones(array(1,4,7),$color);
  181. }
  182. if ($this->checkStones(3,$color)&&
  183. $this->checkStones(4,$color)&&
  184. $this->checkStones(5,$color)){
  185. $this->removeStones(array(3,4,5),$color);
  186. }
  187. if ($this->checkStones(0,$color)&&
  188. $this->checkStones(4,$color)&&
  189. $this->checkStones(8,$color)){
  190. $this->removeStones(array(0,4,8),$color);
  191. }
  192. if ($this->checkStones(2,$color)&&
  193. $this->checkStones(4,$color)&&
  194. $this->checkStones(6,$color)){
  195. $this->removeStones(array(2,4,6),$color);
  196. }
  197. break;
  198. case 5:
  199. if ($this->checkStones(3,$color)&&
  200. $this->checkStones(4,$color)&&
  201. $this->checkStones(5,$color)){
  202. $this->removeStones(array(3,4,5),$color);
  203. }
  204. if ($this->checkStones(2,$color)&&
  205. $this->checkStones(5,$color)&&
  206. $this->checkStones(8,$color)){
  207. $this->removeStones(array(2,5,8),$color);
  208. }
  209. break;
  210. case 6:
  211. if ($this->checkStones(0,$color)&&
  212. $this->checkStones(3,$color)&&
  213. $this->checkStones(6,$color)){
  214. $this->removeStones(array(0,3,6),$color);
  215. }
  216. if ($this->checkStones(6,$color)&&
  217. $this->checkStones(7,$color)&&
  218. $this->checkStones(8,$color)){
  219. $this->removeStones(array(6,7,8),$color);
  220. }
  221. if ($this->checkStones(2,$color)&&
  222. $this->checkStones(4,$color)&&
  223. $this->checkStones(6,$color)){
  224. $this->removeStones(array(2,4,6),$color);
  225. }
  226. break;
  227. case 7:
  228. if ($this->checkStones(6,$color)&&
  229. $this->checkStones(7,$color)&&
  230. $this->checkStones(8,$color)){
  231. $this->removeStones(array(6,7,8),$color);
  232. }
  233. if ($this->checkStones(1,$color)&&
  234. $this->checkStones(4,$color)&&
  235. $this->checkStones(7,$color)){
  236. $this->removeStones(array(1,4,7),$color);
  237. }
  238. break;
  239. case 8:
  240. if ($this->checkStones(6,$color)&&
  241. $this->checkStones(7,$color)&&
  242. $this->checkStones(8,$color)){
  243. $this->removeStones(array(6,7,8),$color);
  244. }
  245. if ($this->checkStones(2,$color)&&
  246. $this->checkStones(5,$color)&&
  247. $this->checkStones(8,$color)){
  248. $this->removeStones(array(2,5,8),$color);
  249. }
  250. if ($this->checkStones(0,$color)&&
  251. $this->checkStones(4,$color)&&
  252. $this->checkStones(8,$color)){
  253. $this->removeStones(array(0,4,8),$color);
  254. }
  255. break;
  256. }
  257. }
  258. private function removeStones($stones,$color){
  259. foreach ($stones as $stone){
  260. $this->score++;
  261. if ($this->positions[$stone]->Remove($color)){
  262. $this->positions[$stone]="";
  263. }
  264.  
  265. }
  266.  
  267.  
  268. }
  269. }
  270.  
  271. class GameManager
  272. {
  273. public $lvl;
  274. public $score;
  275. public $colors;
  276. public $field;
  277. public $randomStone;
  278. function __construct()
  279. {
  280. $this->lvl = 1;
  281. $this->score = 0;
  282. $this->colors = array('blue', 'orange', 'silver', 'yellow');
  283. $this->field = new field();
  284. $this->randomStone = new Stone(1 ,$this->colors);
  285. }
  286. public function Show(){
  287. $this->field->Show();
  288. echo "<br/><randomstone><box>";
  289. $this->randomStone->Show();
  290. echo "</box></randomstone>";
  291. }
  292.  
  293.  
  294. public function Clicked($id){
  295. //op vakje nummer $id is gekliked
  296. }
  297.  
  298. }
  299.  
  300. //$colors = array("hotpink","tomato","lime","chocolate");
  301. //$colors = array('aqua', 'blue', 'fuchsia', 'lime', 'orange', 'red', 'silver', 'yellow');
  302.  
  303.  
  304. //$colors = array("tomato","tomato","tomato");
  305.  
  306. session_start();
  307. if(isset($_SESSION['Game'])){$Game = $_SESSION['Game'];}else{$Game = new GameManager();}
  308. if(isset($_GET['reset'])){session_destroy();header("location:index.php");}
  309. if(isset($_GET['click'])){$Game->clicked($_GET['click']);}
  310. ?>
  311. <html lang="en" dir="ltr">
  312. <head>
  313. <meta charset="utf-8">
  314. <title>Make A Match</title>
  315. </head>
  316. <style type="text/css">
  317. field{margin: auto; position: inherit; display: block; border: 1px solid black; height: 306px; width: 306px;}
  318. box{position: relative; display: block; border: 1px solid black; height: 100px; width: 100px; float: left;}
  319. ring{position: absolute; display: block; border: 10px solid black; border-radius: 50%; width: calc(100% - 20px); height: calc(100% - 20px);}
  320. randomstone{display: block; margin: auto; width: 102px; height: 102px;}
  321.  
  322.  
  323.  
  324.  
  325. <?php for ($i=0; $i < count($Game->colors); $i++) {
  326. echo ".". $Game->colors[$i] . "{border: 10px solid " . $Game->colors[$i] . ";}";
  327. }
  328. ?>
  329.  
  330. .big{width: calc(100% - 20px); height: calc(100% - 20px);}
  331. .medium{width: calc(66% - 20px); height: calc(66% - 20px); margin: 18px;}
  332. .small{width: calc(33% - 20px); height: calc(33% - 20px); margin: 35px;}
  333. </style>
  334. <body>
  335.  
  336.  
  337. <?php $Game->Show();?>
  338. <!--
  339. <php $field->Show();
  340. <br/>
  341. <randomstone>
  342. <box>
  343. <php $randomStone->Show(); ?>
  344. </box>
  345. </randomstone>
  346. <br/>
  347. -->
  348.  
  349. <a href="index.php?reset=">Reset</a>
  350. </body>
  351. </html>
  352. <?php $_SESSION['Game'] = $Game;?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement