Added support for quitting without ^C, and outputting to file
This commit is contained in:
parent
6d879da5fa
commit
d0c257b310
5 changed files with 68 additions and 23 deletions
23
ui_vt100.c
23
ui_vt100.c
|
|
@ -94,7 +94,7 @@ void updateBoard(
|
|||
printf( "\033[2K\n" );
|
||||
}
|
||||
|
||||
int askColumn(
|
||||
columnsint_t askColumn(
|
||||
const board_t board
|
||||
){
|
||||
columnsint_t column;
|
||||
|
|
@ -102,21 +102,16 @@ int askColumn(
|
|||
printf( "Wher player %d put? ", board.player );
|
||||
printf( "\033[K" ); // clear everything after cursor
|
||||
fflush( stdout );
|
||||
column = -1;
|
||||
column = 0;
|
||||
for( char ch = '0'; ch != '\n'; read( STDIN_FILENO, &ch, 1 ) ){
|
||||
if( ch >= '0' && ch <= '9' ){
|
||||
if( column == -1 )
|
||||
column = 0;
|
||||
else
|
||||
column *= 10;
|
||||
if( column >= 0 )
|
||||
column += (columnsint_t)( ch - '0' );
|
||||
} else {
|
||||
column = -2;
|
||||
}
|
||||
column *= 10;
|
||||
column += (columnsint_t)( ch - '0' );
|
||||
} else return QUITCOLUMN;
|
||||
}
|
||||
if( column < FIRST_NUMBER ) return QUITCOLUMN;
|
||||
column -= FIRST_NUMBER;
|
||||
if( column >= 0 && column < board.columns )
|
||||
if( column < board.columns )
|
||||
if( board.height [ column ] < board.rows )
|
||||
return column;
|
||||
else printf( "\033[2Apls enter a column that ain't full" );
|
||||
|
|
@ -126,6 +121,10 @@ int askColumn(
|
|||
}
|
||||
}
|
||||
|
||||
void exit_ui(void){
|
||||
printf( "\n" );
|
||||
}
|
||||
|
||||
#undef BOARD_WIDTH_CHARS
|
||||
#undef SCOREBOARD_OFFSET
|
||||
#undef SCOREBOARD_WIDTH
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue