| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- export enum LvDir {
- none = 0,
- left = 1,
- right = 2,
- up = 3,
- down = 4,
- xCenter = 5,
- xOut = 6,
- yCenter = 7,
- yOut = 8,
- }
- interface event_protocol {
- life_change(life: number): void;
- dir_change(dir: LvDir): void;
- }
- /**关卡*/
- export class Lv {
- private _lv: number;//关卡数
- public get lv(): number { return this._lv };
- private _life: number = 3;//生命值
- public get life(): number { return this._life };
- private _is_win: boolean = false;//连胜
- public get is_win(): boolean { return this._is_win };
- private _dir: LvDir = LvDir.none;//关卡状态
- public get dir(): LvDir { return this._dir };
- private _time: number = 0;//时间设置
- public get time(): number { return this._time };
- public evt = chsdk.get_new_event<event_protocol>();
- public _seed: number;
- public get seed(): number { return this._seed };
- private _relive_count: number = 0;
- public get relive_count(): number { return this._relive_count };
- public readonly relive_max: number = 5;
- public record: { item1: number, item2: number, item3: number, relive: number };
- constructor() {
-
- }
- public init(lv: number) {
- this.record = {
- item1: 0, item2: 0, item3: 0, relive: 0,
- }
- //this._seed = ch.util.getRandomInt(1000, 10000000000) + floor * lv;
- this._time = 0;
- this._is_win = false;
- this._lv = lv;
- this._life = 3;
- this._relive_count = 0;
- this.evt.emit(this.evt.key.life_change, this._life);
- switch (this._lv) {
- case 1:
- case 2:
- this._dir = LvDir.none;
- break;
- case 3:
- this._dir = LvDir.left;
- break;
- case 4:
- this._dir = LvDir.up;
- break;
- case 5:
- this._dir = LvDir.right;
- break;
- case 6:
- this._dir = LvDir.down;
- break;
- case 7:
- this._dir = LvDir.xOut;
- break;
- case 8:
- this._dir = LvDir.yOut;
- break;
- case 9:
- this._dir = LvDir.xCenter;
- break;
- case 10:
- this._dir = LvDir.yCenter;
- break;
- }
- }
- public change_dir(): LvDir {
- switch (this._dir) {
- case LvDir.none:
- break;
- case LvDir.left:
- this._dir = LvDir.right;
- break;
- case LvDir.up:
- this._dir = LvDir.down;
- break;
- case LvDir.right:
- this._dir = LvDir.left;
- break;
- case LvDir.down:
- this._dir = LvDir.up;
- break;
- case LvDir.xOut:
- this._dir = LvDir.xCenter;
- break;
- case LvDir.yOut:
- this._dir = LvDir.yCenter;
- break;
- case LvDir.xCenter:
- this._dir = LvDir.xOut;
- break;
- case LvDir.yCenter:
- this._dir = LvDir.yOut;
- break;
- }
- this.evt.emit(this.evt.key.dir_change, this._dir);
- return this._dir;
- }
- /**剩余复活次数*/
- public get_relife_count_down(): number {
- const count = this.relive_max - this._relive_count;
- return count < 0 ? 0 : count;
- }
- /**复活*/
- public relife(): void {
- this._life = 3;
- this._relive_count++;
- this.record.relive++;
- this.evt.emit(this.evt.key.life_change, this._life);
- }
- /**扣血*/
- public change_life(n: number): void {
- this._life += n;
- if (this._life <= 0) {
- this._life = 0;
- this.lose();
- } else if (this._life > 6) {
- this._life = 6;
- }
- this.evt.emit(this.evt.key.life_change, this._life);
- }
- private lose(): void {
- this._is_win = false;
- // GameLink.getInst().game_end();
- }
- public win(): void {
- this._is_win = true;
- //GameLink.getInst().game_end();
- }
- public time_run(dt: number): void {
- this._time += dt;
- }
- }
|