From 9877565fea8ca30999e5737f16e8cfca9bc7aa1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vasi=C4=BE?= Date: Thu, 28 Apr 2022 14:27:28 +0200 Subject: [PATCH] du7_kontrola_suborov --- a2/Makefile | 14 ++++ a2/README.md | 16 +++++ a2/game | Bin 0 -> 22464 bytes a2/main.c | 110 ++++++++++++++++++++++++++++ a2/main.o | Bin 0 -> 5896 bytes a2/snake.c | 104 +++++++++++++++++++++++++++ a2/snake.h | 114 +++++++++++++++++++++++++++++ a2/snake.o | Bin 0 -> 4940 bytes a2/world.c | 198 +++++++++++++++++++++++++++++++++++++++++++++++++++ a2/world.h | 122 +++++++++++++++++++++++++++++++ a2/world.o | Bin 0 -> 11420 bytes 11 files changed, 678 insertions(+) create mode 100644 a2/Makefile create mode 100644 a2/README.md create mode 100755 a2/game create mode 100644 a2/main.c create mode 100644 a2/main.o create mode 100644 a2/snake.c create mode 100644 a2/snake.h create mode 100644 a2/snake.o create mode 100644 a2/world.c create mode 100644 a2/world.h create mode 100644 a2/world.o diff --git a/a2/Makefile b/a2/Makefile new file mode 100644 index 0000000..d71d436 --- /dev/null +++ b/a2/Makefile @@ -0,0 +1,14 @@ +CFLAGS=-std=c99 -Wall -g + +all: game + +%.o: %.c + gcc $(CFLAGS) -c $< -o $@ + +clean: + rm *.o + rm game + +game: main.o world.o snake.o + gcc -rdynamic -g main.o world.o snake.o -lcurses -lm -o game + diff --git a/a2/README.md b/a2/README.md new file mode 100644 index 0000000..79a2d67 --- /dev/null +++ b/a2/README.md @@ -0,0 +1,16 @@ +# Snake Master + +Implement Snake game. + +Make the game to pass the automatic tests and make the game to be nice. + +## Files + +Please do not change file names. + +- `snake.h`: you implementation should follow this header. +- `snake.c`: implemement the game according to the documentation in header file in this file to pass automatic tests. +- `Makefile`: rules to build the game. +- `main.c`: trivial main function that runs the game, modify this file to change the appereance of the game and the initial state. +- `world.c`: world game loop and ASCII graphics library (do not change). +- `world.h`: world library interface (do not change). diff --git a/a2/game b/a2/game new file mode 100755 index 0000000000000000000000000000000000000000..46790ef0b4bfee04d176ad262297acacc368132f GIT binary patch literal 22464 zcmbV!4SZC^x%Zs2C*fqX`A!f4VSym17=i}*#_+K!@+l+=t-5Too88DJo4eT!i7!xa zLCFnRLQ(Of0ZX$ymaKkzZyI`6FfTdnFif;z}F#dx`n`WHgClTiQx02g?N6SVbVPb9-Ym<0erwOT(TAG1J0x zL21tf3l9aI3^&TcHYtFIHjS_YKreFm>1CeB!<7->x)3f8?h*p)$_JeX$Gp#gn-0f| zY>MS)nK3Q81G`pu@;qBt zOw@#?XBTh2!yORjL~o7}$<8XgIZvviJnM@2V0)q-UbKy6#P-3q!}d`P$BSjdyz~0~ zzyC3R-8UZCaA@kwwI?szG4g-!{3!p<>TO`|Iw; zZAJNgCw~3*FW-Oo%DVsf@PY}c4W60z<*w=ZuY-2}k080FD24?x%7x`gF1rVRKnV`fUW#IqHz!zo2 z|15*=%HZ2=iel9NT84aGhI}*wv)=5>3(xWl{yjDml=^SZ;CE!;yE1Tj2Hu>3Z^^*N zGt&E62ENsSz3_j}foWe&hQ7Fi?}fkDfhoTu1IIJs9|eB?VT?Dpiba9g1N_;y43qs# zvB(!AaMNAC$1o3A_y$npXNJjsvIxCFBlrh*+VMT&e#9@l+s3dT`23R!7mAPiS0kS3 zi2nijyB{>nEtdYN(D(OUhWUnt7XhE>Hq6UFX-_re-+{d<{X+2*;8N&=IQra=`X7bd zMA$plia!zfY&!i5#SY+J@Nc*H4ruUo*X@fR7?QM3eY+-~$gC<_|#0 ze;c#}c!|aLK+u1$VSaAmYT#1f#TNb(I+hD3c`JQP?b z)+ZX9La}5*`2FFgShK%15r`-Jez9Qrl2xKL5p1oGizSPe`Bn-4^=`dBm;Zxx~D z;QB@|lte>=knx)Wt*|y8YKVtgBVv71tSuxOn;R4UmOx`%`e>>$Un*j0BpRC=VyZ0G zg*sXSK_njxMFSmVHj!}^ef7%cU$h+g4>mUYVQ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=TcV*v zC|EId+Le{i{3Sy2SR?ghiUW@lSm#vFvcY6i6V^PfCtHd9a@Aix&|0F_%DCLR1k>#m zKEMB(mGhSR{9LT_TN$$b?bENSz@bw9mU@38l5AdAQHM3l!J2vMQm{4VkKj-ztjhZr zu30v3>7oUL#jG=${5UqtPUqSs%jeHq;$MEvHLH9z{+fC7m-v{vJn!j?2RQwsQ?Y>wKy7p;?30PSZzg zS5ps5S gFz5g|bp)IJvdZx~fNy@~(Qope6ZP_pG^fu03-V$hB>(^b literal 0 HcmV?d00001 diff --git a/a2/main.c b/a2/main.c new file mode 100644 index 0000000..9e5ec9a --- /dev/null +++ b/a2/main.c @@ -0,0 +1,110 @@ +#include "world.h" +#include +#include +#include +#include +#include "snake.h" +// This file contains functions for drawing the the game and changing the state + +// Start is called one in the beginning +void* init_game(){ + // Allocate memory for the state + struct state* st = calloc(1,(sizeof(struct state))); + return st; +} + +// The first event +// Initialize game state +// - borders +// - snake position +// - food position +void init_snake(struct event* world, struct state* st){ + int cy = world->height/2; + int cx = world->width/2 - 5; + for (int i = 0; i < 5; i++){ + st->snake = add_snake(st->snake,cx + i ,cy); + } + + int h = world->height; + int w = world->width; + for (int i = 0; i < 5; i++){ + st->foodx[i] = rand() % w; + st->foody[i] = rand() % h; + } + // Initial game vector + st->sx = 1; + st->sy = 0; +} + +// Step is called in a loop once in interval. +// It should modify the state and draw it. +int world_event(struct event* w,void* game){ + // Get state pointer + struct state* st = game; + if (w->type == EVENT_START){ + // Called on beginning + init_snake(w,st); + } + // Called on key press + else if (w->type == EVENT_KEY){ + int key = w->key; + // Modifies vector of snake movement + if (key == KEY_RIGHT){ + st->sx = 1; + st->sy = 0; + } + else if (key == KEY_LEFT){ + st->sx = -1; + st->sy = 0; + } + else if (key == KEY_DOWN){ + st->sx = 0; + st->sy = 1; + } + else if (key == KEY_UP){ + st->sx = 0; + st->sy = -1; + } + } + // Called on esc key + else if (w->type == EVENT_ESC){ + // Non zero means finish the loop and stop the game. + return 1; + } + // Called on interval timeout + else if (w->type == EVENT_TIMEOUT){ + clear_screen(); + // Copy screen size + st->width = w->width; + st->height = w->height; + // Change game state + int r = step_state(st); + char ms[200]; + sprintf(ms,"r %d\n",r); + set_message(ms,9,9); + // Draw snake + struct snake* sn = st->snake; + while (sn != NULL){ + set_cell('x',sn->x,sn->y); + sn = sn->next; + } + // Draw food + for (int i = 0 ; i < FOOD_COUNT; i++){ + if (st->foodx[i] >= 0 && st->foody[i] >= 0){ + set_cell('*',st->foodx[i],st->foody[i]); + } + } + // Stop the game + if (r){ + char message[] = "Koniec"; + set_message(message,10,10); + } + } + return 0; +} + + +int main(int argc, char** argv){ + start_world(init_game,world_event,free); + return 0; +} diff --git a/a2/main.o b/a2/main.o new file mode 100644 index 0000000000000000000000000000000000000000..8cc7e78403b2d668202894113c6bc306832d9568 GIT binary patch literal 5896 zcma)Adu$xV9iG`++k5u;{K^X@5GOHUh&kt3rz8PGvZW?3lGrJs5toZ^eZKl0(cRhD zh@>FnHdiYYqe4MQ4fLN<393FRlu8Xjt(yu#0JTMxQiYPBq!`szU7&?F{l1x5`|PSx zN8bH@@A>`ab+i7myZv)gO5ryt0%C>}!VYWAIt9&QfoKq2#S6m|&Es2}>`jo4+f8)1 z`03@#my7Pys5^D~6=ktu)OAMN?c%AI|GZS5dE?`vJ3)z<77Sl3E4mlQ-6_U?|9W_i zc3nIkvPRv|s2J^kko*Q>3RirkZ z%c+|Z$QP82Z`$iYwZ(v&ho?X|-nTQwt(s!(7ZRQte@i)B#vUje`A zZa}GSF8vHDSlA^N7}d+lR$Dx-Evym?Ca5hS6qg3HMF3DUlEhp0G-Jhxm+nvsonu*l zbCI)f9s}WUS+K9;BlFRZuZPqL zLP{-hwibb~EZnL0o4E!UehNHiALdwJgYYnkOsQdm;$OS5gv3R(9P{@Uv zIT-F0a*3u7gzpjZN=@HczZ1c}isvKFn0WCIG+)6pPIt4RDBWozlY~B`XJ*2e#Q+GkTTMIq#$JX zNs!i97w9T(9kObU#x;M&=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o#3=kWZ_@*C%o`@lcr8Gp!E z0;xYbhxhMS>XM?a0^P9`&+C#~ODrBY_ZJ-8@mbe|?vxkHMf2S`&&%Mt;~kFbJ5T;_ z4nM^`BJUNV)3+he-CioCx)eQd;RPvIi0WH|!2jp4KaeDAurScyCSo1FWN ziF1%!S>pSFtAfZqL*$%G#N>HETt>vwYc~2;gP$?D+2B@#+YIhEc+g-~ka79ZOPn5s2>!#S;%2{(gi10nY})kN^Mx literal 0 HcmV?d00001 diff --git a/a2/snake.c b/a2/snake.c new file mode 100644 index 0000000..3b20d43 --- /dev/null +++ b/a2/snake.c @@ -0,0 +1,104 @@ +#include "snake.h" +#include + +struct snake* add_snake(struct snake* snake,int x,int y){ + struct snake* novyZaciatok = calloc(1, sizeof(struct snake)); //alokujem pamäť smerníka + novyZaciatok->x = x; //nastavím súradnice hada + novyZaciatok->y = y; + + if (snake != NULL) { //ak má had telo, + novyZaciatok->next = snake; //tak mu iba pridám hlavu + } else { + novyZaciatok->next = NULL; //inak musím vytvoriť nové telo + } + + return novyZaciatok; +} + +struct snake* remove_snake(struct snake* snake){ + if (snake == NULL) return NULL; //ak nezadám ako vstup hada, tak okamžite vrátim NULL + + else if (snake->next == NULL) { //ak had nemá pokračovanie, + free(snake); //tak ho zruším + return NULL; //a vrátim NULL + } + + else { //inak prebehnem celého hada od začiatku + struct snake* medzipamat = calloc(1, sizeof(struct snake)); //alokujem medzipamäť + medzipamat = snake; //adresu hlavy hada uložím do medzipamäte + + while (snake->next->next != NULL) snake = snake->next; //hada budem prezerať dovtedy, kým nenájdem jeho koniec + + free(snake->next); //koniec hada zmažem + + snake->next = NULL; // nastavím nový koniec hada + return medzipamat; //vrátim hlavu hada + } +} + +void free_snake(struct snake* sn){ //funkcia odstráni hada z hry + struct snake* medzipamat = calloc(1, sizeof(struct snake)); //alokujem medzipamäť + + while (sn != NULL) { //v cykle vymažem každý jeden prvok hada + medzipamat = sn->next; //hlavu hada uložím do medzipamäte + free(sn); //ak odstránim ju + sn = medzipamat; //nastavím novú hlavu hada + } + + free(medzipamat); //nakoniec vyčistím aj medzipamäť +} + +int is_snake(struct snake* snake,int x,int y){ + if (snake == NULL) return 0; + + while (snake != NULL) { + if (snake->x == x || snake->y == y) return 1; + snake = snake->next; + } + + return 0; +} + +int step_state(struct state* st){ + int nx = (st->snake->x + st->sx); + int ny = (st->snake->y + st->sy); + int i, pocetJedal = FOOD_COUNT; + + struct snake* had = calloc(1, sizeof(struct snake)); + struct snake* hlava = calloc(1, sizeof(struct snake)); + + had = st->snake; + hlava = st->snake; + + while (had != NULL) { + if (had->x == nx || had->y == ny) return END_SNAKE; + + for (i = 0; i < FOOD_COUNT; i++) { + if (st->foodx[i] == had->x) { + if (st->foody[i] == had->y) { + had = add_snake(had, st->foodx[i], st->foody[i]); + + st->foodx[i] = -1; + st->foody[i] = -1; + pocetJedal--; + } + } + } + + if (pocetJedal == 0) return END_FOOD; + + had = had->next; + } + + had = hlava; + free(hlava); + + if (nx > 0 && nx < st->width) { + if (ny > 0 && ny < st->height) { + had = add_snake(had, nx, ny); + had = remove_snake(had); + } + } + + return END_CONTINUE; +} diff --git a/a2/snake.h b/a2/snake.h new file mode 100644 index 0000000..4d1ff74 --- /dev/null +++ b/a2/snake.h @@ -0,0 +1,114 @@ +#ifndef snake_h_INCLUDED +#define snake_h_INCLUDED + +// Number of food items on the plane +#define FOOD_COUNT 5 + +/** + * One part of the snake; + * + * The snake is a linked list; + */ + +struct snake { + // x position of the snake part + int x; + // y position of the snake part + int y; + // Pointer to the next snake part. + // The last part of the snake has NULL pointer to the next part. + struct snake* next; +}; + +// End game reason constants, return value of step_state +enum endgame { + // Continue the game + END_CONTINUE = 0, + // Snake hit a wall + END_WALL, + // Snake hit itself + END_SNAKE, + // No food left + END_FOOD, + // Other reason to end + END_USER +}; + +/** + * State of the game. + * + * The state consists of the snake, its speed and food on the plane. + * + * The snake is a linked list of snake parts. + * + * Speed vector is a vector added to the last head position to create a new head. + * + * Food are points on the plane. Food with negative coordinates meads food is already eaten. + */ + +struct state { + // Snake as a linked list + struct snake* snake; + // X of the food positions + int foodx[FOOD_COUNT]; + // Y of the food positions + int foody[FOOD_COUNT]; + int sx; + int sy; + int width; + int height; +}; + +/** + * Add a new snake part with given position. The new snake part becomes the new head. + * + * @param head of the snake. + * @param x coordinate of the new head; + * @param y coordinate of the new head. + * @return new head of the snake. + */ +struct snake* add_snake(struct snake* snake,int x,int y); + +/** + * Remove the last snake part. + * The last snake part should always have NULL next pointer. + * + * @param head of the snake. + * @return new head of the snake. + */ +struct snake* remove_snake(struct snake* snake); + +/** + * Finds out if given coordinates are part of the snake. + * @param snake + * @param x coordinate to search in snake + * @param y coordinate to search in snake + * @return True, if there is a snake part with coordinates x,y. False otherwise + * + */ +int is_snake(struct snake* snake,int x, int y); +/** + * Remove and free each snake part; + * @param head of the snake. + */ +void free_snake(struct snake* sn); +/** + * Change game state. + * + * The function shoud calculate new posision of the snake head + * from the current position and speed vector. + * Then it should modify snake parst or food coordinates according to the rules: + * + * - If the new position is on the snake, end the game, return END_SNAKE. + * - If the new position is on the food, mark food as eaten + * (set its coordinates to -1) and add new snake part on the position of the food. If there is no food left, return END_FOOD. else return END_CONTINUE. + * - If the new position is on the plane, add new snake part on the new position and remove the last part of the snake, return END_CONTINUE. + * + * @param current state of the game + * @return reason to end the game according to enum endgame. + */ +int step_state(struct state* state); + + +#endif // snake_h_INCLUDED + diff --git a/a2/snake.o b/a2/snake.o new file mode 100644 index 0000000000000000000000000000000000000000..f99e7efe1766fe41ebea9cf7932c6bdc0ef068d3 GIT binary patch literal 4940 zcma)9ZERE589w*=#$2%Dd>A?gYzt}_=?YF(LP-hG05LQvgtR3ZOt9d@H;#p4N3oqI ztjUT})Ot}-vLD-zu7ydPw68F2KPIM4>Q=Nx?X<3|G;QjyOrjDrnZ~4OAL=&tJm6RiG)rg@8$_+>DZM|n)G*&(?@&4K z)YIYCzwX|>TZ%7FUO3kTu}%~)-83ri|atnx4Dc5>dhM}8m)?Ju2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FL@z7oESU4S9`)B91eEzOgXcxTk3s0MF5}#^I4%Y9xW|6WO%aJDSL+GmXh2 z{`QEhH>RrYc_#j}5JwLm-doqu?)9Y;S(U`j-4E$(&=-8wa#$Ch#%ZM8FWHAGE9}l+!bIx!Y2C$D`iZjs4CMUH9b2V;qO5-oa{jgs`Sp`hE#rS3 za{h+CgIQib@GVPP#PZ`qg+!l-j3lxtZ+;>ABu3W+)}Py&iwdMZSrdaZG1qA524)Z z6Bv>`XlUAP!FSt6pTLl3KVsL6qUz|Nhq2?=jX%FI62lhC{3tj14TCm5AjL_H<+)vhv+qfK$Jx?F*4@Wzk_L(5yNpkYL({J}YZexB-nPKc^ARukVtFZGA zqx&X=q|H%Xh23?Zq3MIGkooJVM*$6xv5sm?voAQ#a<70Cr%>cI5_*_*{cBRyU4;oD z-#ZaZ#$#NrX?hQ&xC-HuB=j)x3~$gccf?=s8aZ+Gf7;~zE08x;E3bg;%#{cM_0K_B z5RfNYX5sJODaPYTuZ)1emzi$_1d8{KfUJB)5WtR@i0t=ToEZ1r4DQn=OzJLTQokK& z2K75I%{!O+J>bndmV6s{^G+pS{$NX{c&Jtn&iq`YKq<&80kF@-T#<#TmZH?~| z;eT7}|EbYI490OahKaCyfQUK{XzbAX;~JkL!tS!xe^;YCH@x53r;Pik#yTKA^hBG+ Ma~hx5cva(n0X=vO!2kdN literal 0 HcmV?d00001 diff --git a/a2/world.c b/a2/world.c new file mode 100644 index 0000000..a45c109 --- /dev/null +++ b/a2/world.c @@ -0,0 +1,198 @@ +#include "world.h" +#include +#include +#include +#include +#include + +int TIMEOUT; + +void abort_game(const char* message){ + endwin(); + puts(message); + exit(1); +} + +void check_bounds(const char* source,int x, int y){ + char msg[200]; + if (x < 0 || x >= COLS){ + sprintf(msg,"%s:: width %d is out of bounds (0,%d)",source,x,COLS); + abort_game(msg); + } + if (y < 0 || y >= LINES){ + sprintf(msg,"%s:: height %d is out of bounds (0,%d)",source,y,LINES); + abort_game(msg); + } +} + +void clear_screen(){ + // Clear screen + mvaddch(0,0,' '); + int screenchars = LINES*COLS; + for (int j = 1; j < screenchars;j++ ){ + addch(' '); + } +} + +void game_speed(int value){ + if (value < 0){ + abort_game("world_seed:: cannot be negative\n"); + } + TIMEOUT =value; +} + +void set_message(const char* message,int x,int y) { + int l = strlen(message); + for (int i = 0; i < l; i++){ + check_bounds("set_message",x+i,y); + set_cell(message[i],x+i,y); + } +} + +void assert_message(int event,const char* message){ + if (event == 0){ + abort_game(message); + } +} + + +void set_cell(int character,int x,int y) { + check_bounds("set_cell",x,y); + set_color_cell(character,x,y,COLOR_WHITE,COLOR_BLACK); +} + +void set_color_cell(int character,int x,int y,short front_color,short back_color){ + check_bounds("set_color_cell",x,y); + if (has_colors()){ + int pair = COLOR_COUNT * front_color + back_color; + attron(COLOR_PAIR(pair)); + mvaddch(y,x,character); + attroff(COLOR_PAIR(pair)); + } + else{ + mvaddch(y,x,character); + } +} + +int start_world(void* (*init_game)(),int (*world_event)(struct event* event,void* game),void (*destroy_game)(void*)){ + srand(time(NULL)); + int r = 1; + // Speed global variable + TIMEOUT = 100; + if (initscr() == NULL){ + // TODO Which Error? + puts("Curses Error."); + return -1; + } + noecho(); // Nevypisuj vstup na obrazovku + cbreak(); // Zabudni starý vstup + nodelay(stdscr,TRUE); // Nečakaj na stlačenie + keypad(stdscr,TRUE); // Aktivuje šípky + curs_set(FALSE); // Neviditeľný kurzor + /* Get all the mouse events */ + mousemask(ALL_MOUSE_EVENTS, NULL); + MEVENT mouse_event; + if (has_colors()){ // Zistenie či terminál podporuje farby + start_color(); + for (int i = 0; i < COLOR_COUNT;i++){ + for (int j = 0; j < COLOR_COUNT;j++){ + init_pair(i * COLOR_COUNT + j, i,j); + } + } + } + else { + puts("No colors!\n"); + } + void* game = NULL; + if (init_game != NULL){ + game = init_game(); + assert_message(game != NULL,"init_game:: should return non null pointer"); + } + timeout(TIMEOUT); + // Initial step + struct event event; + memset(&event,0,sizeof(struct event)); + event.height = LINES; + event.width = COLS; + event.type = EVENT_START; + clock_t start_time = clock(); + clock_t last_timeout = start_time; + clock_t next_timeout = last_timeout + TIMEOUT; + event.time_ms = start_time; + // Start event + r = world_event(&event,game); + refresh(); + while (!r) { + memset(&event,0,sizeof(struct event)); + event.height = LINES; + event.width = COLS; + event.key = getch(); + // No key was pressed + if (event.key == ERR){ + event.type = EVENT_TIMEOUT; + last_timeout = clock(); + next_timeout = last_timeout + TIMEOUT; + } + // Mouse event + else if (event.key == KEY_MOUSE ){ + event.type = EVENT_MOUSE; + if(getmouse(&mouse_event) == OK){ + event.mouse_x = mouse_event.x; + event.mouse_y = mouse_event.y; + if(mouse_event.bstate & BUTTON1_PRESSED){ + event.mouse_left = 1; + } + if(mouse_event.bstate & BUTTON2_PRESSED){ + event.mouse_middle = 1; + } + if(mouse_event.bstate & BUTTON3_PRESSED){ + event.mouse_right = 1; + } + } + } + else if (event.key == KEY_RESIZE) { + event.type = EVENT_RESIZE; + } + else{ + event.type = EVENT_KEY; + if (event.key == 27){ + int k = getch(); + if (k == -1){ + // Esc Was pressed + event.type = EVENT_ESC; + } + else { + // Alt was pressed + event.key = k; + event.alt_key = 1; + } + } + } + // Draw new world + event.time_ms = clock(); + r = world_event(&event,game); + refresh(); + event.time_ms = clock(); + // set new timeout + int nt = next_timeout - event.time_ms; + //printf("%d\n",nt); + if (nt > 0){ + timeout(nt); + } + else { + timeout(TIMEOUT); + next_timeout = event.time_ms + TIMEOUT; + } + } + memset(&event,0,sizeof(struct event)); + event.height = LINES; + event.width = COLS; + event.type = EVENT_END; + event.time_ms = clock(); + world_event(&event,game); + if (destroy_game != NULL){ + destroy_game(game); + } + endwin(); + return r; +}; diff --git a/a2/world.h b/a2/world.h new file mode 100644 index 0000000..e7a3fdb --- /dev/null +++ b/a2/world.h @@ -0,0 +1,122 @@ +#ifndef _WORLD_H_ +#define _WORLD_H_ + +#include + +/** + * World represented as a rectangular matrix of colorful characters. + * + * Point [0,0] is displayed the upper left corner of the screen. + * + */ + +enum event_type { + EVENT_START, + EVENT_TIMEOUT, + EVENT_KEY, + EVENT_MOUSE, + EVENT_RESIZE, + EVENT_ESC, + EVENT_END, +}; + +struct event { + /** + * Last width of the screen. + */ + int width; + /** + * Last height of the screen. + */ + int height; + /** + * Last pressed key or Curses event. + * + * Special event values: + * ERR if timeout, + * KEY_RESIZE if screen resize + * KEY_EVENT, other event, + * KEY_MOUSE, mouse clicked + * + * Key values: + * + * ' ' Space + * KEY_DOWN Arrow down + * KEY_UP Arrow up + * KEY_LEFT Arrow left + * KEY_RIGHT Arrow right + * KEY_A1 Upper left of keypad + * KEY_A3 Upper right of keypad + * KEY_B2 Center of keypad + * KEY_C1 Lower left of keypad + * KEY_C3 Lower right of keypad + * + * KEY_ENTER + * KEY_BACKSPACE + */ + int key; + int alt_key; + enum event_type type; + int mouse_x; + int mouse_y; + int mouse_left; + int mouse_right; + int mouse_middle; + long int time_ms; +}; + +/** + * Sets cell to a state. + * @param event + * @param x coordinate of cell + * @param y coordinate of cell + * @param new state of the cell + */ +void set_cell(int character,int x,int y); + +/** + * COLOR_BLACK 0 + * COLOR_RED 1 + * COLOR_GREEN 2 + * COLOR_YELLOW 3 + * COLOR_BLUE 4 + * COLOR_MAGENTA 5 + * COLOR_CYAN 6 + * COLOR_WHITE 7 + */ + +#define COLOR_COUNT 8 + +void set_color_cell(int character,int x,int y,short front_color,short back_color); + + +/** + * + * @param event + * @param number of commandline arguments + * @param init_world + * @param destroy_world + * + * void init_world(struct event* w); + * Initializes user state. + * Free user state. + * @param event + */ + +int start_world(void* (*init_game)(),int (*world_event)(struct event* event,void* game),void (*destroy_game)(void* game)); +/** + * Set timeout interval in miliseconds + */ +void game_speed(int value); + +/* + * Prints a message in screen on a position x,y + */ + +void set_message(const char* message,int x,int y); +/* + * Clears screen + */ +void clear_screen(); + +#endif diff --git a/a2/world.o b/a2/world.o new file mode 100644 index 0000000000000000000000000000000000000000..921685aee8d53d816e19469b3b0c5082f159ab36 GIT binary patch literal 11420 zcmbVS3w%`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