-
Notifications
You must be signed in to change notification settings - Fork 4
Player
This Documentation is from a code still under heavy development, you may find errors,sudden changes or the answer to life,universe and everything
###Overview
Player implements all actions and data referred to a DCmC player in a match, (life,name,...) and provides the interaction between [Input Handler](Input Handler) and [Player Controller](Player Controller)
A player class will create his own player controller, and through the methods click_action
and key_action
(with the same syntax as in [input handler](Input Handler) will do the actions (if possible)
Also a callback function (lose_funcion) should be given, so it will be called when player life drops to 0
Name | Version | Header | Implementation |
---|---|---|---|
Player | 0.7.6 | player.h | player.cpp |
###Variables Private
-
player_controller controller
[controller](Player Controller) that will be created and used by the player -
string name
name of the player -
string current_tower
current tower selected for building -
unsigned int lives
remaining lives (if 0, lose_function will be called) -
unsigned int coins
player coins -
bool active
if the player is active (false when dies) -
function<void>()> lose_function
callback function to call when player dies
###Constructors
-
player()
default constructor, with all values to 0 and active to false -
player(const string &name,tower_set &towers,game_objects &objects,tilemap &game_map,unsigned int lifes,unsigned int coins,function<void()> lose_function)
full constructor, with all the necessary information to create the player and player_controller
###Destructor
-
~player()
destroy player and player controller, but don't modify the tower_set game_objects or map
###Methods Public
-
void remove_life(unsigned int lives_removes=1)
removes given number of lives (total life will never be less than 0), callgame_over
if live=0 -
void recover_life(unsigned int lifes_recovered=1)
recovers given lives, adding to the total lives -
void add_coins(unsigned int coins)
adds given coins to the player -
void remove_coins(unsigned int coins)
removes given coins (total coins will never be less than 0) -
bool is_active() const
return true if player is active -
string get_name() const
returns player name (empty if there is no name) -
unsigned int get_coins() const
returns the remaining coins of the player -
unsigned int get_lives() const
returns the remaining lives of the player -
void set_current_tower(const string &tower)
sets the current tower to build -
set<string> get_tower_names() const
returns all the possible towers to build -
void click_action(int button,unsigned int x,unsigned int y)
will perform the action to a mouse click in position [x,y] (by default it will be build if left click and remove tower if right click) if possible -
void key_action(int keycode)
will perform the action to given key pressed
These two functions have the same structure as [input handler](Input Handler) callbacks, so it is possible to use directly as callbacks for input handlers, but it is not recommendable as any possible action outside of in-game actions will not be performed -
bool check() conts
will check that everything is working and return false if not (will also check that callback functionlose_function
is callable)
Private
-
void build_tower(double x,double y)
will try to build a current_tower in given position (x,y) (tower will be built if player controller allows building in given position,current_tower exists and there are enough coins). If build is successful coins will be taken -
void remove_tower(double x,double y)
will remove tower in position (x,y) (if there is a tower) if the tower exists, half of its costs will be retrieved as coins to the player -
game_over()
will deactivate the player and will call the functionlose_function
Don't Crush My Castle Wiki is under CC License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
_______________________
/ Don't Crush My Castle \
\ is a cool name /
-----------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
DCmC Wiki 0.7.6
- [Home] (Home)
- [Getting Started] (Getting Started)
- Documentation
- Reference
- Attributions