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
|
//
// KBlackBox
//
// A simple game inspired by an emacs module
//
/***************************************************************************
* Copyright (c) 1999-2000, Robert Cimrman *
* cimrman3@students.zcu.cz *
* *
* Copyright (c) 2007, Nicolas Roffet *
* nicolas-kde@roffet.com *
* *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
***************************************************************************/
#ifndef KBBBALLSONBOARD_H
#define KBBBALLSONBOARD_H
#include <QList>
#include <QObject>
class KBBGameDoc;
#define DIM_X 0
#define DIM_Y 1
#define DIM_MAX 2
/**
* @brief Set of balls (or various objects) with positions on the board
*
* The set of balls manages the position and the number of the balls. The balls can be placed of any kind (placed by the player or the hiden balls to find for instance).
*
* It computes also the trajectory of the laser ray with the given balls.
*
* There are 3 different kinds of coordinates for object positions.
* - The 1st one is the (absolute) position in 2 dimensions between (0,0) and (2 + m_columns + 2, 2 + m_rows + 2). It is used to manage the positions of the graphic elements but also to calculate the laser ray trajectory.
* - The 2nd one is the border position in 1 dimension between 0 and (2 * m_rows + 2 * m_columns -1). Only borders can be managed with this coordinate.
* - The 3rd one is the box position in 1 dimension between 0 and (m_columns*m_rows - 1). It is used to manage the postion of the balls in the black box.
*/
class KBBBallsOnBoard : public QObject
{
Q_OBJECT
public:
/**
* @brief Constructor
*/
KBBBallsOnBoard(KBBGameDoc* parent, const int columns, const int rows);
/**
* @brief Convert (absolute) position to border position
*
* @param position The (absolute) position to convert.
* @return The result of the conversion: border position.
* @see borderPositionToAbsolutePosition(int borderPosition, int position[DIM_MAX])
* @see absolutePositionToBorderPosition(int position[DIM_MAX])
*/
int absolutePositionToBorderPosition(int position[DIM_MAX]);
/**
* @brief Convert (absolute) position to box position
*
* @param position The (absolute) position to convert.
* @return The result of the conversion: box position.
* @see absolutePositionToBorderPosition(int position[DIM_MAX])
*/
int absolutePositionToBoxPosition(int position[DIM_MAX]);
/**
* @brief Add a ball on this board
*
* @param boxPosition The box position of the ball to add
* @see remove(int boxPosition)
*/
void add(int boxPosition);
/**
* @brief Convert border position to (abosulte) position
*
* @param borderPosition The border position to convert.
* @param position The result of the conversion: (absolute) position.
* @see borderPositionToAbsolutePosition(int position[DIM_MAX])
*/
void borderPositionToAbsolutePosition(int borderPosition, int position[DIM_MAX]);
int columns();
/**
* @brief Check if there is a ball at the given position in the black box
*
* @param boxPosition Box position to check
*/
bool contains(int boxPosition);
/**
* @brief Number of balls on this board
*/
int count();
/**
* @brief Define a new board and remove all balls
*
* @param columns Number of columns
* @param rows Number of rows
*/
void newBoard(const int columns, const int rows);
/**
* @brief Compares 2 boards and return the number of differences
*
* @param otherBoard Other set of balls in a board
* @return Number of balls in the set that are not in the other given set
*/
int numberOfBallsNotIn(KBBBallsOnBoard* otherBoard);
/**
* @brief Compute the opposite border position of the given position
*
* @param borderPosition The border position
*/
int oppositeBorderPosition(int borderPosition);
int oppositeBorderPositionWithPoints(const int borderPosition, QList<int> &points);
/**
* @brief Compute the trajectory of a ray with the balls of the set
*
* @param borderPosition The border position
*/
void ray(const int borderPosition, QList<int> &points);
/**
* @brief Remove a ball on this board
*
* @param boxPosition The box position of the ball to be removed
* @see add(int boxPosition);
*/
void remove(int boxPosition);
int rows();
signals:
void changes();
private:
/**
* @brief Find the position where the laser ray leaves the black box
*
* @param position[DIM_MAX] Current incoming (absolute) position. It can be on a border or in the black box.
* @param incomingDirection[DIM_MAX] Direction to move in the black box as a vector (difference of (absolute) positions)
*/
void getOutgoingPosition( int position[DIM_MAX], int incomingDirection[DIM_MAX], QList<int> &points );
/**
* @brief Check if the given (absolute) position is in the box
*
* @param position (Absolute) position to check
*/
bool positionInTheBox( int position[DIM_MAX] );
QList<int> m_balls;
int m_columns;
int m_rows;
};
#endif // KBBBALLSONBOARD_H
|