卷轴

#include <iostream>
#include <windows.h>
#include <conio.h>

void main()
{
	const int w = 100; //大地图宽高
	const int h = 100;
	const int s = w * h;
	const int sw = 11;//小地图宽高
	const int sh = 11;
	char map[s] = {};
	//英雄坐标
	int px = w/2;
	int py = h/2;

	//设置障碍
	for (int i = 0;i < 500; ++i)
		map[rand() % s] = 1;
	
	while (1)
	{
		system("cls");
		int leftx = px-sw/2;
		if (leftx < 0)
			leftx = 0;
		else if (leftx > w - sw)
			leftx = w - sw;

		int topy = py-sh/2;
		if (topy < 0)
			topy = 0;
		else if (topy > h - sh)
			topy = h - sh;

		for (int y = topy; y < topy + sh; ++y)
		{
			for (int x = leftx; x < leftx + sw; ++x)
			{
				if (x == px && y == py)
					std::cout<<"人";
				else if (map[x+y*w] == 1)
					std::cout<<"■";
				else
					std::cout<<"□";
			}
			std::cout<<"\n";
		}
		std::cout<< px <<", " <<py<<"\n";

		int a = _getch();
		if (a == 'w' && py > 0)
			py --;
		if (a == 's' && py < h-1)
			py ++;
		if (a == 'a' && px > 0)
			px --;
		if (a == 'd' && px < w -1)
			px ++;
	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值