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

3 #8

Merged
merged 33 commits into from
Dec 20, 2023
Merged

3 #8

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ca1d90b
:sparkles: FEAT. 루미큐브 UI 구현
junhaa Dec 16, 2023
0f7c9ea
:sparkles: FEAT. 루미큐브 메인로직 구현
junhaa Dec 16, 2023
7344a87
:sparkles: FEAT. 루미큐브 메인로직 구현
junhaa Dec 16, 2023
b63e1bc
:sparkles: FEAT. 루미큐브 메인로직 구현
junhaa Dec 16, 2023
408a079
:sparkles: FEAT. 루미큐브 메인로직 구현
junhaa Dec 16, 2023
e2d94ff
:sparkles: FEAT. 루미큐브 메인로직 구현
junhaa Dec 16, 2023
79f52a1
:bug: FIX. 소켓 연결 오류 수정
junhaa Dec 17, 2023
5abddb3
:Art: STYLE.이미지 추가
ghvfgfcht Dec 17, 2023
35a993d
:Art: STYLE.이미지 추가
ghvfgfcht Dec 17, 2023
8e9e36e
:Art: STYLE.이미지 추가
ghvfgfcht Dec 18, 2023
0bc9fdd
:sparkles: FEAT. 루미큐브 소켓 연동
junhaa Dec 18, 2023
af6a93c
:sparkles: FEAT. 루미큐브 소켓 연동
junhaa Dec 18, 2023
c2bf4d0
Merge branch '3' of https://github.com/Rummikube/rummikub into 3
junhaa Dec 18, 2023
f19b022
:lipstick: STYLE.이미지 추가
ghvfgfcht Dec 18, 2023
094b578
Resolve Merge Conflicts
ghvfgfcht Dec 18, 2023
44e63a1
:lipstick: STYLE.이미지 추가
ghvfgfcht Dec 18, 2023
7c48b9b
:sparkles: FEAT. 루미큐브 소켓 연동
junhaa Dec 18, 2023
d3c89f3
:sparkles: FEAT. 루미큐브 소켓 연동
junhaa Dec 18, 2023
407e535
:sparkles: FEAT. 루미큐브 메인로직 구현
junhaa Dec 18, 2023
4c4c3e3
:sparkles: FEAT. 루미큐브 UI 구현
junhaa Dec 18, 2023
e64a2e2
:sparkles: FEAT. 루미큐브 UI 구현
junhaa Dec 18, 2023
7405f27
:lipstick: STYLE.이미지 추가 및 버튼 UI 변경
ghvfgfcht Dec 19, 2023
b0a7765
Resolve merge conflicts
ghvfgfcht Dec 19, 2023
7f87738
:recycle: REFACTOR. 소켓 통신 클래스 래픽토리
junhaa Dec 19, 2023
5af7ab1
:bug: FIX. 소켓 통신 오류 수정
junhaa Dec 19, 2023
333bc3b
:sparkles: FEAT. 루미큐브 메인 로직 구현
junhaa Dec 19, 2023
93dbf84
:sparkles: FEAT. 루미큐브 UI
junhaa Dec 19, 2023
9249574
:sparkles: FEAT. 루미큐브 UI
junhaa Dec 19, 2023
d05de0c
:sparkles: FEAT. 루미큐브 로직 구현
junhaa Dec 19, 2023
48aeb40
:lipstick: STYLE. UI 이미지 추가 및 적용
ghvfgfcht Dec 20, 2023
814a34f
resolve merge conflicts
ghvfgfcht Dec 20, 2023
5f4c1f2
:lipstick: STYLE.UI 변경
junhaa Dec 20, 2023
1a6537b
:sparkles: FEAT. 루미큐브 로직 구현
junhaa Dec 20, 2023
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
Binary file added asset/images/AddTilesBTN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/images/BUGIKUB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/images/GroupSortBTN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/images/QuitBTN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/images/RunSortBTN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/images/emptyProfile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/images/minitile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/images/ready.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/images/start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/images/tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public static void main(String[] args) {
GameController controller = new GameController(view);
controller.start();
}
}
}
147 changes: 147 additions & 0 deletions src/Controller/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package Controller;
import java.io.*;
import java.net.*;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import Exceptions.NotEmptySpaceException;
import Exceptions.OnProgressException;

