Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <cstring>
- #include <sstream>
- #include <vector>
- using std::cout;
- using std::cin;
- using std::endl;
- using std::string;
- using std::vector;
- enum Direction { None, Left, Right, Up, Down };
- enum Controller_t {PC , User};
- //Global Variables:
- char*board;
- int Height, Width;
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //Classes - Prototypes
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- class board_t;
- class peg_t;
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //Classes Decleratios
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- class peg_t
- {
- private:
- bool Moving;
- Controller_t controller;
- public:
- char Peg;
- peg_t (char,bool,Controller_t);
- Direction Move;
- };
- class board_t
- {
- private:
- void SetBoard(int,int);
- public:
- void SetValues(int, int);
- void PrintBoard();
- friend class peg_t;
- }Board;
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //Class Functions:
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //PEG_T_FUNCTIONS:
- peg_t::peg_t(const char a, bool b, Controller_t c)
- {
- Peg = a;
- Moving = b;
- controller = c;
- }
- //BOARD_T_FUNCTIONS:
- void board_t::SetValues(int a, int b)
- {
- SetBoard(a,b);
- }
- void board_t::SetBoard(int a, int b)
- {
- board = new char [a*b];
- for (int i = 0; i < a; i++)
- {
- for (int j = 0;j<b;j++)
- {
- board[i*b + j] = '.';
- }
- }
- }
- void board_t::PrintBoard()
- {
- for (int i = 0; i < Height; i++)
- {
- cout << "\t";
- for (int j = 0;j < Width ;j++)
- {
- cout << board[i*Width + j];
- }
- cout << endl;
- }
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //Main Function:
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- int main ()
- {
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //Variables:
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- peg_t Hero ('H',true, User);
- peg_t Enemy ('X', true, PC);
- peg_t Trap ('O', false, PC);
- peg_t Treasure ('T', false, PC);
- char Move;
- cout << "Please enter the Dimensions of the Board you want to play on[Min - 5*5 | Max - 8*8]: " << endl;
- cout << "Height: ";
- cin >> Height;
- if (Height > 8)
- Height = 8;
- if (Height < 5)
- Height = 5;
- cout << "Width: ";
- cin >> Width;
- if (Width > 8)
- Width = 8;
- if (Width < 5)
- Width = 5;
- Board.SetValues(Height,Width);
- int playh = 1, playw = 1;
- board [ (Height-1)*Width + (Width-1)] = Treasure.Peg;
- while (true)
- {
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //board[ (Height-1) * Width + (Width-1) ] = CHARACTER
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- board[ (playh-1) * (Width) + (playw-1)] = Hero.Peg;
- Board.PrintBoard();
- cout << "In What direction do you want to move: ";
- cin >> Move;
- cin.sync();
- switch (Move)
- {
- case 'W':
- case 'w':
- Hero.Move = Up;
- break;
- case 'S':
- case 's':
- Hero.Move = Down;
- break;
- case 'A':
- case 'a':
- Hero.Move = Left;
- break;
- case 'D':
- case 'd':
- Hero.Move = Right;
- break;
- }
- switch (Hero.Move)
- {
- case Up:
- if (playh != 1)
- {
- board[ (playh-1) * Width + (playw-1)] = '.';
- playh -= 1;
- }
- break;
- case Down:
- if (playh != Height)
- {
- board[ (playh-1) * Width + (playw-1)] = '.';
- playh += 1;
- }
- case Left:
- if (playw != 1)
- {
- board[ (playh-1) * Width + (playw-1)] = '.';
- playw -= 1;
- }
- break;
- case Right:
- if (playw != Width)
- {
- board[ (playh-1) * Width + (playw-1)] = '.';
- playw += 1;
- }
- break;
- }
- }
- cout << endl << endl;
- cout << "================================================================================";
- cout << endl;
- cout << "Press ENTER/RETURN to Exit . . .";
- cin.sync();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment