This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added data access modifiers, moved GUI and communication outside of c…
…lient/Runner, polished MenuScreen and BoardGUI
- Loading branch information
Adam Procio
committed
Apr 19, 2019
1 parent
b9d2e74
commit 9195ae1
Showing
27 changed files
with
251 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
package client.GUI; | ||
|
||
import javafx.geometry.Pos; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.layout.GridPane; | ||
import javafx.stage.Stage; | ||
|
||
public class BoardGUI extends GridPane { | ||
Integer[][] state; | ||
public class BoardGUI{ | ||
private Scene scene; | ||
private GridPane pane, boardPane; | ||
private Integer[][] state; | ||
private Button saveGame; | ||
|
||
public BoardGUI(Integer[][] state){ | ||
public BoardGUI(Stage stage, Integer[][] state){ | ||
this.state = state; | ||
this.setMinSize(320,320); | ||
this.setAlignment(Pos.CENTER); | ||
this.setGridLinesVisible(true); | ||
Button button; | ||
this.pane = new GridPane(); | ||
this.pane.setAlignment(Pos.CENTER); | ||
this.boardPane = new GridPane(); | ||
this.boardPane.setGridLinesVisible(true); | ||
for (int i = 0; i < 8; i++) { | ||
for (int j = 0; j < 8; j++) { | ||
button = new Button(""); | ||
button.setMinSize(40,40); | ||
this.add(button, i, j); | ||
Button button = new Button(""); | ||
button.setMinSize(MinDims.BUTTON.width, MinDims.BUTTON.height); | ||
this.boardPane.add(button, i, j); | ||
} | ||
} | ||
this.pane.add(this.boardPane, 0, 0); | ||
this.saveGame = new Button("Save Game"); | ||
this.pane.add(this.saveGame, 0, 1); | ||
this.scene = new Scene(this.pane); | ||
stage.setScene(this.scene); | ||
} | ||
|
||
public Integer[][] getState() { | ||
return state; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package client.GUI; | ||
|
||
import javafx.application.Application; | ||
import javafx.event.EventHandler; | ||
import javafx.scene.input.MouseEvent; | ||
import javafx.stage.Stage; | ||
|
||
public class MainGUI extends Application { | ||
public void start(Stage stage) throws Exception { | ||
stage.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { | ||
public void handle(MouseEvent mouseEvent) { | ||
System.out.println(mouseEvent.getTarget().toString()); | ||
} | ||
}); | ||
stage.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { | ||
public void handle(MouseEvent mouseEvent) { | ||
System.out.println("uhh"); | ||
} | ||
}); | ||
/**New game | ||
* vs Computer | ||
* vs player on 1 pc | ||
* vs player on the internet | ||
* Load game (PGN) | ||
* Watch game (PGN) | ||
*/ | ||
System.out.println("Setting menu screen"); | ||
MenuScreen menuScreen = new MenuScreen(stage); | ||
/* TODO catch messages from MenuScreen gui */ | ||
} | ||
|
||
public static void main(String[] args) { | ||
launch(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,105 @@ | ||
package client.GUI; | ||
|
||
import javafx.stage.Stage; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.layout.GridPane; | ||
import javafx.scene.text.Text; | ||
import javafx.event.EventHandler; | ||
import javafx.geometry.Pos; | ||
import javafx.scene.input.MouseEvent; | ||
|
||
public class MenuScreen { | ||
Scene scene; | ||
public MenuScreen(){ | ||
class MenuScreen { | ||
private Scene scene; | ||
private Text titleText; | ||
private GridPane pane; | ||
private Button button1, button2, button3; | ||
|
||
MenuScreen(Stage stage){ | ||
this.pane = new GridPane(); | ||
this.pane.setAlignment(Pos.CENTER); | ||
this.pane.setVgap(5); | ||
this.titleText = new Text("Game Menu"); | ||
this.pane.add(this.titleText, 0, 0); | ||
this.button1 = new Button("New Game"); | ||
this.button1.setOnMouseClicked(newHandler(1, stage)); | ||
this.pane.add(this.button1, 0, 1); | ||
this.button2 = new Button("Load Game"); | ||
this.button2.setOnMouseClicked(newHandler(2, stage)); | ||
this.pane.add(this.button2, 0, 2); | ||
this.button3 = new Button("Watch Game"); | ||
this.button3.setOnMouseClicked(newHandler(3, stage)); | ||
this.pane.add(this.button3, 0, 3); | ||
this.scene = new Scene(this.pane, MinDims.SCENE.width, MinDims.SCENE.height); | ||
stage.setScene(this.scene); | ||
stage.show(); | ||
} | ||
|
||
private EventHandler<MouseEvent> newHandler(int i, final Stage stage){ | ||
switch(i){ | ||
case 1: | ||
return new EventHandler<MouseEvent>() { | ||
public void handle(MouseEvent mouseEvent) { | ||
System.out.println("NewGame Button clicked"); | ||
newGameClicked(stage); | ||
} | ||
}; | ||
case 2: | ||
return new EventHandler<MouseEvent>() { | ||
public void handle(MouseEvent mouseEvent) { | ||
System.out.println("LoadGame Button clicked"); | ||
loadGameClicked(stage); | ||
} | ||
}; | ||
case 3: | ||
return new EventHandler<MouseEvent>() { | ||
public void handle(MouseEvent mouseEvent) { | ||
System.out.println("WatchGame Button clicked"); | ||
watchGameClicked(stage); | ||
} | ||
}; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
private void newGameClicked(final Stage stage){ | ||
this.titleText = new Text("New Game Menu"); | ||
this.pane = new GridPane(); | ||
this.pane.setAlignment(Pos.CENTER); | ||
this.pane.setVgap(5); | ||
this.button1 = new Button("Local Game"); | ||
// this.button1.setOnMouseClicked(new EventHandler<MouseEvent>() { | ||
// public void handle(MouseEvent mouseEvent) { | ||
// System.out.println("stuff"); | ||
// } | ||
// }); | ||
this.button2 = new Button("Remote Game"); | ||
this.pane.add(this.titleText, 0, 0); | ||
this.pane.add(this.button1, 0, 1); | ||
this.pane.add(this.button2, 0, 2); | ||
this.scene = new Scene(this.pane, MinDims.SCENE.width, MinDims.SCENE.height); | ||
stage.setScene(this.scene); | ||
} | ||
|
||
private void loadGameClicked(final Stage stage){ | ||
this.titleText = new Text("Load Game Menu"); | ||
this.pane = new GridPane(); | ||
this.pane.setAlignment(Pos.CENTER); | ||
this.pane.setVgap(5); | ||
this.pane.add(this.titleText, 0, 0); | ||
this.scene = new Scene(this.pane, MinDims.SCENE.width, MinDims.SCENE.height); | ||
stage.setScene(this.scene); | ||
} | ||
|
||
private void watchGameClicked(final Stage stage){ | ||
this.titleText = new Text("Watch Game Menu"); | ||
this.pane = new GridPane(); | ||
this.pane.setAlignment(Pos.CENTER); | ||
this.pane.setVgap(5); | ||
this.pane.add(this.titleText, 0, 0); | ||
this.scene = new Scene(this.pane, MinDims.SCENE.width, MinDims.SCENE.height); | ||
stage.setScene(this.scene); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package client.GUI; | ||
|
||
public enum MinDims{ | ||
BUTTON (40, 40), | ||
SCENE (320, 320); | ||
|
||
public int width, height; | ||
|
||
MinDims(int w, int h) { | ||
this.width = w; | ||
this.height = h; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,19 @@ | ||
package client; | ||
|
||
import client.GUI.BoardGUI; | ||
import javafx.application.Application; | ||
import javafx.collections.ObservableList; | ||
import javafx.event.Event; | ||
import javafx.event.EventHandler; | ||
import javafx.event.EventType; | ||
import javafx.geometry.Pos; | ||
import javafx.scene.Group; | ||
import javafx.scene.Node; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.input.MouseEvent; | ||
import javafx.scene.layout.GridPane; | ||
import javafx.scene.layout.Pane; | ||
import javafx.scene.text.Text; | ||
import javafx.stage.Stage; | ||
import logic.Player; | ||
import server.Board; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.DataOutputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.Socket; | ||
|
||
public class Runner extends Application{ | ||
/* has gui, player and sockets */ | ||
BoardGUI gui; | ||
Player player; | ||
|
||
public void start(Stage stage) throws Exception { | ||
/* menu screen */ | ||
/**TODO | ||
* New game | ||
* vs Computer | ||
* vs player on 1 pc | ||
* vs player on the internet | ||
* Load game | ||
* Watch game (PGN) | ||
*/ | ||
menuSetup(stage); | ||
/* Board GUI setup */ | ||
import client.GUI.MainGUI; | ||
import client.communication.Utils; | ||
|
||
public class Runner{ | ||
public static void main(String[] args) throws Exception { | ||
/* TODO get port from user to connect to in the GUI*/ | ||
/* TODO if single game, run server from here */ | ||
MainGUI.main(args); | ||
int port = 8888; | ||
try { | ||
connect(); | ||
System.out.println("Connecting to server"); | ||
Utils.connect(port); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
public static void connect() throws Exception { | ||
/**TODO | ||
* if game selected is on 1 machine, create thread with server running in background | ||
*/ | ||
String sentence; | ||
String modifiedSentence; | ||
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
Socket clientSocket = new Socket("localhost", 8888); | ||
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); | ||
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); | ||
|
||
sentence = inFromUser.readLine(); | ||
outToServer.writeBytes(sentence + '\n'); | ||
modifiedSentence = inFromServer.readLine(); | ||
System.out.println(modifiedSentence); | ||
clientSocket.close(); | ||
} | ||
public void menuSetup(final Stage stage){ | ||
/**TODO | ||
* if button selected, create new scene based on button | ||
*/ | ||
GridPane pane = new GridPane(); | ||
pane.setAlignment(Pos.CENTER); | ||
pane.setVgap(5); | ||
|
||
Text titleText = new Text("Game Menu"); | ||
pane.add(titleText, 0, 0); | ||
Button newGameButton = new Button("New Game"); | ||
newGameButton.setOnMouseClicked( | ||
new EventHandler<MouseEvent>() { | ||
public void handle(MouseEvent mouseEvent) { | ||
System.out.println("Button click"); | ||
/*TODO setup board correctly */ | ||
gui = new BoardGUI(null); | ||
Scene scene = new Scene(gui, 400, 400); | ||
stage.setScene(scene); | ||
} | ||
}); | ||
pane.add(newGameButton, 0, 1); | ||
Button loadGameButton = new Button("Load Game"); | ||
pane.add(loadGameButton, 0, 2); | ||
Button watchGameButton = new Button("Watch Game"); | ||
pane.add(watchGameButton, 0, 3); | ||
|
||
Scene scene = new Scene(pane, 400, 400); | ||
stage.setScene(scene); | ||
stage.show(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
launch(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package client.communication; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.DataOutputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.Socket; | ||
|
||
public class Utils { | ||
public static void connect(int port) throws Exception { | ||
/**TODO | ||
* if game selected is on 1 machine, create thread with server running in background | ||
*/ | ||
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
Socket clientSocket = new Socket("localhost", port); | ||
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); | ||
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); | ||
|
||
String sentence = inFromUser.readLine(); | ||
outToServer.writeBytes(sentence + '\n'); | ||
String modifiedSentence = inFromServer.readLine(); | ||
System.out.println(modifiedSentence); | ||
clientSocket.close(); | ||
} | ||
} |
Oops, something went wrong.