More to come...
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

61 lines
1.9KB

  1. /*
  2. Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
  3. Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
  4. And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
  5. It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
  6. */
  7. #ifndef CHAPTER_5_SOURCE
  8. #define CHAPTER_5_SOURCE
  9. #include "chapter_5.h"
  10. /*
  11. static void (* game_action [GAME_ACTION_COUNT]) (game_t * game, player_t * player);
  12. */
  13. static number_t game_is_active (game_t * game) { return (game->active = curses_active); }
  14. /*
  15. So, what are actually getters and setters, and why you should never use them? Lets explain.
  16. @C
  17. static number_t game_get_screen_width (game_t * game) { return (game->screen_width); }
  18. static number_t game_get_screen_height (game_t * game) { return (game->screen_height); }
  19. static number_t game_set_screen_width (game_t * game, number_t width) { return (game->screen_width = width); }
  20. static number_t game_set_screen_height (game_t * game, number_t height) { return (game->screen_height = height); }
  21. @
  22. */
  23. static void game_configure (game_t * game, player_t * player) {
  24. curses_configure ();
  25. game->active = curses_active;
  26. game->screen_width = curses_screen_width;
  27. game->screen_height = curses_screen_height;
  28. player->x = 0;
  29. player->y = 0;
  30. }
  31. static void game_synchronize (game_t * game, player_t * player) {
  32. (void) game;
  33. curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL);
  34. curses_render_character ('@', COLOUR_CYAN, EFFECT_BOLD, player->x, player->y);
  35. curses_synchronize ();
  36. }
  37. void play_game (void) {
  38. game_t game;
  39. player_t player;
  40. game_configure (& game, & player);
  41. while (game_is_active (& game)) {
  42. game_synchronize (& game, & player);
  43. }
  44. }
  45. #endif