Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h> //need for mac
- using namespace std;
- //global variables are declared outside the functions
- //global means anything can access and edit it
- int width = 20;
- int height =20;
- int x;
- int y;
- bool gameover;
- //enumberator to stor keyboard inputs
- enum direction{STOP = 0, LEFT, RIGHT, UP, DOWN};
- direction dir;
- void input(){
- if(_kbhit()){ //check if keyboard has been struck
- switch(_getch()){//switch statement to check which key hit
- case 'a' : //note single quotes (character), not " (string)
- dir = LEFT; //a=left
- cout << "left" <<endl;
- break; //exit switch statement
- case 'd' :
- dir = RIGHT;
- cout << "right" <<endl;
- break;
- case 'w' :
- dir = UP;
- cout << "up" << endl;
- break;
- case 's' :
- dir = DOWN;
- cout << "down" << endl;
- break;
- default :
- break; //if non are true break
- }
- }
- }
- void setup(){
- gameover = false;
- //start snake in middle of screen
- x=width/2;
- y=height/2;
- }
- void draw()
- {
- //makeing top wall
- for (int i=0; i<width+2; i++){
- cout << "#";
- }
- cout << endl;
- //making side walls
- for(int j = 0; j < height; j++)
- { // runs program down
- for(int j = 0; j < width+2; j++)
- { //run prgram across
- if (j==x && j==y)
- {
- cout << ">";
- }
- else if(j==0||j==width+1){ //checks if 1 or width
- cout << "#";
- }else{
- cout << " ";
- }
- }
- cout << endl;
- }
- //makeing Bottom wall
- for (int i=0; i<width+2; i++){
- cout << "#";
- }
- cout << endl;
- //drawing head of snake
- }
- void logic(){
- }
- int main(){
- // setup();
- // draw();
- //input();
- while(!gameover){
- input();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement