标题:我的想法是通过stage==0来显示初始界面,在初始界面通过按任意键进入菜单界面 ...
只看楼主
C00000001
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-5-8
结帖率:100%
已结贴  问题点数:20 回复次数:3 
我的想法是通过stage==0来显示初始界面,在初始界面通过按任意键进入菜单界面,然后通过1,2,3,按键进行相应的界面
我的想法是通过stage==0来显示初始界面,在初始界面通过按任意键进入菜单界面,然后通过1,2,3,按键进行相应的界面,但是代码运行时,在初始界面按1,2,3直接进入相应的界面,跳过了菜单界面,(if else if 没有起作用),不知道错在哪,帮我看下
void Container::show()const
    {
        // stage=0,初始化面
        //stage=1,选择界面(进入)
        //stage=2,选择界面(保存)
        //stage=3,第1关
        //stage=4,第2关
        //stage=5,商店画面
        //stage=6,结束画面
        
        if (stage == 0)
        {
            putimage(0, 0, &(*image.begin()));
            if (_kbhit())
            {

                stage = 1;
            }
        }
        else if (stage == 1)
        {
            cleardevice();
            setbkmode(TRANSPARENT);
            setbkcolor(BLACK);
            settextcolor(RGB(255, 255, 255));
            settextstyle(50, 0, _T("黑体"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.3, _T("1.新游戏"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.4, _T("2.读取游戏档案"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.5, _T("3.EXIT"));
            Sleep(10);
            char input;
            if (_kbhit())
            {
                input = _getch();
                switch (input)
                {
                case '1':
                    stage = 3;
                    break;
                case '2':
                    break;
                case '3':
                    exit(0);
                    break;
                }
            }
        }
        else if (stage == 2)
        {
            cleardevice();
            setbkmode(TRANSPARENT);
            setbkcolor(BLACK);
            settextcolor(RGB(255, 255, 255));
            settextstyle(50, 0, _T("黑体"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.3, _T("1.保存游戏"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.4, _T("2.继续游戏"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.5, _T("3.EXIT"));
            Sleep(10);
        }
        else if (stage == 3)
        {
            putimage(0, 0, &(*(image.begin() + 2)));
            
        }
        else if (stage == 4)
        {
            putimage(0, 0, &(*(image.begin() + 2)));
        }
        else if (stage == 5)
        {
            putimage(0, 0, &(*(image.begin() + 3)));
        }
        else if (stage == 6)
        {
            putimage(0, 0, &(*(image.begin() + 1)));
        }
        
        FlushBatchDraw();
        return;
    }
搜索更多相关主题的帖子: 界面 image 初始 begin screen 
2021-07-26 22:20
C00000001
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-5-8
得分:0 
完成代码如下
#pragma once
#include"comheadifle.h"
#include"Object.h"
#include"Screen.h"
#include<mmsystem.h>
#pragma comment(lib,"WINMM.LIB")
namespace CONTAINER
{
    class Container
    {
    private:
        SCREEN::Screen screen;
        OBJECT::Object character;
        OBJECT::Object eneny;
        std::vector<IMAGE>image;
        mutable int stage;
        // stage=0,初始化面
        //stage=1,选择界面(进入)
        //stage=2,选择界面(保存)
        //stage=3,第1关
        //stage=4,第2关
        //stage=5,商店画面
        //stage=6,结束画面
    public:
        Container();
        virtual ~Container();
        void show()const;
        void associated();
        void updatewithoutinput();
        void updatewithinput();
        void status_change();
    };
}
#include "Container.h"
namespace CONTAINER
{
    Container::Container() :screen(900, 670), character(0, 0), eneny(0, 0)
    {
        stage = 0;
        mciSendString(_T("open .\\resource\\bkmusic.mp3 alias bkmusic"), NULL, 0, NULL);
        mciSendString(_T("play bkmusic repeat"), NULL, 0, NULL);
        image.reserve(58);
        IMAGE background;
        loadimage(&background, _T(".\\resource\\background.jpg"));
        image.push_back(background);
        IMAGE endbackground, level_1, shop, energy, oxygen;
        loadimage(&endbackground, _T(".\\resource\\endbackground.jpg"));
        loadimage(&level_1, _T(".\\resource\\level_1.jpg"));
        loadimage(&shop, _T(".\\resource\\shop.jpg"));
        loadimage(&energy, _T(".\\resource\\energy.jpg"));
        loadimage(&oxygen, _T(".\\resource\\oxygen.jpg"));
        image.push_back(endbackground);
        image.push_back(level_1);
        image.push_back(shop);
        image.push_back(energy);
        image.push_back(oxygen);
        IMAGE bwbomb_1, bomb_1, bwbomb_boom, bomb_boom, digdownperson_1, digdownperson_2,
            digleftperson_1, digleftperson_2, digrightperson_1, digrightperson_2,
            ener_oxy1, ener_oxy2, person_0, person_00, person_1, person_2, shoes_1,
            shoes_2, monsterrun_00, monsterrun_0, coal_0, coal_1, coal_2, coal_3,
            coal_4, coal_5, Copper_0, Copper_1, Copper_2, Copper_3, Copper_4, Copper_5,
            Copper_6, silver_0, silver_1, silver_2, silver_3, silver_4, silver_5, stone_0,
            stone_1, stone_2, stone_3, stone_4, stone_5, stone_6, stone_7, stone_99;
        loadimage(&bwbomb_1, _T(".\\resource\\bwbomb_1.jpg"));
        loadimage(&bomb_1, _T(".\\resource\\bomb_1.jpg"));
        loadimage(&bwbomb_boom, _T(".\\resource\\bwbomb_boom.jpg"));
        loadimage(&bomb_boom, _T(".\\resource\\bomb_boom.jpg"));
        loadimage(&digdownperson_1, _T(".\\resource\\digdownperson_1.jpg"));
        loadimage(&digdownperson_2, _T(".\\resource\\digdownperson_2.jpg"));
        loadimage(&digleftperson_1, _T(".\\resource\\digleftperson_1.jpg"));
        loadimage(&digleftperson_2, _T(".\\resource\\digleftperson_2.jpg"));
        loadimage(&digrightperson_1, _T(".\\resource\\digrightperson_1.jpg"));
        loadimage(&digrightperson_2, _T(".\\resource\\digrightperson_2.jpg"));
        loadimage(&ener_oxy1, _T(".\\resource\\ener_oxy1.jpg"));
        loadimage(&ener_oxy2, _T(".\\resource\\ener_oxy2.jpg"));
        loadimage(&person_0, _T(".\\resource\\person_0.jpg"));
        loadimage(&person_00, _T(".\\resource\\person_00,.jpg"));
        loadimage(&person_1, _T(".\\resource\\person_1.jpg"));
        loadimage(&person_2, _T(".\\resource\\person_2.jpg"));
        loadimage(&shoes_1, _T(".\\resource\\shoes_1.jpg"));
        loadimage(&shoes_2, _T(".\\resource\\shoes_2.jpg"));
        loadimage(&monsterrun_00, _T(".\\resource\\monsterrun_00.jpg"));
        loadimage(&monsterrun_0, _T(".\\resource\\monsterrun_0.jpg"));
        loadimage(&coal_0, _T(".\\resource\\coal_0.jpg"));
        loadimage(&coal_1, _T(".\\resource\\coal_1.jpg"));
        loadimage(&coal_2, _T(".\\resource\\coal_2.jpg"));
        loadimage(&coal_3, _T(".\\resource\\coal_3.jpg"));
        loadimage(&coal_4, _T(".\\resource\\coal_4.jpg"));
        loadimage(&coal_5, _T(".\\resource\\coal_5.jpg"));
        loadimage(&Copper_0, _T(".\\resource\\Copper_0.jpg"));
        loadimage(&Copper_1, _T(".\\resource\\Copper_1.jpg"));
        loadimage(&Copper_2, _T(".\\resource\\Copper_2.jpg"));
        loadimage(&Copper_3, _T(".\\resource\\Copper_3.jpg"));
        loadimage(&Copper_4, _T(".\\resource\\Copper_4.jpg"));
        loadimage(&Copper_5, _T(".\\resource\\Copper_5.jpg"));
        loadimage(&Copper_6, _T(".\\resource\\Copper_6.jpg"));
        loadimage(&silver_0, _T(".\\resource\\silver_0.jpg"));
        loadimage(&silver_1, _T(".\\resource\\silver_1.jpg"));
        loadimage(&silver_2, _T(".\\resource\\silver_2.jpg"));
        loadimage(&silver_3, _T(".\\resource\\silver_3.jpg"));
        loadimage(&silver_4, _T(".\\resource\\silver_4.jpg"));
        loadimage(&silver_5, _T(".\\resource\\silver_5.jpg"));
        loadimage(&stone_0, _T(".\\resource\\stone_0.jpg"));
        loadimage(&stone_1, _T(".\\resource\\stone_1.jpg"));
        loadimage(&stone_2, _T(".\\resource\\stone_2.jpg"));
        loadimage(&stone_3, _T(".\\resource\\stone_3.jpg"));
        loadimage(&stone_4, _T(".\\resource\\stone_4.jpg"));
        loadimage(&stone_5, _T(".\\resource\\stone_5.jpg"));
        loadimage(&stone_6, _T(".\\resource\\stone_6.jpg"));
        loadimage(&stone_7, _T(".\\resource\\stone_7.jpg"));
        loadimage(&stone_99, _T(".\\resource\\stone_99.jpg"));
        image.push_back(bwbomb_1);
        image.push_back(bomb_1);
        image.push_back(bwbomb_boom);
        image.push_back(bomb_boom);
        image.push_back(digdownperson_1);
        image.push_back(digdownperson_2);
        image.push_back(digleftperson_1);
        image.push_back(digleftperson_2);
        image.push_back(digrightperson_1);
        image.push_back(digrightperson_2);
        image.push_back(ener_oxy1);
        image.push_back(ener_oxy2);
        image.push_back(person_0);
        image.push_back(person_00);
        image.push_back(person_1);
        image.push_back(person_2);
        image.push_back(shoes_1);
        image.push_back(shoes_2);
        image.push_back(monsterrun_0);
        image.push_back(monsterrun_00);
        image.push_back(coal_0);
        image.push_back(coal_1);
        image.push_back(coal_2);
        image.push_back(coal_3);
        image.push_back(coal_4);
        image.push_back(coal_5);
        image.push_back(Copper_0);
        image.push_back(Copper_1);
        image.push_back(Copper_2);
        image.push_back(Copper_3);
        image.push_back(Copper_4);
        image.push_back(Copper_5);
        image.push_back(Copper_6);
        image.push_back(silver_0);
        image.push_back(silver_1);
        image.push_back(silver_2);
        image.push_back(silver_3);
        image.push_back(silver_4);
        image.push_back(silver_5);
        image.push_back(stone_0);
        image.push_back(stone_1);
        image.push_back(stone_2);
        image.push_back(stone_3);
        image.push_back(stone_4);
        image.push_back(stone_5);
        image.push_back(stone_6);
        image.push_back(stone_7);
        image.push_back(stone_99);
    }
    Container::~Container()
    {
        screen.~Screen();
    }
    void Container::associated()
    {

    }
    void Container::updatewithoutinput()
    {

    }
    void Container::updatewithinput()
    {

    }
    void Container::status_change()
    {

    }
    void Container::show()const
    {
        // stage=0,初始化面
        //stage=1,选择界面(进入)
        //stage=2,选择界面(保存)
        //stage=3,第1关
        //stage=4,第2关
        //stage=5,商店画面
        //stage=6,结束画面
        
        if (stage == 0)
        {
            putimage(0, 0, &(*image.begin()));
            if (_kbhit())
            {

                stage = 1;
            }
        }
        else if (stage == 1)
        {
            cleardevice();
            setbkmode(TRANSPARENT);
            setbkcolor(BLACK);
            settextcolor(RGB(255, 255, 255));
            settextstyle(50, 0, _T("黑体"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.3, _T("1.新游戏"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.4, _T("2.读取游戏档案"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.5, _T("3.EXIT"));
            Sleep(10);
            char input;
            if (_kbhit())
            {
                input = _getch();
                switch (input)
                {
                case '1':
                    stage = 3;
                    break;
                case '2':
                    break;
                case '3':
                    exit(0);
                    break;
                }
            }
        }
        else if (stage == 2)
        {
            cleardevice();
            setbkmode(TRANSPARENT);
            setbkcolor(BLACK);
            settextcolor(RGB(255, 255, 255));
            settextstyle(50, 0, _T("黑体"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.3, _T("1.保存游戏"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.4, _T("2.继续游戏"));
            outtextxy(screen.R_width() * 0.35, screen.R_high() * 0.5, _T("3.EXIT"));
            Sleep(10);
        }
        else if (stage == 3)
        {
            putimage(0, 0, &(*(image.begin() + 2)));
            
        }
        else if (stage == 4)
        {
            putimage(0, 0, &(*(image.begin() + 2)));
        }
        else if (stage == 5)
        {
            putimage(0, 0, &(*(image.begin() + 3)));
        }
        else if (stage == 6)
        {
            putimage(0, 0, &(*(image.begin() + 1)));
        }
        
        FlushBatchDraw();
        return;
    }
}
#include "Container.h"
int main()
{
    CONTAINER::Container one;
    while (1)
    {
        one.show();
        one.associated();
        one.updatewithoutinput();
        one.status_change();
        one.updatewithinput();
    }
    one.~Container();
}
2021-07-26 22:22
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:20 
代码编译不了,你自己学一学调试(debug)吧,不难
2021-07-27 08:58
C00000001
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-5-8
得分:0 
回复 3楼 rjsp
是不是按照我的想法
在每一if条件下才能做出相应的按键相应,
每个else if 正确情况下互不干涉
2021-07-27 11:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-506336-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016214 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved