80 lines
1.9 KiB
TypeScript
80 lines
1.9 KiB
TypeScript
|
|
|
|
import { StorageManager } from "../models/StorageManager"
|
|
|
|
|
|
export class DOBlock {
|
|
|
|
private data: any
|
|
private preset: boolean = false//预设格子
|
|
private correct: number = 0;
|
|
private checked: boolean = false//是否正确
|
|
|
|
|
|
constructor(dataBlock: any, preset: boolean, correct: number) {
|
|
this.data = dataBlock
|
|
this.preset = preset
|
|
this.correct = correct
|
|
this.checked = preset || (dataBlock.show == correct)
|
|
}
|
|
|
|
//====================================持久化数据
|
|
public get_index(): number {
|
|
return this.data.index
|
|
}
|
|
|
|
public get_show(): number {
|
|
return this.data.show
|
|
}
|
|
public set_show(show: number): void {
|
|
this.data.show = show
|
|
if (show == this.get_correct())
|
|
this.checked = true
|
|
if (this.get_checked() || show == 0)
|
|
this.clean_notes()//正确或者擦除
|
|
StorageManager.getInstance().onChanged()
|
|
}
|
|
|
|
public get_score(): number {
|
|
return this.data.score
|
|
}
|
|
public set_score(score: number): void {
|
|
this.data.score = score
|
|
StorageManager.getInstance().onChanged()
|
|
}
|
|
|
|
public get_notes(): Array<number> {
|
|
return this.data.notes
|
|
}
|
|
public add_note(noteNumber: number): boolean {
|
|
var b = false
|
|
if (this.data.notes.indexOf(noteNumber) < 0) {
|
|
this.data.notes.push(noteNumber)
|
|
StorageManager.getInstance().onChanged()
|
|
b = true
|
|
}
|
|
return b
|
|
}
|
|
public clean_notes(): void {
|
|
if (this.data.notes.length > 0) {
|
|
this.data.notes = new Array()
|
|
StorageManager.getInstance().onChanged()
|
|
}
|
|
}
|
|
//====================================持久化数据
|
|
|
|
public get_preset(): boolean {
|
|
return this.preset
|
|
}
|
|
|
|
public get_correct(): number {
|
|
return this.correct
|
|
}
|
|
|
|
public get_checked(): boolean {
|
|
return this.checked
|
|
}
|
|
|
|
|
|
|
|
} |