.
This commit is contained in:
		
							
								
								
									
										9
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| Resursi | ||||
|  | ||||
| Ncurses: | ||||
|  | ||||
| https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html | ||||
|  | ||||
| https://invidious.einfachzocken.eu/watch?v=pjT5wq11ZSE&list=PL2U2TQ__OrQ8jTf0_noNKtHMuYlyxQl4v | ||||
|  | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								Snakes/snakes
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Snakes/snakes
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -1,11 +1,13 @@ | ||||
| #include <iostream> | ||||
| #include <cstdlib> | ||||
| #include <ncurses.h> | ||||
| #include <thread> | ||||
| using namespace std; | ||||
| const int width = 80; | ||||
| const int height = 20; | ||||
| int snakeX = width/2; | ||||
| int snakeY = height/2; | ||||
| bool gameover; | ||||
| const int snakeX = width/2; | ||||
| const int snakeY = height/2; | ||||
|  | ||||
|  | ||||
| void start(){ | ||||
| @@ -22,8 +24,8 @@ for(int i=0; i<width; i++){ | ||||
| } | ||||
| cout << endl; | ||||
| for(int i=0; i<height; i++){ | ||||
|     for(int j=0; j<=width; j++){ | ||||
|         if(j==0 || j==width){ | ||||
|     for(int j=0; j<width; j++){ | ||||
|         if(j==0 || j==width-2){ | ||||
|             cout<<"#";   | ||||
|         } | ||||
|         if(j==snakeX && i==snakeY) | ||||
| @@ -38,12 +40,47 @@ for(int i=0; i<width; i++){ | ||||
| cout<<endl; | ||||
| } | ||||
|  | ||||
| void GameUpdate(int snakeXmv, WINDOW * win){ | ||||
| int c = getch(); | ||||
| printw("%d", c); | ||||
| if(c == 97 || c == 68){ | ||||
|     for(int i; i < snakeX; snakeXmv--){ | ||||
|         curs_set(0); | ||||
|         mvwprintw(win,snakeY,snakeXmv,"o"); | ||||
|         mvwprintw(win,snakeY,snakeXmv+1," "); | ||||
|         wrefresh(win); | ||||
|         this_thread::sleep_for(chrono::milliseconds(1000)); | ||||
|         } | ||||
|     } | ||||
| if(c == 67 || c == 100){ | ||||
|     for(int i; i < snakeX; snakeXmv++){ | ||||
|         curs_set(0); | ||||
|         mvwprintw(win,snakeY,snakeXmv,"o"); | ||||
|         mvwprintw(win,snakeY,snakeXmv-1," "); | ||||
|         wrefresh(win); | ||||
|         this_thread::sleep_for(chrono::milliseconds(1000)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| int main(){ | ||||
|  | ||||
| while(!gameover) | ||||
|     draw(); | ||||
| int snakeXmv = snakeX; | ||||
|    | ||||
| while(!gameover){ | ||||
|     start(); | ||||
|     initscr(); | ||||
|     WINDOW * win = newwin(height, width, 0, 0); | ||||
|     refresh(); | ||||
|      | ||||
|     box(win, 0, 0); | ||||
|     mvwprintw(win,snakeY,snakeXmv,"o"); | ||||
|     wrefresh(win); | ||||
|      | ||||
|     GameUpdate(snakeXmv, win); | ||||
|     cout << snakeXmv << endl; | ||||
|     getch(); | ||||
|     endwin(); | ||||
| } | ||||
|  | ||||
|  | ||||
| return 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user