3D Game of Life implementation in c++
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gameoflife.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* GameOfLife - Conway's Game of Life in 3D
  2. *
  3. * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
  4. * http://www.seba-geek.de
  5. *
  6. * This file is part of GameOfLife.
  7. *
  8. * GameOfLife is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * GameOfLife is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GameOfLife. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef __GAMEOFLIFE_H
  22. #define __GAMEOFLIFE_H
  23. #include <string>
  24. #include <fstream>
  25. #include <SDL_opengl.h>
  26. #include <cstdlib>
  27. #include <ctime>
  28. #include <SDL.h>
  29. #include "emath.h"
  30. #include "punkt2d.h"
  31. typedef enum { dead=0, alife, dies, born } State;
  32. class GameOfLife {
  33. private:
  34. State **feld;
  35. int x, y;
  36. bool torus;
  37. bool fullcelluse;
  38. unsigned long generation;
  39. GLUquadricObj *quad;
  40. // Brett
  41. float thickness;
  42. float cellwidth;
  43. // Cylinder
  44. float radius;
  45. float height;
  46. int parts;
  47. float *sinval;
  48. float *cosval;
  49. //render
  50. bool view3d;
  51. float sectobuild;
  52. float b_secdone;
  53. float secpertick;
  54. float t_secdone;
  55. // Edit
  56. segl::Punkt2D setpos;
  57. bool editmode;
  58. void init();
  59. void allocate();
  60. void cleanup();
  61. void renderBrett();
  62. void renderStein(State s);
  63. void translateTo(int _x, int _y);
  64. void lockStates();
  65. public:
  66. GameOfLife(int _x, int _y);
  67. GameOfLife(int _x, int _y, int r_life, int r_dead);
  68. GameOfLife(std::string file);
  69. ~GameOfLife();
  70. void set3D(bool on);
  71. bool load(std::string file);
  72. bool save(std::string file);
  73. void fillRandom(int _x, int _y, int r_life, int r_dead);
  74. // void toggle(int _x, int _y);
  75. void setEditMode(bool e);
  76. void move(int up, int right);
  77. void toggle();
  78. float getTickSec();
  79. float getBuildSec();
  80. void setTickSec(float s);
  81. void setBuildSec(float s);
  82. void setTorus(bool t);
  83. unsigned long getGeneration();
  84. // const bool** getFeld();
  85. void tick();
  86. void render(float sec);
  87. void clear();
  88. };
  89. #endif