猫史档案馆


自学的c喵程序~(第三期

用户:SCS_user_EHQ0z2l6elSCS_user_EHQ0z2l6el查看:0 回复:1 评论:0 创建时间:2022-09-04T14:39:14


不说了,直接上die码

#include<iostream>
#include<cstdio>
#include<conio.h>
#include<windows.h>
using namespace std;
int main(){
	char m[100][100]={
	"######### ",
	"#O#       ",
	"# ### ### ",
	"# # #   # ",
	"# # # ### ",
	"#   #   # ",
	"#     ### ",
	"######### ",
	};
	int x=1,y=1,x1=10,y1=8,y2=1,x2=9;
	while(true){
		for(int i=0;i<y1;i++)puts(m[i]);
		if(x>=y2&&x>=x2){
			break;
		}
		char a=getch();
		if(a=='w'){
			if(m[y-1][x]==' '){
				m[y][x]=' ';
				y--;
				m[y][x]='O';
			}
		}
		if(a=='d'){
			if(m[y][x+1]==' '){
				m[y][x]=' ';
				x++;
				m[y][x]='O';
			}
		}
		if(a=='s'){
			if(m[y+1][x]==' '){
				m[y][x]=' ';
				y++;
				m[y][x]='O';
			}
		}
		if(a=='a'){
			if(m[y][x-1]==' '){
				m[y][x]=' ';
				x--;
				m[y][x]='O';
			}
		}
		system("cls");
	}
	cout<<"恭喜你走出迷宫!";
    return 0;
}


回复

上一页1 页 / 共 1下一页
苏文星苏文星

需要先安装easyx哦

#include <algorithm>
#include <conio.h>
#include <ctime>
#include <graphics.h>
#include <stdio.h>
#include <vector>
using namespace std;

#define cell 25

const unsigned short large = 250;
short x = 0, y = 0, s = 10;

struct wall
{
    short x, y;
};

vector<wall> walls;

void draw()
{
    cleardevice();
    for (int i = 0; i < (int)walls.size(); i++)
    {
        solidrectangle(large + (walls[i].x - x) * cell,
                       large + (walls[i].y - y) * cell,
                       large + (walls[i].x - x + 1) * cell,
                       large + (walls[i].y - y + 1) * cell);
    }
    setfillcolor(WHITE);

    solidrectangle(large, large, large + cell, large + cell);

    setfillcolor(RED);
    char str[10];
    sprintf(str, "X=%d Y=%d", x, y);
    outtextxy(0, 0, str);
}

void move()
{
    char c = _getch();
    switch (c)
    {
    case 'w':
        y--;
        break;
    case 'a':
        x--;
        break;
    case 's':
        y++;
        break;
    case 'd':
        x++;
        break;
    }
    walls.push_back((wall){x, y});
    if ((int)walls.size() > s)
        walls.erase(walls.begin());
    if (rand() % 10 == 9)
        s++;
}
void init()
{
    srand(time(NULL));
}
int main()
{
    init();
    initgraph(large * 2, large * 2);

    draw();
    while (true)
    {
        move();
        draw();
    }
    return 0;
}

点赞0


评论