-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue : #15
- Loading branch information
Showing
10 changed files
with
155 additions
and
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.fourtrashes.pokerface.core.game; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
public class Card { | ||
private int card; | ||
private boolean isOpen; | ||
} |
28 changes: 22 additions & 6 deletions
28
src/main/java/com/fourtrashes/pokerface/core/game/GameController.java
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,29 +1,45 @@ | ||
package com.fourtrashes.pokerface.core.game; | ||
|
||
import com.fourtrashes.pokerface.domain.Room; | ||
import com.fourtrashes.pokerface.dto.PlayerStateDTO; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.stereotype.Controller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class GameController { | ||
|
||
private final SimpMessagingTemplate simpMessagingTemplate; | ||
private final ConcurrentMap<Integer, Room> roomList; | ||
|
||
// 추후 구현사항 room객체에 들어가야 할듯 | ||
boolean isAllPlayerReady(){ | ||
return true; | ||
} | ||
|
||
@MessageMapping(value = "/game/ready/{roomId}") | ||
public void ready(@DestinationVariable("roomId") Integer roomId, SimpMessageHeaderAccessor header){ | ||
Room room = roomList.get(roomId); | ||
GameManager gameManager = room.getGameManager(); | ||
gameManager.ready(header.getSessionId()); | ||
// 전달할 메세지 타입 | ||
// 1. 모두 준비가 되었을 때 방장이 시작하면 준비된 플레이어들 전달 | ||
// 2. 모든사람이 ready일때 자동 시작하려면 메세지 없어도 무방 | ||
// 구현 내용에 따라 시작하는 함수 달라짐 | ||
// 모든사람이 ready일때 자동 시작 | ||
ConcurrentHashMap<String, Object> users = roomList.get(roomId).getUserList(); | ||
PokerGameManager gameManager = roomList.get(roomId).getGameManager(); | ||
if (isAllPlayerReady()) { | ||
gameManager.startGame(users); | ||
gameManager.firstDeal(); | ||
} | ||
ArrayList<Player> players = gameManager.getPlayers(); | ||
for(Player player : players){ | ||
// destination에 무엇이 들어가야 하는지 결정 필요 | ||
simpMessagingTemplate.convertAndSendToUser(player.getSessionId(),"", new PlayerStateDTO(player)); | ||
} | ||
} | ||
|
||
} |
12 changes: 3 additions & 9 deletions
12
src/main/java/com/fourtrashes/pokerface/core/game/GameManager.java
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,14 +1,8 @@ | ||
package com.fourtrashes.pokerface.core.game; | ||
|
||
import java.util.concurrent.ConcurrentMap; | ||
|
||
public interface GameManager { | ||
void startGame(); | ||
void endGame(); | ||
void ready(String sessionId); | ||
void bet(); | ||
void firstDeal(); | ||
void deal(); | ||
void lastDeal(); | ||
void startGame(ConcurrentMap<String, Object> users); | ||
void settle(); | ||
void getUserTurn(); | ||
void setUser(String sessionId); | ||
} |
108 changes: 0 additions & 108 deletions
108
src/main/java/com/fourtrashes/pokerface/core/game/GameManagerImpl.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/main/java/com/fourtrashes/pokerface/core/game/Player.java
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,29 @@ | ||
package com.fourtrashes.pokerface.core.game; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.ArrayList; | ||
|
||
@Getter | ||
@Setter | ||
public class Player { | ||
|
||
private String sessionId; | ||
private int turn; | ||
private boolean isDead; | ||
private boolean isReady; | ||
private ArrayList<Card> cardList; | ||
|
||
public Player(String sessionId){ | ||
this.sessionId = sessionId; | ||
this.turn = -1; | ||
this.isDead = false; | ||
this.isReady = false; | ||
this.cardList = new ArrayList<>(); | ||
} | ||
|
||
public void putInCard(int card, boolean isOpen){ | ||
cardList.add(new Card(card, isOpen)); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/com/fourtrashes/pokerface/core/game/PokerGameManager.java
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,66 @@ | ||
package com.fourtrashes.pokerface.core.game; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
@Getter | ||
public class PokerGameManager implements GameManager { | ||
|
||
public ArrayList<Player> players; | ||
private CardDeck cardDeck = new CardDeckImpl(); | ||
|
||
// 로직변경 : 모든 유저가 레디상태가 되면 GameManager의 startGame(유저 목록)을 불러주세요. | ||
@Override | ||
public void startGame(ConcurrentMap<String, Object> users) { | ||
cardDeck.shuffle(); | ||
|
||
Iterator<String> sessionIds = users.keySet().iterator(); | ||
int turn = 0; | ||
while (sessionIds.hasNext()) { | ||
String sessionId = sessionIds.next(); | ||
Player player = new Player(sessionId); | ||
player.setTurn(turn++); | ||
players.add(player); | ||
} | ||
|
||
} | ||
|
||
public void firstDeal() { | ||
int turn = getUserTurn(); | ||
// 카드 4장 배분 | ||
for(int i=0;i<players.size() * 4;i++){ | ||
int card = cardDeck.getTop(); | ||
players.get(turn).putInCard(card, false); | ||
turn = (turn + 1) % players.size(); | ||
} | ||
|
||
} | ||
|
||
public void lastDeal(){ | ||
|
||
} | ||
|
||
public void bet() { | ||
|
||
} | ||
|
||
public void deal() { | ||
|
||
} | ||
|
||
@Override | ||
public void settle() { | ||
|
||
} | ||
|
||
private int getUserTurn(){ | ||
/* | ||
4명의 플레이어중에 가장 높은 패를 들고있는 플레이어의 index를 return 해야함. | ||
자리 순서대로 카드가 분배될 것이므로 인원수만큼 반복 돌리면 됌. | ||
*/ | ||
return 0; | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
src/main/java/com/fourtrashes/pokerface/core/game/UserStatus.java
This file was deleted.
Oops, something went wrong.
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/fourtrashes/pokerface/dto/PlayerStateDTO.java
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,21 @@ | ||
package com.fourtrashes.pokerface.dto; | ||
|
||
import com.fourtrashes.pokerface.core.game.Card; | ||
import com.fourtrashes.pokerface.core.game.Player; | ||
import lombok.Data; | ||
|
||
import java.util.ArrayList; | ||
|
||
@Data | ||
public class PlayerStateDTO { | ||
private ArrayList<Card> cardList; | ||
private int turn; | ||
private boolean isDead; | ||
|
||
public PlayerStateDTO(Player player){ | ||
this.cardList = player.getCardList(); | ||
this.turn = player.getTurn(); | ||
this.isDead = player.isDead(); | ||
} | ||
|
||
} |
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