diff --git a/html/main.js b/html/main.js
index 8e1cce7..40b70eb 100644
--- a/html/main.js
+++ b/html/main.js
@@ -118,19 +118,19 @@ connection.onmessage = function(evt){
document.getElementById(i + "," + j).innerHTML = wordgrid[i][j];
// apply colors using Game.colorgrid;
- if(colorgrid[i][j] == 'w'){
+ if(colorgrid[i][j] == 'W'){
document.getElementById(i + "," + j).style.backgroundColor = "white";
}
- else if(colorgrid[i][j] == 'r'){
+ else if(colorgrid[i][j] == 'R'){
document.getElementById(i + "," + j).style.backgroundColor = "red";
}
- else if(colorgrid[i][j] == 'g'){
+ else if(colorgrid[i][j] == 'G'){
document.getElementById(i + "," + j).style.backgroundColor = "green";
}
- else if(colorgrid[i][j] == 'b'){
+ else if(colorgrid[i][j] == 'B'){
document.getElementById(i + "," + j).style.backgroundColor = "blue";
}
- else if(colorgrid[i][j] == 'y'){
+ else if(colorgrid[i][j] == 'Y'){
document.getElementById(i + "," + j).style.backgroundColor = "yellow";
}
diff --git a/src/main/java/uta/cse3310/Game.java b/src/main/java/uta/cse3310/Game.java
index 6e9cb65..08f7299 100644
--- a/src/main/java/uta/cse3310/Game.java
+++ b/src/main/java/uta/cse3310/Game.java
@@ -76,6 +76,7 @@ public void highlightCell(int playerIdx, int[] coord){
casted[0] = coord[0];
casted[1] = coord[1];
temps.set(playerIdx, casted);
+ System.out.println(temps.get(playerIdx)[0] + " " + temps.get(playerIdx)[1]);
}
public boolean checkWord(int[] startCoords, int[] endCoords){
// parses coords, strings together word, checks if it's inside words used
@@ -343,14 +344,11 @@ public boolean playerFoundWord(int[] startCoords, int[] endCoords){
//words xS, yS, xE, yE
//
-
-
-
//edit score
// p.score += 1; // possible change here --------------------------
//highlight cooresponding portion of the colorGrid
- Words w = wordsFound.get(wordsFound.size() - 1);
- highlight(w, 'W');
+ // Words w = wordsFound.get(wordsFound.size() - 1);
+ // highlight(w, 'W');
return true;
diff --git a/src/main/java/uta/cse3310/Main.java b/src/main/java/uta/cse3310/Main.java
index 1dd17d9..1a37b1d 100644
--- a/src/main/java/uta/cse3310/Main.java
+++ b/src/main/java/uta/cse3310/Main.java
@@ -196,7 +196,17 @@ public void onMessage(WebSocket conn, String message) {
// NEEDS HEAVY AMOUNT OF REWORK. THIS IS A BAREBONES PROTOTYPE
if(U.code == 500){
- color(U,conn,gson);
+ int destGame = 0;
+ int index = 0;
+ // find out what game we're working with
+ for(Player x: playerList){
+ // find who sent it
+ if(conn == x.playerConn){
+ destGame = x.gameNum;
+ index = x.index;
+ }
+ }
+ color(gson, index, destGame, U);
}
@@ -235,24 +245,12 @@ public void handleChatMessage(UserMsg userMsg) {
- public void color(UserMsg U, WebSocket conn, Gson gson){
- int destGame = 0;
- int index = 0;
- // find out what game we're working with
- for(Player x: playerList){
- // find who sent it
- if(conn == x.playerConn){
- destGame = x.gameNum;
- index = x.index;
- }
- }
+ public void color(Gson gson, int index, int destGame, UserMsg U){
// User wants to highlight a cell.
+ System.out.println(games[destGame].temps);
if(U.endCoords == null){
System.out.println(U.name + " highlighted cell. Modify temps");
int[] firstCoord = {U.startCoords[0],U.startCoords[1]};
- // tempVal[0] = U.startCoords[0];
- // tempVal[1] = U.startCoords[1];
- // games[destGame].temps.set(index, tempVal);
games[destGame].highlightCell(index, firstCoord);
}
else{
@@ -262,8 +260,8 @@ public void color(UserMsg U, WebSocket conn, Gson gson){
int x2 = U.endCoords[1];
System.out.printf("[%d, %d] -> [%d, %d]\n", y,x,y2,x2);
if(y == y2 && x == x2){
- // if the two coords are identical, null temp,
- System.out.println("identical coords. Modifying temps");
+ System.out.println("identical coords.");
+ // clear highlighted starting cell for player
Integer[] clearVal = {-1,-1};
games[destGame].temps.set(index, clearVal);
}
@@ -293,29 +291,64 @@ else if(x2 - x == 0 || y2 - y == 0){
games[destGame].colorGrid[y][end - i] = indexToChar(index);
}
}
+ // clear highlighted starting cell for player
Integer[] clearVal = {-1,-1};
games[destGame].temps.set(index, clearVal);
}
else{
- System.out.println("straight checkout return false. clear temps");
+ System.out.println("Word not found or already found.");
+ // clear highlighted starting cell for player
Integer[] clearVal = {-1,-1};
games[destGame].temps.set(index, clearVal);
}
}
- // else if(Math.abs((y2-y)/(x2-x)) == 1){ // diagonal slope
- // // sys out what direction we're highlighting.
- // }
+ else if(Math.abs((U.endCoords[0] - U.startCoords[0])/(U.endCoords[1] - U.startCoords[1])) == 1){ // diagonal slope
+ System.out.println(Math.abs((U.endCoords[0] - U.startCoords[0])/(U.endCoords[1] - U.startCoords[1])));
+ int length = Math.max(Math.abs(y2-y), Math.abs(x2-x));
+ int endY = U.endCoords[0];
+ int endX = U.endCoords[1];
+ System.out.printf("%d/%d ", y2-y, x2-x);
+ boolean isWordinBank = games[destGame].checkWord(U.startCoords,U.endCoords);
+ if(isWordinBank){
+ if(y2-y > 0 && x2-x > 0){
+ System.out.println("Down Right.");
+ for(int i = 0; i < length + 1; i++){
+ System.out.printf("[%d, %d]\n", endY - i, endX - i);
+ games[destGame].colorGrid[endY - i][endX - i] = indexToChar(index);
+ }
+ }
+ else if(y2-y < 0 && x2-x > 0){
+ System.out.println("Up Right.");
+ for(int i = 0; i < length + 1; i++){
+ System.out.printf("[%d, %d]\n", endY + i, endX - i);
+ games[destGame].colorGrid[endY + i][endX - i] = indexToChar(index);
+ }
+ }
+ else if(y2-y > 0 && x2-x < 0){
+ System.out.println("Down Left.");
+ for(int i = 0; i < length + 1; i++){
+ System.out.printf("[%d, %d]\n", endY - i, endX + i);
+ games[destGame].colorGrid[endY - i][endX + i] = indexToChar(index);
+ }
+ }
+ else{
+ System.out.println("Up Left.");
+ for(int i = 0; i < length + 1; i++){
+ System.out.printf("[%d, %d]\n", endY + i, endX + i);
+ games[destGame].colorGrid[endY + i][endX + i] = indexToChar(index);
+ }
+ }
+ }
+ Integer[] clearVal = {-1,-1};
+ games[destGame].temps.set(index, clearVal);
+ }
else{
- // slope is invalid; modify temps
+ // slope is invalid; do nothing
System.out.println("invalid slope.");
+ // clear highlighted starting cell for player
Integer[] clearVal = {-1,-1};
games[destGame].temps.set(index, clearVal);
- }
- // if(dx == 0 || dy == 0){
- // }
- // User chose a complete start and end of a word. check if the word is correct.
- // if yes, modify colorgrid, otherwise, use temps.set(index, {-1,-1}) to remove the temp value for the player with the index;
- }
+ }}
for(Player y: playerList){
// check if the player is in the destined game
if(games[destGame].names.contains(y.name)){
@@ -324,22 +357,23 @@ else if(x2 - x == 0 || y2 - y == 0){
y.playerConn.send(jsonString);
}
}
+ System.out.println(games[destGame].temps.toString());
}
// parses user's index to a color-character
public char indexToChar(int index){
if(index == 0){
- return 'r';
+ return 'R';
}
else if(index == 1){
- return 'g';
+ return 'G';
}
else if(index == 2){
- return 'b';
+ return 'B';
}
else if(index == 3){
- return 'y';
+ return 'Y';
}
else{
return '-';
diff --git a/src/main/java/uta/cse3310/backEndFunctionalityExamples/Game.java b/src/main/java/uta/cse3310/backEndFunctionalityExamples/Game.java
index 499ac90..1f119ac 100644
--- a/src/main/java/uta/cse3310/backEndFunctionalityExamples/Game.java
+++ b/src/main/java/uta/cse3310/backEndFunctionalityExamples/Game.java
@@ -95,7 +95,7 @@ public boolean verifyWord(String word){
//verifies word is within our grid
//adds valid words to the 'wordsFound' list
//return true if valid, false if not valid
- public boolean verifyWordCoords(int xStart, int yStart, int xEnd, int yEnd){
+ public Words verifyWordCoords(int xStart, int yStart, int xEnd, int yEnd){
//Alwasy have to check inverse of every word
@@ -113,11 +113,11 @@ public boolean verifyWordCoords(int xStart, int yStart, int xEnd, int yEnd){
int yE = w.y_endPoint;
// if coordinates match, then we've already found this word
if(xStart == xS && xEnd == xE && yStart == yS && yEnd == yE){
- return false;
+ return null;
// word already found
}
else if(xStart == xE && xEnd == xS && yStart == yE && yEnd == yS){
- return false;
+ return null;
}
}
}
@@ -139,11 +139,11 @@ else if(xStart == xE && xEnd == xS && yStart == yE && yEnd == yS){
int yE = w.y_endPoint;
// if coordinates match, then we've already found this word
if(xStart == xS && xEnd == xE && yStart == yS && yEnd == yE){
- return true;
+ return w;
// word already found
}
else if(xStart == xE && xEnd == xS && yStart == yE && yEnd == yS){
- return true;
+ return w;
}
@@ -151,7 +151,7 @@ else if(xStart == xE && xEnd == xS && yStart == yE && yEnd == yS){
- return false;
+ return null;
}
//verify player belongs to this game
@@ -302,7 +302,8 @@ else if(color1 == 'Z' || color2 == 'Z'){ //grey color with anything else
//word found by a player returns true if word is adds points to player
public boolean playerFoundWord(Player p, int[] startCoords, int[] endCoords){
- if(verifyWordCoords(startCoords[1], startCoords[0], endCoords[1], endCoords[0])){
+ if(verifyWordCoords(startCoords[1], startCoords[0], endCoords[1], endCoords[0]) != null){
+ wordsFound.add(verifyWordCoords(startCoords[1], startCoords[0], endCoords[1], endCoords[0]));
//word verified and added to 'wordsFound'
}
else{
@@ -321,7 +322,7 @@ public boolean playerFoundWord(Player p, int[] startCoords, int[] endCoords){
//edit score
- p.score += 1;
+ p.score += 1; // possible change here --------------------------
//highlight cooresponding portion of the colorGrid
Words w = wordsFound.get(wordsFound.size() - 1);
highlight(w, p.color);
diff --git a/src/main/java/uta/cse3310/backEndFunctionalityExamples/GameTest.java b/src/main/java/uta/cse3310/backEndFunctionalityExamples/GameTest.java
deleted file mode 100644
index 1019c5c..0000000
--- a/src/main/java/uta/cse3310/backEndFunctionalityExamples/GameTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-import java.util.ArrayList;
-
-
-public class GameTest {
-
-
-
- public static void main(String[] args){
-
-
- Player p1 = new Player("p1");
- Player p2 = new Player("p2");
- Player p3 = new Player("p3");
- Player p4 = new Player("p4");
-
-
- ArrayList players = new ArrayList();
- players.add(p1);
- players.add(p2);
- players.add(p3);
- players.add(p4);
-
- //pass in an array of players ready to play
- Game game = new Game(players, 0);
-
- //for this test just continue finding words until the game is won
-
-
- //only use things through GAME dont acces players or anything else
- int index = 0;
- boolean gameStatus = false;
- while(!gameStatus){ //loop until the game is finsihed
- for(Player p: players){ //let each player find a word
- //chose a word to find automatically
- //get the next word
- Words word = game.matrix.usedWordList.get(index);
- //get the word in string format
- //System.out.println(word.word); //debugging
- String wordFound = word.word;
- index ++;
-
-
- //can be edited to work with coordinates instead of string words
- game.playerFoundWord(p, wordFound); //tell the game a player possibly found a word
- if(game.gameFinished()){
- gameStatus = true;
- break;
- }
-
-
-
-
- }
- }
-
- //when game is done we can transfer players back to the lobby
- //remove their color
- //remove their gameID
- //list them as 'NOT READY'
-
-
-
-
- }
-}
diff --git a/src/test/java/uta/cse3310/ChatTest.java b/src/test/java/uta/cse3310/ChatTest.java
index b7dab60..b0f0de4 100644
--- a/src/test/java/uta/cse3310/ChatTest.java
+++ b/src/test/java/uta/cse3310/ChatTest.java
@@ -6,5 +6,5 @@
public class ChatTest extends TestCase {
-
+ assert(true);
}
diff --git a/src/test/java/uta/cse3310/GameTest.java b/src/test/java/uta/cse3310/GameTest.java
index dfc4820..900d797 100644
--- a/src/test/java/uta/cse3310/GameTest.java
+++ b/src/test/java/uta/cse3310/GameTest.java
@@ -18,8 +18,8 @@ public void testGameInitialization() {
assertTrue(game.isOpen);
assertEquals(0, game.numPlayers);
- assertEquals(30, game.matrix.length);
- assertEquals(30, game.matrix[0].length);
+ assertEquals(30, game.matrixDup.length);
+ assertEquals(30, game.matrixDup[0].length);
assertEquals(30, game.colorGrid.length);
assertEquals(30, game.colorGrid[0].length);
assertEquals(0, game.temps.size());