SFML多房间游戏设计,如何组织程序?

SFML Multiple Room Game design, How to organize the program?

用c++和sfml制作游戏时,如何组织多个关卡?在我的游戏中会有多个房间,我打算通过改变 sf::View 来改变房间,但我不希望冗长的 main.cpp 没有组织,所以我让每个 room/level单独的功能?或者制作一个 class 来管理当前的 room/level 并相应地切换房间?在 sfml 游戏中组织多个级别的最佳方式是什么?谢谢。

为了创建游戏,我强烈建议您阅读有关游戏设计和 SFML 游戏架构的书籍。 https://www.sfml-dev.org/learn.php。游戏不是简单快速的制作程序,必须要有很好的构思。慢慢来,测试 SFML 并了解你的环境,否则你会浪费时间。

我决定使用枚举 class,感谢 domsson 的 link 和建议。我的枚举 class 和 switch 语句如下所示:

int windowWidth = 5000;//width of window
int windowHeight = 5000;//height of window
sf::View leveltwo(sf::FloatRect(x, y, 5000, 5000));
sf::View start(sf::FloatRect(0, 0, 2500, 1500));
sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight ), "Awesome Game" );


enum Levels{
    StartRoom, LevelTwo
};
Levels room = StartRoom;
void WhatRoom(int TheLevel){
    switch (room){
        case StartRoom:
            window.setView(start);
            if (TheLevel == 2){
                room = LevelTwo;
            }

        case LevelTwo:
            window.setView(leveltwo);

    }
};

效果很好。