Weak Game/app Structure

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?

Here is my simplified code structure...
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
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();
    else if (GamePart==1)
      GamePart=Instructions();
    else if (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];
    }
  }
}
}




Sorry if the code is pseudo code-ish
Last edited on
Topic archived. No new replies allowed.