Commit 5325c76d authored by Jonathan Michalon's avatar Jonathan Michalon

Beginning of player implementation.

New source file player.c, new module player (compilation, documentation).
New function handling a request from player to add a tile at a given position.
Updated test to use it (in addition of the other tests).
parent b202d49a
......@@ -22,6 +22,7 @@
<xi:include href="xml/tileset.xml"/>
<xi:include href="xml/stack.xml"/>
<xi:include href="xml/board.xml"/>
<xi:include href="xml/player.xml"/>
<xi:include href="xml/xmlutils.xml"/>
</chapter>
......
......@@ -29,6 +29,7 @@ ovcc_tileset_size
<SECTION>
<FILE>player</FILE>
<TITLE>Player</TITLE>
ovcc_player_request_tile_addition
</SECTION>
<SECTION>
......
......@@ -2,11 +2,12 @@ lib_LTLIBRARIES = libovcc.la
noinst_PROGRAMS = test
libovcc_la_CPPFLAGS = -DG_LOG_DOMAIN=\"libovcc\"
libovcc_la_SOURCES = tile.c \
libovcc_la_SOURCES = board.c \
player.c \
stack.c \
tile.c \
tileset.c \
tilesdef.c \
stack.c \
board.c \
xmlutils.c
test_LDADD = libovcc.la -lpthread
......
/*
*
* Copyright (C) 2009 Colomban Wendling <ban@herbesfolles.org>
* Jonathan Michalon <studios.chalmion@no-log.org>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "player.h"
#include <glib.h>
#include "tile.h"
#include "board.h"
/**
* SECTION: player
* @short_description: Implementation of OVCC players
* @include: libovcc/player.h
*
* This is the API of the players for OVCC.
*/
/**
* ovcc_player_request_tile_addition:
* @board: An #OVCCBoard, on which to add the tile.
* @tile: An #OVCCTile, the tile to add.
* @pos: The #OVCCPosition where to add the tile on the board.
*
* This routine manages the request of a player to add a tile on the
* board, making all tests needed and returning the consequent bits.
*/
OVCCPlayerResult
ovcc_player_request_tile_addition (OVCCBoard *board,
OVCCTile *tile,
OVCCPosition *pos)
{
if (ovcc_board_add_tile_check (board, tile, pos)) {
ovcc_board_add_tile (board, tile, pos);
return OVCC_PLAYER_ACTION_COMPLETED;
}
return OVCC_PLAYER_ERROR_ENCOUNTERED;
}
......@@ -21,9 +21,34 @@
#ifndef H_OVCC_PLAYER
#define H_OVCC_PLAYER
#include <glib.h>
#include "tile.h"
#include "board.h"
G_BEGIN_DECLS
/**
* OVCCPlayerResult:
* @OVCC_PLAYER_ACTION_COMPLETED: The requeted action has been successfully
* completed, without any problem.
* @OVCC_PLAYER_ERROR_ENCOUNTERED: The requested action has not been executed
* because of an unrecoverable error.
*
* Status of a request made to the player.
*/
typedef enum
{
OVCC_PLAYER_ACTION_COMPLETED,
OVCC_PLAYER_ERROR_ENCOUNTERED
} OVCCPlayerResult;
OVCCPlayerResult ovcc_player_request_tile_addition (OVCCBoard *board,
OVCCTile *tile,
OVCCPosition *pos);
G_END_DECLS
#endif /* guard */
......@@ -27,6 +27,7 @@
#include "tileset.h"
#include "tile.h"
#include "board.h"
#include "player.h"
static gboolean
......@@ -109,6 +110,42 @@ test_board (OVCCStack *stack)
return n_failed == 0;
}
static void
test_player (OVCCStack *stack)
{
OVCCTile *tile;
OVCCBoard *board;
OVCCPosition pos;
int answer;
int wise;
board = ovcc_board_new (stack);
while (NULL != (tile = ovcc_stack_pop (stack))) {
ovcc_board_dump (board);
g_print ("The tile to place is:\n");
ovcc_tile_dump (tile, OVCC_TILE_DUMP_ALL);
do {
g_print ("Put (0) or rotate (1)? [01] ");
scanf ("%d", &answer);
if (answer) {
g_print ("How much (clockwise)? ");
scanf ("%d", &wise);
ovcc_tile_rotate (tile, wise);
g_print ("Now the tile is:");
ovcc_tile_dump (tile, OVCC_TILE_DUMP_ALL);
} else {
g_print ("Put at position: (x y) ");
scanf ("%d %d", &pos.x, &pos.y);
}
}
while (answer != 0 ||
ovcc_player_request_tile_addition (board, tile, &pos) !=
OVCC_PLAYER_ACTION_COMPLETED);
ovcc_tile_unref (tile);
}
ovcc_board_free (board);
}
int
main (int argc,
char **argv)
......@@ -152,7 +189,10 @@ main (int argc,
if (! test_board (stack)) {
g_warning ("Some tiles were not placed!");
}
ovcc_stack_free (stack);
stack = ovcc_stack_new_from_tileset (set);
test_player (stack);
ovcc_stack_free (stack);
}
g_object_unref (file_set);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment