Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h> //need for mac
  3. using namespace std;
  4.  
  5. //global variables are declared outside the functions
  6. //global means anything can access and edit it
  7. int width = 20;
  8. int height =20;
  9. int x;
  10. int y;
  11. bool gameover;
  12. //enumberator to stor keyboard inputs
  13. enum direction{STOP = 0, LEFT, RIGHT, UP, DOWN};
  14. direction dir;
  15.  
  16. void input(){
  17. if(_kbhit()){ //check if keyboard has been struck
  18. switch(_getch()){//switch statement to check which key hit
  19. case 'a' : //note single quotes (character), not " (string)
  20. dir = LEFT; //a=left
  21. cout << "left" <<endl;
  22. break; //exit switch statement
  23. case 'd' :
  24. dir = RIGHT;
  25. cout << "right" <<endl;
  26. break;
  27. case 'w' :
  28. dir = UP;
  29. cout << "up" << endl;
  30. break;
  31. case 's' :
  32. dir = DOWN;
  33. cout << "down" << endl;
  34. break;
  35. default :
  36. break; //if non are true break
  37. }
  38. }
  39. }
  40.  
  41. void setup(){
  42. gameover = false;
  43. //start snake in middle of screen
  44. x=width/2;
  45. y=height/2;
  46. }
  47.  
  48. void draw()
  49. {
  50. //makeing top wall
  51. for (int i=0; i<width+2; i++){
  52. cout << "#";
  53. }
  54. cout << endl;
  55. //making side walls
  56. for(int j = 0; j < height; j++)
  57. { // runs program down
  58. for(int j = 0; j < width+2; j++)
  59. { //run prgram across
  60. if (j==x && j==y)
  61. {
  62. cout << ">";
  63. }
  64. else if(j==0||j==width+1){ //checks if 1 or width
  65. cout << "#";
  66. }else{
  67. cout << " ";
  68. }
  69. }
  70. cout << endl;
  71. }
  72.  
  73. //makeing Bottom wall
  74. for (int i=0; i<width+2; i++){
  75. cout << "#";
  76. }
  77. cout << endl;
  78.  
  79. //drawing head of snake
  80.  
  81. }
  82.  
  83. void logic(){
  84.  
  85. }
  86.  
  87.  
  88.  
  89.  
  90. int main(){
  91. // setup();
  92. // draw();
  93. //input();
  94. while(!gameover){
  95. input();
  96. }
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement