php实现贪吃蛇小游戏

前端之家收集整理的这篇文章主要介绍了php实现贪吃蛇小游戏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

贪吃蛇游戏是经典手机游戏,既简单又耐玩。通过控制蛇头方向吃蛋,使得蛇变长,从而获得积分。在诺基亚时代,风靡整个手机界,今天我们来看看另类的,如何使用PHP来实现贪吃蛇小游戏

废话不多说,代码奉上:

control.PHP

main.PHP

<Meta charset="utf-9"/> <Meta http-equiv="refresh" content="0.5"/> PHP" name="top"/> PHP" name="menu"/>

tcs.PHP

PHP;"> PHP session_start(); $_SESSION['ud']; $_SESSION['lr']; $im = imagecreatetruecolor(300,300); $blue = imagecolorallocate($im,255); $red = imagecolorallocate($im,255,0); $c1 = imagecolorallocate($im,200,200); imagefill($im,$c1); if(!isset($_SESSION['a'])&&!isset($_SESSION['b'])){ $_SESSION['a'] =rand(0,290); $_SESSION['b'] =rand(0,290); } if(isset($_SESSION['a'])&&isset($_SESSION['b'])){ imagerectangle($im,$_SESSION['a'],$_SESSION['b'],$_SESSION['a']+10,$_SESSION['b']+10,$red); } if(abs(($_SESSION['lr']-$_SESSION['a']))<=5&&abs($_SESSION['ud']-$_SESSION['b'])<=5){ unset($_SESSION['a']); unset($_SESSION['b']); $_SESSION['count']++; } switch($_SESSION['con']){ case "up"; if($_SESSION['ud']>10) $_SESSION['ud']-=10; else $_SESSION['ud']=0; break; case "down": if($_SESSION['ud']<=280) $_SESSION['ud']+=10; else $_SESSION['ud']=290; break; case "left": if($_SESSION['lr']>10) $_SESSION['lr']-=10; else $_SESSION['lr']=0; break; case "right": if($_SESSION['lr']<=280) $_SESSION['lr']+=10; else $_SESSION['lr']=290; break; } for($i=0;$i<=$_SESSION['count'];$i++){ switch($_SESSION['con']){ case "up": $_SESSION['udnext'] = $_SESSION['ud']+10*$i; imagerectangle($im,$_SESSION['lr'],$_SESSION['udnext'],$_SESSION['lr']+10,$_SESSION['udnext']+10,$blue); // imagerectangle($im,$_SESSION['udtime'][time()-$i],$_SESSION['udtime'][time()-$i]+10,$blue); break; case "down": $_SESSION['udnext'] = $_SESSION['ud']-10*$i; imagerectangle($im,$_SESSION['udtime'][time()+$i],$_SESSION['udtime'][time()+$i]+10,$blue); break; case "left": $_SESSION['lrnext'] = $_SESSION['lr']+10*$i; imagerectangle($im,$_SESSION['lrnext'],$_SESSION['ud'],$_SESSION['lrnext']+10,$_SESSION['ud']+10,$_SESSION['lrtime'][time()-$i],$_SESSION['lrtime'][time()-$i]+10,$blue); break; case "right": $_SESSION['lrnext'] = $_SESSION['lr']-10*$i; imagerectangle($im,$_SESSION['lrtime'][time()+$i],$_SESSION['lrtime'][time()+$i]+10,$blue); break; } //imagerectangle($im,$blue); } header("Content-Type: image/jpeg"); imagejpeg($im); imagedestroy($im); ?>
原文链接:https://www.f2er.com/php/19250.html

猜你在找的PHP相关文章