/* * Biloba * Copyright (C) 2004-2005 Guillaume Demougeot, Colin Leroy * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ /** * Biloba - Q1 2005 * Game by Guillaume Demougeot * Code by Colin Leroy * * This file contains the board handling code (drawing * and placing pawns). */ #include #include #include #include #include "utils.h" #include "tile.h" #include "pawn.h" #include "player.h" #include "options.h" #include "font.h" #include "msg.h" static SDL_Surface *border = NULL; static SDL_Surface *player = NULL; void board_build(void) { int x, y; int num = 0, nb_players = 0; for (x = 0; x < MAX_TILES_X; x++) { for (y = 0; y < MAX_TILES_Y; y++) { tile_get(x, y)->pawn = NULL; tile_draw(tile_get(x, y)); } } for (nb_players = 0; nb_players < game_num_players(); nb_players++) { Player *p = NULL; for (num = 0; num < pawn_get_max(); num++) { pawn_draw(pawn_get(num, (PawnColor)nb_players, TRUE)); } p = player_get((PawnColor)nb_players, TRUE, INPUT_LOCAL); player_set_name(p, options_get_player_name(nb_players)); p->method = options_get_player_type(nb_players); } if (!border) { border = biloba_load_image("border.png"); assert(border != NULL); } if (!player) { player = biloba_load_image("player.png"); assert(player != NULL); } put_image(border, X_OFFSET - 36, Y_OFFSET - 36); put_image(player, 10, YS - 70); SDL_UpdateRect(screen, 0, 0, 0, 0); } void board_destroy(void) { tile_free_all(); pawn_free_all(); } void board_refresh(void) { assert(border != NULL); put_image(border, X_OFFSET - 36, Y_OFFSET - 36); } void board_set_player(Player *player) { LList *pawns = pawn_get_all(player->color); Pawn *pawn; char *turn = malloc(strlen(get_msg(M_ROUND))+strlen(player->name)+1); if (!pawns) return; pawn = pawns->data; put_image(pawn->surface, 20, YS - 50); SDL_UpdateRect(screen, 20, YS - 50, 30, 30); strcpy(turn, get_msg(M_ROUND)); strcat(turn, player->name); clear_text(20/* max len, probably */, 20 + 50, YS - 50); draw_message(turn, 20 + 50, YS - 50, FALSE); free(turn); llist_free(pawns); } static int frozen = 0; void board_freeze(void) { frozen++; } void board_thaw(void) { frozen--; if (frozen < 0) frozen = 0; } int board_frozen(void) { return frozen; }