贪吃蛇

贪吃蛇_蓝图

拈花ヽ惹草 提交于 2019-12-05 04:27:02
思路: 对于蛇的移动,构建一个方块1,通过控制按键改变基于方块1另一个方块1的方向并摧毁原方块,于是得到一个会随按键移动的方块1(记为蛇头)。创建一个位置变量数组0,创建一个变量0控制数组储存位置变量的的个数(为蛇的长度),遍历数组0并生成方块,即可得到蛇,在随机位置创建食物蓝图,触发食物蓝图时随机位置生成另一个食物蓝图,并将变量2加一,则实现蛇长度的变化。 生成会移动的方块1(蛇头) 将新生成的方块1的位置与位置变量数组0逐一对比,若有相等则,蛇头撞到蛇身,停止游戏。 将数组0的位置变量后一位,并将蛇头位置记录到数组0的第0位。set array Elem 结点应勾选上size to fit,以避免数组长度不够。 判定游戏未结束,遍历数组0并在对应位置生成方块。 随机生成食物 通过按键控制方向,并直接变为相反的方向 来源: https://www.cnblogs.com/cdprojekt/p/11905761.html

JAVA——贪吃蛇

本秂侑毒 提交于 2019-12-03 06:53:19
转载请注明出处: https://www.cnblogs.com/love-fromAtoZ/p/11781329.html Project共有3个类:   UI类:主要负责绘制界面以及时间监听和键盘监听。   Snake类:负责内部的地图(int数组),蛇身移动的算法,随机食物位置以及吃掉食物的算法,以及对于是否撞墙和撞到身体的判断。   Main类:程序入口。 运行效果:    程序代码: UI.java 1 package Snake; 2 3 import java.awt.event.*; 4 import javax.swing.*; 5 import javax.swing.Timer; 6 import javax.swing.border.EmptyBorder; 7 import javax.swing.table.*; 8 import java.awt.*; 9 import java.util.*; 10 import java.math.*; 11 12 public class UI extends JFrame implements KeyListener{ 13 static Timer timer; 14 static Font enFont1 = new Font("Times New Roman",Font.BOLD,15); 15

C++ 贪吃蛇二维

我只是一个虾纸丫 提交于 2019-12-03 06:23:33
#include <iostream> #include <conio.h> #include <windows.h> #include <time.h> int g_Dir = 3; #define UP 0 #define DOWN 1 #define LEFT 2 #define RIGHT 3 struct FOOD { int X = 0; int Y = 0; bool State = 0; }Food; //方向控制 void SnekeMove() { if (::GetAsyncKeyState(VK_UP) & 1) g_Dir = 0; if (::GetAsyncKeyState(VK_DOWN) & 1) g_Dir = 1; if (::GetAsyncKeyState(VK_LEFT) & 1) g_Dir = 2; if (::GetAsyncKeyState(VK_RIGHT) & 1) g_Dir = 3; } //主函数 int main() { srand((unsigned int)time(NULL)); int W = 20; int H = 20; int Len = 3; int Map[20][20] = { 0 }; int Snake[50][2] = { 0 }; //Snake[0] = 2;//为蛇头 for (int

C++ 贪吃蛇一维

落爺英雄遲暮 提交于 2019-12-03 06:22:54
#include <iostream> #include <conio.h> #include <windows.h> #include <time.h> int g_Dir = 3; #define UP 0 #define DOWN 1 #define LEFT 2 #define RIGHT 3 struct FOOD { int X = 0; int Y = 0; bool State = 0; }Food; //方向控制 void SnekeMove() { if (::GetAsyncKeyState(VK_UP) & 1) g_Dir = 0; if (::GetAsyncKeyState(VK_DOWN) & 1) g_Dir = 1; if (::GetAsyncKeyState(VK_LEFT) & 1) g_Dir = 2; if (::GetAsyncKeyState(VK_RIGHT) & 1) g_Dir = 3; } //主函数 int main() { srand((unsigned int)time(NULL)); int W = 20; int H = 20; int Len = 3; int Map[20 * 20] = { 0 }; int Snake[50] = { 0 }; //Snake[0] = 2;//为蛇头 for (int i

qt的贪吃蛇实现

匿名 (未验证) 提交于 2019-12-03 00:34:01
通过查阅资料,完成最终样品 snake.pro为配置文件 widget为父窗口相关文件 gamewidget为子窗口相关文件 ⒉widget.h中的代码 #ifndef WIDGET_H#define WIDGET_H #include<QWidget>#include<QIcon>#include<QPalette>#include<QBrush>#include<QPixmap>#include<QPushButton>#include<QMessageBox> #include"gamewidget.h" class Widget public QWidget { public : 0 ); //声明一个新的界面 private void void }; #endif // WIDGET_H 3. widget.cpp中的代码 #include "widget.h" #include "gamewidget.h" #include< QDebug > Widget ::Widget (QWidget * parent ) parent ) { -> resize( 891 , 510 ); -> setWindowTitle( "贪吃蛇" ); -> setWindowIcon(QIcon( ":/Picture/img/WindowPicture.jpg" )); .

