modif jeu avec match nul
This commit is contained in:
parent
3264ccfe28
commit
84329b651b
4
.gitignore
vendored
4
.gitignore
vendored
@ -53,4 +53,6 @@ Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# VSCode files
|
||||
.vscode
|
||||
.vscode
|
||||
|
||||
morpion
|
@ -56,7 +56,7 @@ void init_graphics(int W, int H) {
|
||||
printf("SDL_ttf absent : affichage dans la console.\n");
|
||||
#endif
|
||||
|
||||
fill_screen(noir);
|
||||
fill_screen(white);
|
||||
affiche_auto_on();
|
||||
affiche_all();
|
||||
|
||||
|
45
jeu.c
45
jeu.c
@ -3,7 +3,7 @@
|
||||
void init_board(int board[10][10]) {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
for(int j = 0; j < 10; j++) {
|
||||
board[i][j] = 0;
|
||||
board[i][j] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -14,19 +14,52 @@ void draw_board(int board[10][10]) {
|
||||
for(int j = 0; j < 10; j++) {
|
||||
p1.x = i*60+60; p1.y = 0;
|
||||
p2.x = i*60+60; p2.y = 600;
|
||||
draw_line(p1,p2,blanc);
|
||||
draw_line(p1,p2,black);
|
||||
p1.y = i*60+60; p1.x = 0;
|
||||
p2.y = i*60+60; p2.x = 600;
|
||||
draw_line(p1,p2,blanc);
|
||||
draw_player(board, i, j);
|
||||
draw_line(p1,p2,black);
|
||||
// draw_player(board, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_player(int board[10][10] ,int i, int j) {
|
||||
point p = {i*60+30, j*60+30};
|
||||
if(board[i][j] == 1)
|
||||
if(board[i][j] == 0)
|
||||
draw_cross(p, 60, blue);
|
||||
if(board[i][j] == 2)
|
||||
if(board[i][j] == 1)
|
||||
draw_circle(p, 30, red);
|
||||
}
|
||||
|
||||
void play(int board[10][10]) {
|
||||
int* winner = malloc(sizeof(int));
|
||||
int joueur = 1;
|
||||
while(fin(board, winner)) {
|
||||
point p = wait_clic();
|
||||
int pos[2];
|
||||
pos[0] = p.x/60;
|
||||
pos[1] = p.y/60;
|
||||
if(board[pos[0]][pos[1]]==-1) {
|
||||
board[pos[0]][pos[1]] = joueur;
|
||||
joueur = 1-joueur;
|
||||
}
|
||||
draw_player(board, pos[0], pos[1]);
|
||||
}
|
||||
free(winner);
|
||||
}
|
||||
|
||||
int fin(int board[10][10], int *winner) {
|
||||
|
||||
int k = 0;
|
||||
for(int i = 0; i < 10; i++) {
|
||||
for(int j = 0; j < 10; j++) {
|
||||
if(board[i][j]!=-1)
|
||||
k++;
|
||||
}
|
||||
}
|
||||
if(k>=100) {
|
||||
*winner = -1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
4
jeu.h
4
jeu.h
@ -2,14 +2,14 @@
|
||||
#define JEU_H
|
||||
#include "graphics.h"
|
||||
|
||||
int board[10][10];
|
||||
|
||||
void init_board(int[10][10]);
|
||||
|
||||
void draw_board(int[10][10]);
|
||||
|
||||
void draw_player(int[10][10] ,int, int);
|
||||
|
||||
void play(int[10][10]);
|
||||
|
||||
int fin(int[10][10], int*);
|
||||
|
||||
#endif
|
7
main.c
7
main.c
@ -1,11 +1,14 @@
|
||||
#include "jeu.h"
|
||||
|
||||
int main() {
|
||||
int board[10][10];
|
||||
init_graphics(600,600);
|
||||
fill_screen(white);
|
||||
init_board(board);
|
||||
board[2][6] = 1;
|
||||
board[3][8] = 2;
|
||||
// board[2][6] = 1;
|
||||
// board[3][8] = 2;
|
||||
draw_board(board);
|
||||
play(board);
|
||||
wait_escape();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user