summaryrefslogtreecommitdiffstats
path: root/src/ctrl/start.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ctrl/start.c')
-rwxr-xr-xsrc/ctrl/start.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/ctrl/start.c b/src/ctrl/start.c
new file mode 100755
index 0000000..1e62b88
--- /dev/null
+++ b/src/ctrl/start.c
@@ -0,0 +1,110 @@
+/******************************************************************************
+ * Copyright (C) 2015 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "mine-sweeper/ctrl/start.h"
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "mine-sweeper/game/core.h"
+#include "mine-sweeper/game/iface.h"
+#include "mine-sweeper/menu/iface.h"
+#include "mine-sweeper/player/iface.h"
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+int start_mode;
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void start_foo (void);
+static void start_rand (void);
+static void start_load (void);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+void start_switch (void)
+{
+
+ switch (start_mode) {
+ case START_FOO:
+ start_foo();
+ break;
+ case START_RAND:
+ start_rand();
+ break;
+ case START_LOAD:
+ start_load();
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void start_foo (void)
+{
+}
+
+static void start_rand (void)
+{
+ int level;
+ ptrdiff_t rows, cols;
+ int mines;
+ ptrdiff_t r, c;
+
+ menu_iface_board(&level, &rows, &cols, &mines);
+ player_iface_init(rows, cols);
+ if (player_iface_start(&r, &c))
+ goto err;
+ game_init_rand(rows, cols, mines, r, c);
+ game_iface_init_rand(level, r, c);
+
+ /* game loop */
+ game_iface();
+
+err:
+ player_iface_cleanup();
+}
+
+static void start_load (void)
+{
+ ptrdiff_t rows, cols;
+
+ /* size & game init (sets errno) */
+ errno = 0;
+ if (game_init_load(&rows, &cols))
+ goto err;
+
+ player_iface_init(rows, cols);
+ game_iface_init_load();
+
+ /* game loop */
+ game_iface();
+
+ player_iface_cleanup();
+ return;
+
+err:
+ fprintf(stderr, "%s:%i: %s(): %s", __FILE__, __LINE__, __func__,
+ strerror(errno));
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/