summaryrefslogtreecommitdiff
path: root/Player.cpp
blob: 19d581d30299b1e8d5dcf345b4f3d2afb09564da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* *******************************************************************
 *  Includes
 * ******************************************************************/

#include "Player.h"
#include "Unit.h"
#include <string.h>

/* *******************************************************************
 *  Defines
 * ******************************************************************/

/* *******************************************************************
 *  Types definition
 * ******************************************************************/

/* *******************************************************************
 *  Global variables definition
 * ******************************************************************/

/* *******************************************************************
 *  Local variables definition
 * ******************************************************************/

/* *******************************************************************
 *  Local prototypes declaration
 * ******************************************************************/

/* *******************************************************************
 *  Functions definition
 * ******************************************************************/

/*****************************************************************//**
 *
 * \brief   Constructor for Player class.
 *
 *********************************************************************/
Player::Player(const char* const strPlayerName):
_name{'\0'}
{
    enum
    {
        DEFAULT_RESOURCES = 300
    };

    if (strPlayerName != NULL)
    {
        strncpy(_name, strPlayerName, MAX_NAME_LENGTH);
    }
    else
    {
        /* Undefined player name. */
    }

    /* Set all resources to default value. */
    memset(_resourcesMap, DEFAULT_RESOURCES, sizeof(uint8_t) * MAX_RESOURCE_TYPES);
}

void Player::handleUnits(void)
{
    for (size_t szUnit = 0; szUnit < MAX_UNITS; szUnit++)
    {
        /* Select Unit object from internal table. */
        Unit& unit = _unitsMap[szUnit];

        /* Execute unit handler. */
        unit.handler();
    }
}

void Player::drawUnits(void)
{
    for (size_t szUnit = 0; szUnit < MAX_UNITS; szUnit++)
    {
        /* Select Unit object from internal table. */
        Unit& u = _unitsMap[szUnit];

        /* Execute drawHandler for selected Unit. */
        u.drawHandler();
    }
}