Introduce LocalGame logic and integrate with LocalMode rendering.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
export interface FieldSize {
|
||||
x: number,
|
||||
y: number
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { FieldSize } from '@/scripts/interfaces/FieldSize.ts'
|
||||
|
||||
class LocalGame {
|
||||
public field: number[][]
|
||||
|
||||
private currentPlayer: number = 1;
|
||||
constructor(fieldSize: FieldSize) {
|
||||
this.field = Array.from({ length: fieldSize.y }, () => Array(fieldSize.x).fill(0))
|
||||
}
|
||||
|
||||
place(locationX: number): void {
|
||||
for (let y = this.field.length - 1; y >= 0; y--) {
|
||||
const row = this.field[y]
|
||||
|
||||
if (row && row[locationX] === 0) {
|
||||
row[locationX] = this.currentPlayer
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
this.currentPlayer = this.currentPlayer === 1 ? 2 : 1
|
||||
}
|
||||
}
|
||||
|
||||
export default LocalGame
|
||||
Reference in New Issue
Block a user