4-gewinnt  1.0.0
Klassiker "4-gewinnt" als Konsolenanwendung
 Alle Datenstrukturen Dateien Funktionen Variablen Makrodefinitionen Seiten
mainMenu.c-Dateireferenz
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
Include-Abhängigkeitsdiagramm für mainMenu.c:
Dieser Graph zeigt, welche Datei direkt oder indirekt diese Datei enthält:

gehe zum Quellcode dieser Datei

Funktionen

void drawLeftArrow (char *menu, int pPos)
 
void drawRightArrow (char *menu, int pPos)
 
void drawMainMenu (int pPos)
 
int mainMenu ()
 
void mainMenuReactToEnter (int pPos)
 

Dokumentation der Funktionen

void drawLeftArrow ( char *  menu,
int  pPos 
)

This method manipulates the array so the left arrow (to indicate the cursor position) is added to the array.

Parameter
menucontains the pointer to the char-array containing main menu in it's current status
pPoscontains the cursor Position of the cursor

Definiert in Zeile 11 der Datei mainMenu.c.

Wird benutzt von drawMainMenu().

11  {
12 #ifndef DEBUG
13  if (pPos>1) pPos--;
14 #endif // DEBUG
15  menu[pPos*20]='-';
16  menu[pPos*20+1]='>';
17  menu[pPos*20+2]=' ';
18 }

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

void drawMainMenu ( int  pPos)

This method is responsible for drawing the mainMenu The raw form of the menu is defined here–>it can not be changed easily because the array size is dependent on the length of the String

Parameter
pPoscurrent position of cursor within mainMenu
mainMenuthe char Array containing the mainMenu

every Menu gets 21 Chars–>each entry starts with 3 spaces followed by the menu entry followed by some spaces to fill up the array till the end and then the line break("\n")

Definiert in Zeile 39 der Datei mainMenu.c.

Benutzt drawLeftArrow(), drawRightArrow(), flushBuffer(), mainMenu(), output(), setLineAlign() und startBuffer().

Wird benutzt von mainMenu().

39  {
40  startBuffer(25);
41  setLineAlign(0);
45 #ifndef DEBUG
46  char mainMenu[] = " NEW GAME \n RULES \n HALL OF SHAME \n CREDITS \n QUIT ";
47 #else
48  char mainMenu[] = " NEW GAME \n SETTINGS \n RULES \n HALL OF SHAME \n CREDITS \n QUIT ";
49 #endif // DEBUG
50 
51  drawLeftArrow(mainMenu,pPos);
52  drawRightArrow(mainMenu,pPos);
53  output("\n%s\n",mainMenu);
54 
55  flushBuffer();
56 }
void setLineAlign(int align)
Definition: system.c:344
void flushBuffer()
Definition: system.c:188
void startBuffer(int maxTextLength)
Definition: system.c:319
int output(const char *input,...)
Definition: system.c:144

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

void drawRightArrow ( char *  menu,
int  pPos 
)

This method manipulates the array so the right arrow (to indicate the cursor position) is added to the array.

Parameter
menucontains the pointer to the char-array containing main menu in it's current status
pPoscontains the cursor Position of the cursor

Definiert in Zeile 24 der Datei mainMenu.c.

Wird benutzt von drawMainMenu().

24  {
25 #ifndef DEBUG
26  if (pPos>1) pPos--;
27 #endif // DEBUG
28  menu[(pPos+1)*20-2]='-';
29  menu[(pPos+1)*20-3]='<';
30  menu[(pPos+1)*20-4]=' ';
31 }

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

int mainMenu ( )
Parameter
con
pPos

Definiert in Zeile 62 der Datei mainMenu.c.

Benutzt animateBanner(), animateBox(), con, drawMainMenu() und mainMenuReactToEnter().

Wird benutzt von drawMainMenu() und main().

62  {
63  //describes where the cursor is, default location is 0(NEW GAME)
64  int pPos=0;
65  //as long as this variable is one the loop won't finish
66  con=1;
67  animateBanner(1);
68  animateBox(1,1,25,8);
69  // menu loop
70  while(con){
71  drawMainMenu(pPos);
72  switch(getch()) {
73  case 72: // key up
74  pPos--;
75 #ifndef DEBUG
76  if (pPos==1) pPos--; //settings temporarily disabled
77 #endif // DEBUG
78  break;
79  case 80: // key down
80  pPos++;
81 #ifndef DEBUG
82  if (pPos==1) pPos++; //settings temporarily disabled
83 #endif // DEBUG
84  break;
85  case 77: // key right
86  break;
87  case 75: // key left
88  break;
89  case 13: // key enter
91  break;
92  case 27: //escape
93  // exit(0);
94  con=0;
95  break;
96  }
97  fflush(stdin);
98  if(pPos>5){
99  //cursor is "below" the menu-->get him back
100  pPos=0;
101  } else if(pPos<0){
102  //cursor is the "over" the menu-->get him back
103  pPos=5;
104  }
105 
106  }
107  animateBox(25,8,1,1);
108  animateBanner(0);
109  return 0;
110 }
void animateBox(int wFrom, int hFrom, int wTo, int hTo)
Definition: system.c:392
int con
Definition: variables.h:35
void animateBanner(int slideIn)
Definition: system.c:378

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

void mainMenuReactToEnter ( int  pPos)

this method handles the game flow by calling the function corresponding to the cursor posotion within the menu

Parameter
pPoscontains the current position (0:Top,4:bottom)

Definiert in Zeile 115 der Datei mainMenu.c.

Benutzt con, flushBuffer(), gameFunction(), NO_HIGHLIGHT, output(), showCredits(), showHallOfShame(), showRules() und startBuffer().

Wird benutzt von mainMenu().

115  {
116  switch(pPos){
117  case 0:
118  gameFunction();
119  break;
120  case 1:
121  startBuffer(60);
122  output("Settings Menu(Dummy)\nPress any key to return to main\n");
123  flushBuffer();
124  getch();
125  break;
126  case 2:
127  showRules();
128  break;
129  case 3:
131  break;
132  case 4:
133  showCredits();
134  break;
135  case 5:
136  //end game
137  con=0;
138  //exit(0);
139  }
140 }
void showHallOfShame(int highlight, int startFrom)
Definition: hallofshame.c:13
void showRules()
Definition: rules.c:35
void flushBuffer()
Definition: system.c:188
void startBuffer(int maxTextLength)
Definition: system.c:319
void gameFunction()
Definition: gamefunction.c:28
void showCredits()
Definition: credits.c:6
int con
Definition: variables.h:35
const int NO_HIGHLIGHT
Definition: variables.h:67
int output(const char *input,...)
Definition: system.c:144

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird: