Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ncurses.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- struct location{
- int y, x;
- } initial;
- char maze[22][51] = {
- "##################################################",
- "#------##########--------------------------------#",
- "###------------------##############----#####--####",
- "#----###########--#------------------#-----------#",
- "#######---------#----------------------#---###--##",
- "#----------------------#--########--------------##",
- "#######---------#-###-----#---#------------------#",
- "#------------############---------#--------------#",
- "#------------------------######--------########--#",
- "##############--------#-----------#------------###",
- "#--###-#-----###-------------#########----------##",
- "#----------------#------------------- ##------#--#",
- "#-----------------###############----------------#",
- "########--#----------###--#---###-------#--#######",
- "#-------------#--#------------------#------------#",
- "#------------#---------#--#----------------------#",
- "######-----------#----------------##########-----#",
- "#-----------#---#-----#########------------------#",
- "#######----------##-------##########----------####",
- "#-----------#------#-----#---------------#-------#",
- "#---------####-----------------#-----------------$",
- "##################################################"
- };
- void printMaze(WINDOW *mazeArea) /* Function to print the maze*/
- {
- int p;
- int o;
- for(p=0;p<50;p++)
- {
- for(o=0;o<22;o++)
- {
- if (maze[o][p] == '#')
- {
- mvwaddch(mazeArea, o, p, ACS_DIAMOND);
- }
- else
- {
- mvwaddch(mazeArea, o, p, ' ');
- }
- }
- }
- }
- int main()
- {
- WINDOW *gameArea;
- int quitInt = 0;
- initial.x = 2;
- initial.y = 1;
- initscr ();
- noecho ();
- cbreak ();
- gameArea = newwin(22, 50, 2, 20); /*Dimensions/ position of maze*/
- keypad(gameArea, TRUE);
- printMaze(gameArea);
- wmove(gameArea, 1,2);
- init_pair(1, COLOR_RED, COLOR_BLACK);
- wbkgd(gameArea, COLOR_PAIR(1));
- refresh ();
- do
- {
- int direction = wgetch(gameArea); /*using if and else statements for movement based on key input*/
- if(direction == 'w' || direction == KEY_UP || direction == 'W'){
- if (maze[initial.y-1][initial.x] != '#')
- initial.y--;
- } else if(direction == 's' || direction == KEY_DOWN || direction == 'S'){
- if (maze[initial.y+1][initial.x] != '#')
- initial.y++;
- } else if(direction == 'a' || direction == KEY_LEFT || direction == 'A'){
- if (maze[initial.y][initial.x-1] != '#')
- initial.x--;
- } else if(direction == 'd' || direction == KEY_RIGHT || direction == 'D'){
- if (maze[initial.y][initial.x+1] != '#')
- initial.x++;
- } else if(direction == 'q' || direction == 'Q')
- quitInt = 1;
- wmove(gameArea, initial.y, initial.x);
- wrefresh(gameArea);
- } while(maze[initial.y][initial.x] != '$' && quitInt != 1);
- endwin();
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement