PHP implementation of greedy snake games _php Example

Source: Internet
Author: User
Tags abs rand

Snake game is a classic mobile phone game, both simple and easy to play. Eat eggs by controlling the direction of the snake, making the snake grow longer to gain points. In the Nokia era, swept the entire mobile phone industry, today we come to see alternative, how to use PHP to achieve the greedy snake games

Nonsense not much to say, code to serve:

control.php

<! DOCTYPE html>
 
 

main.php

<! DOCTYPE html>
 
 

tcs.php

<?php session_start ();
  $_session[' ud '];  
  $_session[' LR '];
  $im = Imagecreatetruecolor (300,300);
  $blue = Imagecolorallocate ($im, 0,0,255);
  $red = Imagecolorallocate ($im, 255,0,0);
  $c 1 = imagecolorallocate ($im, 200,200,200);
  Imagefill ($im, 0,0, $c 1);
    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 ', $blue); Imagerectangle ($im, $_session[' lr '],$_session[' Udtime '][time ()-$i],$_session[' lr ']+10,$_session[' udtime ' [
      Time ()-$i]+10, $blue);
      Break
        Case "Down": $_session[' udnext '] = $_session[' ud ']-10* $i;
        Imagerectangle ($im, $_session[' lr '],$_session[' udnext '],$_session[' lr ']+10,$_session[' udnext ', $blue); Imagerectangle ($im, $_session[' lr '],$_session[' Udtime '][time () + $i],$_session[' lr ']+10,$_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, $blue); Imagerectangle ($im, $_session[' Lrtime '][time ()-$i],$_session[' ud ',],$_session[' lrtime ' ()-$i][time
      Session[' ud ']+10, $blue);
      Break
        Case "right": $_session[' lrnext '] = $_session[' LR ']-10* $i;
        Imagerectangle ($im, $_session[' lrnext '],$_session[' ud '],$_session[, Lrnext ']+10,$_session[' ud ')]+10, $blue); Imagerectangle ($im, $_session[' Lrtime '][time () + $i],$_session[' ud "],$_session[' Lrtime '"][time "() + $i]+10,$_
      Session[' ud ']+10, $blue);
    Break
  }//imagerectangle ($im, $_session[' LR '],$_session[' ud '],$_session[' LR ']+10,$_session[' ud ']+10, $blue);
  Header ("Content-type:image/jpeg");
  Imagejpeg ($im);  
Imagedestroy ($im);
 ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.