From 53c54eac8edd368a4db147dc5236e69f460705ae Mon Sep 17 00:00:00 2001 From: Nazar Sendetskyi Date: Tue, 14 Jun 2022 07:44:07 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20'du8?= =?UTF-8?q?'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du8/program | Bin 0 -> 24664 bytes du8/program.c | 263 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 263 insertions(+) create mode 100644 du8/program create mode 100644 du8/program.c diff --git a/du8/program b/du8/program new file mode 100644 index 0000000000000000000000000000000000000000..d3754bb4f034c3d04d10e94437ae509bc4e65126 GIT binary patch literal 24664 zcmeHvdvsgXx#vETwtf7PWjRjlJe3zs2(g`zqzS~0oWwy6d6+y(0t7|2WLu3bxq9Tm zB_v=dXoO3`ZD~4_Ho#1$X@Qb^=avbNNdj~rKmq68-Zr$WZQ2DzF3_e1E(QXg-?z`+ z^3jRaxvT5`F>6+~md>}o=l=G$ALs0S9{ZZstg>kuQ_0T0#0Wd*HYi@n*mAwh0C?GA zR)*sYHk}m!cL;>k7{83P+N==k8v-Xzro~wee`}e8DHb zs0`{;*R0#j&@88jrka!TV6@9So$KJqqKH6UUo1(i!$o@=@5u=DCe-}!{BK23P^c!Bn{+ofYIb% z%tPOnhyLX}^pEq<@61ELHxK>EJakW<`o5hxgwf(~OCEZ0o^s#IBcI4a z|7{-nFZ0l8y7Ay|P1I3F^FNq}p2AlA2E{P~T|=Dffu+6lqJw;-NSV zqD9Q#ylJgJ7>b2D!tq2XwrTB(u4p8*DbU&#Vt#)|cQoRUCjzmA-*1SHDj11|+B&0b zS4Sw(*2#7Sg26~U5o4i9a923Oc6CR0hFCZfPWXEQ;h4z9+hWYH+ZOGL#-Ni(z^Md- ze~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{)DJuf-zv-^nZJI+>lg)8_M=$4!Gv-?PMK}1q=1~!5#`e$HJ-&N(S{U-HY zZkP0*#vdi6r`qum(5U`OU+rI3%LQqMluSwKD@glIW_{+B!u1AJ}X6f)&eR>j@Xx4fTcn$p+*0<)Q^v%%Xq7dJ{ z%FybR^`8dxO8iy(tNELz7uEKLhH*UIVnBNK)0|Yfibm7rX!;*-HY9GaC|FSTe*lI# B0Q&#{ literal 0 HcmV?d00001 diff --git a/du8/program.c b/du8/program.c new file mode 100644 index 0000000..03fa5d4 --- /dev/null +++ b/du8/program.c @@ -0,0 +1,263 @@ +#include +#include +#include +#include +#include +#include + +#define DESIRED_WIDTH 70 +#define DESIRED_HEIGHT 25 + +WINDOW * g_mainwin; +int g_oldcur, g_score = 0, g_width, g_height; +typedef struct { + int x; + int y; +} pos; +pos fruit; + +// 2D array of all spaces on the board. +bool *spaces; + +// -------------------------------------------------------------------------- +// Queue stuff + +// Queue implemented as a doubly linked list +struct s_node +{ + pos *position; // **TODO: make this a void pointer for generality. + struct s_node *prev; + struct s_node *next; +} *front=NULL, *back=NULL; +typedef struct s_node node; + +// Returns the position at the front w/o dequeing +pos* peek( ) +{ + return front == NULL ? NULL : front->position; +} + +// Returns the position at the front and dequeues +pos* dequeue( ) +{ + node *oldfront = front; + front = front->next; + return oldfront->position; +} + +// Queues a position at the back +void enqueue( pos position ) +{ + pos *newpos = (pos*) malloc( sizeof( position ) ); + node *newnode = (node*) malloc( sizeof( node ) ); + + newpos->x = position.x; + newpos->y = position.y; + newnode->position = newpos; + + if( front == NULL && back == NULL ) + front = back = newnode; + else + { + back->next = newnode; + newnode->prev = back; + back = newnode; + } +} + +// End Queue stuff + +// Snake stuff + +// Writes text to a coordinate +void snake_write_text( int y, int x, char* str ) +{ + mvwaddstr( g_mainwin, y , x, str ); //add a string of characters to a curses window and advance cursor +} + +// Draws the borders +void snake_draw_board( ) +{ + int i; + for( i=0; inext; + free( n ); + } + endwin(); + exit(0); +} + +// Is the current position in bounds? +bool snake_in_bounds( pos position ) +{ + return position.y < g_height - 1 && position.y > 0 && position.x < g_width - 1 && position.x > 0; +} + +// 2D matrix of possible positions implemented with a 1D array. This maps +// the x,y coordinates to an index in the array. +int snake_cooridinate_to_index( pos position ) +{ + return g_width * position.y + position.x; +} + +// Similarly this functions maps an index back to a position +pos snake_index_to_coordinate( int index ) +{ + int x = index % g_width; + int y = index / g_width; + return (pos) { x, y }; +} + +// Draw the fruit somewhere randomly on the board +void snake_draw_fruit( ) +{ + attrset( COLOR_PAIR( 3 ) );//curses character and window attribute control routines + int idx; + do + { + idx = rand( ) % ( g_width * g_height ); + fruit = snake_index_to_coordinate( idx ); + } + while( spaces[idx] || !snake_in_bounds( fruit ) ); + snake_write_text( fruit.y, fruit.x, "F" ); +} + +// Handles moving the snake for each iteration +bool snake_move_player( pos head ) +{ + attrset( COLOR_PAIR( 1 ) ) ; + + // Check if we ran into ourself + int idx = snake_cooridinate_to_index( head ); + if( spaces[idx] ) + snake_game_over( ); + spaces[idx] = true; // Mark the space as occupied + enqueue( head );//Inserting at the end of a linked list, returning head of list + g_score += 10; + + // Check if we're eating the fruit + if( head.x == fruit.x && head.y == fruit.y ) + { + snake_draw_fruit( ); + g_score += 1000; + } + else + { + // Handle the tail + pos *tail = dequeue( ); + spaces[snake_cooridinate_to_index( *tail )] = false; + snake_write_text( tail->y, tail->x, " " ); + } + + // Draw the new head + snake_write_text( head.y, head.x, "S" ); + + // Update scoreboard + char buffer[25]; + sprintf( buffer, "%d", g_score ); + attrset( COLOR_PAIR( 2 ) ); + snake_write_text( g_height+1, 9, buffer ); + return true; + +} + +int main( int argc, char *argv[] ) +{ + int key = KEY_RIGHT; + if( ( g_mainwin = initscr() ) == NULL ) {//initscr-создает окно курсес + perror( "error initialising ncurses" );// для вывода ошибок + exit( EXIT_FAILURE ); + } + + // Set up + srand( time( NULL ) ); + noecho( ); + curs_set( 2 ); + halfdelay( 1 ); + keypad( g_mainwin, TRUE ); + g_oldcur = curs_set( 0 ); + start_color( ); + init_pair( 1, COLOR_RED, COLOR_BLACK ); + init_pair( 2, COLOR_GREEN, COLOR_BLACK ); + init_pair( 3, COLOR_YELLOW, COLOR_BLACK ); + init_pair( 4, COLOR_BLUE, COLOR_BLACK ); + init_pair( 5, COLOR_CYAN, COLOR_BLACK ); + init_pair( 6, COLOR_MAGENTA, COLOR_BLACK ); + init_pair( 7, COLOR_WHITE, COLOR_BLACK ); + getmaxyx( g_mainwin, g_height, g_width );//Robot with colors + + g_width = g_width < DESIRED_WIDTH ? g_width : DESIRED_WIDTH; + g_height = g_height < DESIRED_HEIGHT ? g_height : DESIRED_HEIGHT; + + // Set up the 2D array of all spaces + spaces = (bool*) malloc( sizeof( bool ) * g_height * g_width );//memory allocation + + snake_draw_board( ); + snake_draw_fruit( ); + pos head = { 5,5 }; + enqueue( head ); + + // Event loop + while( 1 ) + { + int in = getch( ); + if( in != ERR ) + key = in; + switch( key ) + { + case KEY_DOWN: + case 'j': + case 'J': + case 's': + case 'S': + head.y++; + break; + case KEY_RIGHT: + case 'l': + case 'L': + case 'd': + case 'D': + head.x++; + break; + case KEY_UP: + case 'k': + case 'K': + case 'w': + case 'W': + head.y--; + break; + case KEY_LEFT: + case 'h': + case 'H': + case 'a': + case 'A': + head.x--; + break; + + } + if( !snake_in_bounds( head ) ) + snake_game_over( ); + else + snake_move_player( head ); + } + snake_game_over( ); +} \ No newline at end of file