Skip to content

Commit e8e6f37

Browse files
committed
Beta 1.0
1 parent ce799e8 commit e8e6f37

File tree

21 files changed

+342
-116
lines changed

21 files changed

+342
-116
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "com.gregmaxin.colourmesilly"
77
minSdkVersion 18
88
targetSdkVersion 26
9-
versionCode 1
10-
versionName "1.0"
9+
versionCode 2
10+
versionName "1.1"
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
externalNativeBuild {
1313
cmake {

app/release/app-release.apk

4.55 MB
Binary file not shown.

app/release/output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.gregmaxin.colourmesilly","split":"","minSdkVersion":"18"}}]

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
1111
android:theme="@style/AppTheme">
12+
android:debuggable="false"
1213
<activity
1314
android:name=".MainActivity"
1415
android:label="@string/app_name"

app/src/main/cpp/Cell.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,24 @@ void Cell::notify(Move m,Cell &from){ //Notify surrounding peices
3434
D = Direction::S;
3535
else if (R == 1 && C == -1)
3636
D = Direction::SW;
37-
3837
else if (R == 0 && C == -1)
3938
D = Direction::W;
40-
else
41-
return;
39+
else
40+
D = Direction::C;
41+
4242

43-
if (m.valid(D) && (from.getDir() == D || from.getDir() == Direction::None)) {
43+
if ((from.getDir() == Direction::C || from.getDir() == D) && m.valid(D)) {
4444
LastDir = D;
4545
this->toggle();
46-
this->notifyObservers(m);
46+
if (D != Direction::C)
47+
this->notifyObservers(m);
48+
else {
49+
Move h{0};
50+
this->notifyObservers(h);
51+
}
52+
4753
}
54+
return;
4855
}
4956

5057

app/src/main/cpp/Grid.cpp

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,26 @@ class TextDisplay;
77
class Move;
88

99
void Grid::init(int n){ //Randomly initializes the board
10-
//td = new TextDisplay(n);
10+
td = new TextDisplay(n);
1111
//sets the new grid
1212
size = n;
1313
int green = 0;
1414
int red = 0;
15+
1516
for(int i = 0; i < n; i ++){
1617
vector<Cell> A;
1718
theGrid.push_back(A);
1819
for(int j = 0; j < n; j++) {
19-
Cell B{1,2};
20-
int randy = rand();
21-
if (randy % 2 == 0 && green < 14) {
22-
B.setColour(Colour::GREEN);
23-
green++;
24-
}
25-
if (randy % 2 == 1 && red < 14){
26-
B.setColour(Colour::RED);
27-
red++;
28-
}
20+
Cell B{i,j};
2921
theGrid[i].push_back(B);
3022
}
3123
}
3224

3325
//sets observers
3426
for(int r = 0; r < n; r++){
3527
for(int c = 0; c < n; c++) {
36-
//theGrid[r][c].attach(td);
28+
theGrid[r][c].attach(td);
29+
theGrid[r][c].attach(&theGrid[r][c]);
3730
if (r-1 >= 0)
3831
theGrid[r][c].attach(&theGrid[r-1][c]);
3932
if (c-1 >= 0 && r-1 >= 0)
@@ -52,39 +45,85 @@ void Grid::init(int n){ //Randomly initializes the board
5245
theGrid[r][c].attach(&theGrid[r][c-1]);
5346
}
5447
}
55-
56-
}
57-
bool Grid::winner() {
58-
return true;
59-
}
60-
std::string Grid::Display(){
61-
stringstream ss;
62-
std::string display ="Test";
63-
int n = size;
6448
for(int i = 0; i < n; i ++) {
6549
for (int j = 0; j < n; j++) {
66-
Colour colours = theGrid[i][j].getColour();
67-
if (colours == Colour::GREEN) {
68-
ss << "G";
69-
}
70-
else if (colours == Colour::RED) {
71-
ss << "R";
50+
int randy = rand();
51+
srand(randy);
52+
if (randy % 2 == 1) {
53+
theGrid[i][j].setColour(Colour::RED);
54+
red++;
55+
}
56+
else {
57+
theGrid[i][j].setColour(Colour::GREEN);
58+
green++;
7259
}
73-
else
74-
ss << "-";
60+
Move m{0};
61+
theGrid[i][j].notifyObservers(m);
7562
}
7663
}
77-
ss >> display;
78-
return display;
64+
}
65+
bool Grid::winner() {
66+
return true;
67+
}
68+
std::string Grid::Display(){
69+
return td->UpdateDisplay();
7970
}
8071

8172
void Grid::use(int row, int col, int p) {
8273
Move m{p};
83-
theGrid[row][col].setDir(Direction::None);
74+
theGrid[row][col].setDir(Direction::C);
8475
theGrid[row][col].notifyObservers(m);
8576
}
8677

8778
std::ostream& operator<<(std::ostream &out, const Grid &g) {
8879
//out << *(g.td);
8980
return out;
81+
}
82+
//Constructs a blank text display
83+
TextDisplay::TextDisplay(int n) : gridSize{n} {
84+
for(int i = 0; i < n; i ++){
85+
vector<char> A;
86+
theDisplay.push_back(A);
87+
for(int j = 0; j < n; j++) {
88+
theDisplay[i].push_back('-');
89+
}
90+
}
91+
}
92+
93+
//Gets Notified of a change on the board
94+
void TextDisplay::notify(Move m, Cell &from) {
95+
const int r = from.getRow();
96+
const int c = from.getCol();
97+
Colour colours = from.getColour();
98+
if (colours == Colour::GREEN) {
99+
theDisplay[r][c] = 'G';
100+
}
101+
if (colours == Colour::RED) {
102+
theDisplay[r][c] = 'R';
103+
}
104+
}
105+
std::string TextDisplay::UpdateDisplay() {
106+
display = "";
107+
stringstream sss;
108+
const int size = gridSize;
109+
for (int i = 0; i < size; i++) {
110+
for (int j = 0; j < size; j++) {
111+
sss << theDisplay[i][j];
112+
}
113+
114+
}
115+
sss >> display;
116+
return display;
117+
}
118+
119+
//Output display to the screen - friend of grids display
120+
std::ostream& operator<<(std::ostream &out, const TextDisplay &td) {
121+
const int size = td.gridSize;
122+
for (int i = 0; i < size; i++) {
123+
for(int j = 0; j < size; j++) {
124+
out << td.theDisplay[i][j];
125+
}
126+
out << endl;
127+
}
128+
return out;
90129
}

app/src/main/cpp/Grid.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
#include "Cell.h"
55
#include "Move.h"
66
using namespace std;
7+
class TextDisplay;
78

89
class Grid {
910
vector<vector<Cell>> theGrid;
10-
//TextDisplay *td = nullptr; // The text display.
11+
TextDisplay *td = nullptr; // The text display.
1112
int size;
1213
public:
1314
void init(int size); //Randomly initializes the board
@@ -16,4 +17,15 @@ class Grid {
1617
friend std::ostream &operator<<(std::ostream &out, const Grid &g);
1718
std::string Display();
1819
};
20+
21+
class TextDisplay: public Observer {
22+
std::vector<std::vector<char>> theDisplay;
23+
const int gridSize;
24+
string display;
25+
public:
26+
TextDisplay(int n);
27+
void notify(Move m,Cell &from) override;
28+
std::string UpdateDisplay();
29+
friend std::ostream &operator<<(std::ostream &out, const TextDisplay &td);
30+
};
1931
#endif

app/src/main/cpp/Move.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ Move::Move(int p) {
1919
move[Direction::SE] = 1;
2020
move[Direction::SW] = 1;
2121
move[Direction::NW] = 1;
22+
move[Direction::C] = 0;
2223
}
23-
if (p == 2) {
24+
if (p == 3) {
2425
move[Direction::N] = 1;
2526
move[Direction::S] = 1;
2627
move[Direction::W] = 1;
@@ -29,5 +30,29 @@ Move::Move(int p) {
2930
move[Direction::SE] = 0;
3031
move[Direction::SW] = 0;
3132
move[Direction::NW] = 0;
33+
move[Direction::C] = 1;
3234
}
35+
if (p == 4) {
36+
move[Direction::N] = 2;
37+
move[Direction::S] = 2;
38+
move[Direction::W] = 2;
39+
move[Direction::E] = 2;
40+
move[Direction::NE] = 0;
41+
move[Direction::SE] = 0;
42+
move[Direction::SW] = 0;
43+
move[Direction::NW] = 0;
44+
move[Direction::C] = 1;
45+
}
46+
if (p == 2) {
47+
move[Direction::N] = 0;
48+
move[Direction::S] = 0;
49+
move[Direction::W] = 0;
50+
move[Direction::E] = 0;
51+
move[Direction::NE] = 1;
52+
move[Direction::SE] = 1;
53+
move[Direction::SW] = 1;
54+
move[Direction::NW] = 1;
55+
move[Direction::C] = 1;
56+
}
57+
3358
}

app/src/main/cpp/Observer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class Cell;
55
class Move;
66
enum class Colour {GREEN,RED,BLUE,NONE};
7-
enum class Direction {N,NE,E,SE,S,SW,W,NW,None};
7+
enum class Direction {N,NE,E,SE,S,SW,W,NW,C,None};
88

99
class Observer {
1010
public:

0 commit comments

Comments
 (0)