Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
asciiGame/player.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
120 lines (109 sloc)
2.1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _PLAYER_H_ | |
#define _PLAYER_H_ | |
#include "island.h" | |
class Player | |
{ | |
private: | |
int x, y, width, height; | |
char character; | |
WINDOW * curwin; | |
public: | |
Player(WINDOW * win, int _y, int _x, char _character) | |
{ | |
curwin = win; | |
y = _y; | |
x = _x; | |
character = _character; | |
getmaxyx(curwin, height, width); | |
keypad(curwin, true); | |
} | |
void mvup() | |
{ | |
mvwaddch(curwin, y, x, 46); | |
y -= 1; | |
character='^'; | |
if(y < 1) | |
y = 1; | |
} | |
void mvdown() | |
{ | |
mvwaddch(curwin, y, x, 46); | |
y += 1; | |
character='v'; | |
if(y > height-2) | |
y = height-2; | |
} | |
void mvleft() | |
{ | |
mvwaddch(curwin, y, x, 46); | |
x -= 1; | |
character='<'; | |
if(x < 1) | |
x = 1; | |
} | |
void mvright() | |
{ | |
mvwaddch(curwin, y, x, 46); | |
x += 1; | |
character='>'; | |
if(x > width-2) | |
x = width-2; | |
} | |
int 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 display() | |
{ | |
/* mvwaddch(curwin, y, x+1, ' '); | |
mvwaddch(curwin, y, x-1, ' '); | |
mvwaddch(curwin, y+1, x, ' '); | |
mvwaddch(curwin, y-1, x, ' '); */ | |
mvwaddch(curwin, y, x, character); | |
/* mvwaddch(curwin, y+1, x, '/'); | |
mvwaddch(curwin, y+1, x-2, ' '); | |
mvwaddch(curwin, y+1, x-1, '-'); | |
mvwaddch(curwin, y-1, x-2, ' '); | |
mvwaddch(curwin, y-1, x, 92); | |
mvwaddch(curwin, y-1, x-1, '-'); | |
mvwaddch(curwin, y, x-1, ' '); | |
mvwaddch(curwin, y, x-2, '|'); | |
mvwaddch(curwin, y, x+1, '-'); */ | |
wrefresh(curwin); | |
} | |
int get_x() | |
{ | |
return x; | |
} | |
int get_y() | |
{ | |
return y; | |
} | |
void set_x(int value) | |
{ | |
x=value; | |
} | |
void set_y(int value) | |
{ | |
y=value; | |
} | |
}; | |
#endif |