Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Legacy - Client Server #1

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7772d93
helper classes refactor
wanghharrisonh Nov 23, 2017
ce0d189
folder restructure v2
wanghharrisonh Nov 23, 2017
07293dc
seperate helper classes
wanghharrisonh Nov 26, 2017
8273182
refactor helper methods
wanghharrisonh Nov 26, 2017
9ea1326
JavaClient refactor
wanghharrisonh Nov 26, 2017
df11115
package names correction
wanghharrisonh Nov 28, 2017
8d6faae
TTTController handleData
wanghharrisonh Nov 28, 2017
c1fb5ac
split java server
wanghharrisonh Nov 28, 2017
0898323
JavaServer description
wanghharrisonh Nov 28, 2017
ddcf8e4
Gomoku button works, still tic tac toe version
davidroster Nov 28, 2017
7006f83
It displays, now we add functionality after this
davidroster Nov 29, 2017
fe30003
Gomoku graphics for pieces, board not to scale yet
davidroster Nov 29, 2017
52c4d80
Graphics complete, mouse clicks ect, next up checkwinner()
davidroster Nov 29, 2017
0d801e1
almost functional
davidroster Nov 29, 2017
2660530
totally functional
wanghharrisonh Nov 29, 2017
65fe320
JavaServerTemplate description fix
wanghharrisonh Nov 29, 2017
96a4278
quick fix
davidroster Nov 29, 2017
537661f
Merge branch 'master' of github.com:davidroster/cs56-games-client-ser…
davidroster Nov 29, 2017
2ae3864
Updated JavaDoc
davidroster Nov 29, 2017
3e5e9ae
readme
davidroster Nov 30, 2017
8cde2de
JavaServerTemplate instance declaration fix
wanghharrisonh Nov 30, 2017
f66d8fc
Lab09 - readme and issues
davidroster Dec 7, 2017
77fd81c
Isuues and readme
davidroster Dec 7, 2017
f65afaf
Merge branch 'master' of github.com:davidroster/cs56-games-client-ser…
davidroster Dec 7, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions F17_lab09.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
List of potential issues to add:
1. [Add J-unit testing (100 points)](https://github.com/UCSB-CS56-Projects/cs56-games-client-server-v2/issues/19)
-> For games
-> Also for the server - client interaction


2. [Cleanup the interaction between Server & Client (200-300 points)](https://github.com/UCSB-CS56-Projects/cs56-games-client-server-v2/issues/20)
-> The code works great, however, its not easy to understand
-> After talking with our TA Kevin, he thought some of the interactions between client and server were "clever" but could be handled better.

3. [A leader board of each session of gaming. (100 points)](https://github.com/UCSB-CS56-Projects/cs56-games-client-server-v2/issues/21)
-> Keeps track of wins and losses for each session
-> When the terminal is exited and restarted, the leaderboard is restarted

4. [Update the GUI (200 points)](https://github.com/UCSB-CS56-Projects/cs56-games-client-server-v2/issues/22)
-> change all java swing to fx, make as close to original as possible
-> Right now we are using old Java Graphics
-> A better implementation would be to utilize JavaFX

//Refurbished existing issues
5. [Further improving Javadoc (50 points)](https://github.com/UCSB-CS56-Projects/cs56-games-client-server-v2/issues/23)
6. Add Chess game (300-350 points)
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
cs56-games-client-server
========================
A simple client-server program that allows people to play iconic online games like Tic-tac-toe. Chat and observation functions are included.
A simple client-server program that allows people to play iconic online games like Tic-tac-toe and Gomoku. Chat and observation functions are included.

How to Run
==========
After compiling, use "ant run-client" and "ant run-server" to start a client or a server respectively.
Only 1 server is necessary, but many clients can be created to play and spectate in the server ran lobby.Currently, this project is only runnable on one computer. In the future, we will expand functionality to be able to play on multiple csil computers.

project history
Project history
===============
Fall 2017, Hong Wang & David Roster:

V2:A new version of cs56-games-client-server that is identical on the outside, but substantially refactored inside to have better MVC separation.
A new version of cs56-games-client-server that is identical on the outside, but substantially refactored inside to have better MVC separation.

Refactored JavaClient and other complex classes to create a more easily understood code while maintainingfunction. Javdoc descriptions have been added for every class and nearly every method. These descriptions will provide helpful insight when deciphering this beauty of a beast project.

We also changed the structure of classes by having just a client & Server directory with their respected Views, models, and controller directories inside. THis can be made very clear by typing "tree" into our root directory called v2 (cs56/cs56-games-client-server-v2/src/edu/ucsb/cs56/games/client_server/v2). WE believed this would help with future user understanding.
We also changed the structure of classes by having a client, server, and games directory with their respected Views, models, and controller directories inside. THis can be made very clear by typing "tree" into our root directory called v2 (cs56/cs56-games-client-server-v2/src/edu/ucsb/cs56/games/client_server/v2). WE believed this would help with future user understanding.

v2: The version from Spring 2013.


Tips
Expand All @@ -31,8 +32,24 @@ Breakdown of Basic Repo Names
=================================
*Both the main client and server repo's have these sub directories because they keep code cleaner and follow the MVC design pattern. Here's a link that will explain more ... https://www.tutorialspoint.com/design_pattern/mvc_pattern.htm

3 main directories:
-games -> controls the game function for our application
-client -> handles the client side
-server -> handles server side

Controller -> This stands for Logic which means that most of our logic handling functions and raw code are in here... have fun

Model -> This is where the data of our actual game is processed and sent between controllers for processing.

Views -> This provides both our GUI application for Server and Client. Server is able to run on the command line but that's not as cool.

F17 Final Remarks
=======================
Explaination of the refactorization of JavaClient and JavaServer:
JavaClient gained 3 helper files. MyCellRenderer and RefreshThread used to be parralel classes inside JavaClient.java, and now they are in their own files. MessageHandler is a helper class that provides helper methods for handleMessage() method from JavaClient.
JavaServer was split into two parts. JavaServer now extends a new abstract class named JavaServerTemplate, which stores the basic methods and variable declarations for JavaServer.

Breakdown of abstract class design:
In certain packages(directories), such as games, there is one or more abstract classes that other classes extend from. For example, each of the subdirectories of Games (ClientController, Models, ServerCobtroller, Views) has an abstract class that each of the other classes implement. These abstract classes are respectively "TwoPlayerGameController, TwoPlayerGameModel, TwoPlayerGameController, TwoPLayerGameViewPanel". The reason for creating these abstract classes are it provides a correct layout for creating other games such as possibly chess. When creating a new game such as chess, you would need to make 4 classes minimum (not including any refactored classes or additional helper classes) that EXTEND these abstarct classes.

From our testings, we did not observe any bugs. We did however observe that we created some complex methods such as checkWinner() in our Gomoku Game. This might need refactorization if the Conrad or the TA's deem it necessary. A resource to use to check how your code is (kinda like a report card) is codeClimate. Just submit your open source github files to it and it will relay back possible improvements to make.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
import javax.swing.SwingUtilities;

import edu.ucsb.cs56.games.client_server.v2.client.Models.ClientModel;
import edu.ucsb.cs56.games.client_server.v2.client.Controllers.TicTacToeController;
import edu.ucsb.cs56.games.client_server.v2.client.Controllers.TwoPlayerGameController;
import edu.ucsb.cs56.games.client_server.v2.games.ClientControllers.TicTacToeController;
import edu.ucsb.cs56.games.client_server.v2.games.ClientControllers.TwoPlayerGameController;
import edu.ucsb.cs56.games.client_server.v2.client.Models.MessageModel;
import edu.ucsb.cs56.games.client_server.v2.client.Models.UsernameModel;
import edu.ucsb.cs56.games.client_server.v2.client.Views.ClientViewPanel;
import edu.ucsb.cs56.games.client_server.v2.client.Views.OfflineViewPanel;
import edu.ucsb.cs56.games.client_server.v2.client.Views.OnlineViewPanel;
import edu.ucsb.cs56.games.client_server.v2.server.Controllers.ServiceController;
import edu.ucsb.cs56.games.client_server.v2.games.ClientControllers.GomokuController;

/**
* JavaClient is the main runnable client-side application, it allows users to connect to a server on a specific port
Expand All @@ -44,8 +45,30 @@
*/

//start a java message client that tries to connect to a server at localhost:X
public class JavaClient extends JavaClientHelperMethods{
public class JavaClient{

protected ClientViewPanel view = null;

protected Socket sock;
protected InputStreamReader stream;
protected BufferedReader reader;
protected PrintWriter writer;

protected ArrayList<ClientModel> clients;
protected ArrayList<Integer> services;

protected ArrayList<MessageModel> messages;

protected int id;
protected String name;
protected int location;

protected InputReader thread;
protected RefreshThread refreshThread;
protected boolean connected;

protected TwoPlayerGameController gameController = null;

public static void main(String [] args) {
JavaClient javaClient = new JavaClient();
}
Expand Down Expand Up @@ -232,44 +255,7 @@ public void connect(String ip, int port) {
* @param string the data from the server to handle
*/
public void handleMessage(String string) {

if(string.indexOf("CON;") == 0) {
handleMessageCON(string);
}
else if(string.indexOf("DCON[") == 0) {
handleMessageDCON(string);
}
else if(string.indexOf("MSG[") == 0) {
handleMessageMSG(string);
}
else if(string.indexOf("PMSG[") == 0) {
handleMessagePMSG(string);
}
else if(string.indexOf("RMSG[") == 0) {
handleMessageRMSG(string);
}
else if(string.indexOf("SMSG;") == 0) {
handleMessageSMSG(string);
}
else if(string.indexOf("ID;") == 0) {
handleMessageID(string);
}
else if(string.indexOf("ALL;") == 0) {
handleMessageALL(string);
}
else if(string.indexOf("SERV;") == 0) {
handleMessageSERV(string);
}
else if(string.indexOf("NEW;") == 0) {
services.add(Integer.parseInt(string.substring(4)));
}
else if(string.indexOf("NAME[") == 0) {
handleMessageNAME(string);
}
else if(string.indexOf("MOVED[") == 0) {
handleMessageMOVED(string);
}
// XXX fix?
MessageHandler.handleMessage(string, this);
if (gameController != null)
gameController.handleMessage(string);
}
Expand Down Expand Up @@ -305,8 +291,13 @@ else if(serviceType == 1) {
gameController = new TicTacToeController(this);
view.setCanvasRef(((TicTacToeController)gameController).getView());
}
/*else if(serviceType == 2)
canvasRef = new GomokuViewPanel();
else if(serviceType == 2){
gameController = new GomokuController(this);
view.setCanvasRef(((GomokuController)gameController).getView());
// CanvasRef = new GomokuViewPanel();
//hopefully this works
}
/*
else if(serviceType == 3)
canvasRef = new ChessViewPanel();*/
}
Expand Down Expand Up @@ -358,6 +349,63 @@ public ClientViewPanel getView() {
return this.view;
}

//Classes within the class
/** listens for the send button's action and sends a message, if connected
*
*/
class SendListener implements ActionListener {
public SendListener() {

}

public void actionPerformed(ActionEvent event) {
String message = view.getSouthPanel().getInputBox().getText();
if(message.length() == 0)
return;

view.getSouthPanel().getInputBox().setText("");
if(isConnected()) {
sendMessage("MSG;"+message);
}
}
}

/** input reader waits for data from the server and forwards it to the client
*
*/
class InputReader extends Thread implements Runnable {
public boolean running;
public void run() {
String line;
running = true;
try {
while(running && (line = reader.readLine()) != null) {
System.out.println("incoming... "+line);
handleMessage(line);
}
} catch(SocketException ex) {
ex.printStackTrace();
System.out.println("lost connection to server...");
} catch(Exception ex) {
ex.printStackTrace();
System.out.println("crashed for some other reason, disconnecting...");
writer.println("DCON;"+getId());
writer.flush();
}

try{
sock.close();
}catch(IOException e){
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
setConnected(false);
view.getOutputBox().setText("");
updateClients();
changeLocation(-1);
System.out.println("quitting, cause thread ended");
//System.exit(0);
}
}
}


Loading