当前位置: 首页>>代码示例>>C++>>正文


C++ Tower::get_cost方法代码示例

本文整理汇总了C++中Tower::get_cost方法的典型用法代码示例。如果您正苦于以下问题:C++ Tower::get_cost方法的具体用法?C++ Tower::get_cost怎么用?C++ Tower::get_cost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tower的用法示例。


在下文中一共展示了Tower::get_cost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: build_mode_run

void Game::build_mode_run() {

	draw_all_views();

	if( keyboard.isKeyPressed() ) {
		coord xy = gs->cursor->get_coord();       //get current location of cursor
    coord oldxy = xy;
		switch( keyboard.getKeyPressed() ) {	
		case 'K':         //left arrow
			if( xy.x > 0 ) {
				xy.x = xy.x - 1;
				update_cursor( xy, oldxy );
				m_change = true;
			}
			break;
		case 'M':         //right arrow
			if( xy.x < 14 ) {
				xy.x = xy.x + 1;
				update_cursor( xy, oldxy );
				m_change = true;
			}
			break;
		case 'H':         //up arrow
			if( xy.y > 0 ) {
				xy.y = xy.y - 1;
				update_cursor( xy, oldxy );
				m_change = true;
			}
			break;
		case 'P':         //down arrow
			if( xy.y < 14 ) {
				xy.y = xy.y + 1;
				update_cursor( xy, oldxy );
				m_change = true;
			}
			break;
		case (int)13:
      Tower *t = new Laser();    //TODO: menu to choose a tower
      if (gs->player->get_money() >= t->get_cost() && gs->map->check_can_build(const_cast<coord &>(gs->cursor->get_coord()))) {      //check if player has enough money, and if the tile can be built on top of(if it's empty and if just a "plain" tile, ie. not path or base)
        coord tower_xy = gs->cursor->get_coord();
        gs->player->set_money(gs->player->get_money() - t->get_cost());   //update player money
        tower_xy.layer = 1;                                               //makes sure that tower is displayed on proper layer
			  t->set_coord(tower_xy);
		  	gs->map->update(t);                                               //update with tower
      }
      else
        delete t;

      gs->map->clear_cursor(gs->cursor->get_coord());                    //clear cursor at current location
			switch_to_edit();
			m_change = true;
		}
	}
	
}
开发者ID:rdelpilar,项目名称:Tower-Defense,代码行数:55,代码来源:Game.cpp


注:本文中的Tower::get_cost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。