Files
sudoku/src/models/DOBlock.ts

80 lines
1.9 KiB
TypeScript
Raw Normal View History

2025-05-28 18:47:51 +08:00
import type { DataBlock } from "../types/global"
2025-05-14 19:22:21 +08:00
import { StorageManager } from "./StorageManager"
2025-05-13 20:31:44 +08:00
export class DOBlock {
2025-05-28 18:47:51 +08:00
private data: DataBlock
private preset: boolean = false// 预设格子
private correct: number = 0
private checked: boolean = false// 是否正确
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
constructor(dataBlock: DataBlock, preset: boolean, correct: number) {
this.data = dataBlock
this.preset = preset
this.correct = correct
this.checked = preset || (dataBlock.show == correct)
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
// ====================================持久化数据
public get_index(): number {
return this.data.index
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public get_show(): number {
return this.data.show
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public set_show(show: number): void {
this.data.show = show
this.checked = show == this.get_correct()
StorageManager.getInstance().onStageChanged()
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public get_score(): number {
return this.data.score
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public set_score(score: number): void {
this.data.score = score
StorageManager.getInstance().onStageChanged()
}
public get_notes(): Array<number> {
return this.data.notes
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public add_note(noteNumber: number): void {
if (!this.data.notes.includes(noteNumber)) {
this.data.notes.push(noteNumber)
StorageManager.getInstance().onStageChanged()
2025-05-13 20:31:44 +08:00
}
2025-05-28 18:47:51 +08:00
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public remove_note(noteNumber: number): void {
const find = this.data.notes.indexOf(noteNumber)
if (find >= 0) {
this.data.notes.splice(find, 1)
StorageManager.getInstance().onStageChanged()
2025-05-13 20:31:44 +08:00
}
2025-05-28 18:47:51 +08:00
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public clean_notes(): void {
if (this.data.notes.length > 0) {
this.data.notes = []
StorageManager.getInstance().onStageChanged()
2025-05-13 20:31:44 +08:00
}
2025-05-28 18:47:51 +08:00
}
// ====================================持久化数据
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public get_preset(): boolean {
return this.preset
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public get_correct(): number {
return this.correct
}
2025-05-13 20:31:44 +08:00
2025-05-28 18:47:51 +08:00
public get_checked(): boolean {
return this.checked
}
}