Home  >  Article  >  Backend Development  >  PHP GUI fun implementation of a greedy snake

PHP GUI fun implementation of a greedy snake

藏色散人
藏色散人forward
2022-02-02 04:00:314609browse

This article will introduce to you how to make a snake with PHP GUI. I hope it will be helpful to you if you need it!

Graphical User Interface (GUI) extension

Read the PHP manual today At that time, I saw that PHP7 has an extension to the ui graphics library, so we rushed to use it

Install the extension

The installation steps in the official manual are for Linux:

Requirements:
    PHP 7
    libui (use current master)
    Windows/MacOSX/Linux (GTK-3)

Install re2c:
    sudo apt install re2c

Install libui:

    git clone https://github.com/andlabs/libui.git
    cd libui
    sudo cp *.h /usr/local/include/
    cmake .
    cd out
    sudo cp * /usr/lib/

Install ui:

    Method one: use pecl:
        sudo pecl install channel://pecl.php.net/ui-2.0.0

    Method two:build source code:
        git clone https://github.com/krakjoe/ui.git
        cd ui
        phpize
        make
        sudo make install

Enable ui.so:
    sudo echo 'extension=ui.so' > /etc/php/7.0/mods-available/ui.ini
    sudo ln -s /etc/php/7.0/mods-available/ui.ini 20-ui.ini

Test:
    php -m
    git clone https://github.com/krakjoe/ui.git
    cd ui/examples/
    php snake.php

Requirements (documentation says)

  • PHP 7
  • libui (use current master)
  • Windows/MacOSX/Linux (GTK-3)

Download the windows dll from PECL. I am using php7 nts 64-bit, so I used this:

PHP GUI fun implementation of a greedy snake

Downloaded file directory structure:

PHP GUI fun implementation of a greedy snake

Next:

  • php_ui.dll is placed in the ext directory of php, and then php.ini is added to extension =php_ui.dll

  • ##pthreadVC2.dll and libui.dll are placed in the php directory, which is the same level as the php.exe file

  • Run the php -m command in cmd to check whether the module is loaded correctly

PHP GUI fun implementation of a greedy snake

PHP GUI fun implementation of a greedy snake##Test a glutton Snake

There is a snake.php file (Snake game) in the folder where the ui extension is downloaded. Go to this directory and run:

php snake.php

PHP GUI fun implementation of a greedy snakeIn addition There is also a particle effect file (starfield.php):

PHP GUI fun implementation of a greedy snake

Recommended learning: "
PHP Video Tutorial

"

The above is the detailed content of PHP GUI fun implementation of a greedy snake. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete