summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/Makefile.in417
-rw-r--r--src/gamestate.cpp273
-rw-r--r--src/gamestate.h59
-rw-r--r--src/includes.h7
-rw-r--r--src/mazeoflife.cpp90
-rw-r--r--src/mazeoflife.h10
-rw-r--r--src/state.h12
8 files changed, 0 insertions, 871 deletions
diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index 4533bc4..0000000 --- a/src/Makefile.am +++ /dev/null
@@ -1,3 +0,0 @@
1gamesdir = /usr/games
2games_PROGRAMS = mazeoflife
3mazeoflife_SOURCES = mazeoflife.cpp gamestate.cpp
diff --git a/src/Makefile.in b/src/Makefile.in deleted file mode 100644 index 6460691..0000000 --- a/src/Makefile.in +++ /dev/null
@@ -1,417 +0,0 @@
1# Makefile.in generated by automake 1.10.2 from Makefile.am.
2# @configure_input@
3
4# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6# This Makefile.in is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it,
8# with or without modifications, as long as this notice is preserved.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
12# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13# PARTICULAR PURPOSE.
14
15@SET_MAKE@
16
17VPATH = @srcdir@
18pkgdatadir = $(datadir)/@PACKAGE@
19pkglibdir = $(libdir)/@PACKAGE@
20pkgincludedir = $(includedir)/@PACKAGE@
21am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
22install_sh_DATA = $(install_sh) -c -m 644
23install_sh_PROGRAM = $(install_sh) -c
24install_sh_SCRIPT = $(install_sh) -c
25INSTALL_HEADER = $(INSTALL_DATA)
26transform = $(program_transform_name)
27NORMAL_INSTALL = :
28PRE_INSTALL = :
29POST_INSTALL = :
30NORMAL_UNINSTALL = :
31PRE_UNINSTALL = :
32POST_UNINSTALL = :
33games_PROGRAMS = mazeoflife$(EXEEXT)
34subdir = src
35DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
36ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
37am__aclocal_m4_deps = $(top_srcdir)/configure.ac
38am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
39 $(ACLOCAL_M4)
40mkinstalldirs = $(install_sh) -d
41CONFIG_HEADER = $(top_builddir)/config.h
42CONFIG_CLEAN_FILES =
43am__installdirs = "$(DESTDIR)$(gamesdir)"
44gamesPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
45PROGRAMS = $(games_PROGRAMS)
46am_mazeoflife_OBJECTS = mazeoflife.$(OBJEXT) gamestate.$(OBJEXT)
47mazeoflife_OBJECTS = $(am_mazeoflife_OBJECTS)
48mazeoflife_LDADD = $(LDADD)
49DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
50depcomp = $(SHELL) $(top_srcdir)/depcomp
51am__depfiles_maybe = depfiles
52CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
53 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
54CXXLD = $(CXX)
55CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
56 -o $@
57SOURCES = $(mazeoflife_SOURCES)
58DIST_SOURCES = $(mazeoflife_SOURCES)
59ETAGS = etags
60CTAGS = ctags
61DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
62ACLOCAL = @ACLOCAL@
63AMTAR = @AMTAR@
64AUTOCONF = @AUTOCONF@
65AUTOHEADER = @AUTOHEADER@
66AUTOMAKE = @AUTOMAKE@
67AWK = @AWK@
68CC = @CC@
69CCDEPMODE = @CCDEPMODE@
70CFLAGS = @CFLAGS@
71CPP = @CPP@
72CPPFLAGS = @CPPFLAGS@
73CXX = @CXX@
74CXXDEPMODE = @CXXDEPMODE@
75CXXFLAGS = @CXXFLAGS@
76CYGPATH_W = @CYGPATH_W@
77DEFS = @DEFS@
78DEPDIR = @DEPDIR@
79ECHO_C = @ECHO_C@
80ECHO_N = @ECHO_N@
81ECHO_T = @ECHO_T@
82EGREP = @EGREP@
83EXEEXT = @EXEEXT@
84GREP = @GREP@
85INSTALL = @INSTALL@
86INSTALL_DATA = @INSTALL_DATA@
87INSTALL_PROGRAM = @INSTALL_PROGRAM@
88INSTALL_SCRIPT = @INSTALL_SCRIPT@
89INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
90LDFLAGS = @LDFLAGS@
91LIBOBJS = @LIBOBJS@
92LIBS = @LIBS@
93LTLIBOBJS = @LTLIBOBJS@
94MAKEINFO = @MAKEINFO@
95MKDIR_P = @MKDIR_P@
96OBJEXT = @OBJEXT@
97PACKAGE = @PACKAGE@
98PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
99PACKAGE_NAME = @PACKAGE_NAME@
100PACKAGE_STRING = @PACKAGE_STRING@
101PACKAGE_TARNAME = @PACKAGE_TARNAME@
102PACKAGE_VERSION = @PACKAGE_VERSION@
103PATH_SEPARATOR = @PATH_SEPARATOR@
104PKG_CONFIG = @PKG_CONFIG@
105SDL_CFLAGS = @SDL_CFLAGS@
106SDL_LIBS = @SDL_LIBS@
107SET_MAKE = @SET_MAKE@
108SHELL = @SHELL@
109STRIP = @STRIP@
110VERSION = @VERSION@
111abs_builddir = @abs_builddir@
112abs_srcdir = @abs_srcdir@
113abs_top_builddir = @abs_top_builddir@
114abs_top_srcdir = @abs_top_srcdir@
115ac_ct_CC = @ac_ct_CC@
116ac_ct_CXX = @ac_ct_CXX@
117am__include = @am__include@
118am__leading_dot = @am__leading_dot@
119am__quote = @am__quote@
120am__tar = @am__tar@
121am__untar = @am__untar@
122bindir = @bindir@
123build_alias = @build_alias@
124builddir = @builddir@
125datadir = @datadir@
126datarootdir = @datarootdir@
127docdir = @docdir@
128dvidir = @dvidir@
129exec_prefix = @exec_prefix@
130host_alias = @host_alias@
131htmldir = @htmldir@
132includedir = @includedir@
133infodir = @infodir@
134install_sh = @install_sh@
135libdir = @libdir@
136libexecdir = @libexecdir@
137localedir = @localedir@
138localstatedir = @localstatedir@
139mandir = @mandir@
140mkdir_p = @mkdir_p@
141oldincludedir = @oldincludedir@
142pdfdir = @pdfdir@
143prefix = @prefix@
144program_transform_name = @program_transform_name@
145psdir = @psdir@
146sbindir = @sbindir@
147sharedstatedir = @sharedstatedir@
148srcdir = @srcdir@
149sysconfdir = @sysconfdir@
150target_alias = @target_alias@
151top_build_prefix = @top_build_prefix@
152top_builddir = @top_builddir@
153top_srcdir = @top_srcdir@
154gamesdir = /usr/games
155mazeoflife_SOURCES = mazeoflife.cpp gamestate.cpp
156all: all-am
157
158.SUFFIXES:
159.SUFFIXES: .cpp .o .obj
160$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
161 @for dep in $?; do \
162 case '$(am__configure_deps)' in \
163 *$$dep*) \
164 ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
165 && { if test -f $@; then exit 0; else break; fi; }; \
166 exit 1;; \
167 esac; \
168 done; \
169 echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
170 cd $(top_srcdir) && \
171 $(AUTOMAKE) --gnu src/Makefile
172.PRECIOUS: Makefile
173Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
174 @case '$?' in \
175 *config.status*) \
176 cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
177 *) \
178 echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
179 cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
180 esac;
181
182$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
183 cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
184
185$(top_srcdir)/configure: $(am__configure_deps)
186 cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
187$(ACLOCAL_M4): $(am__aclocal_m4_deps)
188 cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
189install-gamesPROGRAMS: $(games_PROGRAMS)
190 @$(NORMAL_INSTALL)
191 test -z "$(gamesdir)" || $(MKDIR_P) "$(DESTDIR)$(gamesdir)"
192 @list='$(games_PROGRAMS)'; for p in $$list; do \
193 p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
194 if test -f $$p \
195 ; then \
196 f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
197 echo " $(INSTALL_PROGRAM_ENV) $(gamesPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(gamesdir)/$$f'"; \
198 $(INSTALL_PROGRAM_ENV) $(gamesPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(gamesdir)/$$f" || exit 1; \
199 else :; fi; \
200 done
201
202uninstall-gamesPROGRAMS:
203 @$(NORMAL_UNINSTALL)
204 @list='$(games_PROGRAMS)'; for p in $$list; do \
205 f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
206 echo " rm -f '$(DESTDIR)$(gamesdir)/$$f'"; \
207 rm -f "$(DESTDIR)$(gamesdir)/$$f"; \
208 done
209
210clean-gamesPROGRAMS:
211 -test -z "$(games_PROGRAMS)" || rm -f $(games_PROGRAMS)
212mazeoflife$(EXEEXT): $(mazeoflife_OBJECTS) $(mazeoflife_DEPENDENCIES)
213 @rm -f mazeoflife$(EXEEXT)
214 $(CXXLINK) $(mazeoflife_OBJECTS) $(mazeoflife_LDADD) $(LIBS)
215
216mostlyclean-compile:
217 -rm -f *.$(OBJEXT)
218
219distclean-compile:
220 -rm -f *.tab.c
221
222@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gamestate.Po@am__quote@
223@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mazeoflife.Po@am__quote@
224
225.cpp.o:
226@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
227@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
228@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
229@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
230@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
231
232.cpp.obj:
233@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
234@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
235@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
236@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
237@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
238
239ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
240 list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
241 unique=`for i in $$list; do \
242 if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
243 done | \
244 $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
245 END { if (nonempty) { for (i in files) print i; }; }'`; \
246 mkid -fID $$unique
247tags: TAGS
248
249TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
250 $(TAGS_FILES) $(LISP)
251 tags=; \
252 here=`pwd`; \
253 list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
254 unique=`for i in $$list; do \
255 if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
256 done | \
257 $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
258 END { if (nonempty) { for (i in files) print i; }; }'`; \
259 if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
260 test -n "$$unique" || unique=$$empty_fix; \
261 $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
262 $$tags $$unique; \
263 fi
264ctags: CTAGS
265CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
266 $(TAGS_FILES) $(LISP)
267 tags=; \
268 list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
269 unique=`for i in $$list; do \
270 if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
271 done | \
272 $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
273 END { if (nonempty) { for (i in files) print i; }; }'`; \
274 test -z "$(CTAGS_ARGS)$$tags$$unique" \
275 || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
276 $$tags $$unique
277
278GTAGS:
279 here=`$(am__cd) $(top_builddir) && pwd` \
280 && cd $(top_srcdir) \
281 && gtags -i $(GTAGS_ARGS) $$here
282
283distclean-tags:
284 -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
285
286distdir: $(DISTFILES)
287 @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
288 topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
289 list='$(DISTFILES)'; \
290 dist_files=`for file in $$list; do echo $$file; done | \
291 sed -e "s|^$$srcdirstrip/||;t" \
292 -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
293 case $$dist_files in \
294 */*) $(MKDIR_P) `echo "$$dist_files" | \
295 sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
296 sort -u` ;; \
297 esac; \
298 for file in $$dist_files; do \
299 if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
300 if test -d $$d/$$file; then \
301 dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
302 if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
303 cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
304 fi; \
305 cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
306 else \
307 test -f $(distdir)/$$file \
308 || cp -p $$d/$$file $(distdir)/$$file \
309 || exit 1; \
310 fi; \
311 done
312check-am: all-am
313check: check-am
314all-am: Makefile $(PROGRAMS)
315installdirs:
316 for dir in "$(DESTDIR)$(gamesdir)"; do \
317 test -z "$$dir" || $(MKDIR_P) "$$dir"; \
318 done
319install: install-am
320install-exec: install-exec-am
321install-data: install-data-am
322uninstall: uninstall-am
323
324install-am: all-am
325 @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
326
327installcheck: installcheck-am
328install-strip:
329 $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
330 install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
331 `test -z '$(STRIP)' || \
332 echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
333mostlyclean-generic:
334
335clean-generic:
336
337distclean-generic:
338 -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
339
340maintainer-clean-generic:
341 @echo "This command is intended for maintainers to use"
342 @echo "it deletes files that may require special tools to rebuild."
343clean: clean-am
344
345clean-am: clean-gamesPROGRAMS clean-generic mostlyclean-am
346
347distclean: distclean-am
348 -rm -rf ./$(DEPDIR)
349 -rm -f Makefile
350distclean-am: clean-am distclean-compile distclean-generic \
351 distclean-tags
352
353dvi: dvi-am
354
355dvi-am:
356
357html: html-am
358
359info: info-am
360
361info-am:
362
363install-data-am: install-gamesPROGRAMS
364
365install-dvi: install-dvi-am
366
367install-exec-am:
368
369install-html: install-html-am
370
371install-info: install-info-am
372
373install-man:
374
375install-pdf: install-pdf-am
376
377install-ps: install-ps-am
378
379installcheck-am:
380
381maintainer-clean: maintainer-clean-am
382 -rm -rf ./$(DEPDIR)
383 -rm -f Makefile
384maintainer-clean-am: distclean-am maintainer-clean-generic
385
386mostlyclean: mostlyclean-am
387
388mostlyclean-am: mostlyclean-compile mostlyclean-generic
389
390pdf: pdf-am
391
392pdf-am:
393
394ps: ps-am
395
396ps-am:
397
398uninstall-am: uninstall-gamesPROGRAMS
399
400.MAKE: install-am install-strip
401
402.PHONY: CTAGS GTAGS all all-am check check-am clean \
403 clean-gamesPROGRAMS clean-generic ctags distclean \
404 distclean-compile distclean-generic distclean-tags distdir dvi \
405 dvi-am html html-am info info-am install install-am \
406 install-data install-data-am install-dvi install-dvi-am \
407 install-exec install-exec-am install-gamesPROGRAMS \
408 install-html install-html-am install-info install-info-am \
409 install-man install-pdf install-pdf-am install-ps \
410 install-ps-am install-strip installcheck installcheck-am \
411 installdirs maintainer-clean maintainer-clean-generic \
412 mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \
413 ps ps-am tags uninstall uninstall-am uninstall-gamesPROGRAMS
414
415# Tell versions [3.59,3.63) of GNU make to not export all variables.
416# Otherwise a system limit (for SysV at least) may be exceeded.
417.NOEXPORT:
diff --git a/src/gamestate.cpp b/src/gamestate.cpp deleted file mode 100644 index 39d589d..0000000 --- a/src/gamestate.cpp +++ /dev/null
@@ -1,273 +0,0 @@
1#include "includes.h"
2
3GameState::GameState()
4{
5 player_color = getColor(255, 255, 0);
6 event_color = getColor(0, 0, 255);
7
8 newGame = false;
9
10 info.playerx = 1;
11 info.playery = 1;
12 info.level = Level();
13 info.doneMaking = false;
14 board = Board(&info);
15
16 SDL_WM_SetCaption("Maze Of Life - Level 1", NULL);
17}
18
19void GameState::input(SDLKey key)
20{
21 if (info.doneMaking)
22 {
23 switch (key)
24 {
25 case SDLK_LEFT:
26 move(info.playerx-1, info.playery);
27
28 break;
29 case SDLK_RIGHT:
30 move(info.playerx+1, info.playery);
31
32 break;
33 case SDLK_UP:
34 move(info.playerx, info.playery-1);
35
36 break;
37 case SDLK_DOWN:
38 move(info.playerx, info.playery+1);
39
40 break;
41 case SDLK_ESCAPE:
42 newGame = false;
43
44 info.playerx = 1;
45 info.playery = 1;
46 info.level = Level();
47 info.doneMaking = false;
48 board = Board(&info);
49
50 SDL_WM_SetCaption("Maze Of Life - Level 1", NULL);
51
52 break;
53 }
54 }
55}
56
57void GameState::tick()
58{
59 if (newGame)
60 {
61 switch (rand()%4)
62 {
63 case 0: info.playerx = 1; info.playery = 1; break;
64 case 1: info.playerx = 1; info.playery = HEIGHT-2; break;
65 case 2: info.playerx = WIDTH-2; info.playery = HEIGHT-2; break;
66 case 3: info.playerx = WIDTH-2; info.playery = 1; break;
67 }
68
69 info.level.incrementLevel();
70 info.doneMaking = false;
71 board = Board(&info);
72 newGame = false;
73
74 char title[32];
75 sprintf(title, "Maze Of Life - Level %d", info.level.getLevel());
76 SDL_WM_SetCaption(title, NULL);
77 }
78
79 board.tick();
80}
81
82void GameState::move(int x, int y)
83{
84 wrap(&x, &y);
85
86 if (board.isObstructed(x,y)) return;
87 if ((x==15)&&(y==15)) newGame = true;
88
89 info.playerx = x;
90 info.playery = y;
91}
92
93void GameState::render(SDL_Surface* screen)
94{
95 // Paint maze
96 board.render(screen);
97
98 // Paint player
99 SDL_Rect block;
100 block.x = info.playerx*16;
101 block.y = info.playery*16;
102 block.w = 16;
103 block.h = 16;
104
105 SDL_FillRect(screen, &block, player_color);
106
107 // Paint event
108 block.x = 15*16;
109 block.y = 15*16;
110
111 SDL_FillRect(screen, &block, event_color);
112}
113
114GameState::Level::Level()
115{
116 level = 1;
117
118 alive[0] = getColor(0, 0, 0); // Black
119 alive[1] = getColor(255, 0, 0); // Red
120 alive[2] = getColor(0, 255, 0); // Green
121 alive[3] = getColor(85, 85, 85); // Dark Gray
122 alive[4] = getColor(255, 0, 255); // Magenta
123
124 dead[0] = getColor(255, 255, 255); // White
125 dead[1] = getColor(255, 192, 203); // Pink
126 dead[2] = getColor(0, 255, 255); // Cyan
127 dead[3] = getColor(170, 170, 170); // Light Gray
128 dead[4] = getColor(255, 128, 0); // Orange
129}
130
131int GameState::Level::getLevel()
132{
133 return level;
134}
135
136bool GameState::Level::checkSquare(int x, int y)
137{
138 switch (level/10+1)
139 {
140 case 1:
141 return ((x>13)&&(x<16)&&(y>13)&&(y<16));
142 case 2:
143 return ((x>13)&&(x<17)&&(y>13)&&(y<17));
144 case 3:
145 case 4:
146 return ((x>12)&&(x<18)&&(y>12)&&(y<18));
147 case 5:
148 case 6:
149 return ((x>11)&&(x<19)&&(y>11)&&(y<19));
150 default:
151 return true;
152 }
153}
154
155Uint32 GameState::Level::getAliveColor()
156{
157 return alive[(level/10)%5];
158}
159
160Uint32 GameState::Level::getDeadColor()
161{
162 return dead[(level/10)%5];
163}
164
165void GameState::Level::incrementLevel()
166{
167 level++;
168}
169
170GameState::Board::Board()
171{
172 GameState::Board::Board(new GameState::Info());
173}
174
175GameState::Board::Board(GameState::Info* info)
176{
177 this->info = info;
178
179 int x,y;
180 for (y=0;y<HEIGHT;y++)
181 {
182 for (x=0;x<WIDTH;x++)
183 {
184 if (info->level.checkSquare(x, y))
185 {
186 blocks[x][y] = rand() % 2;
187 } else {
188 blocks[x][y] = false;
189 }
190 }
191 }
192
193 blocks[15][15] = false;
194}
195
196bool GameState::Board::isObstructed(int x, int y)
197{
198 return blocks[x][y];
199}
200
201void GameState::Board::render(SDL_Surface* screen)
202{
203 SDL_Rect block;
204 block.w = 16;
205 block.h = 16;
206
207 int x,y;
208
209 for (y=0;y<HEIGHT;y++)
210 {
211 for (x=0;x<WIDTH;x++)
212 {
213 block.x = x*16;
214 block.y = y*16;
215
216 SDL_FillRect(screen, &block, (blocks[x][y] ? info->level.getAliveColor() : info->level.getDeadColor()));
217 }
218 }
219}
220
221void GameState::Board::tick()
222{
223 bool temp[WIDTH][HEIGHT];
224 int x,y;
225 for (x=0;x<WIDTH;x++)
226 {
227 for (y=0;y<HEIGHT;y++)
228 {
229 temp[x][y] = blocks[x][y];
230 }
231 }
232
233 for (x=0;x<WIDTH;x++)
234 {
235 for (y=0;y<HEIGHT;y++)
236 {
237 if ((x==15)&&(y==15))
238 {
239 continue;
240 }
241
242 int neighbors = 0;
243
244 if ((x>0)&&(y>0)) incrementIfNeighbor(x-1,y-1,temp,&neighbors);
245 if ((x>0)) incrementIfNeighbor(x-1,y,temp,&neighbors);
246 if ((x>0)&&(y<HEIGHT-1)) incrementIfNeighbor(x-1,y+1,temp,&neighbors);
247 if ((y>0)) incrementIfNeighbor(x,y-1,temp,&neighbors);
248 if ((y<HEIGHT-1)) incrementIfNeighbor(x,y+1,temp,&neighbors);
249 if ((x<WIDTH-1)&&(y>0)) incrementIfNeighbor(x+1,y-1,temp,&neighbors);
250 if ((x<WIDTH-1)) incrementIfNeighbor(x+1,y,temp,&neighbors);
251 if ((x<WIDTH-1)&&(y<HEIGHT-1)) incrementIfNeighbor(x+1,y+1,temp,&neighbors);
252
253 if (temp[x][y])
254 {
255 blocks[x][y] = ((neighbors >= 1) && (neighbors <= 4));
256 } else {
257 blocks[x][y] = (neighbors == 3);
258 }
259 }
260 }
261
262 if (!info->doneMaking && ++gens > 100) info->doneMaking = true;
263}
264
265void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick)
266{
267 wrap(&x, &y);
268
269 if ((temp[x][y])||((info->playerx==x)&&(info->playery==y))||((x==15)&&(y==15)))
270 {
271 ++*tick;
272 }
273}
diff --git a/src/gamestate.h b/src/gamestate.h deleted file mode 100644 index 7d9d798..0000000 --- a/src/gamestate.h +++ /dev/null
@@ -1,59 +0,0 @@
1#ifndef GAMESTATE_H
2#define GAMESTATE_H
3
4class GameState : public State {
5 public:
6 GameState();
7 void input(SDLKey key);
8 void tick();
9 void render(SDL_Surface* screen);
10
11 class Level
12 {
13 private:
14 int level;
15 Uint32 alive[5];
16 Uint32 dead[5];
17
18 public:
19 Level();
20 int getLevel();
21 int getLevelGroup();
22 bool checkSquare(int x, int y);
23 Uint32 getAliveColor();
24 Uint32 getDeadColor();
25 void incrementLevel();
26 };
27
28 struct Info {
29 int playerx, playery;
30 Level level;
31 bool doneMaking;
32 };
33
34 class Board
35 {
36 private:
37 bool blocks[WIDTH][HEIGHT];
38 void incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick);
39 GameState::Info* info;
40 int gens;
41
42 public:
43 Board();
44 Board(GameState::Info* info);
45 bool isObstructed(int x, int y);
46 void render(SDL_Surface* screen);
47 void tick();
48 };
49
50 private:
51 Uint32 player_color;
52 Uint32 event_color;
53 bool newGame;
54 Info info;
55 Board board;
56 void move(int x, int y);
57};
58
59#endif
diff --git a/src/includes.h b/src/includes.h deleted file mode 100644 index a47a307..0000000 --- a/src/includes.h +++ /dev/null
@@ -1,7 +0,0 @@
1#include <SDL.h>
2#include <stdio.h>
3#include <time.h>
4#include <string>
5#include "mazeoflife.h"
6#include "state.h"
7#include "gamestate.h"
diff --git a/src/mazeoflife.cpp b/src/mazeoflife.cpp deleted file mode 100644 index 7819ffd..0000000 --- a/src/mazeoflife.cpp +++ /dev/null
@@ -1,90 +0,0 @@
1#include "includes.h"
2
3SDL_Surface *screen;
4bool gameSleep = false;
5
6int main(int argc, char *argv[])
7{
8 srand(time(NULL));
9
10 /* Initialize defaults, Video and Audio */
11 if((SDL_Init(SDL_INIT_VIDEO)==-1)) {
12 printf("Could not initialize SDL: %s.\n", SDL_GetError());
13 exit(-1);
14 }
15
16 /* Clean up on exit */
17 atexit(SDL_Quit);
18
19 SDL_WM_SetCaption("Maze Of Life", NULL);
20
21 /*
22 * Initialize the display in a 640x480 8-bit palettized mode,
23 * requesting a software surface
24 */
25 screen = SDL_SetVideoMode(WIDTH*16, HEIGHT*16, 8, SDL_DOUBLEBUF);
26 if ( screen == NULL ) {
27 fprintf(stderr, "Couldn't set %dx%dx8 video mode: %s\n", WIDTH*16, WIDTH*16, SDL_GetError());
28 exit(1);
29 }
30
31 SDL_EnableKeyRepeat(100, 50);
32
33 State* state = new GameState();
34
35 SDL_Event anEvent;
36 for (;;)
37 {
38 state->tick();
39
40 while (SDL_PollEvent(&anEvent))
41 {
42 switch (anEvent.type)
43 {
44 case SDL_ACTIVEEVENT:
45 if (anEvent.active.state == SDL_APPINPUTFOCUS)
46 {
47 gameSleep = !anEvent.active.gain;
48 }
49
50 break;
51 case SDL_QUIT:
52 exit(0);
53
54 break;
55 case SDL_KEYDOWN:
56 state->input(anEvent.key.keysym.sym);
57
58 break;
59 }
60 }
61
62 state->render(screen);
63
64 SDL_Flip(screen);
65 }
66
67 exit(0);
68}
69
70void wrap(int* x, int* y)
71{
72 if (*x < 0)
73 {
74 *x = WIDTH-(0-*x);
75 } else if (*y < 0)
76 {
77 *y = HEIGHT-(0-*y);
78 } else if (*x >= WIDTH)
79 {
80 *x = *x-WIDTH;
81 } else if (*y >= HEIGHT)
82 {
83 *y = *y-HEIGHT;
84 }
85}
86
87Uint32 getColor(int r, int g, int b)
88{
89 return SDL_MapRGB(screen->format, r, g, b);
90}
diff --git a/src/mazeoflife.h b/src/mazeoflife.h deleted file mode 100644 index 6af0cf4..0000000 --- a/src/mazeoflife.h +++ /dev/null
@@ -1,10 +0,0 @@
1#ifndef MAZEOFLIFE_H
2#define MAZEOFLIFE_H
3
4const int WIDTH = 30;
5const int HEIGHT = 30;
6
7void wrap(int* x, int* y);
8Uint32 getColor(int r, int g, int b);
9
10#endif
diff --git a/src/state.h b/src/state.h deleted file mode 100644 index 1a97a1b..0000000 --- a/src/state.h +++ /dev/null
@@ -1,12 +0,0 @@
1#ifndef STATE_H
2#define STATE_H
3
4class State
5{
6 public:
7 virtual void input(SDLKey key) = 0;
8 virtual void tick() = 0;
9 virtual void render(SDL_Surface* screen) = 0;
10};
11
12#endif