qt的贪吃蛇实现

匿名 (未验证) 提交于 2019-12-03 00:34:01
通过查阅资料,完成最终样品 snake.pro为配置文件 widget为父窗口相关文件 gamewidget为子窗口相关文件 ⒉widget.h中的代码 #ifndef WIDGET_H#define WIDGET_H #include<QWidget>#include<QIcon>#include<QPalette>#include<QBrush>#include<QPixmap>#include<QPushButton>#include<QMessageBox> #include"gamewidget.h" class Widget public QWidget { public : 0 ); //声明一个新的界面 private void void }; #endif // WIDGET_H 3. widget.cpp中的代码 #include "widget.h" #include "gamewidget.h" #include< QDebug > Widget ::Widget (QWidget * parent ) parent ) { -> resize( 891 , 510 ); -> setWindowTitle( "贪吃蛇" ); -> setWindowIcon(QIcon( ":/Picture/img/WindowPicture.jpg" )); .

基于stc89C52的贪吃蛇小程序

匿名 (未验证) 提交于 2019-12-03 00:30:01
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

SIKI_Unity_2_初级案例_贪吃蛇

匿名 (未验证) 提交于 2019-12-02 23:49:02
SIKI_Unity_2_初级案例_贪吃蛇 任务5: 素材的导入与制作 确定游戏窗口分辨率并隐藏Build出来每次开始运行时跳出的UnityResolution窗口:   PlayerSettings -> Resolution and Presentation中   设置 Default Screen Width/ Height    DisplayResolutionDialog = Disabled 任务6:创建工程并搭建开始场景 Canvas的RenderMode选择ScreenSpace-Camera,并将主摄像机赋值   此时在Scene中UI的框会和Camera的框重叠 一般而言,3D游戏的HUD如小地图之类的UI会用ScreenSpace-Overlay实现   因为这个模式相当于把画布蒙在相机之前,会遮挡住游戏物体,保证UI在最上方 而2D游戏且使用UGUI主实现的时候,会选择ScreenSpace-Camera模式 任务10:贪吃蛇实现的思路 蛇头控制每一段蛇身 InvokeRepeat()调用前进方法 思路1: 每一段蛇身前进到前一段蛇身当前的位置 思路2: 增加一个蛇头,原来的蛇头变成第一节蛇身,其他不变 因为是双色贪吃蛇,因此只能使用思路1,使用思路2会导致颜色错乱 转载请标明出处: SIKI_Unity_2_初级案例_贪吃蛇 文章来源: SIKI

基于51单片机的点阵贪吃蛇

匿名 (未验证) 提交于 2019-12-02 23:43:01
程序如下: #include <reg52.h> #include <intrins.h> #include <stdlib.h> #define SNAKE 20 unsigned char x[SNAKE]; //存放蛇的X轴坐标 unsigned char y[SNAKE]; //存放蛇的Y轴坐标 unsigned char point_x; //存放果实的X轴坐标 unsigned char point_y; //存放果实的Y轴坐标 /* //点阵模块接口定义 sbit LEDARRAY_LAT = P3^6;//储存寄存器是时钟 sbit LEDARRAY_CLK = P3^5;//移位寄存器时钟输入端 sbit LEDARRAY_DI = P3^4;//串行数据输入端 sbit up = P3^0; sbit down = P3^1; sbit left = P3^2; sbit right = P3^3; unsigned char num[8][8]={ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 };//定义8*8数组作为清屏数据(有点走弯路

pygame试水,写一个贪吃蛇

匿名 (未验证) 提交于 2019-12-02 22:11:45
最近学完python基础知识,就想着做一个游戏玩玩,于是就在https://www.pygame.org/docs/学着做了个贪吃蛇游戏。 首先要导入模块。 1 import pygame 2 import sys 3 from pygame.locals import * 4 import time 5 import random 首先需要一个游戏运行的界面。 1 screen = pygame.display.set_mode((1000,700)) 其次要有一条蛇和一份食物。 这是蛇: 1 snake_Position = [200,200] #蛇的起始位置,即蛇头的位置。 2 snakeBody = [[100,100],[90,100],[80,100]] #列表的嵌套,每一个子列表代表一节身子的坐标。 这是食物: 1 foodPosition = [500,350] #初始时食物的位置,坐标随便设置就好,在屏幕内就行。 然后就是把蛇和食物画出来咯~ 1 for body in snakeBody: #吧蛇的每节身子都画出来。2   pygame.draw.rect(screen,pygame.Color(255,255,255),Rect(body[0], body[1],10,10)) 3 pygame.draw.rect(screen, pygame.Color