Skip to content

Commit

Permalink
Refactor file paths and import statements for game configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhuid committed Jun 1, 2024
1 parent 180dd83 commit ae670df
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 266 deletions.
4 changes: 2 additions & 2 deletions src/brick/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bricks, gameParam } from "../config"
import { gameParam } from "../gameConfig"
import { drawBrick } from "../draw"
import { BinaryString, BrickLetter, BrickStruct, IBrick } from "../types"

import { bricks } from "./brickConfig"

const getRandomLetter = (): BrickLetter => {
const letters = Object.keys(bricks) as BrickLetter[]
Expand Down
91 changes: 0 additions & 91 deletions src/config.ts

This file was deleted.

163 changes: 0 additions & 163 deletions src/draw.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/draw/brickStyle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Brick } from "../brick"
import { gameParam } from "../config"
import { gameParam } from "../gameConfig"

export const drawStyle = (
ctx: CanvasRenderingContext2D,
Expand Down
2 changes: 1 addition & 1 deletion src/draw/drawBrickPiece.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Brick } from "../brick"
import { gameParam } from "../config"
import { gameParam } from "../gameConfig"
import { drawStyle } from "./brickStyle"

const offsetCanvas = document.createElement("canvas")
Expand Down
4 changes: 2 additions & 2 deletions src/draw/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Brick } from "../brick"
import { gameParam } from "../config"
import { drawBrickPiece } from "../draw"
import { gameParam } from "../gameConfig"
import { BrickColor } from "../types"
import { drawBrickPiece } from "./drawBrickPiece"

export const drawBrick = (
ctx: CanvasRenderingContext2D,
Expand Down
4 changes: 2 additions & 2 deletions src/game.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Brick } from "./brick"
import { gameParam } from "./config"
import { drawBg } from "./draw"
import { drawBg } from "./draw/index"
import { gameParam } from "./gameConfig"
import { eliminate, record } from "./helper"
import { userActions } from "./inputHandler"
import Operate from "./operate"
Expand Down
29 changes: 29 additions & 0 deletions src/gameConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { GameParam } from "./types"
import { $ } from "./utils"
const container = $("#container") as HTMLDivElement
const { width, height } = container.getBoundingClientRect()
export const gameParam: GameParam = {
column: 10,
row: 20,
FPS: 60,
speed: 2,
keySpeed: 10,
score: 0,
devicePixelRatio: window.devicePixelRatio,
// 给方块计算出整数值宽高,不然小数情况可能会出现方块间的间隙
get brickWidth() {
return Math.round((width * this.devicePixelRatio) / this.column)
},
get brickHeight() {
return Math.round((height * this.devicePixelRatio) / this.row)
},
// 以方块的整数值加上行列算出整个画布的宽高
get windowWidth() {
return this.brickWidth * this.column
},
get windowHeight() {
return this.brickHeight * this.row
},
}


2 changes: 1 addition & 1 deletion src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Brick } from "./brick"
import { gameParam } from "./config"
import { gameParam } from "./gameConfig"
import { BrickColor } from "./types"

/**
Expand Down
5 changes: 3 additions & 2 deletions src/inputHandler.ts → src/inputHandler/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { gameParam, control } from "./config"
import { OperateEvents } from "./types"
import { gameParam } from "../gameConfig"
import { OperateEvents } from "../types"
import { control } from "./inputHandlerConfig"

const isKeyPressed = {
left: false,
Expand Down
13 changes: 13 additions & 0 deletions src/inputHandler/inputHandlerConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const control = {
operate: {
left: ["a", "ArrowLeft"],
right: ["d", "ArrowRight"],
up: ["w", "ArrowUp"],
down: ["s", "ArrowDown"],
bottom: [" "],
},
onceKey: ["up", "bottom"],
speedUpKey: ["down"],
speedUpRate: 2,
pause: ["Enter", "p"],
} as const
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gameParam } from "./config"
import { gameParam } from "./gameConfig"
import Game from "./game"
import { customRaf } from "./utils"

Expand Down

0 comments on commit ae670df

Please sign in to comment.