计算积分

This commit is contained in:
2025-05-22 17:17:47 +08:00
parent 2bf07ab8f6
commit b3681e5c1e
19 changed files with 41383 additions and 378 deletions

View File

@@ -1,27 +1,26 @@
import { config } from "./constants/config"
Laya.addBeforeInitCallback((stageConfig) => {
// const { breakpoint } = config
// if (window.innerWidth / window.innerHeight <= breakpoint) {
// stageConfig.designWidth = 1080
// stageConfig.designHeight = 1920
// stageConfig.scaleMode = "fixedwidth"
// }
// else {
console.log(`window innerWidth=${window.innerWidth} innerHeight=${window.innerHeight}`)
console.log(`stageConfig designWidth=${stageConfig.designWidth} designWidth=${stageConfig.designHeight}`)
// if (window.innerWidth > window.innerHeight) {
// stageConfig.designWidth = 1920
// stageConfig.designHeight = 1080
// stageConfig.scaleMode = "fixedauto"
// stageConfig.scaleMode = "fixedwidth"
// config.H_SCREEN = true
// }
// else {
// stageConfig.designWidth = 1080
// stageConfig.designHeight = 1920
// stageConfig.scaleMode = "fixedheight"
// config.H_SCREEN = false
// }
// console.log(`横屏=${config.H_SCREEN}`)
})
export async function main() {
console.log("entry")
const { BREAK_POINT } = config
// 加载场景并打开场景
if (window.innerWidth / window.innerHeight <= BREAK_POINT) {
Laya.Scene.open("Scene.ls")
}
else {
Laya.Scene.open("Scene.ls")
}
Laya.Scene.open("Scene.ls")
}

View File

