Advertisement
Guest User

Untitled

a guest
Apr 29th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <vector>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. /* Class prototype */
  9. class Board_level;
  10. class PlayerOn_Board;
  11.  
  12.  
  13. /* Class definition */
  14. class Board_level{
  15. public:
  16.     vector<vector<char> > myBoard;
  17.     int itsRows;
  18.     int itsColumns;
  19.     int MINX = 10, MINY = 10, MAXX = 50, MAXY = 50;
  20.     Board_level();
  21.     void setValues(int rows, int columns);
  22.     void createBoard(int Xrows, int Ycols);
  23.     void drawBoard();
  24.     ~Board_level();
  25. };
  26.  
  27. /* Class "Board_Level" Functions */
  28.  
  29. Board_level::Board_level(){
  30.     itsRows = 0;
  31.     itsColumns = 0;
  32. }
  33.  
  34.  
  35. void Board_level::setValues(int rows, int columns){
  36.     if (rows < MINX || rows > MAXX){
  37.         rows = 10;
  38.     }
  39.     if (columns < MINY || columns > MAXY){
  40.         columns = 10;
  41.     }
  42.  
  43.     itsRows = rows;
  44.     itsColumns = columns;
  45.     createBoard(itsRows, itsColumns);
  46. }
  47.  
  48. void Board_level::createBoard(int Xrows, int Ycols){
  49.     /* Resizes double dimensional vector based on user's input */
  50.     myBoard.resize(Xrows);
  51.     for (int i = 0; i < Xrows; ++i){
  52.         myBoard[i].resize(Ycols);
  53.     }
  54.     /* fills an array with '.' */
  55.     for (int x = 0; x < Xrows; x++){
  56.         for (int y = 0; y < Ycols; y++)
  57.         {
  58.             myBoard[x][y] = '.';
  59.         }
  60.     }
  61. }
  62.  
  63.  
  64. void Board_level::drawBoard(){
  65.     for (int x = 0; x < itsRows; x++){
  66.         cout << endl;
  67.         for (int y = 0; y < itsColumns; y++)
  68.         {
  69.             cout << myBoard[x][y];
  70.         }
  71.     }
  72. }
  73.  
  74. Board_level::~Board_level(){
  75.  
  76. }
  77.  
  78.  
  79.  
  80.  
  81. /* PlayerOn_Board class */
  82.  
  83. class PlayerOn_Board {
  84. private:
  85.     int *playerX;
  86.     int *playerY;
  87. public:
  88.     PlayerOn_Board(int x, int y);
  89.     void setPosition (int x, int y);
  90.     void movePlayer(int keyValue);
  91.     void drawPlayer_board(Board_level *test);
  92.     int returnX();
  93.     int returnY();
  94.     ~PlayerOn_Board();
  95. };
  96.  
  97. /* Class "PlayerOn_Board" functions */
  98.  
  99. PlayerOn_Board::PlayerOn_Board(int initX, int initY){
  100.     playerX = &initX;
  101.     playerY = &initY;
  102. }
  103.  
  104. void PlayerOn_Board::setPosition(int xPos, int yPos){
  105.     playerX = &xPos;
  106.     playerY = &yPos;
  107. }
  108.  
  109. void PlayerOn_Board::movePlayer(int keyValue){
  110.     if (keyValue == 72){
  111.         *playerY++;
  112.     }
  113.     if (keyValue == 80){
  114.         *playerY--;
  115.     }
  116.     if (keyValue == 75){
  117.         *playerX--;
  118.     }
  119.     if (keyValue == 77){
  120.         *playerX++;
  121.     }
  122. }
  123.  
  124. int PlayerOn_Board::returnX(){
  125.     return *playerX;
  126. }
  127.  
  128. int PlayerOn_Board::returnY(){
  129.     return *playerY;
  130. }
  131.  
  132.  
  133. void PlayerOn_Board::drawPlayer_board(Board_level *test){
  134.     //test->myBoard[*playerX][*playerY] = '*';
  135.     //cout << *playerX << " " << *playerY << endl;
  136. }
  137.  
  138. PlayerOn_Board::~PlayerOn_Board(){
  139.  
  140. }
  141.  
  142. /* Main */
  143.  
  144. int main(){
  145.     Board_level board;
  146.     PlayerOn_Board player(0,0);
  147.     board.setValues(20,20);
  148.     //player.setPosition(10, 15);
  149.     cout << player.returnX() << " " << player.returnY() << endl;
  150.     return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement