Skip to content

Commit

Permalink
Added Coordinate + Locations classes to track start and end of words
Browse files Browse the repository at this point in the history
  • Loading branch information
NotVeridion committed Apr 9, 2024
1 parent 2df2bcb commit 675c805
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/cse3310/Coordinate
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cse3310;

class Coordinate {
public int x;
public int y;

public void Coordinate(int x, int y){
this.x = x;
this.y = y;
}

public void getCoordinate(){
return int[] location = new int[] {x, y};
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/cse3310/Game.Java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import java.utils.ArrayList;
public class Game{
private ArrayList User users;
public int GameId;

public int[][] grid;

public Game()
{

}

public boolean checkVertical(array selectedLetters, int length){
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/cse3310/Locations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cse3310;

import java.util.HashMap;

class Locations {
static HashMap <String, Coordinate[]> locationMap;

public int[] getStart(String s){
return (locationMap.get(s)[0]).getCoordinate;
}

public int[] getEnd(String s){
return (locationMap.get(s)[1]).getCoordinate;
}
}
1 change: 1 addition & 0 deletions src/main/java/com/cse3310/UserEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public class UserEvent {
int GameId;
User UserId;
int Button[][];
String message;
}
20 changes: 20 additions & 0 deletions src/main/java/com/cse3310/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ public void onClose(Connection conn, int code, String reason, boolean remote) {
@Override
public void onMessage(Connection conn, String message) {
// TODO Auto-generated method stub
System.out.println(conn + ": " + message); // Log message in console

// Bring in the data from the webpage
// A UserEvent is all that is allowed at this point
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
UserEvent U = gson.fromJson(message, UserEvent.class);
System.out.println(U.Button);

// Get our Game Object
Game G = conn.getAttachment();
G.Update(U);

// send out the game state every time
// to everyone
String jsonString;
jsonString = gson.toJson(G);

System.out.println(jsonString);
broadcast(jsonString);
throw new UnsupportedOperationException("Unimplemented method 'onMessage'");
}

Expand Down

0 comments on commit 675c805

Please sign in to comment.