Discover snake game javascript code, include the articles, news, trends, analysis and practical advice about snake game javascript code on alibabacloud.com
Once Nokia's greedy snake rage, in the era of the game is scarce, with the Java implementation is too difficult, now web production 20 lines of code to make a simple demo, The Times in progress AH
Code:
This is the beginning of the game:
This is the end of the
# Include
Error display:
This is what I saw on the Internet. It took more than half an hour to figure out the source image, but there are still a lot of problems. The online stuff is really untrustworthy. It seems that most of them are in C language, if you have time, please help me change it to C ++, find out the error and correct it. Thank you. If you are a newbie, please take care of it...
The code of the greedy
In the process of the exercises to try the snake game with JS to achieve. Had succeeded.
Idea: Use the 10px*10px div layer as "pixel" and then use the 40*40 matrix 160 "Pixels" to make up the game's interface.
Here's the code:
Copy Code code as follows:
algorithm immediately changes from O (n) to O (1). And we'll also find that we just need to record One direction and then the complexity of the space is reduced.
3) map. Describes the ground information.
Our Snake game map information is simple, with a total of 3 types of objects standing on the ground: walls, snakes, and prizes. In each update, we populate the map with information about 3 types of object
game main cycle logic is roughly as follows:
Initialize while
(true)
{
if (Player has keyboard action)
{
if (Esc key)
{
//jump Out of loop
}
else if (arrow key)
{
if (the game is in progress without end)
{
//snake moves in the direction of player
action
}
else//other key
{
//non-
processing
}
//assumes 300 milliseconds
Javascript implements simple snake-Greedy games and javascript snake-Greedy games
Javascript implements a simple Snake game. The function is very simple, and the
Javascript is a snake, and javascript is a snake.
The idea of writing a snake in javascript
First:Control variables of the snake movement: speed, direction, length. These three variab
Transfer from C language network
Today I show you the C language to write the greedy snake game, let everyone play a game of their own write ~ is pure C language Oh ~vc6.0 development No problem
First, start the interface:
The game interface is as follows:
The code is as
qt Edition snake gameReprint please indicate the source: Muni column http://blog.csdn.net/u012027907recently in the study of QT, took one months to master the most basic knowledge of QT, also completed the "QT version of the music player", "QT version of the snake Game", "QT version of Double Tetris" and "QT version of the scientific calculator," and so on, befor
Js1k.com collected a small example of less than 1k JavaScript, there are a lot of cool games and special effects, this year the rules added a twist, the traditional classic type based on the addition of the WebGL type, and allowed to increase to 2K + + type, Many times want to try to submit a small game, but always can not write to let their satisfaction and control in such a small byte range.Can't write, s
Tutorial This is the first game I wrote. The function is not perfect yet. Only the most basic function. Let's take a rough look first.
Effect and source file:
greedy snake. rar
/uploadpic/2007-7/20077814321316.swf
In fact, the whole game to solve a number of problems.
1. How do I get snakes to move in the direction of the keyboard?
2. How to make food randomly d
Greedy snake childhood memories, today just learn to this, just do one, but also learn it, need to grasp the knowledge:
1, JS function of the master,
2, JS array of applications,
3, JS small part of the learning of Ajax
4, JS in the splice, shift and other functions of the application,
Basically, here's the key part:The front end of the page, here can be self layout, and I provide a layout of my own here:
Here is the CSS
1. First specify the Movement area width (stagew) and height of the snake (Stageh)2. Increase the keyboard to listen, get the keying code, if the key and the previous key is reversed will not change3. In the initialization, please note: The size of the snake head, snake body, food is 7 pixels4. Each moving step (move)
Ideas:1. First specify the Movement area width (stagew) and height of the snake (Stageh)2. Increase the keyboard to listen, get the keying code, if the key and the previous key is reversed will not change3. In the initialization, please note: The size of the snake head, snake body, food is 7 pixels4. Each moving step (
OneDescription: Snake game is a classic puzzle game, with a PC and mobile phone and other multi-platform version. It is simple and easy to play and is popular with people.TwoUser needs: 1. The game can be played on the browser.2. Can adjust the difficulty.3. You can view historical record.4. You can change the backgrou
The example of this article for everyone to share the relevant code JS snake game, for your reference, the specific content as follows
Effect Chart:
Ideas:
function Newgame () {Reset
the data of snakes and fractions;
clear interval;
initialize canvas;
draw a snake;
place food;
Use the
Just touch the Java text box drawing knowledge point, and then can follow the teacher's reminders to do some simple game, to jframe deepen, the following on the greedy snake give some source code, in fact, the implementation of the code is not much, just a little processing can be understood, the following
OneDescription: Snake game is a classic puzzle game, with a PC and mobile phone and other multi-platform version. It is simple and easy to play and is popular with people.TwoUser needs: 1. The game can be played on the browser.2. Can adjust the difficulty.3. You can view historical record.4. You can change the backgrou
Js1k.com collected a small example of less than 1k JavaScript, there are a lot of cool games and special effects, this year the rules added a twist, the traditional classic type based on the addition of the WebGL type, and allowed to increase to 2K + + type, Many times want to try to submit a small game, but always can not write to let their satisfaction and control in such a small byte range.Can't write, s
() operation. The so-called avoidance means turning in the direction of the snake, which may lead to a dead end. To prevent it from entering a dead end, this program temporarily uses the number of spaces enclosed by the body and wall of the snake on both sides of the side, the snake goes to the side with many spaces.
Before proceeding to the next step, please
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.