4-gewinnt
1.0.0
Klassiker "4-gewinnt" als Konsolenanwendung
Hauptseite
Zusätzliche Informationen
Datenstrukturen
Dateien
Auflistung der Dateien
Datei-Elemente
Alle
Datenstrukturen
Dateien
Funktionen
Variablen
Makrodefinitionen
Seiten
mainMenu.c
gehe zur Dokumentation dieser Datei
1
#pragma once
2
#include <stdlib.h>
3
#include <stdio.h>
4
#include <string.h>
5
#include <conio.h>
11
void
drawLeftArrow
(
char
* menu,
int
pPos){
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
}
24
void
drawRightArrow
(
char
* menu,
int
pPos){
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
}
32
39
void
drawMainMenu
(
int
pPos){
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
}
62
int
mainMenu
(){
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
90
mainMenuReactToEnter
(pPos);
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
}
115
void
mainMenuReactToEnter
(
int
pPos){
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:
130
showHallOfShame
(
NO_HIGHLIGHT
,0);
131
break
;
132
case
4:
133
showCredits
();
134
break
;
135
case
5:
136
//end game
137
con
=0;
138
//exit(0);
139
}
140
}
showHallOfShame
void showHallOfShame(int highlight, int startFrom)
Definition:
hallofshame.c:13
animateBox
void animateBox(int wFrom, int hFrom, int wTo, int hTo)
Definition:
system.c:392
drawMainMenu
void drawMainMenu(int pPos)
Definition:
mainMenu.c:39
showRules
void showRules()
Definition:
rules.c:35
drawRightArrow
void drawRightArrow(char *menu, int pPos)
Definition:
mainMenu.c:24
setLineAlign
void setLineAlign(int align)
Definition:
system.c:344
flushBuffer
void flushBuffer()
Definition:
system.c:188
startBuffer
void startBuffer(int maxTextLength)
Definition:
system.c:319
gameFunction
void gameFunction()
Definition:
gamefunction.c:28
showCredits
void showCredits()
Definition:
credits.c:6
mainMenu
int mainMenu()
Definition:
mainMenu.c:62
con
int con
Definition:
variables.h:35
drawLeftArrow
void drawLeftArrow(char *menu, int pPos)
Definition:
mainMenu.c:11
NO_HIGHLIGHT
const int NO_HIGHLIGHT
Definition:
variables.h:67
mainMenuReactToEnter
void mainMenuReactToEnter(int pPos)
Definition:
mainMenu.c:115
output
int output(const char *input,...)
Definition:
system.c:144
animateBanner
void animateBanner(int slideIn)
Definition:
system.c:378
4-gewinnt
mainMenu.c
DHBW-MA - TINF13AIBC - Projektmanagement - Team 1337 (Stand: 17.06.2014)