Files
2025-09-21 20:11:21 +08:00

79 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 贪吃蛇
{
class Game
{
//窗口宽高
public const int h = 20;
public const int w = 80;
//当前游戏场景
public static ISceneUpdate nowScene;
public Game()
{
Console.CursorVisible = false;
Console.SetWindowSize(w, h);
Console.SetBufferSize(w, h);
ChangeScene(E_Scene.Begin);//初始场景为开始场景
}
public void Start()
{
//游戏主循环
while (true)
{
try
{
if (nowScene != null)
{
nowScene.Update();//场景不为空就更新场景
}
}
catch
{
}
}
}
public static void ChangeScene(E_Scene type)
{
//切场景时先擦除上一次绘制的内容
Console.Clear();
switch (type)
{
case E_Scene.Begin:
nowScene = new BeginScene();
break;
case E_Scene.Game:
nowScene = new GameScene();
break;
case E_Scene.End:
nowScene = new EndScene();
break;
default:
break;
}
}
}
enum E_Scene
{
/// <summary>
/// 开始场景
/// </summary>
Begin,
/// <summary>
/// 游戏场景
/// </summary>
Game,
/// <summary>
/// 结束场景
/// </summary>
End,
}//游戏场景枚举
}