mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-26 09:58:48 +01:00
upper limit for -l, starting from 1 ; number levels
This commit is contained in:
parent
a3da293035
commit
d794acf4a4
1 changed files with 34 additions and 31 deletions
65
star.c
65
star.c
|
@ -7,7 +7,7 @@
|
|||
#include <ncurses.h>
|
||||
#include <getopt.h>
|
||||
|
||||
char *levels[] = { "################"
|
||||
char *levels[] = { "################" /* 0 */
|
||||
"#@## x#H#"
|
||||
"# x ###"
|
||||
"# ##x #"
|
||||
|
@ -17,7 +17,7 @@ char *levels[] = { "################"
|
|||
"# ##x x#"
|
||||
"################",
|
||||
|
||||
" # # # # # ##"
|
||||
" # # # # # ##" /* 1 */
|
||||
"# x @#"
|
||||
" #x #x x "
|
||||
"# # x x # #"
|
||||
|
@ -27,7 +27,7 @@ char *levels[] = { "################"
|
|||
"# # "
|
||||
" # # # ",
|
||||
|
||||
"################"
|
||||
"################" /* 2 */
|
||||
"# x#@#"
|
||||
"# ## ##H#"
|
||||
"# #x x #"
|
||||
|
@ -37,7 +37,7 @@ char *levels[] = { "################"
|
|||
"#x ##x #"
|
||||
"################",
|
||||
|
||||
"################"
|
||||
"################" /* 3 */
|
||||
"# #H#"
|
||||
"# # #"
|
||||
"##x#x x#x#x#x#x#"
|
||||
|
@ -47,7 +47,7 @@ char *levels[] = { "################"
|
|||
"# # #@ #"
|
||||
"################",
|
||||
|
||||
" ############## "
|
||||
" ############## " /* 4 */
|
||||
"#@ # # # #"
|
||||
"# #x # x x # #"
|
||||
"## # # #"
|
||||
|
@ -57,7 +57,7 @@ char *levels[] = { "################"
|
|||
"# # x# #x#"
|
||||
" ############## ",
|
||||
|
||||
" ############"
|
||||
" ############" /* 5 */
|
||||
" # x #x x#"
|
||||
" # x # ##"
|
||||
" # x #"
|
||||
|
@ -67,7 +67,7 @@ char *levels[] = { "################"
|
|||
"#H # x ##x #"
|
||||
"################",
|
||||
|
||||
"################"
|
||||
"################" /* 6 */
|
||||
"# #"
|
||||
" ## ### #x ##x#"
|
||||
" #x #x # # # # "
|
||||
|
@ -77,7 +77,7 @@ char *levels[] = { "################"
|
|||
"# @#x H #x#"
|
||||
"################",
|
||||
|
||||
"############### "
|
||||
"############### " /* 7 */
|
||||
"# x## ##"
|
||||
"# #x ## x #"
|
||||
"# x## # #x #"
|
||||
|
@ -87,7 +87,7 @@ char *levels[] = { "################"
|
|||
"## #"
|
||||
" ###############",
|
||||
|
||||
" # ########### "
|
||||
" # ########### " /* 8 */
|
||||
" #x#x # @#"
|
||||
"#x x# x # "
|
||||
" # # x## x# #"
|
||||
|
@ -97,7 +97,7 @@ char *levels[] = { "################"
|
|||
"# # "
|
||||
"############ ",
|
||||
|
||||
" ########### "
|
||||
" ########### " /* 9 */
|
||||
"#### x #"
|
||||
"# H ###x x# x#"
|
||||
"# x #x #x # "
|
||||
|
@ -107,7 +107,7 @@ char *levels[] = { "################"
|
|||
"# # # # "
|
||||
" ######### # #",
|
||||
|
||||
"################"
|
||||
"################" /* 10 */
|
||||
"# # @#"
|
||||
"# #xx xx ##"
|
||||
"## x ## x#"
|
||||
|
@ -117,7 +117,7 @@ char *levels[] = { "################"
|
|||
"##x### # ##"
|
||||
" ## ########### ",
|
||||
|
||||
"## ## #### "
|
||||
"## ## #### " /* 11 */
|
||||
"#@#####x ### x##"
|
||||
"# xx x #"
|
||||
"# ## ##x #x# #"
|
||||
|
@ -127,7 +127,7 @@ char *levels[] = { "################"
|
|||
"# x #"
|
||||
"################",
|
||||
|
||||
" ############## "
|
||||
" ############## " /* 12 */
|
||||
"# @# x ##"
|
||||
"# # #x x## #"
|
||||
"# x # #"
|
||||
|
@ -137,7 +137,7 @@ char *levels[] = { "################"
|
|||
"#H # x # # #"
|
||||
" ############## ",
|
||||
|
||||
"################"
|
||||
"################" /* 13 */
|
||||
"#x#x x#x#"
|
||||
"# x#@ ## #"
|
||||
"# H x #"
|
||||
|
@ -147,7 +147,7 @@ char *levels[] = { "################"
|
|||
"#x#x x#x#"
|
||||
"################",
|
||||
|
||||
" ###### ####### "
|
||||
" ###### ####### " /* 14 */
|
||||
"# x# x #"
|
||||
"# # x # # x #"
|
||||
"# @# #xx #x #"
|
||||
|
@ -157,7 +157,7 @@ char *levels[] = { "################"
|
|||
"#x x#"
|
||||
" ############## ",
|
||||
|
||||
"################"
|
||||
"################" /* 15 */
|
||||
"## H#x x x#"
|
||||
"#x @x#x ##"
|
||||
"## ### x ##"
|
||||
|
@ -167,7 +167,7 @@ char *levels[] = { "################"
|
|||
"##x# # #"
|
||||
"################",
|
||||
|
||||
"################"
|
||||
"################" /* 16 */
|
||||
"# x# #@ #"
|
||||
"# # x#xx#x # #"
|
||||
"# #x##x# x #"
|
||||
|
@ -177,7 +177,7 @@ char *levels[] = { "################"
|
|||
"# x #x H #"
|
||||
"################",
|
||||
|
||||
"################"
|
||||
"################" /* 17 */
|
||||
"# x x H# #"
|
||||
"# #x#x #x #"
|
||||
"# #x# #x #"
|
||||
|
@ -187,7 +187,7 @@ char *levels[] = { "################"
|
|||
"#x#@ # # #"
|
||||
"################",
|
||||
|
||||
"################"
|
||||
"################" /* 18 */
|
||||
"#x ## ##x#"
|
||||
"# # # #x #"
|
||||
"# x# x## x #"
|
||||
|
@ -197,7 +197,7 @@ char *levels[] = { "################"
|
|||
"# x# #x ##@#"
|
||||
"################",
|
||||
|
||||
"################"
|
||||
"################" /* 19 */
|
||||
"# x#x #"
|
||||
"##x x# ##x ##"
|
||||
"# # # x # # #"
|
||||
|
@ -207,7 +207,7 @@ char *levels[] = { "################"
|
|||
"# x#x #"
|
||||
"################",
|
||||
|
||||
"################"
|
||||
"################" /* 20 */
|
||||
"# ### x ##"
|
||||
"# # # ##"
|
||||
"# ##x x #"
|
||||
|
@ -217,7 +217,7 @@ char *levels[] = { "################"
|
|||
"################"
|
||||
" ",
|
||||
|
||||
"################"
|
||||
"################" /* 21 */
|
||||
"#x# #x# #x # #"
|
||||
"# # #"
|
||||
"#x # #x x #"
|
||||
|
@ -227,7 +227,7 @@ char *levels[] = { "################"
|
|||
"################"
|
||||
" ",
|
||||
|
||||
" ############## "
|
||||
" ############## " /* 22 */
|
||||
"# # #x# #x # #"
|
||||
"# x # #"
|
||||
"## # x #x #"
|
||||
|
@ -237,7 +237,7 @@ char *levels[] = { "################"
|
|||
" ############## "
|
||||
" ",
|
||||
|
||||
"################"
|
||||
"################" /* 23 */
|
||||
"# # ##"
|
||||
"# ##x x ##x##"
|
||||
"# #x x# ###"
|
||||
|
@ -247,7 +247,7 @@ char *levels[] = { "################"
|
|||
"################"
|
||||
" ",
|
||||
|
||||
"################"
|
||||
"################" /* 24 */
|
||||
"# # #"
|
||||
"# x ##x x #"
|
||||
"# #x x ## #"
|
||||
|
@ -464,7 +464,7 @@ void display_level( struct state *s )
|
|||
refresh();
|
||||
}
|
||||
|
||||
int parse_args( int argc, char* argv[], struct options *o )
|
||||
int parse_args( int argc, char* argv[], struct options *o, struct state *s )
|
||||
{
|
||||
int option_index;
|
||||
char c = '?';
|
||||
|
@ -495,7 +495,10 @@ int parse_args( int argc, char* argv[], struct options *o )
|
|||
o->black_and_white = 1;
|
||||
break;
|
||||
case 'l' :
|
||||
o->starting_level = atoi( optarg );
|
||||
o->starting_level = atoi( optarg ) - 1;
|
||||
if ( o->starting_level > s->nb_levels ) {
|
||||
o->starting_level = s->nb_levels - 1;
|
||||
}
|
||||
break;
|
||||
case '?' :
|
||||
case ':' :
|
||||
|
@ -520,10 +523,13 @@ int main( int argc, char* argv[] )
|
|||
struct state *s = malloc( sizeof( struct state ) );
|
||||
struct options *o = malloc( sizeof( struct options ) );
|
||||
|
||||
/* trick to count how many levels we have */
|
||||
s->nb_levels = sizeof( levels ) / sizeof( levels[ 0 ] );
|
||||
|
||||
o->starting_level = 0;
|
||||
o->black_and_white = 0;
|
||||
|
||||
parse_args( argc, argv, o ); /* not caring about return value here, it's treated inside the function */
|
||||
parse_args( argc, argv, o, s ); /* not caring about return value here, it's treated inside the function */
|
||||
|
||||
/* ncurses */
|
||||
WINDOW *w_main = initscr( ); /* why can't stdscr be used transparently? */
|
||||
|
@ -543,9 +549,6 @@ int main( int argc, char* argv[] )
|
|||
init_pair( color_BALL_SELECTED, COLOR_BLUE, COLOR_YELLOW );
|
||||
}
|
||||
|
||||
/* trick to count how many levels we have */
|
||||
s->nb_levels = sizeof( levels ) / sizeof( levels[ 0 ] );
|
||||
|
||||
/* load the first level to start the loop in a correct state */
|
||||
load_level( s, levels, o->starting_level );
|
||||
|
||||
|
|
Loading…
Reference in a new issue