File indexing completed on 2024-04-28 04:05:21

0001 /*
0002     SPDX-FileCopyrightText: 2015 Jakob Gruber <jakob.gruber@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef BOARD_H
0008 #define BOARD_H
0009 
0010 #include <QList>
0011 
0012 #include "src/outofboundsexception.h"
0013 
0014 class Board
0015 {
0016 public:
0017 
0018     enum State {
0019         Nothing,
0020         Box,
0021         Cross
0022     };
0023 
0024     /* 0 < width, height */
0025     Board(int width, int height);
0026 
0027     virtual ~Board() { }
0028 
0029     /* 0 <= x < m_width; 0 <= y < m_height */
0030     enum State get(int x, int y) const;
0031 
0032     /* returns whether (x, y) is outside the playing area */
0033     bool outOfBounds(int x, int y) const;
0034 
0035     int width() const { return m_width; }
0036     int height() const { return m_height; }
0037 
0038 protected:
0039     /* throws OutOfBoundsException if x,y are not located in bounds */
0040     void assertInbounds(int x, int y) const;
0041 
0042     /* convert between (x,y) coordinates and the flat list index */
0043     int xy_to_i(int x, int y) const;
0044     int i_to_x(int i) const;
0045     int i_to_y(int i) const;
0046 
0047     const int m_width, m_height, m_size;
0048     QList<enum State> m_state;
0049 };
0050 
0051 #endif // BOARD_H