source: trunk/c_abi.cxx @ 14

Last change on this file since 14 was 5, checked in by jtv, 14 years ago

Implemented saving/restoring of game state

File size: 2.1 KB
Line 
1/*
2This file is part of libmines.
3
4Copyright (C) 2005, Jeroen T. Vermeulen <jtv@xs4all.nl>
5
6libmines is free software; you can redistribute it and/or modify it under the
7terms of the GNU General Public License as published by the Free Software
8Foundation; either version 2 of the License, or (at your option) any later
9version.
10
11libmines is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License along with
16libmines; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17Suite 330, Boston, MA  02111-1307  USA
18*/
19#include <set>
20
21#include "gamelogic.hxx"
22#include "c_abi.h"
23
24using namespace std;
25
26namespace
27{
28Lake *castback(Minefield *f)
29{
30  return static_cast<Lake *>(f);
31}
32
33const Lake *castback(const Minefield *f)
34{
35  return static_cast<const Lake *>(f);
36}
37} // namespace
38
39extern "C"
40{
41Minefield *mines_init(int rows, int cols, int mines)
42{
43  return new Lake(rows, cols, mines);
44}
45
46
47Minefield *mines_load(const char buffer[])
48{
49  return new Lake(buffer);
50}
51
52
53void mines_close(Minefield *f)
54{
55  delete castback(f);
56}
57
58
59int mines_save(Minefield *f, char buffer[])
60{
61  return castback(f)->save(buffer);
62}
63
64
65int mines_max_intelligence()
66{
67  return Lake::max_intelligence();
68}
69
70
71void mines_set_intelligence(Minefield *f, int i)
72{
73  castback(f)->set_intelligence(i);
74}
75
76
77int mines_probe(Minefield *f, int row, int col, int minedP)
78{
79  try
80  {
81    set<Coords> changes;
82    castback(f)->probe(row,col,changes,minedP);
83  }
84  catch (const Boom &)
85  {
86    return 0;
87  }
88  catch (const exception &)
89  {
90    return -1;
91  }
92  return 1;
93}
94
95
96int mines_moves(const Minefield *f)
97{
98  return castback(f)->moves();
99}
100
101char mines_at(const Minefield *f, int row, int col)
102{
103  return castback(f)->status_at(row,col);
104}
105
106int mines_togo(const Minefield *f)
107{
108  return castback(f)->to_go();
109}
110
111int mines_rows(const Minefield *f)
112{
113  return castback(f)->rows();
114}
115
116int mines_cols(const Minefield *f)
117{
118  return castback(f)->cols();
119}
120
121} // extern "C"
122
Note: See TracBrowser for help on using the repository browser.