-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
018532f
commit 85128a5
Showing
12 changed files
with
228 additions
and
134 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
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,6 @@ | ||
import { User } from '../../users/entities/user.entity'; | ||
|
||
export class acceptGameParamDto { | ||
invitationId: number; | ||
invitedUser: User; | ||
} |
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,4 +1,37 @@ | ||
import { GameStatus, GameType } from '../../common/enum'; | ||
|
||
export class CreateGameParamDto { | ||
invitationId: number; | ||
invitedUserId: number; | ||
winnerId: number; | ||
loserId: number; | ||
gameType: GameType; | ||
winnerScore: number; | ||
loserScore: number; | ||
gameStatus: GameStatus; | ||
ballSpeed: number; | ||
racketSize: number; | ||
|
||
constructor(player1Id: number, player2Id: number, gameType: GameType) { | ||
this.winnerId = player1Id; | ||
this.loserId = player2Id; | ||
this.gameType = gameType; | ||
this.winnerScore = 0; | ||
this.loserScore = 0; | ||
this.gameStatus = GameStatus.WAITING; | ||
if ( | ||
this.gameType === GameType.SPECIAL_INVITE || | ||
this.gameType === GameType.SPECIAL_MATCHING | ||
) { | ||
this.ballSpeed = this.getRandomNumber(1, 3); | ||
this.racketSize = this.getRandomNumber(1, 3); | ||
} else { | ||
// Set to 1 for NORMAL | ||
this.ballSpeed = 1; | ||
this.racketSize = 1; | ||
} | ||
} | ||
|
||
private getRandomNumber(min: number, max: number): number { | ||
// Generate a random integer between min and max (inclusive) | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { GameStatus } from '../../common/enum'; | ||
import { Game } from '../entities/game.entity'; | ||
import { ViewMapDto } from './view-map.dto'; | ||
|
||
export class GameDto { | ||
private gameId: number; | ||
player1Id: number; | ||
player2Id: number; | ||
winnerId: number | null; | ||
loserId: number | null; | ||
score1: number; | ||
score2: number; | ||
gameStatus: GameStatus; | ||
viewMap: ViewMapDto; | ||
|
||
constructor(game: Game) { | ||
this.setGameId(game.id); | ||
this.player1Id = game.winnerId; | ||
this.player2Id = game.loserId; | ||
this.winnerId = null; | ||
this.loserId = null; | ||
this.score1 = game.winnerScore; | ||
this.score2 = game.loserScore; | ||
this.gameStatus = game.gameStatus; | ||
this.viewMap = new ViewMapDto(game.ballSpeed, game.racketSize); | ||
} | ||
getGameId() { | ||
return this.gameId; | ||
} | ||
|
||
private setGameId(gameId: number) { | ||
this.gameId = gameId; | ||
} | ||
} |
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
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,43 @@ | ||
// ball 변하는 값 | ||
type ball = { | ||
x: number; | ||
y: number; | ||
speed: number; | ||
}; | ||
|
||
// racket 변하는 값 | ||
type racket = { | ||
y: number; | ||
size: number; | ||
}; | ||
|
||
export class ViewMapDto { | ||
ball: ball; | ||
racket1: racket; | ||
racket2: racket; | ||
|
||
constructor( | ||
ballSpeed: number, | ||
racketSize: number, | ||
|
||
// 고정값 | ||
private readonly canvasWidth = 1400, | ||
private readonly canvasHeight = 1000, | ||
|
||
private readonly ballRadius = 2, | ||
|
||
private readonly racketWidth = canvasWidth * 0.1, | ||
private readonly racketHeight = canvasHeight * 0.4, | ||
private readonly racket1X = 0, | ||
private readonly racket2X = canvasWidth - racketWidth, | ||
) { | ||
this.ball.x = canvasWidth / 2; | ||
this.ball.y = canvasHeight / 2; | ||
this.ball.speed = ballSpeed; | ||
|
||
this.racket1.y = canvasHeight / 2 - racketHeight / 2; | ||
this.racket2.y = canvasHeight / 2 - racketHeight / 2; | ||
this.racket1.size = racketSize; | ||
this.racket2.size = racketSize; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.