Advertisement
gopro_2027

ncursesv5.cpp

Mar 15th, 2014
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.29 KB | None | 0 0
  1. //this version fixed deleting problem
  2. /*
  3.  *Notes might be a bit scattered or maybe wrong to some extent*
  4.  
  5.  how to play:
  6.  #start game in full terminal. it will look funny is u dont
  7.  #use arrow keys to move
  8.  #press 'o' to place barrier
  9.  #to delete barrier piece stand by it ans press w,a,s,d. ex: stand under the barrer u wanna delete and press w
  10.  #if you get stuck in a barrier and cant move (this is a bug) press 'r' to go to (0,0)
  11.  #press 'q' to end the game
  12.  #to save the game u are on, while in the terminal copy all the blue area. now go make a copy of this file here. see that big open space printw? well u need to replace all the stuff it is printing with the screen u copied. then put \n after every 'o' and it should work
  13. */
  14.  
  15. #include <curses.h>//header for all this ncurses stuff
  16. #include <unistd.h>//used for sleep command
  17. int main()//used in every program
  18. {
  19.             //start of gui
  20.  
  21. initscr();//makes the screen
  22. start_color();//says we can have color
  23. noecho();//keeps from pressing other characters
  24. nodelay(stdscr, TRUE);//keeps it from delaying :P
  25. keypad(stdscr, TRUE);//lets me use arrow keys
  26. init_pair(1, COLOR_RED, COLOR_CYAN);//1 is the name of the pair, white is the text, cyan is the background.kind of like setting a varriable
  27. attron(COLOR_PAIR(1));//initiating color pair 1
  28. printw("                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\n                                                                                                                  o\nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n");//makes it show color background
  29. move(0,0);//sets cursor position to here so the next printw will print at this position (not really needed anymore but here)
  30.          
  31.            //end  of gui
  32.  
  33.            //start of arrow keys input (moving person)
  34. for( ; ; ) {//loop
  35. char wall = inch();//defines wall as something on screen
  36. int y, x;//some varriables
  37. int ch = getch();//sets varriable ch(input) as getch to be used specially
  38. switch (ch) {//changes that getch varriable to the special keys below
  39.   case KEY_DOWN://special key
  40.     getyx(stdscr , y, x);//recieves the current curser position
  41.     move(y+1,x);//moves cursor accordingly based on current position
  42.     refresh();//refreshes the screen to show that the cursor moved
  43.     getch();//recieves input or something. needed but not sure exactly what it does
  44.   }
  45. switch (ch) {      //the other arrows...
  46.   case KEY_UP:
  47.     getyx(stdscr , y, x);
  48.     move(y-1,x);
  49.     refresh();
  50.     getch();
  51.   }
  52. switch (ch) {
  53.   case KEY_LEFT:
  54.     getyx(stdscr , y, x);
  55.     move(y,x-1);
  56.     refresh();
  57.     getch();
  58.   }
  59. switch (ch) {
  60.   case KEY_RIGHT:
  61.     getyx(stdscr , y, x);
  62.     move(y , x+1 );
  63.     refresh();
  64.     getch();
  65.   }                  //end of arrow keys input (moving person)
  66.   if(ch=='z') {
  67. //THE STUFF I NEED HELP WITH WILL MOST LIKELY GO HERE
  68.   }
  69.                      //barrier
  70.   if(ch=='o') {//checks to see if u press o
  71.     printw("o");//makes a barrier
  72.     refresh();//shows changes
  73.   }                  //deleting barriers (buggy. may not be compatabe with how the barrier are not able to go thru)
  74.   if(ch=='w') {//checks to see if u press d
  75.     wall=='b';//sets the barrier to b instead of o for a sec because o is the barrier o it changes b to the barrier
  76.     getyx(stdscr,y,x);
  77.     move(y-1,x);// mover cursor up onto the barrier to replace it with  space then back one cuz the spaces pushes it forward
  78.     printw(" ");//prints the space
  79.     getyx(stdscr,y,x);
  80.     move(y+1,x-1);
  81.     refresh();//refreshes the screen to show the changes
  82.   }                
  83.   if(ch=='a') {//checks to see if u press d
  84.     wall=='b';//sets the barrier to b instead of o for a sec because o is the barrier o it changes b to the barrier
  85.     getyx(stdscr,y,x);
  86.     move(y,x-1);// mover cursor up onto the barrier to replace it with  space then back one cuz the spaces pushes it forward
  87.     printw(" ");//prints the space
  88.     getyx(stdscr,y,x);
  89.     move(y,x);
  90.     refresh();//refreshes the screen to show the changes
  91.   }
  92.   if(ch=='s') {//checks to see if u press d
  93.     wall=='b';//sets the barrier to b instead of o for a sec because o is the barrier o it changes b to the barrier
  94.     getyx(stdscr,y,x);
  95.     move(y+1,x);// mover cursor up onto the barrier to replace it with  space then back one cuz the spaces pushes it forward
  96.     printw(" ");//prints the space
  97.     getyx(stdscr,y,x);
  98.     move(y-1,x-1);
  99.     refresh();//refreshes the screen to show the changes
  100.   }
  101.   if(ch=='d') {//checks to see if u press d
  102.     wall=='b';//sets the barrier to b instead of o for a sec because o is the barrier o it changes b to the barrier
  103.     getyx(stdscr,y,x);
  104.     move(y,x+1);// mover cursor up onto the barrier to replace it with  space then back one cuz the spaces pushes it forward
  105.     printw(" ");//prints the space
  106.     getyx(stdscr,y,x);
  107.     move(y,x-2);
  108.     refresh();//refreshes the screen to show the changes
  109.   }      //quitting the game
  110.   if(ch=='q') {//checks to see if u press q
  111.     endwin();//ends the window. screws up the termnal if u retrn 0 without this
  112.     return 0;//ends program
  113.   }                  //classification of barrier
  114.   if (wall=='o') {//asking is wall = 'o' (wall is defines as inch earlier in program so it is inside terminal not user input)
  115.     move(y,x);//moves cursor to its last known coordinates (notice i didnt getxy. this would make it move to the spot on the barrier)
  116.     refresh();//shows changes
  117.     getch();//tell that the input has been done (i think)
  118.   }             //in case of glitch this resets the cursor to (0,0)
  119.   if (ch=='r') {//checks to see if u pressed r
  120.   move(0,0);//moves u to (0,0)
  121.   refresh();//shows changes
  122.   }
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement