From a84b5918b9cbc44dcedd127394528729a02f069f Mon Sep 17 00:00:00 2001 From: simonkellet Date: Sun, 22 May 2022 11:54:30 +0100 Subject: [PATCH] added options for single player and two player --- main.c | 49 ++++++++++++++++++++++++++++++++++++------------- ttt | Bin 19552 -> 19616 bytes 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index 62edd49..b2eca5a 100644 --- a/main.c +++ b/main.c @@ -24,26 +24,49 @@ int free_spaces(); int main(int argc, char *argv[]){ char flag = ' '; + int players; clear_board(); + + printf("How many players? (1/2)\n> "); + scanf("%d", &players); - do{ - flag = check_win(); - if(free_spaces() == 0){ - break; - } + //this could be tidier i think + if(players == 1){ + do{ + flag = check_win(); + if(free_spaces() == 0){ + break; + } + + print_board(); + + player_choice('X'); + print_board(); - print_board(); + cpu_choice('O'); + flag = check_win(); + print_board(); - player_choice('X'); - flag = check_win(); - print_board(); + } while(flag == ' '); - player_choice('O'); - flag = check_win(); - print_board(); + } else if(players == 2){ + do{ + flag = check_win(); + if(free_spaces() == 0){ + break; + } - } while(flag == ' '); + print_board(); + player_choice('X'); + print_board(); + + player_choice('O'); + flag = check_win(); + print_board(); + + } while(flag == ' '); + } if(flag == ' ') printf(BOLDMAGENTA "\nNo-one won!" RESET); else diff --git a/ttt b/ttt index 7e66a8c1d2bb0412081b4f7c62bf0b9c19f62d58..36a415fc93d736648513c024b224a27dc158ef9d 100755 GIT binary patch delta 2891 zcmZ8jeQZgNC*tfRU1aL;!15*wQDEjg32Zl3M-HbZA_gs)@o{3isUYVCM4a+V0k;|9VfMT z(!1xJ-}#;2{dmXk`Kx0*@oRphgeT&qU)sksW?o}5o0mI$7K(h9cf z7`}hl{}g>C`%uq&uJbPr?SJ>@;cXTBlf9N2cdRMWZGET&Y9d{sI~C_HhDHJ(p+f4o z0@xwpbYtogVH?K{BXTG-8tJ-te`+VBx|2W1J=hmvL)HwPFCh2wOCy1{-hnOVbjrkZ{h72!%<0;ekiy%j zx&l>qP0n-_v84>=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