Added option to input via arrow keys
This commit is contained in:
parent
30c1b383e5
commit
70b1eef1d6
1 changed files with 25 additions and 3 deletions
28
connect4.c
28
connect4.c
|
|
@ -47,6 +47,8 @@
|
||||||
|
|
||||||
#define ONLYPUT
|
#define ONLYPUT
|
||||||
|
|
||||||
|
#define ARROWS
|
||||||
|
|
||||||
#ifndef ONLYPUT
|
#ifndef ONLYPUT
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PUT,
|
PUT,
|
||||||
|
|
@ -276,6 +278,27 @@ static int askColumn(
|
||||||
#endif /* ONLYPUT */
|
#endif /* ONLYPUT */
|
||||||
){
|
){
|
||||||
int column = 0;
|
int column = 0;
|
||||||
|
#ifdef ARROWS
|
||||||
|
move( BOARD_Y, BOARD_X );
|
||||||
|
if( board.player ) addstr( "1" );
|
||||||
|
else addstr( "0" );
|
||||||
|
for(;;){
|
||||||
|
int ch = mvgetch(
|
||||||
|
BOARD_Y + BOARD_DY * ( BOARD_HEIGTH - board.heigth[ column ] ),
|
||||||
|
BOARD_X + 1 + BOARD_DX * ( column + 1 )
|
||||||
|
);
|
||||||
|
switch( ch ){
|
||||||
|
case KEY_RIGHT:
|
||||||
|
column += ( column < BOARD_WIDTH - 1 );
|
||||||
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
|
column -= ( column > 0 );
|
||||||
|
break;
|
||||||
|
case KEY_DOWN:
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else /* !ARROWS */
|
||||||
for(;;){
|
for(;;){
|
||||||
mvaddstr(
|
mvaddstr(
|
||||||
INPUT_Y,
|
INPUT_Y,
|
||||||
|
|
@ -290,7 +313,6 @@ static int askColumn(
|
||||||
#endif /* ONLYPUT */
|
#endif /* ONLYPUT */
|
||||||
addstr( " put the piece? " );
|
addstr( " put the piece? " );
|
||||||
#ifndef ONLYPUT
|
#ifndef ONLYPUT
|
||||||
break;
|
|
||||||
case POP:
|
case POP:
|
||||||
addstr( " pop a piece? " );
|
addstr( " pop a piece? " );
|
||||||
}
|
}
|
||||||
|
|
@ -304,8 +326,7 @@ static int askColumn(
|
||||||
INPUT_X
|
INPUT_X
|
||||||
);
|
);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
if( column >= 0 && column < BOARD_WIDTH ) // The collumn--; is a really
|
if( column >= 0 && column < BOARD_WIDTH )
|
||||||
// temporary placeholder to make the unfinished shit compile at least
|
|
||||||
#ifndef ONLYPUT
|
#ifndef ONLYPUT
|
||||||
switch( move ){
|
switch( move ){
|
||||||
case PUT:
|
case PUT:
|
||||||
|
|
@ -323,6 +344,7 @@ static int askColumn(
|
||||||
#endif /* ! ONLYPUT */
|
#endif /* ! ONLYPUT */
|
||||||
else addstr( "Pls enter a column that exists" );
|
else addstr( "Pls enter a column that exists" );
|
||||||
}
|
}
|
||||||
|
#endif /* ! ARROWS */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ONLYPUT
|
#ifndef ONLYPUT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue