Dev Ghai commited on 2013-09-23 08:22:07
Showing 8 changed files, with 227 additions and 0 deletions.
... | ... |
@@ -0,0 +1,28 @@ |
1 |
+#------------------------------------------------- |
|
2 |
+# |
|
3 |
+# Project created by QtCreator 2013-04-14T23:25:39 |
|
4 |
+# |
|
5 |
+#------------------------------------------------- |
|
6 |
+ |
|
7 |
+QT += core |
|
8 |
+ |
|
9 |
+QT -= gui |
|
10 |
+ |
|
11 |
+TARGET = Boggle |
|
12 |
+CONFIG += console |
|
13 |
+CONFIG -= app_bundle |
|
14 |
+ |
|
15 |
+TEMPLATE = app |
|
16 |
+ |
|
17 |
+ |
|
18 |
+SOURCES += main.cpp \ |
|
19 |
+ logic/impl/Board.cpp |
|
20 |
+ |
|
21 |
+HEADERS += \ |
|
22 |
+ logic/headers/Tile.h \ |
|
23 |
+ logic/headers/Board.h |
|
24 |
+ |
|
25 |
+FORMS += |
|
26 |
+ |
|
27 |
+OTHER_FILES += \ |
|
28 |
+ ui/forms/Boggle.qml |
... | ... |
@@ -0,0 +1,47 @@ |
1 |
+//Comments on readability, niceness of the solution, efficiency if possible. |
|
2 |
+#ifndef BOARD_H |
|
3 |
+#define BOARD_H |
|
4 |
+ |
|
5 |
+#include <QObject> |
|
6 |
+#include <QList> |
|
7 |
+#include "Tile.h" |
|
8 |
+ |
|
9 |
+class Board : public QObject |
|
10 |
+{ |
|
11 |
+ //QVector http://qt-project.org/doc/qt-4.8/qvector.html |
|
12 |
+ //QList http://qt-project.org/doc/qt-4.8/qlist.html |
|
13 |
+ Q_OBJECT |
|
14 |
+private: |
|
15 |
+ QList<Tile> _tiles; |
|
16 |
+ |
|
17 |
+ int _sideLength; |
|
18 |
+ |
|
19 |
+ |
|
20 |
+ |
|
21 |
+public: |
|
22 |
+ QList<Tile> getTiles() |
|
23 |
+ { |
|
24 |
+ return _tiles; |
|
25 |
+ } |
|
26 |
+ |
|
27 |
+ int getSideLength() |
|
28 |
+ { |
|
29 |
+ return _sideLength; |
|
30 |
+ } |
|
31 |
+ |
|
32 |
+ explicit Board(QObject *parent = 0); |
|
33 |
+ explicit Board(int sideLength, QString letters); |
|
34 |
+ |
|
35 |
+ //Copy constructor. Might not need a copy constructor as we may not be going multithreaded to preserve operating memory. |
|
36 |
+ Board(const Board& originalBoard); |
|
37 |
+ |
|
38 |
+ /** |
|
39 |
+ * TODO: Convert to properties |
|
40 |
+ */ |
|
41 |
+ |
|
42 |
+ Tile* getTileAt(int x, int y); |
|
43 |
+ |
|
44 |
+ void Print(); |
|
45 |
+}; |
|
46 |
+ |
|
47 |
+#endif // BOARD_H |
... | ... |
@@ -0,0 +1,74 @@ |
1 |
+#ifndef TILE_H |
|
2 |
+#define TILE_H |
|
3 |
+ |
|
4 |
+#include <QString> |
|
5 |
+ |
|
6 |
+class Tile |
|
7 |
+{ |
|
8 |
+ |
|
9 |
+ private: |
|
10 |
+ /// <summary> |
|
11 |
+ /// X co-ordinate of the tile in the board array. |
|
12 |
+ /// This is a read only property. |
|
13 |
+ /// </summary> |
|
14 |
+ int _x; |
|
15 |
+ |
|
16 |
+ /// <summary> |
|
17 |
+ /// Y co-ordinate of the tile in the board array. |
|
18 |
+ /// This is a read only property. |
|
19 |
+ /// </summary> |
|
20 |
+ int _y; |
|
21 |
+ |
|
22 |
+ /// <summary> |
|
23 |
+ /// The alphabet contained in the tile. It can be any valid letter or 'QU'. |
|
24 |
+ /// This is a read only property. |
|
25 |
+ /// </summary> |
|
26 |
+ QString _alphabet; |
|
27 |
+ |
|
28 |
+ bool _hasBeenVisited; |
|
29 |
+ |
|
30 |
+ public: |
|
31 |
+ int getX() |
|
32 |
+ { |
|
33 |
+ return _x; |
|
34 |
+ } |
|
35 |
+ |
|
36 |
+ |
|
37 |
+ int getY() |
|
38 |
+ { |
|
39 |
+ return _y; |
|
40 |
+ } |
|
41 |
+ |
|
42 |
+ |
|
43 |
+ QString getAlphabet() |
|
44 |
+ { |
|
45 |
+ return _alphabet; |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+ void setVisited(bool hasBeenVisited) |
|
49 |
+ { |
|
50 |
+ this->_hasBeenVisited = hasBeenVisited; |
|
51 |
+ } |
|
52 |
+ |
|
53 |
+ bool isVisited() |
|
54 |
+ { |
|
55 |
+ return this->_hasBeenVisited; |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ Tile(int x, int y, QString alphabet) |
|
59 |
+ { |
|
60 |
+ this->_x = x; |
|
61 |
+ this->_y = y; |
|
62 |
+ this->_alphabet = alphabet; |
|
63 |
+ this->_hasBeenVisited = false; |
|
64 |
+ } |
|
65 |
+ |
|
66 |
+ Tile(const Tile& tileToBeCopied) |
|
67 |
+ { |
|
68 |
+ this->_x = tileToBeCopied._x; |
|
69 |
+ this->_y = tileToBeCopied._y; |
|
70 |
+ this->_alphabet = tileToBeCopied._alphabet; |
|
71 |
+ this->_hasBeenVisited = tileToBeCopied._hasBeenVisited; |
|
72 |
+ } |
|
73 |
+}; |
|
74 |
+#endif // TILE_H |
... | ... |
@@ -0,0 +1,37 @@ |
1 |
+#include "logic/headers/Board.h" |
|
2 |
+#include <QStringBuilder> |
|
3 |
+#include <iostream> |
|
4 |
+ |
|
5 |
+//Constructor |
|
6 |
+Board::Board(int sideLength, QString letters) |
|
7 |
+{ |
|
8 |
+ this->_sideLength = sideLength; |
|
9 |
+ |
|
10 |
+} |
|
11 |
+ |
|
12 |
+Tile* Board::getTileAt(int x, int y) |
|
13 |
+{ |
|
14 |
+ return new Tile(0,0, "a"); |
|
15 |
+} |
|
16 |
+ |
|
17 |
+void Board::Print() |
|
18 |
+{ |
|
19 |
+ int horizontalLength = this->_sideLength * 4 + 1; |
|
20 |
+ QString lineToPrint(horizontalLength); |
|
21 |
+ QString horizontalSeparator(horizontalLength); |
|
22 |
+ |
|
23 |
+ horizontalSeparator.fill('=', horizontalLength); |
|
24 |
+ |
|
25 |
+ for (int i= 0; i < this->_sideLength; i++) |
|
26 |
+ { |
|
27 |
+ std::cout<<horizontalSeparator.toStdString()<<std::endl; |
|
28 |
+ lineToPrint.clear(); |
|
29 |
+ lineToPrint.append("\u2551"); |
|
30 |
+ for(int j = 0; j < this->_sideLength; j++) |
|
31 |
+ { |
|
32 |
+ lineToPrint.append(this->getTileAt(j,i)->getAlphabet() % "\u2551"); |
|
33 |
+ } |
|
34 |
+ std::cout<<lineToPrint.toStdString()<<std::endl; |
|
35 |
+ } |
|
36 |
+ std::cout<<horizontalSeparator.toStdString(); |
|
37 |
+} |
... | ... |
@@ -0,0 +1,19 @@ |
1 |
+//Coding style guide: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml |
|
2 |
+ |
|
3 |
+#include <QCoreApplication> |
|
4 |
+#include <iostream> |
|
5 |
+ |
|
6 |
+#include "logic/headers/Board.h" |
|
7 |
+ |
|
8 |
+int main(int argc, char *argv[]) |
|
9 |
+{ |
|
10 |
+// QCoreApplication a(argc, argv); |
|
11 |
+ char* keypress = new char[10]; |
|
12 |
+ std::cout<<"\u2250"; |
|
13 |
+ std::cin>>keypress; |
|
14 |
+ |
|
15 |
+ Board* b = new Board(4, "abcdef"); |
|
16 |
+ b->Print(); |
|
17 |
+// return a.exec(); |
|
18 |
+} |
|
19 |
+ |