Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ncurses.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7.  
  8. struct location{
  9.     int y, x;
  10. } initial;
  11.  
  12.  
  13. char maze[22][51] = {
  14. "##################################################",
  15. "#------##########--------------------------------#",
  16. "###------------------##############----#####--####",
  17. "#----###########--#------------------#-----------#",
  18. "#######---------#----------------------#---###--##",
  19. "#----------------------#--########--------------##",
  20. "#######---------#-###-----#---#------------------#",
  21. "#------------############---------#--------------#",
  22. "#------------------------######--------########--#",
  23. "##############--------#-----------#------------###",
  24. "#--###-#-----###-------------#########----------##",
  25. "#----------------#------------------- ##------#--#",
  26. "#-----------------###############----------------#",
  27. "########--#----------###--#---###-------#--#######",
  28. "#-------------#--#------------------#------------#",
  29. "#------------#---------#--#----------------------#",
  30. "######-----------#----------------##########-----#",
  31. "#-----------#---#-----#########------------------#",
  32. "#######----------##-------##########----------####",
  33. "#-----------#------#-----#---------------#-------#",
  34. "#---------####-----------------#-----------------$",
  35. "##################################################"
  36. };
  37.  
  38.  
  39. void printMaze(WINDOW *mazeArea) /* Function to print the maze*/
  40. {
  41.     int p;
  42.     int o;
  43.    
  44.     for(p=0;p<50;p++)
  45.     {
  46.         for(o=0;o<22;o++)
  47.         {
  48.             if (maze[o][p] == '#')
  49.             {
  50.                 mvwaddch(mazeArea, o, p, ACS_DIAMOND);
  51.             }
  52.             else
  53.             {
  54.                 mvwaddch(mazeArea, o, p, ' ');
  55.             }
  56.         }
  57.     }
  58.    
  59. }
  60.  
  61.  
  62. int main()
  63. {
  64.     WINDOW *gameArea;
  65.     int quitInt = 0;
  66.     initial.x = 2;
  67.     initial.y = 1;
  68.     initscr ();
  69.     noecho ();
  70.     cbreak ();
  71.     gameArea = newwin(22, 50, 2, 20); /*Dimensions/ position of maze*/
  72.     keypad(gameArea, TRUE);
  73.     printMaze(gameArea);
  74.     wmove(gameArea, 1,2);
  75.     init_pair(1, COLOR_RED, COLOR_BLACK);
  76.     wbkgd(gameArea, COLOR_PAIR(1));
  77.     refresh ();
  78.  
  79.     do
  80.     {
  81.         int direction = wgetch(gameArea); /*using if and else statements for movement based on key input*/
  82.  
  83.         if(direction == 'w' || direction == KEY_UP || direction == 'W'){
  84.             if (maze[initial.y-1][initial.x] != '#')
  85.                 initial.y--;
  86.         } else if(direction == 's' || direction == KEY_DOWN || direction == 'S'){
  87.             if (maze[initial.y+1][initial.x] != '#')
  88.                 initial.y++;
  89.         } else if(direction == 'a' || direction == KEY_LEFT || direction == 'A'){
  90.             if (maze[initial.y][initial.x-1] != '#')
  91.                 initial.x--;
  92.         } else if(direction == 'd' || direction == KEY_RIGHT || direction == 'D'){
  93.             if (maze[initial.y][initial.x+1] != '#')
  94.                 initial.x++;   
  95.         } else if(direction == 'q' || direction == 'Q')
  96.             quitInt = 1;
  97.        
  98.         wmove(gameArea, initial.y, initial.x);
  99.         wrefresh(gameArea);
  100.    
  101.     } while(maze[initial.y][initial.x] != '$' && quitInt != 1);
  102.     endwin();
  103.     return(0);  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement