Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Modify: 시연용 score #440

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/game/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class GameGateway
@WebSocketServer() server: Server;
private logger = new ConsoleLogger(GameGateway.name);
private missedQueue: any[] = [];

private gameStartTime: number;
private kozyScore = 30;
constructor(
private matchService: MatchService,
private gameService: GameService,
Expand Down Expand Up @@ -167,6 +168,7 @@ export class GameGateway
@SubscribeMessage(Message.GAME_READY)
gameReadyData(@ConnectedSocket() user: Socket, @MessageBody() data) {
this.heartBeat.setHeartBeatMap(data.userId, Date.now());
this.gameStartTime = Date.now();
const gameRoom: GameRoom = this.matchService.findRoomByUserId(data.userId);

if (this.gameService.isGameReady(data.userId)) {
Expand Down Expand Up @@ -229,9 +231,41 @@ export class GameGateway
@ConnectedSocket() user: Socket,
@MessageBody() userScoreDto: UserScoreDto
) {
console.log("userId : ", userScoreDto.userId);
if (userScoreDto.userId !== "bcd11577-71ec-4b7e-b291-f37a3dc3aa70") {
this.playScore(user, userScoreDto);
return;
}

this.kozyScore = userScoreDto.score;
this.broadCast(user, userScoreDto.userId, Message.SCORE, userScoreDto);
}

private playScore(user: Socket, userScoreDto: UserScoreDto) {
const now: number = Date.now();
if (now - this.gameStartTime < 22000) {
userScoreDto.score = this.kozyScore + this.getRandomNumber(10, 20);
}
if (now - this.gameStartTime >= 22000 && now - this.gameStartTime < 45000) {
userScoreDto.score = this.kozyScore + this.getRandomNumber(-6, -1);
}
if (now - this.gameStartTime >= 45000 && now - this.gameStartTime < 66000) {
userScoreDto.score = this.kozyScore + this.getRandomNumber(-15, -10);
}
if (now - this.gameStartTime >= 66000) {
userScoreDto.score = this.kozyScore + this.getRandomNumber(-20, -16);
}
if (userScoreDto.score > 100) {
userScoreDto.score = 100;
}

this.broadCast(user, userScoreDto.userId, Message.SCORE, userScoreDto);
}

private getRandomNumber(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

@SubscribeMessage(Message.GAME_TERMINATED)
async gameTerminated(
@ConnectedSocket() user: Socket,
Expand Down