#ifndef GAME_H
#define GAME_H

#include <SDL2/SDL.h>
#include <vector>
#include "../data_config.h"
#include "Map.h"
#include "Tank.h"
#include "Bullet.h"
#include "AssetManager.h"
#include "Renderer.h"

enum class Scene { MENU, LEVEL, GAME, WIN, LOSE, QUIT };

class Game {
public:
    Game();
    ~Game();
    int run();

private:
    SDL_Window* window = nullptr;
    SDL_Renderer* sdlRenderer = nullptr;
    AssetManager* assets = nullptr;
    Renderer* render = nullptr;

    Scene scene = Scene::MENU;
    bool running = true;

    Map map;
    Tank player;
    std::vector<Tank> enemies;
    std::vector<Bullet> playerBullets;
    std::vector<Bullet> enemyBullets;
    Tank enemyCfg;
    int killCount = 0;

    // 计时
    Uint32 lastPlayerMove = 0, lastPlayerShoot = 0;
    Uint32 lastEnemyMove = 0, lastEnemyShoot = 0;
    Uint32 lastBulletMove = 0, lastEnemyBulletMove = 0;

    bool initSDL();
    bool initFont();
    void handleEvents(SDL_Event& e);
    void update();
    void renderScene();

    void initGame();
    void updateGame();

    void renderMenu();
    void renderLevel();
    void renderGameView();
    void renderWin();
    void renderLose();

    bool isWin() const;
};

#endif
