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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#include <iostream>
void setLevel(int);
void displayLevel();
// this is where our map we are currently
// playing will be copied to.
char Map[20][30];
// example level data.
char levels[60][30] = {
"#############################", // Level 1
"# # c #### #",
"# ## c # #",
"# ## # c ## #",
"# # #### c #",
"# ### c #",
"# * c #",
"# # c c c #",
"# # c @ c c #",
"# c c c #",
"# # # c # ## #",
"#c ##### c ######## #",
"# ################## c #",
"# c # ! c # #",
"# ####### ###### #",
"# # # c #",
"# c # ## #",
"# c # c #",
"# c # c #",
"#############################",
"#############################", // Level 2
"# #",
"# ############## #",
"# #",
"# # #### cccccc #",
"# ### c #",
"# ccc * c #",
"# # # # c # #",
"# # c @ # # c #",
"# # c c # ## #",
"# # # # ## #",
"# #### #### #",
"# # ### #### #",
"# # #",
"# ######## #",
"# # # ##### c #",
"# c # ## # #",
"# c## ## # #c#### #",
"# c # ! c #",
"#############################",
"#############################", // Level 3
"# cc ## cccc #",
"# ## # # c # ## #",
"# ## #",
"# # #### ##### c ## #",
"# ### c #",
"# * ## # c #",
"# # c c c # #",
"# # c @ c # c #",
"# c c c # #",
"# # # c # ## #",
"#c ##### c ######## #",
"# # ## #",
"# c ##### !# c ##### #",
"# # # # #",
"# # #### # c #",
"# # # #",
"# c######### c #",
"# c # c #",
"#############################",
};
int main()
{
int level = 1;
const int MAX_LEVELS = 3;
// create a demo loop to show each level
for (int i = 0; i < MAX_LEVELS; i++) {
// set level
setLevel(level);
// display level
displayLevel();
// next level
level++;
}
return 0;
}
void setLevel(int level)
{
std::cout << std::endl << "Level: " << level << std::endl;
// remember arrays start at 0 so level 1
// would need to point to position 0.
level--;
// we use the level to create an offset to
// next level
level = 20 * level;
// copy level data to map
int mapDown = level, mapAcross = 0;
for (int d = 0; d < 20; d++) {
mapAcross = 0;
for (int a = 0; a < 30; a++) {
Map[d][a] = levels[mapDown][mapAcross];
mapAcross++;
}
mapDown++;
}
}
// display level simply shows whats in map, map
// was written to by setLevel as per the current
// level you are playing on.
void displayLevel()
{
for (int d = 0; d < 20; d++) {
for (int a = 0; a < 30; a++) {
std::cout << Map[d][a];
}
std::cout << std::endl;
}
}
|
Level: 1
#############################
# # c #### #
# ## c # #
# ## # c ## #
# # #### c #
# ### c #
# * c #
# # c c c #
# # c @ c c #
# c c c #
# # # c # ## #
#c ##### c ######## #
# ################## c #
# c # ! c # #
# ####### ###### #
# # # c #
# c # ## #
# c # c #
# c # c #
#############################
Level: 2
#############################
# #
# ############## #
# #
# # #### cccccc #
# ### c #
# ccc * c #
# # # # c # #
# # c @ # # c #
# # c c # ## #
# # # # ## #
# #### #### #
# # ### #### #
# # #
# ######## #
# # # ##### c #
# c # ## # #
# c## ## # #c#### #
# c # ! c #
#############################
Level: 3
#############################
# cc ## cccc #
# ## # # c # ## #
# ## #
# # #### ##### c ## #
# ### c #
# * ## # c #
# # c c c # #
# # c @ c # c #
# c c c # #
# # # c # ## #
#c ##### c ######## #
# # ## #
# c ##### !# c ##### #
# # # # #
# # #### # c #
# # # #
# c######### c #
# c # c #
#############################
|