-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.cpp
More file actions
91 lines (79 loc) · 2.68 KB
/
World.cpp
File metadata and controls
91 lines (79 loc) · 2.68 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "Level.h"
#include "World.h"
#include "Mario.h"
#include "FileProcessor.h"
#include <stdlib.h>
/* This is the default constructor.
It takes no parameters. */
World::World(){
m_levelNum = 0;
}
/* This is the overloaded constructor.
It takes a size as the only parameter. */
World::World(int levelNum){
m_levelNum = levelNum;
}
/* Default destructor. */
World::~World(){
}
/* Accessor for size. */
int World::getLevelNum(){
return m_levelNum;
}
/* Mutator for size. */
void World::setLevelNum(int levelNum){
m_levelNum = levelNum;
}
char*** World::createWorld(){
srand(time(NULL));
FileProcessor f;
f.levelMaker("input.txt");
int levelNumber = f.getNumLevel();
int size = f.getDimensionGrid();
int coinPercent = f.getPercentageCoins();
int nothingPercent = f.getPercentageNothing();
int goombaPercent = f.getPercentageGoomba();
int koopaPercent = f.getPercentageKooba();
int mushroomPercent = f.getPercentageMushroom();
char*** world = new char**[levelNumber];
bool marioPlaced = false;
for(int i = 0; i < levelNumber; i++){
Level* lvl = new Level(size,coinPercent,nothingPercent,goombaPercent,koopaPercent,mushroomPercent);
char** singleLevel = lvl->createLevel(size,coinPercent,nothingPercent,goombaPercent,koopaPercent,mushroomPercent);
int bossRow = (rand() % size);
int bossColumn = (rand() % size);
singleLevel[bossRow][bossColumn] = 'b';
bool same;
int warpRow = (rand() % size);
int warpColumn = (rand() % size);
if ((bossRow == warpRow) && (bossColumn == warpColumn)){
same = true;
while (same == true){
int warpRow = (rand() % size);
int warpColumn = (rand() % size);
if ((bossRow != warpRow) || (bossColumn != warpColumn)){
if (i != (levelNumber - 1)){
singleLevel[warpRow][warpColumn] = 'w';
same = false;
}
// singleLevel[warpRow][warpColumn] = 'w';
// same = false;
}
}
}
else{
if (i != (levelNumber - 1)){
singleLevel[warpRow][warpColumn] = 'w';
}
// singleLevel[warpRow][warpColumn] = 'w';
}
world[i] = singleLevel;
// if (marioPlaced == false){
// int marioRow = (rand() % size);
// int marioColumn = (rand() % size);
// world[0] [marioRow][marioColumn] = 'H';
// marioPlaced = true;
// }
}
return world;
}