Commit b2b41594 authored by 18신대성's avatar 18신대성 Committed by 18류지석

중간발표본

parents 429e22d3 2fdf73fd
var GameServer = GameServer || {}; var GameServer = GameServer || {};
GameServer.Phase = {READY: 0, START: 1, MAIN: 2, MUSIC: 3}; GameServer.Phase = {READY: 0, START: 1, MAIN: 2, MUSIC: 3};
GameServer.startCount = 2; GameServer.startCount = 4;
GameServer.currentPlayer = []; GameServer.currentPlayer = [];
GameServer.playingRoom = []; GameServer.playingRoom = [];
...@@ -57,14 +57,32 @@ GameServer.findRoomIndex = function(roomNum) ...@@ -57,14 +57,32 @@ GameServer.findRoomIndex = function(roomNum)
GameServer.enterRoom = function(roomIdx, playerData) GameServer.enterRoom = function(roomIdx, playerData)
{ {
let room = this.playingRoom[roomIdx]; let room = this.playingRoom[roomIdx];
let player = new Player(room.currentPlayer.length, playerData); let nextIdx = -1;
for (let i = 0; i < room.currentPlayer.length; i++)
{
if (room.currentPlayer[i] === null)
{
nextIdx = i;
break
}
}
let player = new Player((nextIdx != -1 ? nextIdx : room.currentPlayer.length), playerData);
if (nextIdx != -1)
{
room.currentPlayer[nextIdx] = player;
room.currentSocket[nextIdx] = playerData;
}
else
{
room.currentPlayer.push(player); room.currentPlayer.push(player);
room.currentSocket.push(playerData); room.currentSocket.push(playerData);
}
playerData.playingData = player; playerData.playingData = player;
playerData.currentRoom = room; playerData.currentRoom = room;
console.log('[' + playerData.id + '] entered to room #' + room.roomNum); console.log('[' + playerData.id + '] entered to room #' + room.roomNum);
playerData.socketId.emit('enterRoom');
if (room.currentPlayer.length >= this.startCount) GameServer.startRoom(roomIdx); if (room.currentPlayer.length >= this.startCount) GameServer.startRoom(roomIdx);
return room; return room;
} }
...@@ -91,6 +109,10 @@ GameServer.startRoom = function(roomIdx) ...@@ -91,6 +109,10 @@ GameServer.startRoom = function(roomIdx)
room.currentPhase = this.Phase.START; room.currentPhase = this.Phase.START;
room.maxTypingPlayer = room.currentPlayer[0]; room.maxTypingPlayer = room.currentPlayer[0];
room.minTypingPlayer = room.currentPlayer[0]; room.minTypingPlayer = room.currentPlayer[0];
room.currentSocket.forEach(function(element)
{
element.isReceivable = true;
});
// sync roomData // sync roomData
let toSync = let toSync =
...@@ -118,7 +140,7 @@ GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = nul ...@@ -118,7 +140,7 @@ GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = nul
{ {
return element.id === targetNum; return element.id === targetNum;
}); });
if (targetSocket != undefined) targetSocket.socketId.emit(_message, _data); if (targetSocket != undefined && targetSocket.isReceivable) targetSocket.socketId.emit(_message, _data);
} }
// 데이터 동기화 함수 만들기 // 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍) // 동기화할것: 유저리스트(id - nickname 쌍)
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<script src="js/WordReader.js"></script> <script src="js/WordReader.js"></script>
<script src="js/CSVParsing.js"></script> <script src="js/CSVParsing.js"></script>
<script src="js/SelectWord.js"></script> <script src="js/SelectWord.js"></script>
<script src="js/BGMsound.js"></script>
</head> </head>
<body> <body>
<script src="js/Client.js"></script> <script src="js/Client.js"></script>
......
var Audio = Audio || {}
Audio.loadSound = function(scene)
{
scene.load.audio('menuBackground', 'assets/sound/BGM_twochae.ogg')
}
Audio.playSound = function(scene)
{
bgm = scene.sound.play('menuBackground')
}
Audio.pauseSound = function(scene)
{
bgm = scene.sound.pause()
}
Audio.resumeSound = function(scene)
{
bgm = scene.sound.resume()
}
Audio.stopSound = function(scene)
{
bgm = scene.sound.stop()
}
// var Audio = new Audio('assets/sound/BGM_twochae.ogg');
// Audio.play();
\ No newline at end of file
...@@ -7,6 +7,14 @@ socket.on('setId', function(msg) // {str, num playerNum} ...@@ -7,6 +7,14 @@ socket.on('setId', function(msg) // {str, num playerNum}
console.log(msg.str); console.log(msg.str);
PlayerData.idNum = msg.num; PlayerData.idNum = msg.num;
}); });
socket.on('errNicknameOverlaped', function()
{
alert('이미 사용중인 닉네임입니다.');
});
socket.on('enterRoom', function()
{
game.scene.remove('menuScene');
});
// init game // init game
socket.on('syncRoomData', function(msg) // {num roomNum, [] players} socket.on('syncRoomData', function(msg) // {num roomNum, [] players}
...@@ -43,6 +51,11 @@ socket.on('defeat', function(msg) // object player ...@@ -43,6 +51,11 @@ socket.on('defeat', function(msg) // object player
console.log(RoomData.players[msg.index].nickname + ' defeated'); console.log(RoomData.players[msg.index].nickname + ' defeated');
}); });
socket.on('attackSucceed', function(msg)
{
WordSpace.nameGroup.push(new NameWord(msg.victim, true));
});
// out game // out game
socket.on('userDisconnect', function(msg) // {num index , num id, str nickname} socket.on('userDisconnect', function(msg) // {num index , num id, str nickname}
{ {
......
...@@ -16,8 +16,7 @@ Input.gameSceneEnterReaction = function() ...@@ -16,8 +16,7 @@ Input.gameSceneEnterReaction = function()
{ {
if (!Input.isEntered) if (!Input.isEntered)
{ {
Input.convInput = Input.removeConVow(Input.convInput); if (Input.attackMode) WordSpace.attack(Input.removeConVow(Input.convInput), Input.attackOption.wordGrade);
if (Input.attackMode) WordSpace.attack(Input.convInput, Input.attackOption.wordGrade);
else WordSpace.findWord(Input.convInput); else WordSpace.findWord(Input.convInput);
Input.reset(); Input.reset();
Input.isEntered = true; Input.isEntered = true;
...@@ -26,12 +25,11 @@ Input.gameSceneEnterReaction = function() ...@@ -26,12 +25,11 @@ Input.gameSceneEnterReaction = function()
Input.menuSceneEnterReaction = function() Input.menuSceneEnterReaction = function()
{ {
Input.convInput = Input.removeConVow(Input.convInput); Input.convInput = Input.removeConVow(Input.convInput);
if (Input.convInput.length > 0) if (Input.convInput.length > 1)
{ {
socket.emit('setNickname', Input.convInput); socket.emit('setNickname', Input.convInput);
PlayerData.nickname = Input.convInput; PlayerData.nickname = Input.convInput;
Input.reset(); Input.reset();
game.scene.remove('menuScene');
} }
else else
{ {
......
...@@ -13,12 +13,14 @@ var menuScene = new Phaser.Class( ...@@ -13,12 +13,14 @@ var menuScene = new Phaser.Class(
{ {
Input.inputField.loadImage(this); Input.inputField.loadImage(this);
BackGround.loadImage(this); BackGround.loadImage(this);
Audio.loadSound(this);
}, },
create: function() create: function()
{ {
Input.inputField.generate(this, Input.menuSceneEnterReaction); Input.inputField.generate(this, Input.menuSceneEnterReaction);
BackGround.drawMenu(this); BackGround.drawMenu(this);
Audio.playSound(this);
} }
}); });
...@@ -85,7 +87,7 @@ var gameScene = new Phaser.Class( ...@@ -85,7 +87,7 @@ var gameScene = new Phaser.Class(
let tempNames = ''; let tempNames = '';
WordSpace.nameGroup.forEach(function(element) WordSpace.nameGroup.forEach(function(element)
{ {
tempNames += element.wordText + element.isStrong + '\n'; tempNames += element.wordText + (element.isStrong?' [강]':'') + '\n';
}); });
WordSpace.nameWordTextForTest.setText('현재 가진 호패들 : \n' + tempNames); WordSpace.nameWordTextForTest.setText('현재 가진 호패들 : \n' + tempNames);
......
...@@ -135,13 +135,12 @@ class AttackWord extends WordObject ...@@ -135,13 +135,12 @@ class AttackWord extends WordObject
super(text); super(text);
this.wordGrade = _wordGrade; this.wordGrade = _wordGrade;
this.wordWeight = WordReader.getWordWeight(this.wordGrade); this.wordWeight = WordReader.getWordWeight(this.wordGrade);
if(WordReader.getWordTyping(_playerData.nickname) <= 9) if(WordReader.getWordTyping(_playerData.nickname) > 9)
this.wordWeight += this.wordWeight * 0.2 * (WordReader.getWordTyping(_playerData.nickname) - 9); this.wordWeight += this.wordWeight * 0.2 * (WordReader.getWordTyping(_playerData.nickname) - 9);
this.wordWeight *= isStrong ? 3 : 2; this.wordWeight *= isStrong ? 3 : 2;
this.attacker = _playerData; this.attacker = _playerData;
//서버 사용하게 되면 PlayerTyping을 피격자의 것으로 바꿔야 함 this.counterTime = WordSpace.gameTimer.now + 1000 * (this.wordTyping <= (5 - _wordGrade) * 2.5 ? this.wordTyping / (Math.max(200, WordSpace.playerTyping) / 60) * 1.5 :
this.counterTime = WordSpace.gameTimer.now + 1000 * (this.wordTyping <= (5 - _wordGrade) * 2.5 ? this.wordTyping * (WordSpace.playerTyping / 60) * 2 : ((5 - _wordGrade) * 3 + (this.wordTyping - (5 - _wordGrade) * 2.5) * 2.5) / (Math.max(200, WordSpace.playerTyping) / 60) * 1.5);
((5 - _wordGrade) * 2.5 + (this.wordTyping - (5 - _wordGrade) * 2.5) * 3) * (WordSpace.playerTyping / 60) * 2);
console.log('Attack text : ' + text + ', Attacker : ' + this.attacker.nickname + ', Weight : ' + this.wordWeight); console.log('Attack text : ' + text + ', Attacker : ' + this.attacker.nickname + ', Weight : ' + this.wordWeight);
console.log('Counter time : ' + this.counterTime); console.log('Counter time : ' + this.counterTime);
} }
...@@ -155,7 +154,10 @@ class AttackWord extends WordObject ...@@ -155,7 +154,10 @@ class AttackWord extends WordObject
case 3: WordSpace.attackGauge.add(0.5); break; case 3: WordSpace.attackGauge.add(0.5); break;
default: console.log('[ERR] wrong grade of word'); break; default: console.log('[ERR] wrong grade of word'); break;
} }
if(WordSpace.gameTimer.now < this.counterTime) WordSpace.nameGroup.push(new NameWord(this.attacker, true)); if(WordSpace.gameTimer.now < this.counterTime)
{
WordSpace.nameGroup.push(new NameWord(this.attacker, true));
}
//강호패 넣기 구현해야됨 //강호패 넣기 구현해야됨
//WordSpace.generateWord.Name(WordSpace.gameSceneForTest, true); //WordSpace.generateWord.Name(WordSpace.gameSceneForTest, true);
super.destroy(); super.destroy();
......
...@@ -292,7 +292,7 @@ WordSpace.setGameOverTimer = function() ...@@ -292,7 +292,7 @@ WordSpace.setGameOverTimer = function()
if(this.brainCapacity < this.totalWeight && !this.isTimerOn) if(this.brainCapacity < this.totalWeight && !this.isTimerOn)
{ {
this.isTimerOn = true; this.isTimerOn = true;
WordSpace.gameOverCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.gameOver, 0, false); WordSpace.gameOverCycle.resetCycle(WordSpace.gameSceneForTest, WordSpace.delay.GameOver, 0, false);
} }
} }
...@@ -354,8 +354,14 @@ WordSpace.findWord = function(wordText) ...@@ -354,8 +354,14 @@ WordSpace.findWord = function(wordText)
{ {
if(WordSpace.getEditDistance(wordText, element.wordText) == minDist) if(WordSpace.getEditDistance(wordText, element.wordText) == minDist)
{ {
//강호패 보내야 함
console.log('Attack word : ' + element.wordText + ' of ' + element.attacker.nickname + ' 오타임'); console.log('Attack word : ' + element.wordText + ' of ' + element.attacker.nickname + ' 오타임');
let victimData =
{
roomNum: RoomData.roomNum,
victim: RoomData.myself,
target: element.attacker.idNum
}
socket.emit('defenseFailed', victimData);
} }
}); });
this.attackGauge.sub(2); this.attackGauge.sub(2);
...@@ -400,6 +406,8 @@ WordSpace.attack = function(wordText, grade) ...@@ -400,6 +406,8 @@ WordSpace.attack = function(wordText, grade)
}); });
//테스트용, 자기 자신에게 공격함 //테스트용, 자기 자신에게 공격함
//WordSpace.generateWord.Attack(WordSpace.gameSceneForTest, wordText, grade, PlayerData, false); //WordSpace.generateWord.Attack(WordSpace.gameSceneForTest, wordText, grade, PlayerData, false);
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
WordSpace.generateWord.Name(WordSpace.gameSceneForTest, false);
WordSpace.nameGroup = []; WordSpace.nameGroup = [];
WordSpace.attackGauge.resetValue(); WordSpace.attackGauge.resetValue();
...@@ -425,8 +433,8 @@ WordSpace.nameQueue = ...@@ -425,8 +433,8 @@ WordSpace.nameQueue =
tempQueue[tempLength - 1] = tempQueue[tempIdx]; tempQueue[tempLength - 1] = tempQueue[tempIdx];
tempQueue[tempIdx] = tempElement; tempQueue[tempIdx] = tempElement;
} }
tempQueue.forEach(function(element){ tempQueue.forEach(function(element)
//console.log(element.id + ' ' + PlayerData.idNum); {
if(element.id != PlayerData.idNum && element.isAlive) if(element.id != PlayerData.idNum && element.isAlive)
WordSpace.nameQueue.queue.push(element); WordSpace.nameQueue.queue.push(element);
}); });
......
This diff is collapsed.
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"express": "^4.17.1", "express": "^4.17.1",
"socket.io": "^2.2.0" "socket.io": "^2.2.0",
"web-audio-player": "^1.3.3"
} }
} }
...@@ -28,8 +28,7 @@ io.on('connection', function(socket) ...@@ -28,8 +28,7 @@ io.on('connection', function(socket)
socketId: socket, socketId: socket,
currentRoom: null, currentRoom: null,
playingData: null, playingData: null,
isReceivable: false
playerTyping: 0
}; };
GameServer.currentPlayer.push(socket.playerData); GameServer.currentPlayer.push(socket.playerData);
console.log('['+socket.playerData.id+'] client request'); console.log('['+socket.playerData.id+'] client request');
...@@ -41,10 +40,20 @@ io.on('connection', function(socket) ...@@ -41,10 +40,20 @@ io.on('connection', function(socket)
}); });
socket.on('setNickname', function(msg) // string new_nickname socket.on('setNickname', function(msg) // string new_nickname
{
let isAlreadyHave = false;
GameServer.currentPlayer.forEach(function(element)
{
if (element.nickname === msg) isAlreadyHave = true;
});
if (isAlreadyHave) socket.emit('errNicknameOverlaped');
else
{ {
socket.playerData.nickname = msg; socket.playerData.nickname = msg;
console.log('['+socket.playerData.id+'] nickname set to ' + msg); console.log('['+socket.playerData.id+'] nickname set to ' + msg);
GameServer.enterEmptyRoom(socket.playerData); GameServer.enterEmptyRoom(socket.playerData);
}
}); });
socket.on('setPlayerTyping', function(msg) // number playerTyping socket.on('setPlayerTyping', function(msg) // number playerTyping
...@@ -72,16 +81,22 @@ io.on('connection', function(socket) ...@@ -72,16 +81,22 @@ io.on('connection', function(socket)
{ {
socket.playerData.playingData.isAlive = false; socket.playerData.playingData.isAlive = false;
socket.playerData.playingData.rank = socket.playerData.currentRoom.nextRank--; socket.playerData.playingData.rank = socket.playerData.currentRoom.nextRank--;
socket.playerData.isReceivable = false;
// 패배단어 체크 // 패배단어 체크
GameServer.announceToRoom(socket.playerData.currentRoom.roomNum, 'defeat', socket.playerData.playingData); GameServer.announceToRoom(socket.playerData.currentRoom.roomNum, 'defeat', socket.playerData.playingData);
console.log('['+socket.playerData.id+']'+ ' defeated'); console.log('['+socket.playerData.id+']'+ ' defeated');
}); });
socket.on('defenseFailed', function(msg)
{
GameServer.announceToTarget(GameServer.findRoomIndex(msg.roomNum), msg.target, 'attackSucceed', msg);
});
socket.on('disconnect', function(reason) socket.on('disconnect', function(reason)
{ {
let data = socket.playerData; let data = socket.playerData;
console.log('['+ data.id +'] client disconnected, reason: ' + reason); console.log('['+ data.id +'] client disconnected, reason: ' + reason);
if (data.id === undefined) if (typeof data.id === undefined)
{ {
console.log('[ERROR] data.id is undefined'); console.log('[ERROR] data.id is undefined');
console.log(GameServer.currentPlayer); console.log(GameServer.currentPlayer);
...@@ -97,13 +112,21 @@ io.on('connection', function(socket) ...@@ -97,13 +112,21 @@ io.on('connection', function(socket)
GameServer.currentPlayer.splice(idxToDel, 1); GameServer.currentPlayer.splice(idxToDel, 1);
// 룸에서도 제거 // 룸에서도 제거
if (data.currentRoom != null) if (data.currentRoom != null)
{
if (data.currentRoom.currentPhase === GameServer.Phase.READY)
{
data.currentRoom.currentPlayer[data.playingData.index] = null;
data.currentRoom.currentSocket[data.playingData.index] = null;
}
else
{ {
data.playingData.isAlive = false; data.playingData.isAlive = false;
if (data.playingData.rank === -1) data.playingData.rank = data.currentRoom.nextRank--; if (data.playingData.rank === -1) data.playingData.rank = data.currentRoom.nextRank--;
data.currentRoom.currentSocket.splice(data.playingData.index, 1); data.currentRoom.currentSocket[data.playingData.index].isReceivable = false;
GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'userDisconnect', data.playingData); GameServer.announceToRoom(GameServer.findRoomIndex(data.currentRoom.roomNum), 'userDisconnect', data.playingData);
} }
} }
}
console.log('['+ data.id +'] disconnect complete'); console.log('['+ data.id +'] disconnect complete');
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment