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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
/*
This file is part of StroQ, Copyright (C) 2005 Luc Vo Van
StroQ 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 2, or (at your option) any
later version.
StroQ 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 StroQ; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Class : Puzzle
Author : Luc Vo Van
Original Date : 18.05.2005
Description : A Puzzle contains dimensions, Squares, hint positions
and can return a unique code which can be used for
its reconstruction. It is what the player will try to
solve.
*/
#ifndef PUZZLE_H
#define PUZZLE_H
#include <qpoint.h>
#include <vector>
#include "square.h"
class Puzzle
{
public:
/**
* Builds a Puzzle from its code
*
* @param code the Puzzle code from which to build
*/
Puzzle(QString code);
/**
* Builds a Puzzle
*
* @param width number of columns
* @param width number of rows
* @param sol1 Coordinate of the start of a solution
* @param sol2 Coordinate of the end of a solution
* @param state State to which to set the Squares of this puzzle
*/
Puzzle(int width, int height, QPoint sol1, QPoint sol2,
Square::States state = Square::Border);
/**
* Builds a Puzzle by making an exact copy of the given puzzle. Even
* the Squares present in the given Puzzle are copied, so that
* changing the resulting Puzzle will NOT modify the original one.
*
* @param srcpuzzle Puzzle to copy from
*/
Puzzle(Puzzle* srcpuzzle);
/**
* Builds a puzzle made of PlaySquares that represent the same Puzzle
* as the given parameter. This is used to copy a Puzzle loaded from a
* code to a displayable Puzzle.
*
* @param srcpuzzle Puzzle to copy from
* @param canvas QCanvas on which to display the resulting puzzle
*/
Puzzle(Puzzle* srcpuzzle, QCanvas* canvas);
/**
* Builds a puzzle made of PlaySquares given a code. See previous
* method.
*/
Puzzle::Puzzle(QString code, QCanvas *canvas);
/**
* Class destructor
*/
~Puzzle();
/**
* Returns true if the given code is valid, false otherwise
*
* @param code the code to check
*/
static bool isCodeValid(QString code);
/**
* Sets a Square on the Puzzle. The Square contains the coordinates
* for which it will be stored. The previous square at that position
* is deleted.
* Caller should pass the Square object and not delete it. (Pass and
* forget)
*
* @param square Square to set
*/
void setSquare(Square* square);
/**
* Returns the Square present at the given position in the Puzzle
*
* @param x row number of the wanted Square (borders start at 0)
* @param y column number of the wanted Square (borders start at 0)
* @return the Square at (x, y) on the Puzzle
*/
Square* getSquareAt(int x, int y);
/**
* Returns the number of squares making up the width of the Puzzle
* (number of columns)
* @see getHeight()
*
* @return number of columns in the Puzzle
*/
int getWidth();
/**
* Returns the number of squares making up the height of the Puzzle
* (number of rows)
* @see getWidth()
*
* @return number of rows in the Puzzle
*/
int getHeight();
/**
* Returns the coordinate of the start of a solution
* @see getSolutionEnd()
*
* @return the coordinate of the end of a solution
*/
QPoint getSolutionStart();
/**
* Returns the coordinate of the end of a solution
* @see getSolutionStart()
*
* @return the coordinate of the end of a solution
*/
QPoint getSolutionEnd();
/**
* Returns the code associated with this puzzle
*
* @return the Puzzle's code
*/
QString getCode();
/**
* Returns this puzzle's number if this puzzle is a stock puzzle. Returns
* -1 otherwise
*
* @return the puzzle's number if puzzle is a stock puzzle, -1 otherwise.
*/
int getPuzzleNumber();
/**
* Sets the puzzle number value of a puzzle
*
* @param puzzlenumber Number to give this puzzle
*/
void setPuzzleNumber(int puzzlenumber);
/**
* Inverts white and black squares
*/
void invert();
private:
/**
* Allocates the memory to store the Squares making up the puzzle
*
* @param state the default state of the Squares in the puzzle
*/
void allocate(Square::States state = Square::Border);
/**
* DEBUG: Prints out the given integer in binary base to standard
* output.
*
* @param number number to print out
*/
static void printbin(int number);
/**
* Concatenates the binary representation of a number to a QString
*
* @param dest the QString to which to concatenate
* @param number the number to calculate the binary value of
*/
static void getBin(QString& dest, int number);
/**
* Concatenates the binary representation of a number to a QString and
* pads the rest of the string with 0's until the destination QString
* has the given length.
* @see getBin()
*
* @param dest the QString to which to concatenate
* @param number the number to calculate the binary value of
* @param length length up to which to pad with 0s (0s added at the
* end)
*/
static void getBin(QString& dest, int number, unsigned int length);
/**
* Returns the integer value of a given QString made up of 0s and 1s
* The given QString has to be made up of 0s and 1s, no error checking
* is currently performed.
*
* @param binstring Binary string to evaluate
* @return the integer value of binstring
*/
static unsigned int evalBin(QString binstring);
/**
* DEBUG: Prints out the specs of the puzzle to standard output
*/
void printSpec();
int m_iWidth; /**< Number of columns */
int m_iHeight; /**< Number of rows */
QPoint m_qpSolutionStart; //!< Coordinate of the start of a solution
QPoint m_qpSolutionEnd; //!< Coordinate of the end of a solution
Square*** m_pArray; /**< The bidimensional array where the Squares
are stored. */
};
#endif
|