You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
1.3 KiB
103 lines
1.3 KiB
#ifndef _PLAYER_H_
|
|
#define _PLAYER_H_
|
|
|
|
class Player
|
|
{
|
|
public:
|
|
Player(WINDOW* win, int y, int x, char c);
|
|
void mvUp();
|
|
void mvDown();
|
|
void mvLeft();
|
|
void mvRight();
|
|
int getMv();
|
|
void display();
|
|
|
|
private:
|
|
int xLoc, yLoc, xMax, yMax;
|
|
char playerChar;
|
|
WINDOW * curWin;
|
|
};
|
|
|
|
|
|
Player::Player(WINDOW* win, int y, int x, char c)
|
|
{
|
|
curWin = win;
|
|
xLoc = x;
|
|
yLoc = y;
|
|
getmaxyx(curWin, yMax, xMax);
|
|
keypad(curWin, true);
|
|
playerChar = c;
|
|
}
|
|
|
|
void Player::mvUp()
|
|
{
|
|
mvwaddch(curWin,yLoc, xLoc, '.');
|
|
yLoc --;
|
|
if(yLoc < 1)
|
|
{
|
|
yLoc = 1;
|
|
}
|
|
}
|
|
|
|
void Player::mvDown()
|
|
{
|
|
mvwaddch(curWin,yLoc, xLoc, '.');
|
|
yLoc ++;
|
|
if(yLoc > yMax-2)
|
|
{
|
|
yLoc = yMax-2;
|
|
}
|
|
}
|
|
|
|
void Player::mvLeft()
|
|
{
|
|
mvwaddch(curWin,yLoc, xLoc, '.');
|
|
xLoc --;
|
|
if(xLoc < 1)
|
|
{
|
|
xLoc = 1;
|
|
}
|
|
}
|
|
|
|
void Player::mvRight()
|
|
{
|
|
mvwaddch(curWin,yLoc, xLoc, '.');
|
|
xLoc ++;
|
|
if(xLoc > xMax-2)
|
|
{
|
|
xLoc = xMax-2;
|
|
}
|
|
}
|
|
|
|
int Player::getMv()
|
|
{
|
|
int choice = wgetch(curWin);
|
|
switch(choice)
|
|
{
|
|
case KEY_UP:
|
|
mvUp();
|
|
break;
|
|
case KEY_DOWN:
|
|
mvDown();
|
|
break;
|
|
case KEY_LEFT:
|
|
mvLeft();
|
|
break;
|
|
case KEY_RIGHT:
|
|
mvRight();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return choice;
|
|
}
|
|
|
|
void Player::display()
|
|
{
|
|
mvwaddch(curWin,yLoc, xLoc, playerChar);
|
|
}
|
|
|
|
|
|
|
|
#endif
|