Advertisement
konalisp

Elk Alpha 0.3

Mar 30th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3. #include <vector>
  4.  
  5. //super secret propreitary software (c) copyright Caesura Software
  6.  
  7. using namespace std;
  8.  
  9. //Elk: The game of fast-paced action-packed boredom.
  10.  
  11. /* ---  VARIABLES    --- */
  12.  
  13. struct bounds { //board size
  14.     const int x = 20;
  15.     const int y = 20;
  16. };
  17.  
  18. /* --- END VARIABLES --- */
  19.  
  20. //vector code
  21.  
  22. typedef vector<vector<int>> i2d;
  23.  
  24. function<i2d(int,int)> retVec = [](int x, int y) -> i2d {
  25.     i2d vec;
  26.     vec.resize(x);
  27.     for(int a = 0; a < x; ++a){
  28.         vec[a].resize(y);
  29.     }
  30.     return vec;
  31. };
  32.  
  33. class Vec2D {
  34.     public:
  35.         i2d vec;
  36.         Vec2D(int x, int y) {
  37.             vec = retVec(x,y);
  38.         };
  39.        
  40.         inline int& at(int x, int y) {
  41.             return vec[x][y];
  42.         }
  43. };
  44.  
  45. //end vector code
  46.  
  47. //print the board
  48.  
  49. function<int(i2d)> show = [](i2d board) -> int {
  50.    
  51.     bounds po;
  52.    
  53.     for (int a = 0; a < po.x; ++a) {
  54.         for (int b = 0; b < po.y; ++b) {
  55.             if (a == 0 or b == 0 or a == po.x-1 or b == po.y-1) {
  56.                 cout << "*" ;
  57.             }
  58.             else if (board[a][b] == 0) {
  59.                 cout << ".";
  60.             }
  61.             else if (board[a][b] == 1) {
  62.                 cout << "@";
  63.             }
  64.             else {
  65.                 cout << board[a][b];
  66.             }
  67.             cout << " ";
  68.         }
  69.         cout << endl;
  70.     }
  71.    
  72.     return 0;
  73. };
  74.  
  75. //end printing the board
  76.  
  77. //player stuff
  78.  
  79. class player {
  80.     public:
  81.         int x;
  82.         int y;
  83.         int hp = 10;
  84.        
  85.         player (int xPos, int yPos) {
  86.             x = xPos;
  87.             y = yPos;
  88.         };
  89. };
  90.  
  91. function<int(i2d&)> movep = [](i2d& board) -> int {
  92.    
  93.     player pl(5,2);
  94.     bounds po;
  95.    
  96.     board[pl.x][pl.y] = 1;
  97.     int temp = 0;
  98.     string input;
  99.    
  100.     function<int(int,int)> plmov = [&](int xPos, int yPos) -> int {
  101.         /*string bmsg = "Bounds checking enabled.";
  102.         if ((pl.x == 0 or pl.y == 0) and (xPos > 0 or yPos > 0)) {
  103.             cout << bmsg << endl;
  104.         }
  105.         else if ((pl.x == po.x-1 or pl.y == po.y-1) and (xPos == 0 or yPos == 0)) {
  106.             cout << bmsg << endl;
  107.         }
  108.         else {
  109.             board[pl.x][pl.y] = temp;
  110.             temp = board[pl.x+xPos][pl.y+yPos];
  111.             board[pl.x+xPos][pl.y+yPos] = 1;
  112.             pl.x += xPos;
  113.             pl.y += yPos;
  114.             show(board);
  115.         }*/
  116.        
  117.         board[pl.x][pl.y] = temp;
  118.         temp = board[pl.x+xPos][pl.y+yPos];
  119.         board[pl.x+xPos][pl.y+yPos] = 1;
  120.         pl.x += xPos;
  121.         pl.y += yPos;
  122.         show(board);
  123.        
  124.         return 0;
  125.     };
  126.    
  127.     show(board);
  128.     show(board); //eh
  129.    
  130.     for(;;){
  131.         cout << "> ";
  132.         cin >> input;
  133.        
  134.         if(input == "left") {
  135.            
  136.             plmov(0, -1);
  137.            
  138.         }
  139.         else if(input == "right") {
  140.            
  141.             plmov(0, 1);
  142.            
  143.         }
  144.         else if(input == "up") {
  145.            
  146.             plmov(-1, 0);
  147.            
  148.         }
  149.         else if(input == "down") {
  150.            
  151.             plmov(1, 0);
  152.            
  153.         }
  154.         else if(input == "end") {
  155.            
  156.             cout << "Thanks for listening." << endl;
  157.             break;
  158.         }
  159.         else {
  160.             cout << "CAN'T LET YOU DO THAT STARFOX" << endl;
  161.         }
  162.     }
  163.     return 0;
  164. };
  165.  
  166. //end player stuff
  167.  
  168. int main(int argc, char **argv){
  169.    
  170.     bounds co;
  171.     Vec2D vec(co.x, co.y);
  172.    
  173.     vec.at(2,3) = 7;
  174.     vec.at(2,4) = 8;
  175.     vec.at(2,5) = 9;
  176.     vec.at(2,7) = 4;
  177.    
  178.     movep(vec.vec);
  179.    
  180.     return 0;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement