⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ns_menu_game.cpp

📁 需要clanlib 库 这个改进版的 在linux 很好玩 但是一定要有clanlib
💻 CPP
字号:
// NS_Menu_Game.cpp: implementation of the NS_Menu_Game class.////////////////////////////////////////////////////////////////////////#include "NS_Menu_Game.h"#include <iostream>#include "ClanLib/display.h"#include "../ZZ_Theme/listbox_zz.h"#include "../NatureParkGame.h"//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////NS_Menu_Game::NS_Menu_Game(NS_MenuManager & menu_manager,                           CL_StyleManager & style_manager,                           std::string const & path_to_resource)    :   NS_MenuGeneric(menu_manager, style_manager, path_to_resource),	back_ground(new CL_Sprite("menu_right_bottom", style_manager.get_resources())){	CL_Button * btn_to_main_menu = dynamic_cast<CL_Button*>(comp_manager->get_component(("btn_to_main_menu")));	if (btn_to_main_menu)		slots.connect(btn_to_main_menu->sig_clicked(), this, &NS_Menu_Game::on_switch_to_main_menu);	CL_Button * btn_to_play = dynamic_cast<CL_Button*>(comp_manager->get_component(("btn_to_play")));	if (btn_to_play)		slots.connect(btn_to_play->sig_clicked(), this, &NS_Menu_Game::on_switch_to_play);    list_player1 = dynamic_cast<CL_ListBox*>(comp_manager->get_component("list_player1"));	list_player2 = dynamic_cast<CL_ListBox*>(comp_manager->get_component("list_player2"));    	is_need_update = true;}NS_Menu_Game::~NS_Menu_Game(){	delete back_ground;}void NS_Menu_Game::on_quit(){    NS_MenuGeneric::quit();}void NS_Menu_Game::on_switch_to_main_menu(){    switch_to("menu_main");}void NS_Menu_Game::on_switch_to_play(){    NatureParkGame g(list_player1->get_current_text(), list_player2->get_current_text());    g.run();}void NS_Menu_Game::switch_to(std::string const & menu_name){	is_need_update = true;    NS_MenuGeneric::switch_to(menu_name);}void NS_Menu_Game::on_begin_paint(){    back_ground->draw(0,0);}//-----------------------------------------------------------------------------void NS_Menu_Game::run_task(){	if (is_need_update)	{        FILE *player_info = fopen("player_info.dat", "r");        int n;        fscanf(player_info, "%d\n", &n);        vector <string> player_name;        for (int i = 0; i < n; i++) {            char s[100];            fgets(s, 100, player_info);            player_name.push_back(s);        }        fclose(player_info);        if (list_player1) {            list_player1->clear();            for (int i = 0; i < n; i++)                list_player1->insert_item(new CL_ListBoxItem_ZZ(player_name[i], true), -1, true);            list_player1->sort();            list_player1->set_current_item(0);        }        if (list_player2) {            list_player2->clear();            for (int i = 0; i < n; i++)                list_player2->insert_item(new CL_ListBoxItem_ZZ(player_name[i], true), -1, true);            list_player2->sort();            list_player2->set_current_item(1);        }		is_need_update = false;    }	NS_MenuGeneric::run_task();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -