zCool

ASCII Pickin' Sticks

May 6th, 2012
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. void draw(string map[17][5]);
  8. string input = "";
  9. string wallTile = "#";
  10. string spaceTile = ".";
  11. string stickTile = "-";
  12. string playerTile = "@";
  13. int playerX = 5;
  14. int playerY = 3;
  15. int stickX = 6;
  16. int stickY = 1;
  17. string map[17][5];
  18. int score = 0;
  19.  
  20. //"Background" Tiles
  21. //first row
  22. for(int x = 0 ; x < 17 ; x++)
  23. {
  24.     map[x][0] = wallTile;
  25. }
  26.  
  27. //second row
  28. map[0][1] = wallTile;
  29. map[16][1] = wallTile;
  30. for(int x = 1 ; x < 16 ; x++)
  31. {
  32.     map[x][1] = spaceTile;
  33. }
  34.  
  35. //third row
  36. map[0][2] = wallTile;
  37. map[16][2] = wallTile;
  38. for(int x = 1 ; x <16 ; x++)
  39. {
  40.     map[x][2] = spaceTile;
  41. }
  42.  
  43. //fourth row
  44. map[0][3] = wallTile;
  45. map[16][3] = wallTile;
  46. for(int x = 1 ; x < 16 ; x++)
  47. {
  48.     map[x][3] = spaceTile;
  49. }
  50.  
  51. //fifth row
  52. for(int x = 0 ; x < 17 ; x++)
  53. {
  54.     map[x][4] = wallTile;
  55. }
  56.  
  57. //"Foreground" Tiles
  58. map[playerX][playerY] = playerTile;
  59. map[stickX][stickY] = stickTile;
  60.  
  61.  
  62.  
  63.  
  64. while(input.compare("Exit") !=0 )
  65. {
  66.  
  67.     //Redraw map
  68.     draw(map);
  69.  
  70.  
  71.     //Get Input
  72.     cout << "Enter a direction: ";
  73.     getline(cin, input);
  74.  
  75.     //Validate
  76.     while(input.compare("East")!=0
  77.         && input.compare("West")!=0
  78.         && input.compare("North")!=0
  79.         && input.compare("South")!=0
  80.         && input.compare("Exit")!=0)
  81.     {
  82.         cout << "Enter a direction: ";
  83.         getline(cin, input);
  84.     }
  85.  
  86.     //Update
  87.     if(input.compare("East") == 0)
  88.     {  
  89.         playerX++;
  90.        
  91.         //collision with wall
  92.         if( playerX ==0 ||
  93.             playerX == 16 ||
  94.             playerY == 0  ||
  95.             playerY == 4)
  96.         {
  97.             playerX--;
  98.         }
  99.         // collision with stick
  100.         else if ( playerX == stickX &&
  101.             playerY == stickY)
  102.         {
  103.             score++;
  104.             cout << "Score: " << score << endl;
  105.             stickX = rand()%14 + 1;
  106.             stickY = rand()%2 + 1;
  107.             map[stickX][stickY] = stickTile;
  108.             map[playerX][playerY] = playerTile;
  109.             map[playerX - 1][playerY] = spaceTile;
  110.  
  111.         }
  112.         else
  113.         {
  114.             map[playerX][playerY] = playerTile;
  115.             map[playerX - 1][playerY] = spaceTile;
  116.         }
  117.     }
  118.  
  119.     if(input.compare("West") == 0)
  120.     {
  121.         playerX--;
  122.        
  123.         //collision with wall
  124.         if( playerX ==0 ||
  125.             playerX == 16 ||
  126.             playerY == 0  ||
  127.             playerY == 4)
  128.         {
  129.             playerX++;
  130.         }
  131.         // collision with stick
  132.         else if ( playerX == stickX &&
  133.             playerY == stickY)
  134.         {
  135.             score++;
  136.             cout << "Score: " << score << endl;
  137.             stickX = rand()%14 + 1;
  138.             stickY = rand()%2 + 1;
  139.             map[stickX][stickY] = stickTile;
  140.             map[playerX][playerY] = playerTile;
  141.             map[playerX + 1][playerY] = spaceTile;
  142.  
  143.         }
  144.         else
  145.         {
  146.             map[playerX][playerY] = playerTile;
  147.             map[playerX + 1][playerY] = spaceTile;
  148.         }
  149.     }
  150.  
  151.     if(input.compare("North") == 0)
  152.     {
  153.         playerY--;
  154.        
  155.         //collision with wall
  156.         if( playerX ==0 ||
  157.             playerX == 16 ||
  158.             playerY == 0  ||
  159.             playerY == 4)
  160.         {
  161.             playerY++;
  162.         }
  163.         // collision with stick
  164.         else if ( playerX == stickX &&
  165.             playerY == stickY)
  166.         {
  167.             score++;
  168.             cout << "Score: " << score << endl;
  169.             stickX = rand()%14 + 1;
  170.             stickY = rand()%2 + 1;
  171.             map[stickX][stickY] = stickTile;
  172.             map[playerX][playerY] = playerTile;
  173.             map[playerX][playerY + 1] = spaceTile;
  174.  
  175.         }
  176.         else
  177.         {
  178.             map[playerX][playerY] = playerTile;
  179.             map[playerX][playerY + 1] = spaceTile;
  180.         }
  181.     }
  182.  
  183.     if(input.compare("South") == 0)
  184.     {
  185.        
  186.         playerY++;
  187.        
  188.         //collision with wall
  189.         if( playerX ==0 ||
  190.             playerX == 16 ||
  191.             playerY == 0  ||
  192.             playerY == 4)
  193.         {
  194.             playerY++;
  195.         }
  196.         // collision with stick
  197.         else if ( playerX == stickX &&
  198.             playerY == stickY)
  199.         {
  200.             score++;
  201.             cout << "Score: " << score << endl;
  202.             stickX = rand()%14 + 1;
  203.             stickY = rand()%2 + 1;
  204.             map[stickX][stickY] = stickTile;
  205.             map[playerX][playerY] = playerTile;
  206.             map[playerX][playerY - 1] = spaceTile;
  207.  
  208.         }
  209.         else
  210.         {
  211.             map[playerX][playerY] = playerTile;
  212.             map[playerX][playerY - 1] = spaceTile;
  213.         }
  214.     }
  215.  
  216. }
  217.    
  218.    
  219.  
  220. }
  221.  
  222. void draw(string map[17][5])
  223. {
  224.     for(int y = 0 ; y < 5 ; y++)
  225.     {
  226.         for(int x = 0; x < 17 ; x++)
  227.         {
  228.             cout << map[x][y];
  229.         }
  230.         cout << endl;
  231.     }
  232. }
RAW Paste Data