Hi all,
as some might know i have been working on a simple roguelike to get better in programming. I am trying to get a function working that will allow a Player to build walls in a dungeon if there isn't allready a wall there.
However i am getting this error
Code:
C:\Users\Thorbenn\RL\Player.cpp||In member function 'void Player::building()':|
C:\Users\Thorbenn\RL\Player.cpp|300|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 0xffffffffffffffffu) * 1804u))[((Player*)this)->Player::posy]'|
C:\Users\Thorbenn\RL\Player.cpp|302|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 0xffffffffffffffffu) * 1804u))[((Player*)this)->Player::posy]'|
C:\Users\Thorbenn\RL\Player.cpp|315|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 1u) * 1804u))[((Player*)this)->Player::posy]'|
C:\Users\Thorbenn\RL\Player.cpp|317|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 1u) * 1804u))[((Player*)this)->Player::posy]'|
C:\Users\Thorbenn\RL\Player.cpp|330|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + -0x000000001)]'|
C:\Users\Thorbenn\RL\Player.cpp|332|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + -0x000000001)]'|
C:\Users\Thorbenn\RL\Player.cpp|345|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + 1)]'|
C:\Users\Thorbenn\RL\Player.cpp|347|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + 1)]'|
||=== Build finished: 8 errors, 0 warnings ===|
and here is my code for the function:
Code:
void Player::building()
{
cout<<"In what direction do you want to build?";
char secondAction;
cin>>secondAction;
switch(secondAction)
{
case'w':
if(pMap[posx-1][posy]==floor && posx !=1 && posx !=mapx-2 && collectedWalls >0)
{
pMap[posx-1][posy]=wall;
collectedWalls--;
}
//Linux Version
// system("clear");
//Windows Version
system("cls");
pMap->printMap();
break;
case's':
if(pMap[posx +1][posy]==floor && posx !=1 && posx !=mapx-2 && collectedWalls >0)
{
pMap[posx +1][posy]=wall;
collectedWalls--;
}
//Linux Version
//system("clear");
//Windows Version
system("cls");
pMap->printMap();
break;
case'a':
if(pMap[posx][posy -1]==floor && posy !=1 && posy !=mapy-4 && collectedWalls >0)
{
pMap[posx][posy-1]=wall;
collectedWalls--;
}
//Linux Version
//system("clear");
//Windows Version
system("cls");
pMap->printMap();
break;
case'd':
if(pMap[posx][posy +1]==floor && posy !=1 && posy !=mapy-4 && collectedWalls >0)
{
pMap[posx][posy+1]=wall;
collectedWalls--;
}
//Linux Version
//system("clear");
//Windows Version
system("cls");
pMap->printMap();
break;
}
}
Player Class:
Code:
class Player
{
private:
string name;
int level;
int healthMax;
int health;
int dexterty;
int strength;
int endurance;
int defense;
int exp;
int expMax;
int pgold;
int collectedWalls;
//Player Location
int posx;
int posy;
int x;
int y;
Map* pMap;
public:
//Constructor
Player();
//Destructor
// ~Player();
void newPlayer();
void levelUp();
void setHealth(int healthBonus);
void movement();
void attack();
void viewCharacter();
void building();
void mineing();
void setMap(Map* Dungeon);
};
Map Class:
Code:
class Map
{
public:
char map[mapx][mapy];
void genMap();
void printMap();
};
mapx and mapy are constants for all to reach mapx is a int with value of 22 and mapy a integer with value of 88.
floor, wall or so are also const chars which are reachable for all.