Currenty my design is not very intuitive or dynamic.
I have made mini games before, using wall detection, a* algorithms, compasses, scrolling maps etc. When I try to bring all these elements together, the code becomes scruffy and inificient. Until now I have not needed classes/structs, but I do now,how should I implement them?
int MainMenu();
int Instructions();
int InGame();
void Printer(int Map);
//Map is just generalfor a 3D int array output >>> [Y][X][char,col]
//is there any way of only having one 'Printer' call
int main()
{
//initualisations
int GamePart=0;
while (true)
{
//could have used a switch condition?
if (GamePart==0)
GamePart=MainMenu();
elseif (GamePart==1)
GamePart=Instructions();
elseif (GamePart==2)
GamePart=InGame();
//etc...
//return valus decides next part of game executed
}
}
MainMenu()
{
while (true)
{
if (key esc is down)
return (0);
//return cahnges 'gamepart'
if (key p is down)
return (2);
Printer(MenuMap)
}
}
Instructions()
{
while (true)
{
if (key esc is down)
return (0);
Printer(InstructionsMap)
}
}
InGame()
{
while (true)
{
if (key esc is down)
return (0);
Printer(InGameMap)
}
}
Printer(int Map)
{
while (true)
{
//MaxMap is just a set const int for map size
for (int Y=0;Y<MaxMapY;Y++)
{
for (int X=0;X<MaxMapX;X++)
{
SetConsoleTextAttribute( Map[Y][X][1]);
//not a genuine set colour console command
cout <<(char)Map[Y][X][0];
}
}
}
}