Apple.cpp

 avataruser_6225994
plain_text
a month ago
570 B
1
Indexable
Never
#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);
}