Skip to content

Commit

Permalink
merged ncurses with master
Browse files Browse the repository at this point in the history
  • Loading branch information
s7rul committed Feb 7, 2018
2 parents 890b862 + 1442138 commit 8207be4
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 168 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TODO for cttt

1 ai 1 player
2 make it interaktive
19 changes: 12 additions & 7 deletions logic.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//all the logical parts of the game
#include <stdlib.h>
#include <stdio.h>
#include <ncurses.h>

void clean_table(int *table){
int n;
Expand Down Expand Up @@ -31,10 +32,12 @@ void place(int *table, int turn, int *xs, int *os){
int input;

while(1 == 1){
printf("Place marker on: ");
scanf("%i", &input);
printw("Place marker on: ");
refresh();
scanw("%i", &input);

printf("input: %d\n", input);
printw("input: %d\n", input);
refresh();

if (table[input - 1] == 0){
table[input - 1] = turn;
Expand All @@ -50,10 +53,12 @@ void take(int *table, int turn, int *xs, int *os){
int input;

while(1 == 1){
printf("take marker from: ");
scanf("%i", &input);
printw("take marker from: ");
refresh();
scanw("%i", &input);

printf("input: %d\n", input);
printw("input: %d\n", input);
refresh();

if (table[input - 1] == turn){
table[input - 1] = 0;
Expand All @@ -68,7 +73,7 @@ void take(int *table, int turn, int *xs, int *os){

void inputfunc(int *table, int turn, int *xs, int *os){

printf("#x: %d #o: %d\n", *xs, *os);
printw("#x: %d #o: %d\n", *xs, *os);

switch(turn){
case(1):
Expand Down
63 changes: 14 additions & 49 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
//main file
#include <stdlib.h>
#include <stdio.h>
#include <ncurses.h>

//functions in logic.c
void clean_table(int *table);
int test_win(int *table, int turn);
void inputfunc(int *table, int turn, int *xs, int *os);

//functions in table.c
//functions in visual.c
void print_table(int *table);
void print_turn(int turn);

void win_message(int turn){
char winner;

if (turn == 1){winner = 'x';}
if (turn == 2){winner = 'o';}

printf("#######################\n");
printf("# #\n");
printf("# %c Won! #\n", winner);
printf("# #\n");
printf("#######################\n");
}
void win_message(int turn);
int menu();


int two_player_loop(){
Expand All @@ -42,9 +32,8 @@ int two_player_loop(){


while(win == 0){
clear();
print_turn(turn);
printf("interger turn:%d\n", turn);
printf("#x: %d #o: %d\n", *xs, *os);
print_table(table);
inputfunc(table, turn, xs, os);
win = test_win(table, turn);
Expand All @@ -63,43 +52,19 @@ int two_player_loop(){
}

int one_player_loop(){
printf("###################\n");
printf("# Under #\n");
printf("# construction! #\n");
printf("###################\n");
move(0, 0);
printw("###################\n");
printw("# Under #\n");
printw("# construction! #\n");
printw("###################\n");
refresh();
getch();
}

int menu(){
int * shoice = (int *) malloc(sizeof(int));

printf("###################\n");
printf("# 1 - two player #\n");
printf("# 2 - one player #\n");
printf("# 3 - quit #\n");
printf("###################\n");
printf("Your shoice: ");
scanf("%d", shoice);

switch(*shoice){
case 1:
free(shoice);
two_player_loop();
break;
case 2:
free(shoice);
one_player_loop();
break;
case 3:
free(shoice);
return 0;
break;
}

menu();
}

int main(){
printf("Hello and wealcome to tic tac toe writhen in c.\n");
initscr();
menu();
endwin();
return 0;
}
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cttt: main.c logic.c table.c
gcc main.c logic.c table.c -fhosted -o cttt
cttt: main.c logic.c visual.c
gcc main.c logic.c visual.c -fhosted -lncurses -o cttt
110 changes: 0 additions & 110 deletions table.c

This file was deleted.

Loading

0 comments on commit 8207be4

Please sign in to comment.