You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

126 lines
2.8 KiB

#include <stdio.h>
#include <SDL/SDL.h>
#include <stdlib.h>
#include <time.h>
#include "api.h"
#include "gui.h"
int main(void) {
struct game_state_t gamestate = {
{ 1,
1,1,
1,1,1,
1,1,1,1,
6,6,6,6,0,0,0,0,0,2,2,2,2,
6,6,6,0,0,0,0,0,0,2,2,2,
6,6,0,0,0,0,0,0,0,2,2,
6,0,0,0,0,0,0,0,0,2,
0,0,0,0,0,0,0,0,0,
5,0,0,0,0,0,0,0,0,3,
5,5,0,0,0,0,0,0,0,3,3,
5,5,5,0,0,0,0,0,0,3,3,3,
5,5,5,5,0,0,0,0,0,3,3,3,3,
4,4,4,4,
4,4,4,
4,4,
4
}
};
struct gui_resource_t gui_res;
gui_res = display_start(&gui_res);
display_render_board(&gui_res, &gamestate, 1, "Name");
int quit = 0;
/* un peu d'interactivité */
SDL_Event event;
if( display_animsg(&gui_res, &gamestate, 1, "Name", "Click to start!", 1200/*ms*/) )
quit = 1;
while(!quit) {
SDL_WaitEvent(&event);
if(event.type == SDL_QUIT) {
quit = 1;
break;
}
if(event.type == SDL_MOUSEBUTTONDOWN)
break;
}
srand(time(NULL));
int pawn1, pawn2, r, i, n;
enum hole_t player1 = 1, player2 = player1;
while(!quit) {
while(player2 == player1)
player2 = (rand()%6)+1;
while(gamestate.board[pawn2 = rand()%121]); /* trouver un trou vide */
pawn1 = pawn2;
/* un pion du joueur courant au hasard. s'il n'y en a pas on déplacera une case vide sur elle-même car pawn1 = pawn2 */
r = rand()%10;
for(n = i = 0; i < 121; i++) {
if(gamestate.board[i] == player1) {
if(n == r) {
pawn1 = i;
break;
}
n++;
}
}
struct move_t user_move;
int moremoves;
if(player1 == 1) {
if( display_animsg(&gui_res, &gamestate, player1, "Name", "Your turn!", 1200/*ms*/) ) {
quit = 1;
break;
}
do {
display_animsg(&gui_res, &gamestate, player1, "Name", "Move a pawn or right-click", 1200/*ms*/);
if( display_usermove_pawn(&gui_res, &gamestate, player1, "Name", &user_move, &moremoves) ) {
quit = 1;
break;
}
if(moremoves) {
gamestate.board[user_move.endPos] = gamestate.board[user_move.startPos];
gamestate.board[user_move.startPos] = none;
}
} while(moremoves);
if(quit)
break;
if( display_animsg(&gui_res, &gamestate, player1, "Name", "You’ve done your move!", 1200/*ms*/) ) {
quit = 1;
break;
}
} else {
if( display_animove_pawn(&gui_res, gamestate, player1, "Name", pawn1, pawn2) ) {
quit = 1;
break;
}
gamestate.board[pawn2] = gamestate.board[pawn1];
gamestate.board[pawn1] = none;
}
if( display_anirotate_board(&gui_res, &gamestate, player1, "Name", player2, "Name2") ) {
quit = 1;
break;
}
if( display_animsg(&gui_res, &gamestate, player2, "Name2", "Next player’s turn!", 1200/*ms*/) ) {
quit = 1;
break;
}
player1 = player2;
}
display_close(&gui_res);
return 0;
}