File size: 1,374 Bytes
0ef7a64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*

Name:Wong Pui Shan

Sdutent ID:52611804

program: AScISD

Name: HAR Chiu Kwong Samson

Sdutent ID:52629360

program: AScISD

Name: LAM Cheuk Man 

Sdutent ID:52621140

program: AScISD

Name:KO Jeffrey KO

Sdutent ID:525 695 30

program: AScISD



*/
#include <iostream>
using namespace std;
#include <fstream>
#include <string>
#include "Utilities.h"
#include "Game.h"
#include "Ghost.h"
#include "Maze.h"
#include "Pacman.h"
#include "Fruit.h"


 Fruit::Fruit(){
	 fx = 1;
	 fy = 1;
	 charF = '!';
	 number = 1;
	 levelFruit = 1;
	 
 }
Fruit::Fruit(char fruit){
	charF = fruit;
	fx = 1;
	fy = 1;
	number = 1;
	levelFruit = 1;
}

void Fruit::showFruit(Game &game, int &dot, Maze &m, Utilities &f){
	//Set the fruit randomly on the map when pacman eat 70 dots
	levelFruit = game.getGameLevel();
	if(dot == 70)
	{
		do{
				fx = rand() % 21 ;
				fy = rand() % 18 ;
				dot = 0;
			}while(m.getMazeArray(fx, fy)=='-' || m.getMazeArray(fx, fy)=='|' || m.getMazeArray(fx, fy)=='.' || m.getMazeArray(fx, fy)=='X');
		f.gotoXY(fx,fy);
		f.changeColour(FOREGROUND_GREEN | FOREGROUND_BLUE);
		switch(levelFruit){
		case 1:
			charF = '!';
			
				break;
		case 2:
			charF = '*';
			
				break;
		case 3:
			charF = '#';
			
				break;
		}
		cout << charF; 
		m.setMazeArray(fx,fy,charF);
	
}
}

 Fruit::~Fruit(){
 }