game.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: game.h
  3. // Purpose: Bombs game
  4. // Author: P. Foggia 1996
  5. // Modified by: Wlodzimierz Skiba (ABX) since 2003
  6. // Created: 1996
  7. // Copyright: (c) 1996 P. Foggia
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_DEMOS_BOMBS_GAME_H_
  11. #define _WX_DEMOS_BOMBS_GAME_H_
  12. #define BG_HIDDEN 0x100
  13. #define BG_BOMB 0x200
  14. #define BG_MARKED 0x400
  15. #define BG_EXPLODED 0x800
  16. #define BG_SELECTED 0x080
  17. #define BG_MASK 0x03F
  18. #include <stddef.h>
  19. class BombsGame
  20. {
  21. public:
  22. BombsGame()
  23. {
  24. m_width = m_height = 0;
  25. m_field = NULL;
  26. };
  27. ~BombsGame();
  28. int GetWidth() const { return m_width; };
  29. int GetHeight() const { return m_height; };
  30. int Get(int x, int y) const
  31. {
  32. return m_field[x+y*m_width];
  33. };
  34. int IsFocussed(int x, int y) const
  35. {
  36. return (m_gridFocusX == x) && (m_gridFocusY == y);
  37. }
  38. int IsHidden(int x, int y) const
  39. {
  40. return Get(x,y) & BG_HIDDEN;
  41. };
  42. int IsMarked(int x, int y) const
  43. {
  44. return Get(x,y) & BG_MARKED;
  45. };
  46. int IsBomb(int x, int y) const
  47. {
  48. return Get(x,y) & BG_BOMB;
  49. };
  50. int IsExploded(int x, int y) const
  51. {
  52. return Get(x,y) & BG_EXPLODED;
  53. };
  54. int IsSelected(int x, int y) const
  55. {
  56. return Get(x,y) & BG_SELECTED;
  57. };
  58. int GetNumBombs() const
  59. {
  60. return m_numBombCells;
  61. };
  62. int GetNumRemainingCells() const
  63. {
  64. return m_numRemainingCells;
  65. };
  66. int GetNumMarkedCells() const
  67. {
  68. return m_numMarkedCells;
  69. };
  70. bool Init(int width, int height, bool easyCorner = false);
  71. // Marks/unmarks a cell
  72. void Mark(int x, int y);
  73. // Unhides a cell
  74. void Unhide(int x, int y, bool b_selected);
  75. // Makes a cell exploded
  76. void Explode(int x, int y);
  77. int m_gridFocusX;
  78. int m_gridFocusY;
  79. private:
  80. // Current difficulty level (Determines grid size).
  81. //int m_level;
  82. int m_width, m_height;
  83. short *m_field;
  84. int m_numBombCells, m_numRemainingCells, m_numMarkedCells;
  85. };
  86. #endif // #ifndef _WX_DEMOS_BOMBS_GAME_H_