game input and output
This commit is contained in:
parent
a517eda978
commit
18a2be5f62
42
src/main.cpp
42
src/main.cpp
@ -1,5 +1,45 @@
|
||||
#include <cstdio>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
// 0 | 1 | 2
|
||||
// ---------
|
||||
// 3 | 4 | 5
|
||||
// ---------
|
||||
// 6 | 7 | 8
|
||||
|
||||
#define TILE_COUNT 9
|
||||
|
||||
int get_player_input(){
|
||||
//TODO get player input
|
||||
return rand()%9;
|
||||
}
|
||||
|
||||
struct game_state {
|
||||
int turn;
|
||||
char board[TILE_COUNT];
|
||||
};
|
||||
|
||||
void game_turn(struct game_state * gs,int player_input){
|
||||
if(player_input > TILE_COUNT && player_input < 0)
|
||||
fprintf(stderr,"ERR: player input not in range.");
|
||||
if(!gs->board[player_input])
|
||||
gs->board[player_input]='O';
|
||||
gs->turn++;
|
||||
}
|
||||
|
||||
void display_game_state(struct game_state * gs){
|
||||
printf("turn %i:\n",gs->turn);
|
||||
for(int i=0;i<TILE_COUNT;i++){
|
||||
printf("[%i]:%c\n",i,gs->board[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
printf("our dick\n");
|
||||
srand(time(NULL));
|
||||
struct game_state gs = {0};
|
||||
while(gs.turn<TILE_COUNT){
|
||||
game_turn(&gs,get_player_input());
|
||||
display_game_state(&gs);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user