Apple.cpp

 avatar
user_6225994
plain_text
2 years ago
570 B
5
Indexable
#include "Apple.h"
#include <time.h>
#include <stdlib.h>
#include "Ulti.h"

Apple::Apple(){
	_pmap = 0;
}

Apple::Apple(Map *p){
	_pmap = p;
}

void Apple::GeneratePosition(){
	ClearApple();
	//check
	int x, y;
	do{
		srand(time(NULL));
		x = rand() % (_pmap->_w - 2) + 1;
		y = rand() % (_pmap->_h - 2) + 1;
	}
	while (_pmap->_map[y][x] != ' ');
	_pos = Point(x, y, '@');
	DisPlayApple();
	_pmap->_map[_pos._y][_pos._x] = '@';
}

void Apple::DisPlayApple(){
	_pos.DrawPoint();
}

void Apple::ClearApple(){
	Clearxy(_pos._x, _pos._y);
}
Editor is loading...