Advertisement
gopro_2027

ncursesv6.cpp

Mar 27th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. /*
  2. *Notes might be a bit scattered or maybe wrong to some extent*
  3.  
  4. how to play:
  5. #start game in full terminal. it will look funny is u dont
  6. #use arrow keys to move
  7. #press 'o' to place barrier
  8. #to delete barrier piece stand by it ans press w,a,s,d. ex: stand under the barrer u wanna delete and press w
  9. #if you get stuck in a barrier and cant move (this is a bug) press 'r' to go to (0,0)
  10. #press 'q' to end the game
  11. #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
  12. */
  13. #include <curses.h>
  14. #include <unistd.h>
  15. #include <stdio.h>
  16. int main()
  17. {
  18. initscr();
  19. start_color();//says we can have color(personal note)
  20. noecho();//keeps from pressing other characters(personal note)
  21. cbreak();
  22. nodelay(stdscr, TRUE);
  23. keypad(stdscr, TRUE);
  24. init_pair(1, COLOR_RED, COLOR_CYAN);
  25. attron(COLOR_PAIR(1));
  26. printw(" #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n #\n###################################################################################################################\n");
  27. move(0,0);
  28. for( ; ; ) {
  29. char readch = inch();
  30. int y, x, stars, stars1, r;
  31. FILE *wfile;
  32. WINDOW *win;
  33. int ch = getch();
  34. switch (ch) {
  35. case KEY_DOWN:
  36. getyx(stdscr , y, x);
  37. move(y+1,x);
  38. refresh();
  39. getch();
  40. }
  41. switch (ch) {
  42. case KEY_UP:
  43. getyx(stdscr , y, x);
  44. move(y-1,x);
  45. refresh();
  46. getch();
  47. }
  48. switch (ch) {
  49. case KEY_LEFT:
  50. getyx(stdscr , y, x);
  51. move(y,x-1);
  52. refresh();
  53. getch();
  54. }
  55. switch (ch) {
  56. case KEY_RIGHT:
  57. getyx(stdscr , y, x);
  58. move(y , x+1 );
  59. refresh();
  60. getch();
  61. }
  62. if(ch=='1') {
  63. printw("#");
  64. refresh();
  65. }
  66. if(ch=='2') {
  67. printw("/");
  68. refresh();
  69. }
  70. if(ch=='3') {
  71. printw("[");
  72. refresh();
  73. }
  74. if(ch=='4') {
  75. printw("]");
  76. refresh();
  77. }
  78. if(ch=='5') {
  79. printw("&");
  80. refresh();
  81. }
  82. if(ch=='k') {
  83. int putwin(WINDOW stdscr , FILE world);//save file not working
  84. WINDOW getstdscr(FILE world);
  85. refresh();
  86. }
  87. if(ch=='l') {
  88. WINDOW getstdscr(FILE world);//load file not working
  89. refresh();
  90. }
  91. if(ch=='w') {
  92. readch=='b';
  93. getyx(stdscr,y,x);
  94. move(y-1,x);
  95. printw(" ");
  96. getyx(stdscr,y,x);
  97. move(y+1,x-1);
  98. refresh();
  99. }
  100. if(ch=='a') {
  101. readch=='b';
  102. getyx(stdscr,y,x);
  103. move(y,x-1);
  104. printw(" ");
  105. getyx(stdscr,y,x);
  106. move(y,x);
  107. refresh();
  108. }
  109. if(ch=='s') {
  110. readch=='b';
  111. getyx(stdscr,y,x);
  112. move(y+1,x);
  113. printw(" ");
  114. getyx(stdscr,y,x);
  115. move(y-1,x-1);
  116. refresh();
  117. }
  118. if(ch=='d') {
  119. readch=='b';
  120. getyx(stdscr,y,x);
  121. move(y,x+1);
  122. printw(" ");
  123. getyx(stdscr,y,x);
  124. move(y,x-2);
  125. refresh();
  126. }
  127. if(ch=='q') {
  128. endwin();
  129. return 0;
  130. }
  131. if (readch=='#') {
  132. move(y,x);
  133. refresh();
  134. getch();
  135. }
  136. if (ch=='r') {
  137. move(0,0);
  138. refresh();
  139. }
  140. {
  141. if (readch=='&') {
  142. printw(" ");
  143. move(0,0);
  144. printw("Hello There!");
  145. refresh();
  146. sleep(2);
  147. move(0,0);
  148. printw("Would you ike some pie? y/n");
  149. getch();
  150. }
  151. if (ch=='y') {
  152. move(0,0);
  153. printw(" ");
  154. move(0,0);
  155. printw("Yay! You get gold star!");
  156. stars=stars+1;
  157. move(0,115);
  158. printw(" gold stars: %d", stars);
  159. refresh();
  160. sleep(2);
  161. move(0,0);
  162. printw(" ");
  163. move(y,x);
  164. refresh();
  165. getch();
  166. }
  167. if (ch=='n') {
  168. move(0,0);
  169. printw(" ");
  170. move(0,0);
  171. printw(":( you dont like my pie...");
  172. refresh();
  173. sleep(2);
  174. move(0,0);
  175. printw(" ");
  176. refresh();
  177. move(y,x);
  178. refresh();
  179. getch();
  180. }
  181. }
  182. }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement