当前位置:网站首页>2022.2.10
2022.2.10
2022-06-26 04:38:00 【bu_ xiang_ tutou】
9:40----13:00
Compress Words
15:00---18:00
[BOI2009]Radio Transmission Wireless transmission
Adjust Snake code
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <easyx.h>
#include <time.h>
#include <conio.h>
#include <cstring>
#define snakenum 30000// Macro definitions do not have semicolons
#define _CRT_SECURE_NO_WARNINGS
HWND hnd = NULL;// Represents the main window
// The snake , food , coordinate
enum position { right = 77, left = 75, down = 80, up = 72 };
struct Snake// The snake
{
int size;// The number of knots
char dir;// Direction
POINT xy[snakenum];// Snake coordinates
}snake;
struct Food// food
{
POINT foodxy;// Food coordinates
int eatgrade=0;// score
int sign;// Record whether the food is present
}food;
void initsnake()// Initialize snake
{
snake.xy[2].x = 10;
snake.xy[2].y = 10;
snake.xy[1].x = 20;
snake.xy[1].y = 10;
snake.xy[0].x = 30;// The snake head is in front
snake.xy[0].y = 10;
snake.size = 3;// Initialize snake , The snake started with 3 section
snake.dir = right;
food.sign = 0;
}
void drawsnake()// Draw a snake
{
for (int i = 0; i < snake.size; i++)
{
setfillcolor(YELLOW);// Set the color of the snake , Before you draw a snake
setlinecolor(BLACK);
fillrectangle(snake.xy[i].x, snake.xy[i].y, snake.xy[i].x+10,snake.xy[i].y+10);// Draw a snake
}
}
void movesnake()// Move the snake
{
for (int i = snake.size - 1; i > 0; i--)
{
snake.xy[i].x = snake.xy[i - 1].x;
snake.xy[i].y = snake.xy[i - 1].y;
}
switch (snake.dir)
{
case up:
snake.xy[0].y -= 10;
break;
case down:
snake.xy[0].y += 10;
break;
case left:
snake.xy[0].x -= 10;
break;
case right:
snake.xy[0].x += 10;
break;
default:
break;
}
}
void keydown()// Keyboard control
{
char userskey = 0;
userskey =_getch();
switch (userskey)
{
case right:
if (snake.dir != left)
snake.dir = right;
break;
case left:
if (snake.dir != right)
snake.dir = left;
break;
case up:
if (snake.dir != down)
snake.dir = up;
break;
case down:
if (snake.dir != up)
snake.dir = down;
break;
default :
break;
}
}
void initfood()// Initializing food
{
food.foodxy.x = rand() % 64 * 10;
food.foodxy.y = rand() % 48 * 10;
for (int i = 0; i < snake.size; i++)
{
if (food.foodxy.x == snake.xy[i].x && food.foodxy.y == snake.xy[i].y)
{
food.foodxy.x = rand() % 64 * 10;
food.foodxy.y = rand() % 48 * 10;
}
}
food.sign = 1;
}
void drawfood()// Painting food
{
setfillcolor(RGB(rand() % 250, rand() % 250, rand() % 250));// Set the color of the food , Before you draw a snake
setlinecolor(RGB(rand() % 250, rand() % 250, rand() % 250));
fillrectangle(food.foodxy.x, food.foodxy.y, food.foodxy.x+10, food.foodxy.y+10);
}
void eatfood()// Eat food
{
if (snake.xy[0].x == food.foodxy.x && snake.xy[0].y == food.foodxy.y)
{
snake.size+=1;// The snake is getting longer
food.eatgrade += 1;// Scores increase
food.foodxy.x = rand() % 64 * 10;
food.foodxy.y = rand() % 48 * 10;
food.sign = 0;
}
}
void show()// Show the score
{
char str[10000];// The window can only display strings , Convert an integer to a string
sprintf(str, "%d", food.eatgrade);
setbkmode(TRANSPARENT);// Set to transparent mode
settextcolor(BLACK);
SetWindowText(hnd," snake ");
outtextxy(560, 20, " fraction :");
outtextxy(600, 20, str);
}
int snakedie()// Snake death
{
if (snake.xy[0].x > 640 || snake.xy[0].x < 0 || snake.xy[0].y>480 || snake.xy[0].y < 0)
{
outtextxy(200, 220," The wall was ");
MessageBox(NULL, " The wall was ", "Gameover",MB_OKCANCEL);// Pop-up window
return 1;
}
for (int i = 1; i < snake.size; i++)
{
if(snake.xy[0].x==snake.xy[i].x&& snake.xy[0].y == snake.xy[i].y)
{
outtextxy(200, 220," Hit yourself ");
MessageBox(NULL, " Hit yourself ", "Gameover", MB_OKCANCEL);
return 1;
}
}
return 0;
}
int main()
{
initgraph(640, 480);// initialization
setbkcolor(WHITE);// Set the background color
srand((unsigned)time(NULL));// Plant random seeds
initsnake();
while (1)
{
cleardevice();
if (food.sign == 0)
{
initfood();// initialization
}
BeginBatchDraw();// Prevent flashing
drawfood();
eatfood();
show();
drawsnake();
EndBatchDraw();// Prevent flashing
if (snakedie())
break;
movesnake();
while (_kbhit())
{
keydown();
}
Sleep(50);// The speed at which the snake moves
}
system("pause");
return 0;
}19:00----21:00
(13 Bar message ) hash problem _bu_xiang_tutou The blog of -CSDN Blog
(13 Bar message ) kmp Simple application of _bu_xiang_tutou The blog of -CSDN Blog
边栏推荐
- There is no response to redirection and jump in the laravel constructor [original]
- Redis cache message queue
- Zhimeng CMS will file a lawsuit against infringing websites
- [Qunhui] Internet access + custom port
- numpy 通用函数
- 做软件测试学历重要还是能力重要
- Simple use of redis in laravel
- LeetCode 94. Middle order traversal of binary tree
- ctf [RoarCTF 2019]easy_ calc
- Realize video call and interactive live broadcast in the applet
猜你喜欢