@@ -2,8 +2,8 @@
export const config = {
BREAK_POINT: 1, // 竖版和横版的分界宽度
H_SCREEN: false, // 是否横屏
DEBUG: false,
OPEN_GUIDE: true,

View File

@@ -1,3 +1,4 @@
import { config } from "./config";
export const respath = {
@@ -8,7 +9,10 @@ export const respath = {
trophy_ui_res: "resources/TrophyRoom.lh",
trophy_year_ui_res: "resources/TrophyRoomYear.lh",
trophy_cell_ui_res: "resources/TrophyRoomCell.lh",
stage_ui_res: "resources/Stage.lh",
stage_ui_res: function func(): string {
return config.H_SCREEN ? "resources/Stage_H.lh" : "resources/Stage.lh"
},
gameover_ui_res: "resources/GameOver.lh",
gamedone_ui_res: "resources/GameDone.lh",

View File

@@ -29,8 +29,6 @@ export class DOBlock {
public set_show(show: number): void {
this.data.show = show
this.checked = show == this.get_correct()
if (this.checked == false)
this.set_score(0)
StorageManager.getInstance().onStageChanged()
}

View File

@@ -126,6 +126,14 @@ export class DOStage {
StorageManager.getInstance().onStageChanged()
}
public get_last_hit_time(): number {
return this.data.last_hit_time
}
public set_last_hit_time(last_hit_time: number): void {
this.data.last_hit_time = last_hit_time
StorageManager.getInstance().onStageChanged()
}
public get_note_open(): boolean {
return this.data.note_open
}

View File

@@ -5,6 +5,7 @@ import { DailyChallenge } from "../views/DailyChallenge"
import { TrophyRecord } from "../types/global"
import { TrophyClaim } from "../views/TrophyClaim"
import { TrophyShow } from "../views/TrophyShow"
import { config } from "../constants/config"
const { regClass, property } = Laya
@@ -76,7 +77,7 @@ export class UIManager extends Laya.Script {
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
}
else {
Laya.loader.load(respath.stage_ui_res).then((go)=>{
Laya.loader.load(respath.stage_ui_res()).then((go)=>{
var prefab = go.create()
this.stage = this.getUIRoot().addChild(prefab).getComponent(Stage)
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))

View File

@@ -25,6 +25,7 @@ export interface DataStage {
mistake?: number,
score?: number,
duration?: number,
last_hit_time?: number,//上一次填对计时
note_open?: boolean,
hint?: number,
select_index?: number,
@@ -36,6 +37,7 @@ export function createDataStage(id: string, type: number, name: string, difficul
data.mistake = 0
data.score = 0
data.duration = 0
data.last_hit_time = 0
data.note_open = false
data.hint = 2
data.select_index = 0

View File

@@ -1,3 +1,4 @@
import { config } from "../constants/config"
@@ -12,4 +13,27 @@ export function Utility_ConvertSecondToString(second: number) {
return value>=10?value.toString():("0"+value)
}
return `${format(hour)}:${format(minite)}:${format(second)}`
}
//计算积分
export function Utility_CalculateScore(difficulty: string, second: number): number {
var score = 0
var currentTime = Math.min(120, second)
if (difficulty == config.DIFFICULTY_TYPE.Easy) {
score = 270 - currentTime
}
else if (difficulty == config.DIFFICULTY_TYPE.Medium) {
score = 420 - currentTime * 2
}
else if (difficulty == config.DIFFICULTY_TYPE.Hard) {
score = 760 - currentTime * 3
}
else if (difficulty == config.DIFFICULTY_TYPE.Expert) {
score = 1120 - currentTime * 3
}
else if (difficulty == config.DIFFICULTY_TYPE.Extreme) {
score = 1320 - currentTime * 4
}
// console.log("计算积分 >>>>>", difficulty, second, score)
return score
}

View File

@@ -21,7 +21,6 @@ export class Block extends Laya.Script {
private tips_labels: Array<Laya.Label> = new Array();
private selected: boolean = false
private newSelect: boolean = false
private data: DOBlock
@@ -56,8 +55,6 @@ export class Block extends Laya.Script {
public setSelected(selected: boolean): void {
this.selected = selected
if (selected)
this.newSelect = true
this.updateBlock()
}
@@ -118,15 +115,16 @@ export class Block extends Laya.Script {
return this.data
}
public setShowNumber(showNumber: number): boolean {
public setShowNumber(showNumber: number, score: number): boolean {
this.data.set_show(showNumber)
if (this.newSelect) {
this.newSelect = false
if (this.data.get_checked() && this.data.get_score() <= 0) {
var score = 150
this.data.set_score(score)
if (this.data.get_checked()) {
this.data.set_score(score)
if (score > 0)
G_ShowScoreTips(score.toString(), this.label_show)
}
}
else {
if (this.data.get_score() != 0)
this.data.set_score(0)
}
this.data.clean_notes()
this.updateBlock()

View File

@@ -5,7 +5,7 @@ import { Candy } from "./Candy";
import { DOStage } from "../models/DOStage";
import { config } from "../constants/config";
import { StorageManager } from "../models/StorageManager";
import { Utility_ConvertSecondToString } from "../utils/utility";
import { Utility_CalculateScore, Utility_ConvertSecondToString } from "../utils/utility";
import { EVENT_TYPES, EventManager } from "../models/EventManager";
import { G_getMonthInfo } from "../models/DCManager";
@@ -246,7 +246,7 @@ export class Stage extends Laya.Script {
this.selectedBlock.setNotes(undo.notes)
}
else {
this.selectedBlock.setShowNumber(undo.show)
this.selectedBlock.setShowNumber(undo.show, 0)
}
// this.onSetBlock(this.selectedBlock)
this.onUpdateScore()
@@ -265,7 +265,7 @@ export class Stage extends Laya.Script {
var notes = this.selectedBlock.getData().get_notes()
if (show > 0 || notes.length > 0) {
this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes)
this.selectedBlock.setShowNumber(0)
this.selectedBlock.setShowNumber(0, 0)
this.onUpdateScore()
this.onSetBlock(this.selectedBlock)
}
@@ -289,7 +289,7 @@ export class Stage extends Laya.Script {
if (hint > 0) {
if (this.selectedBlock.getData().get_checked() == false) {//当前选中的格子没有完成
var correct = this.selectedBlock.getData().get_correct()
this.onApplyCandy(correct)
this.onApplyCandy(correct, true)
this.data.set_hint(hint-1)
this.onUpdateHintStatus()
}
@@ -308,7 +308,7 @@ export class Stage extends Laya.Script {
var block = list[index]
this.onApplyBlock(block)
var correct = block.getData().get_correct()
this.onApplyCandy(correct)
this.onApplyCandy(correct, true)
this.data.set_hint(hint-1)
this.onUpdateHintStatus()
}
@@ -328,7 +328,7 @@ export class Stage extends Laya.Script {
this.btn_hint_label.text = hint.toString()
}
public onApplyCandy(showNumber: number): void {
public onApplyCandy(showNumber: number, hint: boolean): void {
var show = this.selectedBlock.getData().get_show()
var notes = this.selectedBlock.getData().get_notes()
if (this.selectedBlock.getData().get_checked() == false) {
@@ -358,14 +358,20 @@ export class Stage extends Laya.Script {
else {
this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes)
if (this.selectedBlock.getData().get_show() == showNumber) {
this.selectedBlock.setShowNumber(0);
this.selectedBlock.setShowNumber(0, 0);
this.onSetBlock(this.selectedBlock)
}
else {
var b = this.selectedBlock.setShowNumber(showNumber)
var blockScore = 0
if (hint == false) {
var duration = this.data.get_duration() - this.data.get_last_hit_time()
blockScore = Utility_CalculateScore(this.data.get_difficulty(), duration)
}
var b = this.selectedBlock.setShowNumber(showNumber, blockScore)
var score = this.onUpdateScore()
this.onSetBlock(this.selectedBlock, true)
if (b) {
this.data.set_last_hit_time(this.data.get_duration())
var user = StorageManager.getInstance().getUser()
var all = 0
var finished = 0
@@ -423,13 +429,13 @@ export class Stage extends Laya.Script {
public onClickCandy(evt: Laya.Event): void {
var candy = evt.target.getComponent(Candy);
this.onApplyCandy(candy.get_show())
this.onApplyCandy(candy.get_show(), false)
}
onKeyUp(evt: Laya.Event): void {
var n = Number(evt.key)
if (n && n > 0) {
this.onApplyCandy(n)
this.onApplyCandy(n, false)
}
}