Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <vector>
- using namespace std;
- /* Class prototype */
- class Board_level;
- class PlayerOn_Board;
- /* Class definition */
- class Board_level{
- public:
- vector<vector<char> > myBoard;
- int itsRows;
- int itsColumns;
- int MINX = 10, MINY = 10, MAXX = 50, MAXY = 50;
- Board_level();
- void setValues(int rows, int columns);
- void createBoard(int Xrows, int Ycols);
- void drawBoard();
- ~Board_level();
- };
- /* Class "Board_Level" Functions */
- Board_level::Board_level(){
- itsRows = 0;
- itsColumns = 0;
- }
- void Board_level::setValues(int rows, int columns){
- if (rows < MINX || rows > MAXX){
- rows = 10;
- }
- if (columns < MINY || columns > MAXY){
- columns = 10;
- }
- itsRows = rows;
- itsColumns = columns;
- createBoard(itsRows, itsColumns);
- }
- void Board_level::createBoard(int Xrows, int Ycols){
- /* Resizes double dimensional vector based on user's input */
- myBoard.resize(Xrows);
- for (int i = 0; i < Xrows; ++i){
- myBoard[i].resize(Ycols);
- }
- /* fills an array with '.' */
- for (int x = 0; x < Xrows; x++){
- for (int y = 0; y < Ycols; y++)
- {
- myBoard[x][y] = '.';
- }
- }
- }
- void Board_level::drawBoard(){
- for (int x = 0; x < itsRows; x++){
- cout << endl;
- for (int y = 0; y < itsColumns; y++)
- {
- cout << myBoard[x][y];
- }
- }
- }
- Board_level::~Board_level(){
- }
- /* PlayerOn_Board class */
- class PlayerOn_Board {
- private:
- int *playerX;
- int *playerY;
- public:
- PlayerOn_Board(int x, int y);
- void setPosition (int x, int y);
- void movePlayer(int keyValue);
- void drawPlayer_board(Board_level *test);
- int returnX();
- int returnY();
- ~PlayerOn_Board();
- };
- /* Class "PlayerOn_Board" functions */
- PlayerOn_Board::PlayerOn_Board(int initX, int initY){
- playerX = &initX;
- playerY = &initY;
- }
- void PlayerOn_Board::setPosition(int xPos, int yPos){
- playerX = &xPos;
- playerY = &yPos;
- }
- void PlayerOn_Board::movePlayer(int keyValue){
- if (keyValue == 72){
- *playerY++;
- }
- if (keyValue == 80){
- *playerY--;
- }
- if (keyValue == 75){
- *playerX--;
- }
- if (keyValue == 77){
- *playerX++;
- }
- }
- int PlayerOn_Board::returnX(){
- return *playerX;
- }
- int PlayerOn_Board::returnY(){
- return *playerY;
- }
- void PlayerOn_Board::drawPlayer_board(Board_level *test){
- //test->myBoard[*playerX][*playerY] = '*';
- //cout << *playerX << " " << *playerY << endl;
- }
- PlayerOn_Board::~PlayerOn_Board(){
- }
- /* Main */
- int main(){
- Board_level board;
- PlayerOn_Board player(0,0);
- board.setValues(20,20);
- //player.setPosition(10, 15);
- cout << player.returnX() << " " << player.returnY() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement