From 683b778e3fff5b685e819adb6a277a6ded3346fc Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Sat, 17 Apr 2021 16:28:00 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20'a4/.gitignore'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a4/.gitignore | 54 --------------------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 a4/.gitignore diff --git a/a4/.gitignore b/a4/.gitignore deleted file mode 100644 index ecf4432..0000000 --- a/a4/.gitignore +++ /dev/null @@ -1,54 +0,0 @@ -game - -# Prerequisites -*.d - -# Object files -*.o -*.ko -*.obj -*.elf - -# Linker output -*.ilk -*.map -*.exp - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb - -# Kernel Module Compile Results -*.mod* -*.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf From 48217e46158581ed2e941e762332dc4c967fbaf2 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Sat, 17 Apr 2021 16:28:14 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20'a4/LICENSE'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a4/LICENSE | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 a4/LICENSE diff --git a/a4/LICENSE b/a4/LICENSE deleted file mode 100644 index 39d1664..0000000 --- a/a4/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2019, Daniel Hládek -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 2bba9bdbdb4753145edea32ebc5527dc5e94b8ea Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Sat, 17 Apr 2021 16:28:28 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20'a4/README.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a4/README.md | 78 ---------------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 a4/README.md diff --git a/a4/README.md b/a4/README.md deleted file mode 100644 index b57958c..0000000 --- a/a4/README.md +++ /dev/null @@ -1,78 +0,0 @@ -# World Game Library - -Learn asycnronous C programming by a game. - -The library implements a game loop for a character-based ncurses game; - -The library finds out the event types: - -- start and end -- mouse events -- keyboard events -- screen resize events - -It can print colors and arbitrary characters on the screen. -Running is interrupted when character is drawn out of the screen. - -## Installation and Running - -Make sure, that `ncurses` is installed. - -Clone this repository. - -Compile: - -```c -make -``` - -Run: - -```c -./game -``` - -## Make your own game - -The game happens in a rectangular world of colorful characters. -Your goal as a programmer is to modify the world according to the pressed keys and the internal game state. -The library implements the game loop and draws the world to screen. - -Your game in file `game.c` consists of two functions: - -- `void* init_game()` is called in the beginning. Here you can initialize the internal state of the game. -The function should return a pointer to an instance of the initial game state `game`. -- `int game_event(struct event* event,void* game)` -is called by the game loop in periodic interval or when a key was pressed. Non-zero return value or `Ctrl+C` key interrupts the game loop. - -The world variable represents state of two-dimensional grid of characters on the screen. The screen matrix looks like this: - -``` - origin - [0,0] width - +--------------------+ -h | | -e | | -i | | -g | | -h | | -t | | - +--------------------+ -``` - -The world has the following parameters: - -- `int height`: y-dimension of the grid. -- `int width`: x-dimension of the grid. -- `int interval`: maximum time between steps in milliseconds. - -### The Event Function - -The `int game_event(struct event* event,void* game)` - function should: - -1. Read the game state (from the `void* game`) pointer. -1. Examine the pressed key from event pointer. If the `key` variable is non-zero, a key was pressed. According to the pressed key, modify the game state `game`. -1. Draw the game state. In the beginning of the step function the screen is empty. -1. Returning non-zero value ends the game loop. - From 0e5571b2e8b26be612d7cfe288994b496003f665 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Sat, 17 Apr 2021 16:40:53 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20'a4/game.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a4/game.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/a4/game.c b/a4/game.c index 6599cf7..22c43b3 100644 --- a/a4/game.c +++ b/a4/game.c @@ -28,7 +28,7 @@ int game_event(struct event* event,void* game){ // Get state pointer struct game* state = game; char msg[200]; - sprintf(msg,"%d",event->type); + sprintf(msg,"%d",event->type); set_message(msg,10,0); if ( event->type == EVENT_ESC){ // Non zero means finish the loop and stop the game. @@ -69,20 +69,7 @@ int game_event(struct event* event,void* game){ int cx = state->catx_position + state->catx; int cy = state->caty_position + state->caty; if (cx < 1 || cy < 0 || cx > event->width || cy > event->height){ - /*state->catx_position = cx; - state->caty_position = cy; - if(state->catx_position < 0){ - state->catx_position = 0; - } - else if(state->catx_position >= event->width){ - state->catx_position = event->width-1; - } - else if(state->caty_position < 0){ - state->caty_position = 0; - } - else if(state->caty_position >= event->height){ - state->caty_position = event->height-1; - }*/ + } else { state->catx_position = cx; @@ -108,8 +95,7 @@ int game_event(struct event* event,void* game){ else if (m == 3 && state->mousey[i] < event->height){ state->mousey[i] += 1; } - } - //Je + } } else if (event->type == EVENT_KEY){ // Move cat according to keyboard @@ -131,14 +117,14 @@ int game_event(struct event* event,void* game){ } } // Draw world state - // + // Draw cat clear_screen(); set_color_cell('c',state->catx_position,state->caty_position,COLOR_YELLOW,COLOR_RED); set_color_cell('-',state->catx_position-1,state->caty_position,COLOR_YELLOW,COLOR_GREEN); //set_cell('c',state->catx_position,state->caty_position); - // Draw mouse + // Draw mouse for(int i = 0; i < MOUSE_COUNT; i++){ if(state->mouse_state[i] != 1){ set_cell('m', state->mousex[i], state->mousey[i]); From 2a0aed698ee7422e6e34e4ca9997525a98e02cfa Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Sat, 17 Apr 2021 19:00:34 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20'a4/game.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a4/game.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/a4/game.c b/a4/game.c index 22c43b3..bf1a495 100644 --- a/a4/game.c +++ b/a4/game.c @@ -10,14 +10,14 @@ void* init_game(){ struct game* st = calloc(1,(sizeof(struct game))); // Initialize state for(int i = 0; i < MOUSE_COUNT; i++){ - st->mousex[i] = rand()%15; - st->mousey[i] = rand()%15; - st->mouse_state[i] = 0; - } - st->catx = 0; - st->caty = 0; - st->catx_position = 15; - st->caty_position = 15; + st->mousex[i] = rand()%15; // Рандомная позиция мышей на карте + st->mousey[i] = rand()%15; // --//-- + st->mouse_state[i] = 0; // состояние мышы -- жива + } //генерация мышей + st->catx = 0; //скорость кота + st->caty = 0; // --//-- + st->catx_position = 15; // Позиция кота на карте + st->caty_position = 15; // --//-- // Store pointer to the state to the world variable return st; } @@ -26,7 +26,7 @@ void* init_game(){ // It should modify the state and draw it. int game_event(struct event* event,void* game){ // Get state pointer - struct game* state = game; + struct game* state = game; // Зоздание игры char msg[200]; sprintf(msg,"%d",event->type); set_message(msg,10,0);