Commit 5dc3642e authored by Jonathan Michalon's avatar Jonathan Michalon

Begun to implement the stack of tiles

Added a function to tileset module that computes the total number of tiles
in a tileset.
parent 926517ee
......@@ -4,6 +4,7 @@ noinst_PROGRAMS = test
libovcc_la_CPPFLAGS = -DG_LOG_DOMAIN=\"libovcc\"
libovcc_la_SOURCES = tile.c \
tileset.c \
stack.c \
board.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 <glib.h>
#include "stack.h"
#include "tileset.h"
struct s_OVCCStack
{
GSList *stack;
};
/**
* @brief Creates a new Stack of tiles
* @returns The newly created Stack
*
*/
static OVCCStack *
ovcc_stack_new (void)
{
OVCCStack *stack;
stack = g_malloc (sizeof *stack);
if (stack) {
stack->stack = NULL;
}
return stack;
}
/**
* @brief Create the Stack from a Tileset
* @return The stack, ready to use
*
*/
OVCCStack *
ovcc_create_stack (OVCCTileSet *set)
{
OVCCStack *stack;
guint ntiles;
gboolean *placed;
gint current;
int i, nplaced = 0;
stack = ovcc_stack_new ();
ntiles = ovcc_tileset_size (set);
placed = g_malloc0 (sizeof(gboolean) * ntiles);
while (nplaced<ntiles) {
current = g_random_int_range (0, ntiles-1);
if (!placed[current]) {
placed[current] = TRUE;
nplaced++;
/*ovcc_stack_append (*/
}
}
}
/*
*
* 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/>.
*
*/
#ifndef H_OVCC_STACK
#define H_OVCC_STACK
typedef struct s_OVCCStack OVCCStack;
#endif /* guard */
......@@ -128,6 +128,18 @@ ovcc_tileset_is_empty (OVCCTileSet *set)
return g_hash_table_size (set->tiles) == 0;
}
/**
* @brief Give the number of tiles in the TileSet
* @param set A TileSet
* @return The number of tiles in the TileSet.
*
*/
guint
ovcc_tileset_size (OVCCTileSet *set)
{
return g_hash_table_size (set->tiles);
}
/**
* @brief Add a Tile to a TileSet
* @param set The TileSet to use
......
......@@ -43,6 +43,7 @@ gboolean ovcc_tileset_remove (OVCCTileSet *set,
gboolean ovcc_tileset_has_tile (OVCCTileSet *set,
OVCCTileID id);
gboolean ovcc_tileset_is_empty (OVCCTileSet *set);
guint ovcc_tileset_size (OVCCTileSet *set);
#endif /* guard */
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