ScummVM API documentation
pegspuzzle.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NANCY_ACTION_PEGSPUZZLE_H
23 #define NANCY_ACTION_PEGSPUZZLE_H
24 
25 #include "engines/nancy/commontypes.h"
26 #include "engines/nancy/action/puzzlerecord.h"
27 #include "engines/nancy/action/mousefollow.h"
28 
29 namespace Nancy {
30 namespace Action {
31 
32 // Peg-solitaire puzzle, new in Nancy13 (AR 173, "leaping" jump game). The board is
33 // a grid of holes (in Nancy13, a 7x7 grid with the four 2x2 corners blocked off,
34 // i.e. the classic 33-hole English peg-solitaire cross). A peg jumps over an
35 // adjacent peg into an empty hole two cells away, removing the jumped peg. The
36 // puzzle is solved when no move remains and the number of pegs left is at most the
37 // target count.
38 //
39 // Pegs are dragged and dropped: clicking a movable peg picks it up (the hand/drag
40 // cursor carries the piece) and dropping it on a hole it can reach performs the jump.
41 // Cell state matches the original: 0 = peg, 1 = empty hole, 2 = blocked (no hole).
42 class PegsPuzzle : public PuzzleRecord {
43 public:
44  PegsPuzzle() : PuzzleRecord(7) {}
45  virtual ~PegsPuzzle() {}
46 
47  void init() override;
48 
49  void readData(Common::SeekableReadStream &stream) override;
50  void execute() override;
51  void handleInput(NancyInput &input) override;
52 
53  bool isViewportRelative() const override { return true; }
54 
55 protected:
56  Common::String getRecordTypeName() const override { return "PegsPuzzle"; }
57 
58  enum CellState : byte { kPeg = 0, kEmpty = 1, kBlocked = 2 };
59 
60  int cellIndex(int col, int row) const { return col + row * 8; }
61  bool validCell(int col, int row) const;
62  // Whether a peg at (col,row) can jump in the direction (dCol,dRow), and if so the
63  // landing cell.
64  bool canJump(int col, int row, int dCol, int dRow, int &destCol, int &destRow) const;
65  // Whether the carried peg can jump onto (col,row).
66  bool isCarriedTarget(int col, int row) const;
67  // The board cell whose destination rect contains the (screen-space) cursor, or false.
68  bool cellAtCursor(const Common::Point &mousePos, int &outCol, int &outRow) const;
69  bool cellHasAnyMove(int col, int row) const;
70  bool anyMovesLeft() const;
71  int pegCount() const;
72  void doJump(int fromCol, int fromRow, int destCol, int destRow);
73 
74  void carryPeg(int col, int row, NancyInput &input);
75 
76  void redraw();
77 
78  // -- File data (96-byte header) --
79  uint16 _hoverCursorType = 0; // 0x21 - cursor while hovering a movable peg (open hand)
80  uint16 _dragCursorType = 0; // 0x23 - cursor while carrying a peg (pointing finger)
81  byte _startEmptyFlag = 0; // 0x25 - 0 => mark _startEmptyPos empty at init
82  byte _startEmptyPos = 0; // 0x26 - the initially-empty hole (usually the centre)
83  byte _targetPegCount = 0; // 0x27 - win when pegs remaining <= this
84  SceneChangeDescription _loseScene; // 0x2d - shown when no move remains and unsolved
85  Common::Rect _pegSrc; // 0x32 - normal peg sprite (viewport image)
86  Common::Rect _selectedSrc; // 0x42 - highlight sprite (selected peg / target holes)
87  uint16 _originY = 0; // 0x52 - board top-left (viewport space)
88  uint16 _originX = 0; // 0x54
89  uint16 _numRows = 0; // 0x56
90  uint16 _numCols = 0; // 0x58
91  uint16 _pitchYBias = 0; // 0x5a
92  uint16 _pitchXBias = 0; // 0x5c
93  uint16 _numBlocked = 0; // 0x5e - count of blocked-corner positions
94 
95  Common::Array<byte> _blockedPositions;
96 
97  Common::Array<RandomSoundBlock> _sounds; // 5 blocks: select / jump / pulse / win / lose
98 
99  // -- Runtime state --
100  Common::Array<byte> _board; // 64 cells (8-wide stride)
101  Common::Array<Common::Rect> _destRects;
102  int _carriedCol = -1; // the peg currently picked up (dragged), or -1
103  int _carriedRow = -1;
104  MouseFollowObject _carriedObject; // the carried peg's sprite, riding the cursor
105  bool _ended = false;
106  bool _solved = false;
107  bool _exitRequested = false;
108  uint32 _endTime = 0;
109  SoundDescription _endSound; // the win/lose cue we wait on before changing scene
110 
111 };
112 
113 } // End of namespace Action
114 } // End of namespace Nancy
115 
116 #endif // NANCY_ACTION_PEGSPUZZLE_H
Definition: str.h:59
Definition: commontypes.h:186
Definition: pegspuzzle.h:42
Definition: rect.h:536
Definition: stream.h:745
Definition: input.h:41
Definition: rect.h:144
Definition: puzzlerecord.h:37
Definition: commontypes.h:306
Definition: mousefollow.h:50
Definition: actionmanager.h:32