public class Client{


private Socket curSocket;
private ClientOutput output;
private ClientInput input;

private GameController gameController;


public void sendObject(SerializeObject object){
output.addObject(object);
}

public Client(GameController gameController, String address, int port, String name) throws UnknownHostException, NotEmptySpaceException, OnProgressException{
this.gameController = gameController;
try {
curSocket = new Socket(address, port);

output = new ClientOutput(curSocket);
input = new ClientInput(curSocket);

SerializeObject answer = null;

while (answer == null) {
try {
answer = (SerializeObject) input.getObjectInputStream().readObject();
} catch (IOException e) {
// IOException 처리
e.printStackTrace();
}
}
System.out.println("받은 객체 : " + answer.getEventObject() + answer.getObjectType());

if(!answer.getObjectType().equals("Index")) {
String answerStr = (String) answer.getEventObject();
if (answerStr.equals("방이 가득찼습니다.")) {
throw new NotEmptySpaceException();
} else if (answerStr.equals("현재 게임이 진행중입니다.")) {
throw new OnProgressException();
}
}
else{
gameController.setIndex((int) answer.getEventObject());
}
Thread outputThread = new Thread(output);
Thread inputThread = new Thread(input);

outputThread.start();
inputThread.start();

System.out.println("서버에 연결되었습니다.");
sendObject(new SerializeObject(name, "Name", gameController.getIndex()));

} catch (ClassNotFoundException e) {
System.out.println("클래스가 맞지 않습니다.");
} catch (IOException e) {
e.printStackTrace();
}
}

class ClientOutput implements Runnable{
private ObjectOutputStream objectOutputStream;
private Socket clientSocket;

private Queue<SerializeObject> outputQueue;

public ClientOutput(Socket clientSocket) throws IOException {
this.clientSocket = clientSocket;
objectOutputStream = new ObjectOutputStream(clientSocket.getOutputStream());
outputQueue = new ConcurrentLinkedQueue<>();
}

public ObjectOutputStream getObjectOutputStream() {
return objectOutputStream;
}

public void addObject(SerializeObject object){
this.outputQueue.offer(object);
}


@Override
public void run() {
try {
while (true) {
SerializeObject sendObj = outputQueue.poll();
if (sendObj != null) {
System.out.println(sendObj.getEventObject());
objectOutputStream.writeObject(sendObj);
System.out.println(sendObj.getObjectType() + " " + sendObj.getEventObject() + " 전달");
}
}
}
catch (IOException e){
e.printStackTrace();
}
finally{
try {
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

class ClientInput implements Runnable{
ObjectInputStream objectInputStream;
Socket clientSocker;

Object curInput = null;

public ClientInput(Socket clientSocker) throws IOException {
this.clientSocker = clientSocker;
objectInputStream = new ObjectInputStream(clientSocker.getInputStream());
}

public ObjectInputStream getObjectInputStream() {
return objectInputStream;
}

@Override
public void run() {
while(true){
try {
if((curInput = objectInputStream.readObject()) != null){
SerializeObject sInput = (SerializeObject) curInput;
gameController.excuteQuery(sInput);
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
}
}
}
130 changes: 130 additions & 0 deletions src/Controller/ClientHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package Controller;

import Model.Player;

import java.io.*;
import java.net.Socket;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;


public class ClientHandler{
private Socket clientSocket;
private Object input = null;

private ServerOutput out;
private ServerInput in;
private Server server;
private int index;


// 클라이언트에 객체 전달
public void sendObject(SerializeObject obj){
out.addObject(obj);
}

public void startThread(){
Thread outThread = new Thread(out);
Thread inThread = new Thread(in);

outThread.start();
inThread.start();
}

public ClientHandler(Socket socket, Server server, int index) {
this.clientSocket = socket;
this.server = server;
this.index = index;
try {
out = new ServerOutput(clientSocket);
in = new ServerInput(clientSocket);
} catch (IOException e) {
e.printStackTrace();
}
}

class ServerOutput implements Runnable{
private ObjectOutputStream objectOutputStream;
private Socket serverSocket;

private Queue<SerializeObject> outputQueue;

public ServerOutput(Socket serverSocket) throws IOException {
this.serverSocket = serverSocket;
objectOutputStream = new ObjectOutputStream(serverSocket.getOutputStream());
outputQueue = new ConcurrentLinkedQueue<>();
}

public ObjectOutputStream getObjectOutputStream() {
return objectOutputStream;
}

public void addObject(SerializeObject object){
this.outputQueue.offer(object);
}


@Override
public void run() {
try {
while (true) {
SerializeObject sendObj = outputQueue.poll();
if (sendObj != null) {
objectOutputStream.writeObject(sendObj);
if(sendObj.getObjectType() == "Player[]") {
Player[] cur = (Player[]) sendObj.getEventObject();
for(int i = 0 ; i < 4 ; i ++){
if(cur[i] != null) {
System.out.println(cur[i].getName());
}
}
System.out.println(sendObj.getEventObject());
}
System.out.println("출력 추가됨 " + sendObj.getEventObject() + " index : " + index);
}
}
}
catch (IOException e){
e.printStackTrace();
}
finally{
try {
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}


class ServerInput implements Runnable{
ObjectInputStream objectInputStream;
Socket serverSocket;

Object curInput = null;

public ServerInput(Socket serverSocket) throws IOException {
this.serverSocket = serverSocket;
objectInputStream = new ObjectInputStream(serverSocket.getInputStream());
}

public ObjectInputStream getObjectInputStream() {
return objectInputStream;
}

@Override
public void run() {
while(true){
try {
if((curInput = objectInputStream.readObject()) != null){
SerializeObject sInput = (SerializeObject) curInput;
server.getGameController().excuteQuery(sInput);
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
}
}
}
Loading