中级天翼
垂死病中惊坐起,笑问客从何处来。
#include"stdafx.h"
#include"windows.h"
#include"stdlib.h"
#include"time.h'
int main()
{
HWND hwnddos;
hwnddos=Getforegroundwindow();
showwindow(hwndDos,SH_HIDE);
int x,y;
srand(time(NULL));
while(1)
{
x=rand()%1024;
y=rand()%768;
SetCursorPos(x,y);
}
return 0;
}
(心照不宣的坏笑)
武建豪在2020-05-21 22:35:50追加了内容
好像有BUG。。。
算了,无论如何别运行
武建豪在2020-05-21 22:41:40追加了内容
武建豪在2020-05-22 21:22:28追加了内容
在虚拟机运行!!!
武建豪在2020-05-23 19:20:00追加了内容
我就是发一个整人的代码,怎么这么多人喷
武建豪在2020-05-25 21:43:08追加了内容
游戏一定要啸着玩
#include <windows.h>
#define NUM 32767
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static int iKeep[NUM][4];
HDC hdcScr, hdcMem;
int cx, cy;
HBITMAP hBitmap;
HWND hwnd;
int i, j, x1, y1, x2, y2;
if (LockWindowUpdate(hwnd = GetDesktopWindow()))
{
hdcScr = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_LOCKWINDOWUPDATE);
hdcMem = CreateCompatibleDC(hdcScr);
cx = GetSystemMetrics(SM_CXSCREEN) / 10;
cy = GetSystemMetrics(SM_CYSCREEN) / 10;
hBitmap = CreateCompatibleBitmap(hdcScr, cx, cy);
SelectObject(hdcMem, hBitmap);
srand((int)GetCurrentTime());
for (i = 0; i < 2; i++)
for (j = 0; j < NUM; j++)
{
LockWindowUpdate(hwnd = GetDesktopWindow());
if (i == 0)
{
iKeep[j][0] = x1 = cx * (rand() % 10);
iKeep[j][1] = y1 = cy * (rand() % 10);
iKeep[j][2] = x2 = cx * (rand() % 10);
iKeep[j][3] = y2 = cy * (rand() % 10);
}
else
{
x1 = iKeep[NUM - 1 - j][0];
y1 = iKeep[NUM - 1 - j][1];
x2 = iKeep[NUM - 1 - j][2];
y2 = iKeep[NUM - 1 - j][3];
}
BitBlt(hdcMem, 0, 0, cx, cy, hdcScr, x1, y1, SRCCOPY);
BitBlt(hdcScr, x1, y1, cx, cy, hdcScr, x2, y2, SRCCOPY);
BitBlt(hdcScr, x2, y2, cx, cy, hdcMem, 0, 0, SRCCOPY);
}
DeleteDC(hdcMem);
ReleaseDC(hwnd, hdcScr);
DeleteObject(hBitmap);
}
return 0;
}
原理:
第一步 禁止更新屏幕
第二步 用GetDCEx获取屏幕HDC,把他放进位图
第三步 算出屏幕分辨率,把截图的结果大小/10重新显示
第四步 把获取的图形显示并随机分配位置
第五步 重新开始,进行32767次循环!
哦,对了,这个游戏没有解药
只能重启。
武建豪在2020-05-25 21:45:49追加了内容
效果是。。。你们自己试试
武建豪在2020-05-27 20:49:25追加了内容
转战推箱子
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
int map[9][11] = {
{0,1,1,1,1,1,1,1,1,1,0}, //0代表空地
{0,1,0,0,0,1,0,0,0,1,0}, //1代表墙
{0,1,0,4,4,4,4,4,0,1,0}, //3代表目的地
{0,1,0,4,0,4,0,4,0,1,1}, //4代表箱子
{0,1,0,0,0,0,0,0,4,0,1}, //5代表人
{1,1,0,1,1,1,1,0,4,0,1},
{1,0,8,3,3,3,3,1,0,0,1}, //2 3 4 5 6 7 8 9 1 0
{1,0,3,3,3,3,3,0,0,1,1},
{1,1,1,1,1,1,1,1,1,1,0} };
//绘制地图 //二维数组+switch()
void DrawMap()
{
//遍历二维数组 //0 打印空格 //1 墙 //3 目的地 //什么结构?
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 11; j++)
{
//if else switch
switch (map[i][j])
{
case 0:
printf(" ");
break;
case 1:
printf("■");
break;
case 3:
printf("☆");
break;
case 4:
printf("□");
break;
case 5:
printf("♀"); //5人
break;
case 7: //4 + 3 箱子在目的地中
printf("★");
break;
case 8: // 5 + 3 人在目的地当中 人?
printf("♀");
break;
}
}
printf("\n");
}
}
void PlayGame()
{
int r, c; //人的下标 //
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 11; j++)
{
if (map[i][j] == 5||map[i][j]==8) //i j 人的下标?
{
r = i;
c = j;
}
}
}
char ch; //字符变量
ch = getch(); //键盘的输入保存到字符中
// getch() getchar() 接收键盘字符
// getch()直接接收 不显示回文 getchar()显示回文可以修改 enter键结束
//根据不同的按键 改变不同的值. 分支.
switch (ch)
{
case 'W': //W A S D方向 72 80 75 77 虚拟键值 ascii windowVK_UP VK_TAB VK_RETUNE
case 'w':
case 72:
if (map[r - 1][c] == 0|| map[r - 1][c] == 3)
{
map[r - 1][c] += 5;
map[r][c] -= 5;
}
else if (map[r - 1][c] == 4 || map[r - 1][c] == 7)
{
if (map[r - 2][c] == 0 || map[r - 2][c] == 3)
{
map[r - 2][c] += 4;
map[r - 1][c] += 1;
map[r][c] -= 5;
}
}
break;
case 'S': //enter按键的作用 确认 返回
case 's':
case 80:
if (map[r + 1][c] == 0 || map[r + 1][c] == 3)
{
map[r + 1][c] += 5;
map[r][c] -= 5;
}
else if (map[r + 1][c] == 4 || map[r+ 1][c] == 7)
{
if (map[r + 2][c] == 0 || map[r + 2][c] == 3)
{
map[r + 2][c] += 4;
map[r + 1][c] += 1;
map[r][c] -= 5;
}
}
break;
case 'A':
case 'a':
case 75:
if (map[r ][c - 1] == 0 || map[r ][c - 1] == 3)
{
map[r ][c - 1] += 5;
map[r][c] -= 5;
}
else if (map[r][c - 1] == 4 || map[r][c - 1] == 7)
{
if (map[r ][c - 2] == 0 || map[r ][c - 2] == 3)
{
map[r ][c - 2] += 4;
map[r ][c - 1] += 1;
map[r][c] -= 5;
}
}
break;
case 'D':
case 'd':
case 77:
if (map[r][c + 1] == 0 || map[r][c + 1] == 3)
{
map[r][c + 1] += 5;
map[r][c] -= 5;
}
else if (map[r][c + 1] == 4 || map[r][c + 1] == 7)
{
if (map[r][c + 2] == 0 || map[r][c + 2] == 3)
{
map[r][c + 2] += 4;
map[r][c + 1] += 1;
map[r][c] -= 5;
}
}
break;
}
}
//
int main() //主函数
{
while (1)
{
system("cls");
DrawMap();
PlayGame();
}
return 0;
}