Project using node.js
-
Game count down clockProject using node.js/Cloning Catch-Mind 2020. 12. 18. 16:58
Client에게 game이 시작되었다는 것을 알리기 // player.js const timeOut = document.getElementById("jsTimeOut"); let count = null; let counter = null; const setTimeOut = () => { count--; if (count { clearTimeout(counter); count = 30; counter = setInterval(setTimeOut, 1000); }; export const handleGameEnded = () => { clearTimeout(counter); }; 30초 안에 그림을 그리고 참가자들은 painter의 그림을 맞춰야 한다. 시간의 count down을 board 오른쪽 위에 표..
-
Add pointsProject using node.js/Cloning Catch-Mind 2020. 12. 18. 16:51
점수 부여 // socketController.js export const socketController = (socket, io) => { const addPoints = (id) => { sockets = sockets.map((socket) => { if (socket.id === id) socket.points += 10; return socket; }); sendPlayerUpdate(); endGame(); }; socket.on(events.sendMsg, ({ message, username }) => { if (word === message) { addPoints(socket.id); superBroadcast(events.newMsg, { message: `Winner is ${sock..
-
Game end eventProject using node.js/Cloning Catch-Mind 2020. 12. 18. 14:08
Client에게 game이 끝났다는 것을 알리기 // globalController.js let painter = null; let word = null; let timeout = null; export const socketController = (socket, io) => { const startGame = () => { if (sockets.length > 1) { superBroadcast(events.gameStarted); painter = choosePainter(); word = chooseWord(); io.to(painter.id).emit(events.painterNotif, { word }); timeout = setTimeout(endGame, 30000); // timeout }..
-
Game Start eventProject using node.js/Cloning Catch-Mind 2020. 12. 18. 13:19
Client에게 game이 시작되었다는 것을 알리기 // socketController.js import { chooseWord } from "./words"; export const socketController = (socket, io) => { const choosePainter = () => sockets[Math.floor(Math.random() * sockets.length)]; const startGame = () => { // painter select if (sockets.length > 1) { superBroadcast(events.gameStarted); const painter = choosePainter(); const word = chooseWord(); io.to(paint..
-
Log out event with socketIOProject using node.js/Cloning Catch-Mind 2020. 12. 17. 14:18
Delete the socket which is logout. // globalController.js export const logout = async (req, res) => { const { user: { id }, } = req; const logoutUser = await User.findById(id); const itemIdx = sockets.findIndex( (aSocket) => aSocket.username === logoutUser.username ); if (itemIdx > -1) sockets.splice(itemIdx, 1); io.emit(events.disconnected, { username: logoutUser.username }); sendPlayerUpdate()..
-
Player updateProject using node.js/Cloning Catch-Mind 2020. 12. 17. 10:10
Player update // globalController.js const superBroadcast = (event, data) => io.emit(event, data); const sendPlayerUpdate = () => superBroadcast(events.playerUpdate, { sockets }); export const notifyLogin = async (req, res) => { io.once("connection", (socket) => { io.to(socket.id).emit(events.login, { username }); socket.broadcast.emit(events.newUser, { username }); }); sendPlayerUpdate(); // 추가..
-
Erase canvas with socketIOProject using node.js/Cloning Catch-Mind 2020. 12. 17. 08:44
Client 'A'가 canvas 를 지우는 logic // paint.js let erasing = false; const handleInputRangeEraser = (e) => { if (erasing) { const size = e.target.value; ctx.lineWidth = size; } }; const erase = () => { erasing = true; ctx.globalCompositeOperation = "destination-out"; ctx.lineWidth = eraserRange.value; }; const handleClickEraser = () => { erase(); getSocket().emit(window.events.erase); }; // events.js..
-
Fill the canvas with socketIOProject using node.js/Cloning Catch-Mind 2020. 12. 17. 07:40
Client 'A'가 canvas 전체를 칠하는 logic // paint.js const fill = (color = null) => { let currentColor = ctx.fillStyle; if (color !== null) currentColor = color; ctx.fillStyle = currentColor; ctx.fillRect(0, 0, CANVAS_SIZE, CANVAS_SIZE); }; const handleClickFill = () => { if (filling) { fill(); getSocket().emit(window.events.fill, { color: ctx.strokeStyle }); } }; canvas.addEventListener("click", handle..