class GameData
{
public enum GameStatus
{
None,
SelectCity,
ActionEnemy,
ActionPlayer,
ShowResult,
GameEnd,
GameOver
}
public GameStatus gameStatus = GameStatus.None;
public List<City> Cities = null;
public List<City> AliveCities = null;
public Battle Battle = null;
public Player Player = null;
このクラスはシングルトンで管理します。
class Singleton
{
private static GameData _gameData = null;
public static GameData GetGameData()
{
if (_gameData == null)
{
_gameData = new GameData();
}
return _gameData;
}
このシングルトンクラス、ゲッターのでいいんじゃないかと思い始めた。
やっていることは同じですが。
メソッドでやるか、プロパティでやるかの違いです。
気が向いたら直します。
シーン遷移は全てシーンクラスのインスタンスを作り直します。
if (asd.Engine.Mouse.LeftButton.ButtonState == asd.ButtonState.Push)
{
var scene = new MainScene();
asd.Engine.ChangeScene(scene);
}
class HokkaidoWar
{
public HokkaidoWar()
{
}
public void Run()
{
asd.Engine.Initialize("北海道大戦", 1200, 1000, new asd.EngineOption());
// シーンの登録
var scene = new MainScene();
asd.Engine.ChangeScene(scene);
while (asd.Engine.DoEvents())
{
asd.Engine.Update();
}
asd.Engine.Terminate();
}
}
class MainScene : asd.Scene
{
中略
protected override void OnRegistered()
{
var layer = Singleton.GetMainSceneLayer();
AddLayer(layer);
// 下地
var background = new asd.GeometryObject2D();
layer.AddObject(background);
var bgRect = new asd.RectangleShape();
bgRect.DrawingArea = new asd.RectF(0, 0, 1800, 1000);
background.Shape = bgRect;
cities = new List<City>();
var r = new Random();
foreach (var map in mapData.list)
{
City city = new City(map.name, map.point, map.population);
cities.Add(city);
}
_battle = new Battle(cities);
aliveCities = _battle.GetAliveCityList();
}
protected override void OnUpdated()
{
asd.Vector2DF pos = asd.Engine.Mouse.Position;
switch (gameStatus)
{
case GameStatus.SelectCity:
cycleProcessSelectCity(pos);
break;
case GameStatus.ActionEnemy:
cycleProcessActionEnemy(pos);
break;
case GameStatus.ActionPlayer:
cycleProcessActionPlayer(pos);
break;
case GameStatus.ShowResult:
break;
case GameStatus.GameEnd:
cycleProcessGameEnd();
break;
case GameStatus.GameOver:
cycleProcessGameOver(pos);
break;
}
if (asd.Engine.Mouse.LeftButton.ButtonState == asd.ButtonState.Push)
{
switch (gameStatus)
{
case GameStatus.SelectCity:
onClickMouseSelectCity(pos);
break;
case GameStatus.ActionEnemy:
break;
case GameStatus.ActionPlayer:
onClickMouseActionPlayer(pos);
break;
case GameStatus.ShowResult:
onClickMouseShowResult();
break;
case GameStatus.GameEnd:
break;
case GameStatus.GameOver:
break;
}
}
}
後略