mysql高级学习(跟着尚硅谷老师周阳学习)
![[Qunhui] Internet access + custom port](/img/7d/c00caeade209a48c8f44a4fecb59d5.jpg)
[Qunhui] Internet access + custom port

1.17 learning summary

CTF serialization and deserialization

A brain map to summarize the needs analysis (a supplement to the actual situation at work)

6、 Project practice --- identifying cats and dogs

Text horizontal alignment attribute text align and element vertical alignment attribute vertical align

Gateway can not connect to tcp://127.0.0.1: Connection refused

Thinkphp6 implements a simple lottery system

MySQL index details
随机推荐
Dameng database backup and restore
Zhubo Huangyu: you can try these non-agricultural operation skills
Multipass中文文档-使用Packer打包Multipass镜像
MySQL index details
Zhimeng CMS will file a lawsuit against infringing websites
Laravel framework Alipay payment fails to receive asynchronous callback request [original]
Advanced learning of MySQL (learning from Shang Silicon Valley teacher Zhou Yang)
防撤回测试记录
How to carry out word-of-mouth marketing for enterprises' products and services? Can word of mouth marketing be done on behalf of others?
How to use the configured slave data source for the scheduled task configuration class scheduleconfig
做软件测试学历重要还是能力重要
[H5 development] 02 take you to develop H5 list page ~ including query, reset and submission functions
Minecraft 1.16.5 生化8 模组 1.9版本 1.18版本同步
BACK-OFF RESTARTING FAILED CONTAINER 的解决方法
1.18 learning summary
Tp6 is easy to tread [original]
Sixtool- source code of multi-functional and all in one generation hanging assistant
Resolve PHP is not an internal or external command
Thymeleaf data echo, single selection backfill, drop-down backfill, time frame backfill
Multipass中文文档-设置驱动