Skip to content

Commit

Permalink
Merge pull request #282 from boostcamp-2020/refactor/#199
Browse files Browse the repository at this point in the history
ํ—๊ฐ€๋ฆฌ์•ˆ ํ‘œ๊ธฐ๋ฒ•์œผ๋กœ ๋ฆฌํŒฉํ† ๋ง + ๋นˆ ๋ฌธ์ž์—ด์„ ๋‹‰๋„ค์ž„์œผ๋กœ ์„ค์ •ํ•  ๋•Œ ๋˜๋Œ๋ฆฌ๊ธฐ
  • Loading branch information
Front-line-dev authored Dec 17, 2020
2 parents fb9f327 + 385c9b3 commit 0e58a72
Show file tree
Hide file tree
Showing 37 changed files with 101 additions and 107 deletions.
5 changes: 1 addition & 4 deletions src/backend/game/GameMethods/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ function dealCards(count = 1) {
}

const setUserTeller = (users, tellerTurnID) => {
users.forEach((user) => {
if (tellerTurnID === user.turnID) user.setTeller(true);
else user.setTeller(false);
});
users.forEach((user) => user.setTeller(tellerTurnID === user.turnID));
};

function startRound() {
Expand Down
10 changes: 4 additions & 6 deletions src/backend/game/GameMethods/scoreBoardScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const isGameOver = (game) => {
if (game.status.unusedCards.length < game.getUsers().length) return true;

// ํ”Œ๋ ˆ์ด์–ด ์ตœ์†Œ ํ•œ๋ช…์ด 30์ ์„ ๋„˜๊ฒผ์„ ๊ฒฝ์šฐ
if (game.getUsers().some((user) => user.score >= SCORE.WIN_SCORE))
return true;

return false;
const bHigherGoal = game
.getUsers()
.some((user) => user.score >= SCORE.WIN_SCORE);
return bHigherGoal;
};

// ๊ฐ€์žฅ ๋†’์€ ์Šค์ฝ”์–ด๋ฅผ ๊ฐ€์ง„ ์œ ์ €์˜ socketID๋ฅผ ๋ฆฌํ„ด
Expand Down Expand Up @@ -49,8 +49,6 @@ function endScoreBoardScene() {

if (isGameOver(this)) {
this.emitGameEnd();

// WaitingScene ์‹œ์ž‘
this.setState(GAME_STATE.WAITING);
} else {
this.startTellerScene();
Expand Down
4 changes: 2 additions & 2 deletions src/backend/game/GameMethods/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ function getUsers() {
}

function getTeller() {
const [teller] = this.getUsers().filter((user) => user.isTeller);
const [teller] = this.getUsers().filter((user) => user.bTeller);
return teller;
}

function getGuessers() {
return this.getUsers().filter((user) => !user.isTeller);
return this.getUsers().filter((user) => !user.bTeller);
}

function getUsersProfile() {
Expand Down
36 changes: 16 additions & 20 deletions src/backend/game/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ class User {
this.nickname = nickname;
this.color = color;

this.isTeller = false;
this.bTeller = false;

this.turnID = 0;
this.score = 0;
this.cards = [];

this.submittedCard = null;
this.votedCard = null;
this.isReady = false;
this.isSkip = false;
this.bReady = false;
this.bSkip = false;
}

initOnStart({ turnID } = {}) {
Expand All @@ -27,20 +27,20 @@ class User {
initOnRound() {
this.submittedCard = null;
this.votedCard = null;
this.isReady = false;
this.isSkip = false;
this.bReady = false;
this.bSkip = false;
}

setTeller(boolean) {
this.isTeller = boolean;
this.bTeller = boolean;
}

setReady(isReady) {
this.isReady = isReady;
setReady(bReady) {
this.bReady = bReady;
}

setSkip() {
this.isSkip = true;
this.bSkip = true;
}

setColor(color) {
Expand All @@ -57,16 +57,12 @@ class User {

submitCard(cardID) {
this.submittedCard = cardID;

// ๋ฝ‘์€ ์นด๋“œ๋ฅผ ๋ฆฌ์ŠคํŠธ์—์„œ ์ง€์›€
this.cards = this.cards.filter((card) => card !== cardID);
}

voteCard(cardID) {
// ์•…์„ฑ ์œ ์ €๊ฐ€ ์žˆ์„๊นŒ๋ด ์ž๊ธฐ ์นด๋“œ ์„ ํƒํ•˜๋Š”๊ฑฐ ๋ฐฉ์ง€
if (cardID === this.submittedCard) return;
// ํ…”๋Ÿฌ๊ฐ€ vote ๋ชปํ•˜๊ฒŒ ๋ง‰๊ธฐ
if (this.isTeller) return;
if (this.bTeller) return;

this.votedCard = cardID;
}
Expand All @@ -83,10 +79,10 @@ class User {
turnID,
submittedCard,
votedCard,
isTeller,
bTeller,
cards,
score,
isReady,
bReady,
} = this;

return {
Expand All @@ -96,20 +92,20 @@ class User {
turnID,
submittedCard,
votedCard,
isTeller,
bTeller,
cards,
score,
isReady,
bReady,
};
}

getProfile() {
const { nickname, color, score, isReady } = this;
const { nickname, color, score, bReady } = this;
return {
nickname,
color,
score,
isReady,
bReady,
};
}

Expand Down
6 changes: 1 addition & 5 deletions src/backend/sockets/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ function onSkipPlayer() {
if (!user || !game) return;

user.setSkip();

// ๋ชจ๋“  ์œ ์ €๊ฐ€ ์Šคํ‚ต์„ ๋ˆŒ๋ €์„ ๊ฒฝ์šฐ
if (game.getUsers().every((u) => u.isSkip)) {
game.endDiscussionScene(true);
}
if (game.getUsers().every((u) => u.bSkip)) game.endDiscussionScene(true);
}

export default function onDiscussion(socket) {
Expand Down
12 changes: 6 additions & 6 deletions src/backend/sockets/waitingRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function onUpdatePlayer(updatedUserProfile = {}) {
const timeoutMap = new Map();

const isPossibleStartGame = ({ users }) => {
const isAllReady = [...users].every(([, user]) => user.isReady);
const isValidSize = users.size >= PLAYER.MIN && users.size <= PLAYER.MAX;
return isAllReady && isValidSize;
const bAllReady = [...users].every(([, user]) => user.bReady);
const bValidSize = users.size >= PLAYER.MIN && users.size <= PLAYER.MAX;
return bAllReady && bValidSize;
};

const deleteGameStartTimeout = (roomID) => {
Expand All @@ -63,7 +63,7 @@ const deleteGameStartTimeout = (roomID) => {
};

// ์‚ฌ์šฉ์ž๊ฐ€ ๋ ˆ๋””๋ฅผ ๋ˆŒ๋ €์„ ๋•Œ or ๋ ˆ๋””๋ฅผ ํ’€์—ˆ์„ ๋•Œ
function onReadyChange({ isReady }) {
function onReadyChange({ bReady }) {
const socket = this;
const { user, game } = socket;

Expand All @@ -77,8 +77,8 @@ function onReadyChange({ isReady }) {
const { users, roomID } = game;

// ํ”Œ๋ ˆ์ด์–ด์˜ ๋ ˆ๋”” ์ƒํƒœ๋ฅผ ๋ณ€๊ฒฝ
users.get(socket.id).setReady(isReady);
socket.in(roomID).emit('ready player', { playerID: socket.id, isReady });
users.get(socket.id).setReady(bReady);
socket.in(roomID).emit('ready player', { playerID: socket.id, bReady });

const validationToStart = isPossibleStartGame({ users });
// ๋ชจ๋“  ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋ ˆ๋”” ์ƒํƒœ์ผ ๋•Œ
Expand Down
4 changes: 2 additions & 2 deletions src/backend/utils/calcScore.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const mapScore = (correctScore, bonusScore) => ({ correctScore, bonusScore });
const getScoreMap = (game) => {
const scoreMap = new Map();
const users = game.getUsers();
const [teller] = users.filter((user) => user.isTeller);
const guessers = users.filter((user) => !user.isTeller);
const [teller] = users.filter((user) => user.bTeller);
const guessers = users.filter((user) => !user.bTeller);

// Teller
// [๋‹ค ๋งž์ถ”๊ฑฐ๋‚˜ ์•„๋ฌด๋„ ๋ชป ๋งž์ถค]์ธ์ง€ [ํ•œ๋ช…์ด๋ผ๋„ ๋งž์ถค]์ธ์ง€ ํ™•์ธ
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/engine/CardObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ImageObject from './ImageObject';
const getFacingStyle = (isUp) => (isUp ? 'rotateY(0deg)' : 'rotateY(180deg)');
const deg2rad = (deg) => (deg * Math.PI) / 180;
const MOVE_PERCENT = 10;
const HIGH_DEPTH = 7;

const CardObject = class extends GameObject {
constructor({
Expand Down Expand Up @@ -73,7 +74,7 @@ const CardObject = class extends GameObject {
return () => {
const movedX = this.fixedX + Math.sin(deg2rad(this.angle)) * MOVE_PERCENT;
const movedY = this.fixedY - Math.cos(deg2rad(this.angle)) * MOVE_PERCENT;
this.setDepth('7');
this.setDepth(HIGH_DEPTH);
this.move(movedX, movedY);

if (this.tellerCard)
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/engine/DuckCursorObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TIME from '@type/time';
import DuckObejct from './DuckObject';

class DuckCursorObject extends DuckObejct {
constructor({ isReady, ...props }) {
constructor({ bReady, ...props }) {
super(props);
this.addClass('cursor-duck-wrapper');
this.setOriginCenter();
Expand All @@ -16,7 +16,7 @@ class DuckCursorObject extends DuckObejct {
this.mouseHandler = this.makeFollowMouse.bind(this);
this.width = 100;
this.render();
this.setVisibility(isReady);
this.setVisibility(bReady);
}

addMouseMoveEvent() {
Expand Down
9 changes: 7 additions & 2 deletions src/frontend/engine/ProgressBarObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import GameObject from './GameObject';
const RED_COLOR = '#d82e21';
const YELLOW_COLOR = '#ffd600';
const GREEN_COLOR = '#3ed78d';
const SMALL_WIDTH = 30;
const MID_WIDTH = 60;

const ProgressBarObject = class extends GameObject {
constructor() {
Expand Down Expand Up @@ -64,8 +66,11 @@ const ProgressBarObject = class extends GameObject {
const remainTime = endTime - new Date().getTime();
const widthSize = (remainTime / this.time) * 100;
progressBar.style.width = `${widthSize}%`;
if (widthSize < 30) progressBar.style.backgroundColor = RED_COLOR;
else if (widthSize < 60) progressBar.style.backgroundColor = YELLOW_COLOR;
if (widthSize < SMALL_WIDTH) {
progressBar.style.backgroundColor = RED_COLOR;
} else if (widthSize < MID_WIDTH) {
progressBar.style.backgroundColor = YELLOW_COLOR;
}
timeText.innerText = (remainTime / 1000).toFixed(0);
}, TIME.HALF_SECOND);

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/game/LeftTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LeftTab {
updateDuck(playerInfo) {
const updatedDuck = this.findDuck(playerInfo.socketID);
if (updatedDuck) {
updatedDuck.setHat(playerInfo.isTeller);
updatedDuck.setHat(playerInfo.bTeller);
updatedDuck.update(playerInfo);
} else this.addDuck(playerInfo);
}
Expand Down
15 changes: 9 additions & 6 deletions src/frontend/scenes/discussion/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import socket from '@utils/socket';
import { $qs } from '@utils/dom';
import PlayerManager from '@utils/PlayerManager';

const changeClass = ({ target }) => {
target.classList.remove('skip-button');
target.classList.add('skip-button-clicked');
};

// eslint-disable-next-line import/prefer-default-export
export const clickSkip = ({ target }) => {
const warningBox = $qs('.warning-bubble');
target.classList.remove('skip-button');
target.classList.add('skip-button-clicked');
changeClass({ target });
target.setAttribute('disabled', true);
warningBox.style.visibility = 'hidden';
socket.emit('skip player');
Expand All @@ -23,11 +27,10 @@ export const mouseOutSkip = () => {
};

export const initTeller = () => {
const isTeller = PlayerManager.isTeller();
const bTeller = PlayerManager.isTeller();
const skipButton = $qs('.skip-button');
if (isTeller) {
skipButton.classList.remove('skip-button');
skipButton.classList.add('skip-button-clicked');
if (bTeller) {
changeClass({ target: skipButton });
skipButton.setAttribute('disabled', true);
socket.emit('skip player');
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/scenes/discussion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Discussion = class {
this.arrayToBeRemoved = arrayToBeRemoved;
}

wrapup() {
wrapUp() {
this.arrayToBeRemoved.forEach((gameObject) => {
gameObject.delete();
});
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/scenes/endGame/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const EndGame = class {
this.arrayToBeRemoved = arrayToBeRemoved;
}

wrapup() {
wrapUp() {
this.arrayToBeRemoved.forEach((gameObject) => {
gameObject.delete();
});
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/scenes/guesserSelectCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const GuesserSelectCard = class {
this.arrayToBeRemoved = arrayToBeRemoved;
}

wrapup() {
wrapUp() {
this.arrayToBeRemoved.forEach((gameObject) => {
gameObject.delete();
});
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/scenes/guesserWaiting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const GuesserWaiting = class {
this.cards = cards;
}

wrapup() {
wrapUp() {
this.arrayToBeRemoved.forEach((gameObject) => {
gameObject.delete();
});
Expand Down
6 changes: 2 additions & 4 deletions src/frontend/scenes/guesserWaiting/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const renderGuesserWaiting = ({ endTime }) => {
ProgressBar.start();

PlayerManager.getPlayers().forEach((player) =>
player.duck.setVisibility(!player.isTeller, player.isCurrentPlayer),
player.duck.setVisibility(!player.bTeller, player.isCurrentPlayer),
);

const tellerColor = PlayerManager.getTeller().color;
Expand All @@ -34,9 +34,7 @@ const renderGuesserWaiting = ({ endTime }) => {

const { CardsWrapper, cards } = createCards(GUESSER_WAITING);
CardsWrapper.attachToRoot();
cards.forEach((card) => {
card.setAnimateMove(false);
});
cards.forEach((card) => card.setAnimateMove(false));

const arrayToBeRemoved = [
NotifyingTellerText,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/scenes/mixCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const MixCard = class {
this.arrayToBeRemoved = arrayToBeRemoved;
}

wrapup() {
wrapUp() {
this.arrayToBeRemoved.forEach((gameObject) => {
gameObject.delete();
});
Expand Down
4 changes: 1 addition & 3 deletions src/frontend/scenes/mixCard/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const stackCards = async ({ Cards, position }) => {
};

const rotateCards = ({ Cards }) => {
Cards.forEach((card) => {
card.rotate(NUMBER.ZERO, NUMBER.ZERO);
});
Cards.forEach((card) => card.rotate(NUMBER.ZERO, NUMBER.ZERO));
};

const shuffleCard = async ({ card, position, zindex = NUMBER.MAX_Z_INDEX }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/scenes/playerWaiting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const PlayerWaiting = class {
this.arrayToBeRemoved = arrayToBeRemoved;
}

wrapup() {
wrapUp() {
this.arrayToBeRemoved.forEach((gameObject) => {
gameObject.delete();
});
Expand Down
Loading

0 comments on commit 0e58a72

Please sign in to comment.