File: board.h

package info (click to toggle)
galois 0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 948 kB
  • sloc: cpp: 4,075; xml: 2,325; makefile: 146
file content (108 lines) | stat: -rw-r--r-- 2,944 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* board.h -- game board for falling blocks game.  -*- C++ -*-
   Copyright (C) 2011-2015 Gerardo Ballabio

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef __BOARD_
#define __BOARD_

#include <vector>
#include "grid.h"
#include "group.h"

class game_board
{
private:
  // game elements
  const group *g;
  grid<int> cells;
  std::vector<block> blocks;
  std::vector<int> series; // how many blocks for each size

  // whether game is active
  bool game;

  // game options
  int mode1, mode2;
  int empty;

  // counters
  int bmin, bmax, bsuper, bsize, isuper, nsuper;
  int level, speed, lines, score;
  std::vector<int> filled;

  // falling block
  int iblock, ishape;
  coords pos;
  // next block
  int nsize, nblock, nshape;

  bool fits(int b, int s, coords c) const;
  bool fits_b(int b, int s, coords c) const;
  coords move_in(int b, int s, coords c) const;

  void first_block();
  void land_block();
  void next_level();
  void next_blockset();

  int score_block() const;
  int score_lines(int lines) const;
public:
  game_board() : g(0), game(false) { }
  ~game_board() { if (g) delete g; } // just in case

  // read-only access to internals
  const group *get_group() const { return g; }
  const grid<int> *get_cells() const { return &cells; }
  int get_iblock() const { return iblock; }
  int get_nblock() const { return nblock; }
  grid<bool> get_block() const;
  const grid<bool> & get_next_block() const
  { return blocks[nblock].shape[nshape]; }
  bool is_game() const { return game; }
  int get_mode1() const { return mode1; }
  int get_bmin() const { return bmin; }
  int get_bmax() const { return bmax; }
  int get_bsuper() const { return bsuper; }
  int get_level() const { return level; }
  int get_speed() const { return speed; }
  int get_lines() const { return lines; }
  int get_score() const { return score; }
  const std::vector<int> get_filled() const { return filled; }

  grid<bool> get_shadow();

  // start new game
  void start_game(const group *gg, int w, int d, int mode1, int mode2,
		  int s, int min, int max, int e);

  // block moves
  bool rotate(int n);
  bool reflect();
  bool left();
  bool right();
  bool front();
  bool back();
  bool down();
  bool drop();

  // actions
  void color_lines(int c);
  void remove_lines();
  void next_block();
  void stop();
};

#endif /* __BOARD_ */