Skip to content

Commit

Permalink
Merge pull request #12 from snuhcs-course/new-feat/multiroom-clean
Browse files Browse the repository at this point in the history
Feat: multiroom & history UI (commit cleaned version)
  • Loading branch information
tangamzaa authored Oct 19, 2023
2 parents 5ececed + 071d774 commit ccd2417
Show file tree
Hide file tree
Showing 62 changed files with 2,772 additions and 55 deletions.
15 changes: 15 additions & 0 deletions android/RunUsAndroid/.idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions android/RunUsAndroid/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
implementation 'androidx.navigation:navigation-fragment:2.7.4'
implementation 'androidx.navigation:navigation-ui:2.7.4'
implementation 'androidx.recyclerview:recyclerview:latest_version'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation files('libs/MultiModeLibrary-1.0-SNAPSHOT.jar')
//implementation project(':OneToOneSocketExample')
}

checkstyle {
Expand Down
Binary file not shown.
153 changes: 153 additions & 0 deletions android/RunUsAndroid/app/src/main/java/MultiMode/MultiModeRoom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package MultiMode;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

public class MultiModeRoom implements Serializable {


private static final long serialVersionUID = 1L;
private int id; // 룸 ID
private List<MultiModeUser> userList; //유저 정보
private MultiModeUser roomOwner; // 방장

private RoomCreateInfo roomCreateInfo; //방 정보

private String title; //방 제목
private double distance; //목표 거리
private int numRunners; //제한 인원

private LocalDateTime startTime; //시작 시각

private LocalTime duration; //목표 시간(달리는 시간)

public MultiModeRoom(int roomId, RoomCreateInfo roomCreateInfo) { // 유저가 방을 만들때
userList = new ArrayList();
this.id = roomId;
this.roomCreateInfo = roomCreateInfo;
this.title = roomCreateInfo.getTitle();
this.distance = roomCreateInfo.getDistance();
this.startTime = roomCreateInfo.getStartTime();
this.duration = roomCreateInfo.getDuration();
this.numRunners = roomCreateInfo.getNumRunners();
}
public MultiModeRoom(MultiModeUser user ) { // 유저가 방을 만들때
userList = new ArrayList();
user.enterRoom(this);
userList.add(user); // 유저를 추가시킨 후
this.roomOwner = user; // 방장을 유저로 만든다.

}

public MultiModeRoom() {

}

public void enterUser(MultiModeUser user){
user.enterRoom(this);
userList.add(user);
}

public void exitUser(MultiModeUser user){
user.exitRoom(this);
userList.remove(user);

if(userList.size() < 1){
RoomManager.removeRoom(this);
return;
}

if(this.roomOwner.equals(user)){
this.roomOwner = userList.get(0);
return;
}
}

public void close(){
for(MultiModeUser user : userList){
user.exitRoom(this);
this.userList.clear();
this.userList = null;
}
}

public void broadcast(byte[] data){

}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

MultiModeRoom multiModeRoom = (MultiModeRoom) o;

return id == multiModeRoom.id;
}


public String getTitle() { // 방 이름을 가져옴
return title;
}

public double getDistance() { return distance;}

public LocalDateTime getStartTime() {return startTime;}

public int getNumRunners() {return numRunners;}

public int getUserSize() { // 유저의 수를 리턴
return userList.size();
}

public MultiModeUser getOwner() { // 방장을 리턴
return roomOwner;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public List getUserList() {
return userList;
}

public void setUserList(List userList) {
this.userList = userList;
}

public MultiModeUser getRoomOwner() {
return roomOwner;
}

public void setRoomOwner(MultiModeUser roomOwner) {
this.roomOwner = roomOwner;
}

public LocalTime getDuration(){
return duration;
}

@Override
public int hashCode() {
return id;
}

@Override
public String toString() {
return "MultiModeRoom{" +
"id=" + id +
", userList=" + userList +
", roomOwner=" + roomOwner +
", roomCreateInfo=" + roomCreateInfo +
'}';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package MultiMode;

import java.io.Serializable;
import java.net.Socket;

public class MultiModeUser implements Serializable {
private static final long serialVersionUID = 1L;

private int id;
private MultiModeRoom room;
private Socket socket;
private String nickname;

public MultiModeUser(String nickName){
this.nickname = nickname;
}

public MultiModeUser(int id, String nickname){
this.id = id;
this.nickname = nickname;
}

public void enterRoom(MultiModeRoom room){
this.room = room;
}

public void exitRoom(MultiModeRoom room){
this.room = null;
}
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getNickname() {return this.nickname; }

public void setnickname(String nickname){
this.nickname = nickname;
}

public MultiModeRoom getRoom() {
return room;
}

public void setRoom(MultiModeRoom room) {
this.room = room;
}

public Socket getSock() {
return socket;
}

public void setSock(Socket socket) {
this.socket = socket;
}

public String getNickName() {
return nickname;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

MultiModeUser gameUser = (MultiModeUser) o;

return id == gameUser.id;
}

@Override
public int hashCode() {
return id;
}
}
69 changes: 69 additions & 0 deletions android/RunUsAndroid/app/src/main/java/MultiMode/Packet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package MultiMode;

import java.io.Serializable;
import java.util.List;

public class Packet implements Serializable { //서버와 통신하기 위해 사용하는 클래스. Protocol + 필요한 정보 넣어서 전송 및 수신
private static final long serialVersionUID = 1L;

// 데이터 유형을 나타내는 필드
private int protocol;

private RoomCreateInfo roomCreateInfo = null;

// 실제 데이터
private MultiModeUser user;

private MultiModeRoom selectedRoom = null;

private List<MultiModeRoom> roomList = null;

public Packet(int protocol, MultiModeUser user) {
this.protocol = protocol;
this.user = user;
}

public Packet(int protocol, MultiModeRoom selectedRoom) {
this.protocol = protocol;
this.selectedRoom = selectedRoom;
}

public Packet(int protocol, MultiModeUser user, RoomCreateInfo roomCreateInfo ){
this.protocol = protocol;
this.user = user;
this.roomCreateInfo = roomCreateInfo;
}

public Packet(int protocol, MultiModeUser user, MultiModeRoom selectedRoom ){
this.protocol = protocol;
this.user = user;
this.selectedRoom = selectedRoom;
}

public Packet(int protocol, List<MultiModeRoom> roomList ){
this.protocol = protocol;
this.roomList = roomList;
}

public Packet(int protocol, List<MultiModeRoom> roomList, MultiModeRoom selectedRoom ){
this.protocol = protocol;
this.roomList = roomList;
this.selectedRoom = selectedRoom;
}



public int getProtocol() {
return protocol;
}

public MultiModeUser getUser() {
return user;
}

public RoomCreateInfo getRoomCreateInfo() {return roomCreateInfo; }

public MultiModeRoom getSelectedRoom() {return selectedRoom;}

public List<MultiModeRoom> getRoomList() {return roomList;}
}
12 changes: 12 additions & 0 deletions android/RunUsAndroid/app/src/main/java/MultiMode/Protocol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package MultiMode;

public class Protocol {
public static final int ROOM_LIST = 1;
public static final int CREATE_ROOM = 2;
public static final int ENTER_ROOM = 3;
public static final int EXIT_ROOM = 4;
// 다른 프로토콜 상수 추가
public static final int UPDATE_ROOM = 5;
public static final int UPDATE_EVERY_ROOM = 6;
}

Loading

0 comments on commit ccd2417

Please sign in to comment.