mycj_demo/mycj/Assets/Game/Scripts/Application/01Modle/FBGameModel.cs
2024-12-02 09:37:47 +08:00

149 lines
3.6 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Felix-BangFBGameModel
//   へ     /|
//  /7    ∠_/
//  / │    
//  Z _,    /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │
//  / へ   / ノ<|
//  ヽ_ノ  (_  │//
//  7       |
//  ―r ̄ ̄`ー―_
// Describe游戏数据的读取/储存
// Createtime2018/10/11
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FBFramework;
using System.IO;
using System;
namespace FBApplication
{
public class FBGameModel : FBModel
{
#region
//所有关卡
List<FBLevel> f_levels = new List<FBLevel>();
//当前关卡索引
int f_playLevelIndex = -1;
//最大通关关卡索引
int f_gameProgressIndex = -1;
//游戏当前分数
int f_gold = 0;
//是否游戏中
bool f_isPlaying = false;
#endregion
#region
public override string Name
{
get { return FBConsts.M_GameModel; }
}
public List<FBLevel> AllLevels
{
get { return f_levels; }
}
public int LevelCount
{
get { return f_levels.Count; }
}
public bool IsPassed
{
get { return f_gameProgressIndex > LevelCount-1; }
}
public FBLevel PlayLevel
{
get
{
if (f_playLevelIndex < 0 || f_playLevelIndex > f_levels.Count-1)
throw new IndexOutOfRangeException("关卡不存在");
else
return f_levels[f_playLevelIndex];
}
}
public int Gold
{
get { return f_gold; }
set { f_gold = value; }
}
public bool IsPlaying
{
get { return f_isPlaying; }
set { f_isPlaying = value; }
}
public int GameProgressIndex
{
get { return f_gameProgressIndex; }
}
public int PlayLevelIndex
{
get { return f_playLevelIndex; }
set { f_playLevelIndex = value; }
}
#endregion
#region
//初始化
public void OnInitialized()
{
//构建Level集合
List<FileInfo> files = FBTools.GetLevelFiles();
for (int i = 0; i < files.Count; i++)
{
FBLevel level = new FBLevel();
FBTools.FillLevel(files[i].FullName, ref level);
f_levels.Add(level);
}
//读取游戏进度
f_gameProgressIndex = FBSaver.GetProgress();
}
public void StartLevel(int levelIndex)
{
f_playLevelIndex = levelIndex;
}
public void StoptLevel(bool isWin)
{
if (isWin && PlayLevelIndex > GameProgressIndex)
{
//更新进度
f_gameProgressIndex = PlayLevelIndex;
//保存进度
FBSaver.SetProgress(PlayLevelIndex);
}
f_isPlaying = false;
}
//清档
public void ClearProgress()
{
f_isPlaying = false;
f_playLevelIndex = -1;
f_gameProgressIndex = -1;
FBSaver.SetProgress(-1);
}
#endregion
}
}