{"id":25282314,"url":"https://github.com/andrewhsugithub/2d-open-world-game","last_synced_at":"2025-04-06T13:19:19.293Z","repository":{"id":129725669,"uuid":"589584531","full_name":"andrewhsugithub/2d-Open-World-Game","owner":"andrewhsugithub","description":"a 2d open world game for you to explore!!!","archived":false,"fork":false,"pushed_at":"2023-01-18T12:35:31.000Z","size":421,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-12T19:40:02.350Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrewhsugithub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-16T13:17:08.000Z","updated_at":"2024-10-25T18:36:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"2a85ef8f-97b2-4cef-bc38-a49d6753fef4","html_url":"https://github.com/andrewhsugithub/2d-Open-World-Game","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewhsugithub%2F2d-Open-World-Game","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewhsugithub%2F2d-Open-World-Game/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewhsugithub%2F2d-Open-World-Game/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewhsugithub%2F2d-Open-World-Game/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewhsugithub","download_url":"https://codeload.github.com/andrewhsugithub/2d-Open-World-Game/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247485294,"owners_count":20946399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-12T19:34:07.395Z","updated_at":"2025-04-06T13:19:19.280Z","avatar_url":"https://github.com/andrewhsugithub.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\n\n# 2d Fighting!!\nIt's a open-world-adventure game in 2d !\n\n![village_perspective](village_perspective.JPG)\n\nHello welcome to my game, you are the selected hero from your village to defend your village from monsters.\n\n\n\n\n# Table of Contents\n\n- [My Game Introduction](#2d-fighting!!)\n- [Table of Contents](#table-of-contents)\n- [Intro](#intro)\n- [Prerequisites](#prerequisites)\n  - [If your strength / hunger / coins = 0](#if-your-strength--hunger--coins--0)\n- [How to play / Rules](#how-to-play--rules)\n  - [Summary of the game](#summary-of-the-game)\n- [Basic Interfaces](#basic-interfaces)\n  - [Basic](#basic)\n  - [Movement Interface](#movement-interface)\n  - [After movement Interface](#after-movement-interface)\n  - [Village Interface](#village-interface)\n  - [Dealer's Shop Interface](#dealers-shop-interface)\n  - [Inventory Interface](#inventory-interface)\n- [Setup](#setup)\n  - [Intro](#intro-1)\n  - [Item setup](#item-setup)\n- [Items in the game](#items-in-the-game)\n  - [Player](#player)\n    - [Inventory (How to use)](#inventory-how-to-use)\n  - [Your Village](#your-village)\n    - [What can you do inside the village](#what-can-you-do-inside-the-village)\n  - [Dealer Shop](#dealer-shop)\n    - [Things in the Dealer Shop](#things-in-the-dealer-shop)\n      - [Potion of Swiftness](#potion-of-swiftness)\n      - [Totem of Undying](#totem-of-undying)\n      - [Golden Apple](#golden-apple)\n      - [Potion of Good Vision](#potion-of-good-vision)\n    - [How to use the items](#how-to-use-the-items)\n  - [Monster](#monster)\n  - [Food](#food)\n  - [Guns / Shields / Traps](#guns--shields--traps)\n  - [Fast Travel Stations](#fast-travel-stations)\n  - [Health Stations](#health-stations)\n- [Functions and Variables](#functions-and-variables)\n  - [Variables](#variables)\n    - [Monster stats](#monster-stats)\n    - [Player Stats](#player-stats)\n    - [Inventory](#inventory)\n    - [Village Stats](#village-stats)\n  - [Create Map](#create-map)\n  - [Decide to travel or not](#decide-to-travel-or-not)\n  - [Check for availability and boundaries](#check-for-availability-and-boundaries)\n  - [Human typed setup](#human-typed-setup)\n  - [Computer setup](#computer-setup)\n  - [Encounters](#encounters)\n  - [Check blood / strength / hunger / if survive new day](#check-blood--strength--hunger--if-survive-new-day)\n  - [Player Movement](#player-movement)\n  - [Print out map / important stats](#print-out-map--important-stats)\n- [Version](#version)\n\n# Intro\n\nYou are the selected hero from your village to defend your village from monsters around it. You always dreamed to be the hero of the village since young. Now it's time for you to shine. Prepare for all kinds of adventures, monsters, traps, you will encounter. All that you know is that this is hard, but you know that *`with great power comes great responsibility`*. So you must go on and defend your village. Be the hero. Wish you good luck!\n\n(*Note: you must go before the dark as nearby monsters attack your village at night.*)\n\n\n# Prerequisites\n\nYou are given *`at most a 5*5 map`* since your village don't have a lot of paper to make you a map.\n\nFor Example: \n\n![village_perspective](village_perspective.JPG)\n\n1. Your default stats (Player)\n+ Blood: 10\n+ Strength: 2\n+ Hunger: 20\n+ Coins: 10 \n+ Level: 1\n\n2. Your village's default stats\n+ Blood: 50\n+ Strength: 0 \n+ Level: 1\n\n## If your strength / hunger / coins = 0\nIf you don't have enough hunger or strength the next time you lose either of them you will lose blood. But if you don't have enough coins (coins = 0), your coins will just be 0 if you lose them next time.\n\n# How to play / Rules\n\nYou start from day 1 of defending the village.\nWhen you `move 1 spot`, it takes a hour and your `hunger will be deducted 1`. So, in **`a day`**, you can only take `24 steps` (unless you have [potion of swiftness](#potion-of-swiftness) ) before it gets dark.\nWhen it's `night` time, your `village` will be `attacked by nearby monsters` (if you can see them from the map in the village's perpective means is nearby) \n\u003eFor Example: \n![village_perspective](village_perspective.JPG)\n\n\u003e\u003evillage's perspective means the village is in the middle of the map\n\n*each nearby `monster` will have `10 damage times days you survived` to the village*. Once the *`night is over`* and you and your village are both ***`still alive`*** everything will *reallocate* to their new places *except you and your village*. This will *`start a whole new day`* of defending your village with new and more unexpected things to come. Your `default blood` will be `added to 20`. Your `village` will become stronger with `50 more blood`.\n***`But`*** if the `village falls down` or 'you died' during the day, you fail your mission, and the ***`game is over`***.\n\nFor example (after the night stats):\n1. Your day 2 stats (best condition) (Player)\n+ Blood: 20\n+ Strength: 2\n+ Hunger: 20\n+ Coins: 10 \n+ Level: 2\n\n2. Your village's day 2 (best condition) stats\n+ Blood: 100\n+ Strength: 0 \n+ Level: 2\n\n## Summary of the game\nYou and your village can't fall down.\n\n# Basic Interfaces\n## Basic\nThere are two main kinds of spot in the game. One is '.' and others.\n| Spots in map | Status |\n| ------ | ----------- |\n| '.'(dot) / 'p' | normal |\n| 'm' / 's' / 'f' / 'c' / 'h'...(even hidden ones) | special |\n\nWhenever you see a map, *`you are in the dead center of the map`*. If you don't see 'p' doesn't mean you are not on the map, it's just that you are standing on a special spot.\n## Movement Interface\nAsk which direction to go or you want to [use inventory](#inventory-how-to-use) or see map or quit game.\n\n![movement_interface](movement_interface.JPG)\n## After movement Interface\nEach time after you move you will be given all kinds of information.\n1. Village's stats\n2. Your stats\n3. What is in your inventory\n4. Effects on you\n5. Map\n6. Coordinate (Yours and Village's)\n7. Time of the day\n8. Small reminder\n   \n![interface](interface.JPG)\n## Village Interface\nAsk what you want to do in the [village](#what-can-you-do-inside-the-village)\n\n![village_interface](village_interface.JPG)\n## Dealer's Shop Interface\nAsk what you want to do in the [dealer's_shop](#dealer-shop)\n\n![dealer's_interface](dealer_interface.JPG)\n\n## Inventory Interface\nsee [inventory_interface](#inventory-how-to-use)\n# Setup\n## Intro\nThe game will first welcome adventurer and give you your stats. And then it will ask you to input the rows and columns of the map (suggestion: square and 50*50 or up) and then it will ask you to input the coordinates of the village. Then, you can choose to create a new map or start playing. You always `start from the village`.\n\n![setup](setup.JPG)\n## Item setup\n| Items | How Many |\n| ------ | ----------- |\n| [Player](#player)  | one |\n| [Village](#your-village) | one |\n| [Dealer](#dealer-shop)  | map size * 1/12 |\n| [Monster](#monster)  | map size * 1/8 |\n| [Food](#food)  | map size * 1/8 |\n| [Guns](#guns--shields--traps)  | map size * 1/24 |\n| [Shield](#guns--shields--traps)  | map size * 1/24 |\n| [Traps](#guns--shields--traps)  | map size * 1/24 |\n| [Fast Travel Stations](#fast-travel-stations)  | map size * 1/48 |\n| [Health Stations](#health-stations)  | map size * 1/48 |\nFor example: a 50*50 map \n![item_setup](item_setup.JPG)\n* The location of the items are randomly generated except for the village.\n\n# Items in the game\n## Player\nIs you\n\nIs `'p'` on the map\n\nsee [stats](#prerequisites)\n\n### Inventory (How to use)\nBefore you move, you can always use your inventory. You just need to type '0' and you can use it.\n\n![use_inventory](use_inventory.JPG)\n\n## Your Village\nIs `'v'` on the map\n\nsee [stats](#prerequisites)\n### What can you do inside the village\n1. Buy a magical sword\n   \n   Each sword is *3 coins* and will give you *1 strength*. You can only *buy once per visit*.\n2. Go to the bar\n\n    You can drink beer in the bar which will give you *+1 blood*. Each beer is worth *2 coins* and you can drink till you are back to health.\n3. Eat a meal\n   \n   Each meal is worth *5 coins* and will give you *+5 hunger*. You can eat till you're full.\n4. Sell things \n\n    You can sell things from your inventory but each thing is only `sold for 5 coins`.\n\n## Dealer Shop\nIs `'d'` on the map\n\nThe dealer shop is like a black market. It can highly improve your game. It sells unique things that you can't normally buy in your village. But because of this you can only buy stuff from this dealer shop once. Once you leave the shop you can only visit other shops in other locations, the shop you visited will `disappear` to avoid being arrested by the cops (there are actually no cops in this game, it is just to tell you that it is like a black market, and it will not be in the same location after you leave).\n\n### Things in the Dealer Shop\n\n#### Potion of Swiftness\nMakes you go faster, you can walk two steps at a time with only `-1 hunger`. *Effect lasts till the day ends*. Costs `25 coins`.\n#### Totem of Undying\nYou won't die if you have this. It will give you `+5 blood` when in need.\nCosts `50 coins`.\n#### Golden Apple\nWhen you eat it, it will give you `+5 blood and +5 hunger`.\nCosts `55 coins`.\n#### Potion of Good Vision\nYou can see `11 * 11 map` everytime you see the map. *Effect lasts till the end of the day*.\nCosts `30 coins`.\n\n### How to use the items\nYou have to go in your inventory (see [how to use inventory ](#inventory-how-to-use)) and use it then the item will be in effect.\nFor example, you want to use the totem of undying, go in your inventory and use it then it will be in effect otherwise no.\n* You can buy a lot of them but only use 1 of them (only 1 can be in effect)\n## Monster\nIs `'m'` on the map\n\nThere are four levels of monsters. When you `encounter` a monster, the `levels` of the monsters are `randomly generated`. You then can *choose to fight or not to fight*. If you choose to `fight` your `hunger` will first be `deducted by the monster's strength`, as you will need tired and hungry after the fight.\n\n| Monsters | Stats (Day 1) (Default) |\n| ------ | ----------- |\n| Lv. 1  | Blood: 1 Strength: 1 Coins:  5 |\n| Lv. 2  | Blood: 2 Strength: 2 Coins: 10 |\n| Lv. 3  | Blood: 3 Strength: 3 Coins: 15 |\n| Lv. 4  | Blood: 4 Strength: 4 Coins: 20 |\n* Monster's Stats  =  Default Stats * (Days you survived) . For example, on day 2, a lv.2 monster will have 4 blood, 4 strength, and 20 coins. \n* When you encounter a monster, each `monster's evasion rate` will be `randomly generated`, and when a monster `successfully` evaded your attack, it will `attack back` (will lose blood). If it `didn't evade`, it means you attacked successfully if your `attack is greater than their blood`. You will `get` the `coins` and your `strength` will be `added 1`, but if your attack is `lesser` than their blood, it means you `lost`, and `you` will be `attacked` (will lose blood). The monster won't go anywhere if you lose, so you can always come back again(may be different level). But the monster will disappear if you win, because you just killed it.\n  \n## Food\nIs `'c'` on the map, as it stands for chicken or cow\n\nWhen you encounter a \"food\", you can eat it, and your hunger will be `added 2`. If you are already full, then the game will say you are full and you don't need to eat it (to save animals). But the animal will go nowhere so you can come back anytime. But if you are almost full (if +2 hunger will be greater than 20 hunger) then you will only be added to 20 hunger.\n\n## Guns / Shields / Traps\nThey are all over the map, but hided from you( can't see from map ) . Each '.' may be a gun, shield, or a trap, so walk with caution.\nAfter you stepped on it, it will disappear (not in the same location).\n| Hidden Items | Description |\n| ------ | ----------- |\n| Guns  | Will give you strength. ( strength +1 ) |\n| Shield  | Will give you protection ( blood+1 ). |\n| Trap 1  | Will lose 1 blood and 1 strength|\n| Trap 2 | Will lose coins |\n* The amount of coins you lose is somewhere between 0 to half your amount (random). So don't be worried.\n* If you don't have any strength (strength = 0) then the next time you lose strength you will lose blood. see [if your strength/hunger/coins = 0](#if-your-strength--hunger--coins--0) for more info\n  \n## Fast Travel Stations\nIs `'f'` on the map\nThey can help you `travel back to the village` right away if you want.\n\n## Health Stations\nIs `'h'` on the map\nIt will give you `+1 blood`. But if you are already healthy, you don't need it.\n\n# Functions and Variables\n## Variables\n### Monster stats\n``` c\ntypedef struct\n{\n    int blood;\n    int strength;\n    int coins;\n    int level;\n    int evasionRate;\n} info; \n//for monster\n``` \n### Player Stats\n``` c\ntypedef struct\n{\n    int default_blood;\n    int blood;\n    int strength;\n    double hunger;\n    int coins;\n    int level;\n    int rp;           // player row coordinate\n    int cp;           // player column coordinate\n    int rv;           // village row coordinate\n    int cv;           // village column coordinate\n    int boot;         // for calculating time of the day\n    int day;          // what day it is\n    inventory things; // like backpack\n    inventory effect; // what effects are on me\n} adventurer;\n// for hero\n``` \n### Inventory\n```c\ntypedef struct\n{\n    int potion_of_swiftness;\n    int totem_of_undying;\n    int golden_apple;\n    int potion_of_good_vision;\n} inventory;\n//inventory\n```\n### Village Stats\n```c\ntypedef struct\n{\n    int blood;\n    int strength;\n    int level;\n} village;\n// for village\n```\n## Create Map\n``` c\nchar **create_map(int *row, int *col)\n{\n    //ask for row and col\n    printf(\"Input the number of row and column for the map (suggestion square and 50*50 or up):\\n\");\n    scanf(\"%d %d\", row, col);\n\n    //malloc\n    char **arr = (char **)malloc(*row * sizeof(char *));\n    for (int i = 0; i \u003c *row; i++)\n        arr[i] = (char *)malloc(*col * sizeof(char));\n\n    //set all to '.'\n    for (int i = 0; i \u003c *row; i++)\n        for (int j = 0; j \u003c *col; j++)\n            arr[i][j] = '.';\n    return arr;\n}\n```\n## Decide to travel or not\n```c\nint travel_decide()\n{\n    int decide; // decide to create a new map or travel\n    printf(\"[0] Create a new map [1] Start travel the map:\");\n    scanf(\"%d\", \u0026decide);\n    return decide;\n}\n```\n## Check for availability and boundaries\n  1. Human input check\n     * Check boundary\n       ```c\n       int check_boundary(int *row, int *col, int r, int c) // row temp and col temp to see if input is in the correct range\n       {\n           if (r \u003e= *row || r \u003c 0 || c \u003e= *col || c \u003c 0)\n           {\n               printf(\"the location is  outside the map\\n\");\n               return 1; // true\n           }\n           else\n               return 0; // false\n       }\n       ```\n      * Check availability\n          ```c\n          int check_availability(char **map, int *row, int *col, int r, int c)\n          {\n              if (map[r][c] !='.') // check if occupied\n              {\n                  printf(\"the location is occupied\\n\");\n                  return 1; // true\n              }\n              else\n                  return 0; // false\n          }\n          ```\n  2. Computer input\n   \n   only need to check availability cause computer won't input a row or column out of range (I coded it)\n   * Check availability\n        ```c\n        int comp_check_availability(char **map, int *row, int *col, int r, int c)\n        {\n            if (map[r][c] != '.') // check if occupied\n                return 1;         // true\n            else\n                return 0; // false\n        }\n        ```\n## Human typed setup\n  1. setup village coordinates\n     ```c\n     void setup_village(char **map, int *row, int *col, adventurer *hero) // input village coordinates\n      {\n          printf(\"Input the row and column for the village location:\\n\");\n          scanf(\"%d %d\", \u0026hero-\u003erv, \u0026hero-\u003ecv);\n          if (check_boundary(row, col, hero-\u003erv, hero-\u003ecv))//check if out of range\n              setup_village(map, row, col, hero);//if yes then call the function again\n          map[hero-\u003erv][hero-\u003ecv] = 'v';//otherwise set coordinate to 'v'\n      }\n      ```\n  2. setup player coordinates\n    ```c\n    hero.rp = hero.rv; // player row = village row\n    hero.cp = hero.cv; // player column = village column\n    ```\n## Computer setup\n  1. setup [dealer](#dealer-shop)\n      ```c\n      void setup_dealer(char **map, int *row, int *col)\n      {\n          int dealers_num = (*row) * (*col) * 1 / 12; // setup how many\n          printf(\"There are %d dealers in total.\\n The location of the dealers are randomly generated.\\n\", dealers_num);\n          for (int i = 0; i \u003c dealers_num;)\n          {\n              int rowd, cold;                                         // dealer row and dealer column\n              rowd = rand() % (*row);                                 // random generate row\n              cold = rand() % (*col);                                 // random generate column\n              if (comp_check_availability(map, row, col, rowd, cold)) // check if available, if not random again\n                  continue;\n              i++;                   // put here so if continue 'i' will not plus 1\n              map[rowd][cold] = 'd'; // set coordinates to dealer\n          }\n      }\n      ```\n  2. setup [monster](#monster)\n      ```c\n      void setup_monster(char **map, int *row, int *col) // input monster coordinates\n      {\n          int monster_num = (*row) * (*col) * 1 / 8; // how many monsters\n          printf(\"There are %d monsters in total.\\n The location of the monsters are randomly generated.\\n\", monster_num);\n          for (int i = 0; i \u003c monster_num;) // check input and coordinates for monster(s)\n          {\n              int rowm, colm;                                         // monster row and monster column\n              rowm = rand() % (*row);                                 // random generate row\n              colm = rand() % (*col);                                 // random generate column\n              if (comp_check_availability(map, row, col, rowm, colm)) // check if available, if not random again\n                  continue;\n              i++;                   // put here so if continue 'i' will not plus 1\n              map[rowm][colm] = 'm'; // set coordinates to monster\n          }\n      }\n      ```\n  3. setup [food](#food)\n      ```c\n      void setup_food(char **map, int *row, int *col) // input cow coordinates\n      {\n          int food_num = (*row) * (*col) * 1 / 8; // how many chicken/cow\n          printf(\"There are %d cows/food in total.\\n The location of the cows are randomly generated.\\n\", food_num);\n          for (int i = 0; i \u003c food_num;)\n          {\n              int rowf, colf;                                         // food row and food column\n              rowf = rand() % (*row);                                 // random generate row\n              colf = rand() % (*col);                                 // random generate column\n              if (comp_check_availability(map, row, col, rowf, colf)) // check if available, if not random again\n                  continue;\n              i++;                   // put here so if continue 'i' will not plus 1\n              map[rowf][colf] = 'c'; // set coordinates to food\n          }\n      }\n      ```\n  4. setup [gun](#guns--shields--traps)\n      ```c\n      void setup_gun(char **map, int *row, int *col)\n      {\n          int gun_num = (*row) * (*col) / 24; // how many guns\n          printf(\"There are %d guns in total.\\n The location of the guns are randomly generated.\\n\", gun_num);\n          for (int i = 0; i \u003c gun_num;)\n          {\n              int rowg, colg;                                         // gun row and gun col\n              rowg = rand() % (*row);                                 // random genrate row;\n              colg = rand() % (*col);                                 // random genrate col\n              if (comp_check_availability(map, row, col, rowg, colg)) // check if available, if not random again\n                  continue;\n              i++;                   // put here so if continue 'i' will not plus 1\n              map[rowg][colg] = 'g'; // set coordinates to guns for computer but map will not show(hidden)\n          }\n      }\n      ```\n  5. setup [shield](#guns--shields--traps)\n      ```c\n      void setup_shield(char **map, int *row, int *col)\n      {\n          int shield_num = (*row) * (*col) / 24; // how many shields\n          printf(\"There are %d shields in total.\\n The location of the shields are randomly generated.\\n\", shield_num);\n          for (int i = 0; i \u003c shield_num;)\n          {\n              int rows, cols;                                         // shield row and shield col\n              rows = rand() % (*row);                                 // random genrate row;\n              cols = rand() % (*col);                                 // random genrate col\n              if (comp_check_availability(map, row, col, rows, cols)) // check if available, if not random again\n                  continue;\n              i++;                   // put here so if continue 'i' will not plus 1\n              map[rows][cols] = 's'; // set coordinates to shields for computer but map will not show(hidden)\n          }\n      }\n      ```\n  6. setup [traps](#guns--shields--traps)\n      ```c\n      void setup_trap(char **map, int *row, int *col)\n      {\n          int trap_num = (*row) * (*col) / 24; // how many traps\n          printf(\"There are %d traps in total.\\n The location of the traps are randomly generated.\\n\", trap_num);\n          for (int i = 0; i \u003c trap_num;)\n          {\n              int rowt, colt;                                         // trap row and trap col\n              rowt = rand() % (*row);                                 // random genrate row;\n              colt = rand() % (*col);                                 // random genrate col\n              if (comp_check_availability(map, row, col, rowt, colt)) // check if available, if not random again\n                  continue;\n              i++;                   // put here so if continue 'i' will not plus 1\n              map[rowt][colt] = 't'; // set coordinates to traps for computer but map will not show(hidden)\n          }\n      }\n      ```\n  7. setup [fast travel stations](#fast-travel-stations)\n      ```c\n      void setup_fast_travel(char **map, int *row, int *col)\n      {\n          int fast_travel_num = (*row) * (*col) * 1 / 48; // how many fast travel stations\n          printf(\"There are %d fast travel stations in total.\\n The location of the stations are randomly generated.\\n\", fast_travel_num);\n          for (int i = 0; i \u003c fast_travel_num;)\n          {\n              int rowf, colf;                                         // fast travel row and fast travel col\n              rowf = rand() % (*row);                                 // random genrate row;\n              colf = rand() % (*col);                                 // random genrate col\n              if (comp_check_availability(map, row, col, rowf, colf)) // check if available, if not random again\n                  continue;\n              i++;                   // put here so if continue 'i' will not plus 1\n              map[rowf][colf] = 'f'; // set coordinates to fast travel stations\n          }\n      }\n      ```\n  8. setup [health stations](#health-stations)\n    ```c\n    void setup_clinic(char **map, int *row, int *col)\n    {\n        int clinic_num = (*row) * (*col) * 1 / 48; // how many health stations\n        printf(\"There are %d health stations in total.\\n The location of the stations are randomly generated.\\n\", clinic_num);\n        for (int i = 0; i \u003c clinic_num;)\n        {\n            int rowh, colh;                                         // health row and health col\n            rowh = rand() % (*row);                                 // random genrate row;\n            colh = rand() % (*col);                                 // random genrate col\n            if (comp_check_availability(map, row, col, rowh, colh)) // check if available, if not random again\n                continue;\n            i++;                   // put here so if continue 'i' will not plus 1\n            map[rowh][colh] = 'h'; // set coordinates to health stations\n        }\n    }\n    ```\n## Encounters\n  1. Encounter [village](#your-village)\n      * buy sword \n      see [what can you do inside the village](#what-can-you-do-inside-the-village) for more info\n          ```c\n          if (count_sword \u003e= 1) // already bought once during this visit\n          {\n              printf(\"You already brought a sword.\\n\");\n              break;\n          }\n          else\n          {\n              printf(\"The magical sword is %d coins\\n\", sword.coins); // show how much sword is\n              printf(\"Do you want to buy it? [0]No [1]Yes:\\n\");\n              int decide; // decide to buy or not\n              scanf(\"%d\", \u0026decide);\n              if (!decide) // decide no\n                  break;\n              if (!check_coins(hero, sword.coins)) // otherwise if yes then check if you have enough money to buy\n                  break;\n              hero-\u003ecoins -= sword.coins;                                                                  // if yes then buy\n              (hero-\u003estrength)++;                                                                          // strength+1\n              printf(\"Nice sword! Now you have %d strength and %d coins!\\n\", hero-\u003estrength, hero-\u003ecoins); // compliment\n              count_sword++;                                                                               // bought sword 1 time\n              break;\n          }\n          ```\n      * go to the bar  \n      see [what can you do inside the village](#what-can-you-do-inside-the-village) for more info\n          ```c\n          if ((hero-\u003eblood) \u003e= hero-\u003edefault_blood) // check if blood is full\n          {\n              printf(\"Your blood is full. You don't need a beer.\\n\");\n              break;\n          }\n          else\n          {\n              printf(\"The magical beer is %d coins\\n\", beer.coins); // show how much one beer is\n              printf(\"Do you want to buy it? [0]No [1]Yes:\\n\");\n              int decide; // decide to buy or not\n              scanf(\"%d\", \u0026decide);\n              if (!decide) // decide no\n                  break;\n              if (!check_coins(hero, beer.coins)) // check if enough money to buy\n                  break;\n              hero-\u003ecoins -= beer.coins;\n              (hero-\u003eblood)++;                                                                      // blood +1\n              printf(\"Nice beer! Now you have %d blood and %d coins!\\n\", hero-\u003eblood, hero-\u003ecoins); // compiment\n              break;\n          }\n          ```\n      * eat meal\n      see [what can you do inside the village](#what-can-you-do-inside-the-village) for more info\n          ```c\n          if ((hero-\u003ehunger) \u003e= 20) // check if full\n          {\n              printf(\"You are full. You don't need a meal.\\n\");\n              break;\n          }\n          else\n          {\n              int meal_coins = 5;                                    // one meal cost 5 coins\n              printf(\"The magical feast is %d coins\\n\", meal_coins); // show how much\n              printf(\"Do you want to buy it? [0]No [1]Yes:\\n\");\n              int decide; // decide to buy or not\n              scanf(\"%d\", \u0026decide);\n              if (!decide) // decide no\n                  break;\n              if (!check_coins(hero, meal_coins)) // check if enough coins to buy\n                  break;\n              hero-\u003ecoins -= meal_coins;\n              (hero-\u003ehunger) += 10;   // hunger +10\n              if (hero-\u003ehunger \u003e 20) // add to full\n                  hero-\u003ehunger = 20;\n              printf(\"Nice meal! Now you have %lf hunger and %d coins!\\n\", hero-\u003ehunger, hero-\u003ecoins); // compiment\n              break;\n          }\n          ```\n      * sell \n      see [what can you do inside the village](#what-can-you-do-inside-the-village) for more info\n          ```c\n          while (1)\n          {\n              printf(\"What do you want to sell?(1:sell potion of swiftness; 2: sell totem of undying; 3:sell golden apple; 4.sell potion of good vision; 5:leave)\\n(Note: each item is sold for 5 coins no matter what)\\n\"); // ask what to sell\n              int decide;\n              scanf(\"%d\", \u0026decide);\n              switch (decide)\n              {\n              case 1:                                        // sell potion of swiftness\n                  if (hero-\u003ethings.potion_of_swiftness == 0) // check if you have it\n                  {\n                      printf(\"You don't have it, stop scamming your village.\\n\");\n                      break;\n                  }\n                  hero-\u003ethings.potion_of_swiftness--;           // sold\n                  hero-\u003ecoins += 10;                            // add 10 coins\n                  printf(\"Now you have %d coins\", hero-\u003ecoins); // show how many coins left\n                  break;\n              case 2:                                     // sell totem of undying\n                  if (hero-\u003ethings.totem_of_undying == 0) // check if you have it\n                  {\n                      printf(\"You don't have it, stop scamming your village.\\n\");\n                      break;\n                  }\n                  hero-\u003ethings.totem_of_undying--;              // sold\n                  hero-\u003ecoins += 10;                            // add 10 coins\n                  printf(\"Now you have %d coins\", hero-\u003ecoins); // show how many coins left\n                  break;\n              case 3:                                 // sell golden apple\n                  if (hero-\u003ethings.golden_apple == 0) // check if you have it\n                  {\n                      printf(\"You don't have it, stop scamming your village.\\n\");\n                      break;\n                  }\n                  hero-\u003ethings.golden_apple--;                  // sold\n                  hero-\u003ecoins += 10;                            // add 10 coins\n                  printf(\"Now you have %d coins\", hero-\u003ecoins); // show how many coins left\n                  break;\n              case 4:                                          // sell potion of good vision\n                  if (hero-\u003ethings.potion_of_good_vision == 0) // check if you have it\n                  {\n                      printf(\"You don't have it, stop scamming your village.\\n\");\n                      break;\n                  }\n                  hero-\u003ethings.potion_of_good_vision--;         // sold\n                  hero-\u003ecoins += 10;                            // add 10 coins\n                  printf(\"Now you have %d coins\", hero-\u003ecoins); // show how many coins left\n                  break;\n              case 5:\n                  printf(\"Thanks for selling\\n\"); // say bye bye\n                  break;\n              default: // invalid action\n                  printf(\"Invalid action!\\n\");\n                  break;\n          }\n          ```\n      * leave\n      ```c\n      case 5: // leave\n          printf(\"You are welcome to come back anytime!\\n\");\n          return;\n      default: // invalid action\n          printf(\"Invalid action! 1:buy a magical sword; 2: go to the bar; 3.eat meal; 4:sale; 5.leave the village\\n\");\n          break;\n      ```\n  2. Encounter [dealer](#dealer-shop)\n      ```c\n      void encounter_dealer(adventurer *hero)\n      {\n          // count the times you buy something\n          int count_one = 0;\n          int count_two = 0;\n          int count_three = 0;\n          int count_four = 0;\n          printf(\"Hello welcome to my shop. Hurry up before the cops catch me! I only sell the most unique things.\\n\"); // welcome\n          while (1)\n          {\n              printf(\"What do you want to do (1:buy potion of swiftness; 2: buy totem of undying; 3:buy golden apple; 4.buy potion of good vision; 5.leave)\\n\"); // ask what to buy\n\n              // how much\n              int potion_of_swiftness = 25;\n              int totem_of_undying = 55;\n              int golden_apple = 50;\n              int potion_of_good_vision = 30;\n\n              // decide\n              int dowhat;\n              scanf(\"%d\", \u0026dowhat);\n              switch (dowhat)\n              {\n                  case 1:                 // buy potion of swiftness\n                      if (count_one \u003e= 1) // check if you already bought once during the visit\n                      {\n                          printf(\"You already brought it.\\n\");\n                          break;\n                      }\n                      else\n                      {\n                          printf(\"The potion of swiftness is %d coins\\n(last for 1 day)\", potion_of_swiftness); // description\n                          printf(\"Do you want to buy it? [0]No [1]Yes:\\n\");\n                          int decide; // decide to buy or not\n                          scanf(\"%d\", \u0026decide);\n                          if (!decide) // decide no\n                              break;\n                          if (!check_coins(hero, potion_of_swiftness)) // check if you have enough money\n                              break;\n                          hero-\u003ecoins -= potion_of_swiftness; // sold\n                          hero-\u003ethings.potion_of_swiftness++;\n                          printf(\"Nice! Now you can 2 times speed, but only cost 1 hunger.\\n\"); // description\n                          count_one++;                                                          // count++\n                          break;\n                      }\n                  case 2:\n                      if (count_two \u003e= 1) // check if you already bought once during the visit\n                      {\n                          printf(\"You already brought it.\\n\");\n                          break;\n                      }\n                      else\n                      {\n                          printf(\"The totem of undying is %d coins(Note: can only use one time, after buying it you have to hold/use it to have the effect)\\n\", totem_of_undying); // description\n                          printf(\"Do you want to buy it? [0]No [1]Yes:\\n\");\n                          int decide; // decide to buy or not\n                          scanf(\"%d\", \u0026decide);\n                          if (!decide) // decide no\n                              break;\n                          if (!check_coins(hero, totem_of_undying)) // check if you have enough money\n                              break;\n                          hero-\u003ecoins -= totem_of_undying; // sold\n                          hero-\u003ethings.totem_of_undying++;\n                          printf(\"Nice! Now if you are strike to death, you will have 5 more blood.\\n\"); // description\n                          count_two++;                                                                   // count++\n                          break;\n                      }\n                  case 3:\n                      if (count_three \u003e= 1) // check if you already bought once during the visit\n                      {\n                          printf(\"You already brought it.\\n\");\n                          break;\n                      }\n                      else\n                      {\n                          printf(\"The golden apple is %d coins(Note: can only use one time)\\n\", golden_apple); // description\n                          printf(\"Do you want to buy it? [0]No [1]Yes:\\n\");\n                          int decide; // decide to buy or not\n                          scanf(\"%d\", \u0026decide);\n                          if (!decide) // decide no\n                              break;\n                          if (!check_coins(hero, golden_apple)) // check if you have enough money\n                              break;\n                          hero-\u003ecoins -= golden_apple; // sold\n                          hero-\u003ethings.golden_apple++;\n                          printf(\"Nice! It will give you five more blood when you eat.\\n\"); // description\n                          count_three++;                                                    // count++\n                          break;\n                      }\n                  case 4:\n                      if (count_four \u003e= 1) // check if you already bought once during the visit\n                      {\n                          printf(\"You already brought it.\\n\");\n                          break;\n                      }\n                      else\n                      {\n                          printf(\"The potion of good vision is %d coins(Note: last for two days)\\n\", potion_of_good_vision); // description\n                          printf(\"Do you want to buy it? [0]No [1]Yes:\\n\");\n                          int decide; // decide to buy or not\n                          scanf(\"%d\", \u0026decide);\n                          if (!decide) // decide no\n                              break;\n                          if (!check_coins(hero, potion_of_good_vision)) // check if you have enough money\n                              break;\n                          hero-\u003ecoins -= potion_of_good_vision; // sold\n                          hero-\u003ethings.potion_of_good_vision++;\n                          printf(\"Nice! Now you can see more when you see the map\\n\"); // description\n                          count_four++;                                                // count++\n                          break;\n                      }\n                  case 5: // say farewell\n                      printf(\"For now, bye bye! Hope we meet again soon and hide those things well or you will be chased by the cops!\\n\");\n                      return;\n                  default: // Invalid action\n                      printf(\"Invalid action! 1:buy potion of swiftness; 2: buy totem of undying; 3:buy golden apple; 4.buy potion of good vision; 5.leave\\n\");\n                      break;\n              }\n          }\n      }\n      ```\n  3. Encounter [monster](#monster)\n      ```c\n      char encounter_monster(adventurer *hero)\n      {\n          info monster = {0, 0, 0, 0, 0};                                                                                            // set monster stats\n          monster.level = (rand() % 4 + 1);                                                                                          // random level 1-4\n          monster.blood = monster.strength = (monster.level * hero-\u003eday);                                                            // set monster blood and strength\n          monster.coins = monster.blood * 5;                                                                                         // monster coins\n          printf(\"You are fighting Monster %d!\\n\", monster.strength);                                                                // show what monster you are fighting\n          printf(\"Monster %d has %d blood, %d strength, %d coins\\n\", monster.level, monster.blood, monster.strength, monster.coins); // show monster stats\n          printf(\"do you want to fight [0]No [1]Yes:\\n\");\n          int decide; // decide to fight or not\n          scanf(\"%d\", \u0026decide);\n          if (decide) // decide yes\n          {\n              hero-\u003ehunger -= monster.level; // hunger - monsterlevel\n              if (check_hunger(hero))        // see if hunger = 0,if yes then lose\n                  return 'l';\n              if (check_blood(hero)) // see if blood = 0, if yes then dead\n                  return 'D';\n              switch (battle_result(\u0026monster, hero)) // battle\n              {\n              case 0: // you are dead (blood=0)\n                  return 'D';\n              case 1:                           // you win\n                  hero-\u003ecoins += monster.coins; // you get monster coins\n                  (hero-\u003estrength)++;           // your strength++\n                  return 'w';\n              case 2: // you lose\n                  return 'l';\n              }\n          } // if decide not to fight, set to you lose\n          return 'l';\n      }\n      ```\n      * battle result function\n      ```c\n      int battle_result(info *monster, adventurer *hero)\n      {\n          srand(time(NULL)); // set random's seed\n          do\n          {\n              monster-\u003eevasionRate = rand() % 101;                              // random monster's evasion rate (0-100)\n              printf(\"monster's evasionRate is: %d%%\\n\", monster-\u003eevasionRate); // show monster evasion_rate\n              if (hero-\u003eblood \u003c= 0)                                             // if blood\u003c=0, you dead\n              {\n                  printf(\"You DEAD!\\n\");\n                  return 0;\n              }\n          } while (monster-\u003elevel \u003e 0 \u0026\u0026 evasion(monster, hero)); // if monster keeps evading then the monster can continue its attack\n\n          // monster evade unsuccessfull\n          if (monster-\u003estrength \u003c= hero-\u003estrength) // if your attack(strength) \u003e= monster blood(strength/blood/level all the same for monster) ==\u003e you win\n          {\n              printf(\"You Win!\\n\");\n              return 1;\n          }\n          else // otherwise you lose and monster will attack\n          {\n              printf(\"You Lose!\\n\");\n              hero-\u003eblood -= monster-\u003estrength; // monster attack\n              return 2;\n          }\n      }\n      ```\n      * evasion function\n      ```c\n      int evasion(info *monster, adventurer *hero)\n      {\n          int e = rand() % 101;          // randomize to compare with monster evasion rate\n          if (e \u003c= monster-\u003eevasionRate) // if e is smaller than the monster evades successfully\n          {\n              printf(\"monster has evaded\\n\");\n              hero-\u003eblood = hero-\u003eblood - monster-\u003elevel; // monster attack\n              return 1;\n          }\n          return 0; // evasion unsuccessful\n      }\n      ```\n  4. Encounter [food](#food)\n      ```c\n      char encounter_food(adventurer *hero)\n      {\n          if (hero-\u003ehunger \u003e= 20) // check if you are full already\n          {\n              printf(\"You are full. You don't need to eat.\\n\");\n              return 'l';\n          }\n          (hero-\u003ehunger) += 3;\n          if (hero-\u003ehunger \u003e 20) // if add too full then hunger = 20\n              hero-\u003ehunger = 20;\n          printf(\"You have %lf hunger\\n\", hero-\u003ehunger); // show hunger\n          return 'w';\n      }\n      ```\n  5. Encounter [gun](#guns--shields--traps)\n      ```c\n      void encounter_gun(adventurer *hero)\n      {\n          printf(\"Congrats you have found a special gun! You may not find it again!!!\\n\");\n          (hero-\u003estrength)++;                               // get +1 strength\n          printf(\"You have %d strength\\n\", hero-\u003estrength); // show strength\n          return;\n      }\n      ```\n  6. Encounter [shield](#guns--shields--traps)\n      ```c\n      void encounter_shield(adventurer *hero)\n      {\n          if (hero-\u003eblood \u003e= 10) // check if healthy\n          {\n              printf(\"You are healthy. You don't need a shield\\n\");\n              return;\n          }\n\n          (hero-\u003eblood)++;                            // get blood +1\n          printf(\"You have %d blood\\n\", hero-\u003eblood); // show blood\n          return;\n      }\n      ```\n  7. Encounter [trap](#guns--shields--traps)\n      ```c\n      void encounter_trap(adventurer *hero)\n      {\n          int type = rand() % 2; // randomize which kind of trap\n          if (!type)             // trap 1 =\u003e lose blood and strength\n          {\n              printf(\"OH OH!\\n You have stepped on the trap\\n\");\n              // lose blood and strength\n              (hero-\u003eblood)--;\n              hero-\u003estrength--;\n              if (hero-\u003estrength \u003c= 0) // if no more strength, lose blood\n              {\n                  printf(\"You have no strength.\\n\");\n                  hero-\u003estrength = 0;\n                  printf(\"You have %d strength\\n\", hero-\u003estrength);\n                  printf(\"You will lose blood.\\n\");\n                  (hero-\u003eblood)--;\n              }\n              if (hero-\u003eblood \u003c= 0) // if no more blood, you dead\n              {\n                  printf(\"You DEAD!\\n\");\n                  return;\n              }\n              printf(\"You have %d blood\\n\", hero-\u003eblood); // show blood\n          }\n          else // trap 2 =\u003e lose coins\n          {\n              printf(\"OH OH!\\n Someone stole your money\\n\");\n              int stole = rand() % ((hero-\u003ecoins) / 2); // random amount of coins to steal\n              if (!check_coins(hero, 1))                // check if you have coins to steal\n                  hero-\u003ecoins = 0;\n              printf(\"You have %d coins left\\n\", hero-\u003ecoins); // show coins\n          }\n\n          return;\n      }\n      ```\n  8. Encounter [fast travel stations](#fast-travel-stations)\n      ```c\n      char encounter_station(adventurer *hero)\n      {\n          printf(\"You are now in the fast travel station\\n\");                // description\n          printf(\"Do you want to travel back to village? [0]No [1]Yes :\\n\"); // decide\n          int decide;\n          scanf(\"%d\", \u0026decide);\n          if (decide) // decide yes\n          {\n              return 'f';\n          }\n          return 'l'; // decide no\n      }\n      ```\n  9. Encounter [health stations](#health-stations)\n    ```c\n    char encounter_clinic(adventurer *hero)\n    {\n        printf(\"You are now in the health station\\n\"); // description\n        if (hero-\u003eblood \u003e= hero-\u003edefault_blood)        // check if blood is full\n            printf(\"You are already healthy you don't need it\");\n        else               // if no\n            hero-\u003eblood++; // add +1 blood\n        return 'l';\n    }\n    ```\n## Check blood / strength / hunger / if survive new day\n  * Check player blood\n      ```c\n      int check_blood(adventurer *hero)\n      {\n          // check if your blood = 0 and have totem of undying or not\n          if (hero-\u003eblood \u003c= 0 \u0026\u0026 hero-\u003eeffect.totem_of_undying == 0) // don't have totem of undying\n          {\n              printf(\"You DEAD\"); // dead\n              return 1;\n          }\n          else if (hero-\u003eblood \u003c= 0 \u0026\u0026 hero-\u003eeffect.totem_of_undying == 1) // if you have totem of undying\n          {\n              hero-\u003eblood = 5;                                                            // give you five more blood\n              printf(\"triggered totem of undying, now you have %d blood\\n\", hero-\u003eblood); // description\n              hero-\u003eeffect.totem_of_undying--;                                            // used effect\n          }\n          return 0;\n      }\n      ```\n  * Check village blood\n      ```c\n      if (village.blood \u003c= 0) // check village blood\n      {\n          printf(\"Your village has fallen\\n\"); // game over\n          free(map);                           // free malloced map\n          break;\n      }\n      printf(\"Congrats you and your village have lived another day.\\n\"); // village survive\n      day++;                                                             // live another day\n      ```\n  * Check player strength\n      ```c\n      if (hero-\u003estrength \u003c= 0) // if no more strength, lose blood\n          {\n              printf(\"You have no strength.\\n\");\n              hero-\u003estrength = 0;\n              printf(\"You have %d strength\\n\", hero-\u003estrength); // show strength\n              printf(\"You will lose blood.\\n\");\n              (hero-\u003eblood)--;\n          }\n      ```\n  * Check player hunger\n      ```c\n      int check_hunger(adventurer *hero)\n      {\n          if (hero-\u003ehunger \u003c= 0) // check if too hungry\n          {\n              hero-\u003ehunger = 0;\n              printf(\"You are hungry! You will lose blood!\\nPlease EAT!!!\\n\");\n              hero-\u003eblood--; // lose blood\n              return 1;\n          }\n          return 0;\n      }\n      ```\n  * Check if survive new day\n    ```c\n    int check_time(char **map, int *row, int *col, adventurer *hero, village *village)\n    {\n        if (hero-\u003eboot == 0) // check if night time\n        {\n            free(map);                                                                     // free malloced map\n            printf(\"It's a new day, things are respawned except your village and you.\\n\"); // new day\n            map = create_map(row, col);                                                    // new map, same size\n            map[hero-\u003erv][hero-\u003ecv] = 'v';                                                 // set village coordinate to the same place\n            map[hero-\u003erp][hero-\u003ecp] = 'p';                                                 // player is sent back to village\n            hero-\u003eeffect.potion_of_good_vision = 0;                                        // no more effect for potion of good vision\n            hero-\u003eeffect.potion_of_swiftness = 0;                                          // no more effect for potion of swiftness\n            int monster_count = 0;                                                         // count nearby monsters\n            for (int i = hero-\u003erp - 2 - hero-\u003eeffect.potion_of_good_vision * 3; i \u003c= hero-\u003erp + 2 + hero-\u003eeffect.potion_of_good_vision * 3; i++)\n            {\n                for (int j = hero-\u003ecp - 2 - hero-\u003eeffect.potion_of_good_vision * 3; j \u003c= hero-\u003ecp + 2 + hero-\u003eeffect.potion_of_good_vision * 3; j++)\n                {\n                    if (i \u003c 0 || i \u003e= *row)\n                        continue;\n                    if (j \u003c 0 || j \u003e= *col)\n                        continue;\n                    if (map[i][j] == 'm')\n                        monster_count++; // if nearby monster ++\n                }\n            }\n\n            village-\u003eblood -= monster_count * 10; // nearby monster attack\n            village-\u003elevel++;                     // village level +1\n            hero-\u003elevel++;                        // player level+1\n            hero-\u003eday++;                          // new day\n            return 1;\n        }\n        return 0;\n    }\n    ```\n## Player Movement\n  * Ask what do you want to do\n      ```c\n      int move(char **map, int *row, int *col, adventurer *hero, village *village)\n      {\n          int decision; // decision to go up /down....\n          printf(\"[0] use inventory [1] go up [2] go down [3] go right [4] go left [5] see map [6] exit:\");\n          scanf(\"%d\", \u0026decision);\n          switch (decision)\n          {\n          case 0: // use inventory\n              printf(\"What do you want to use?(1:potion of swiftness; 2: totem of undying; 3:golden apple; 4.potion of good vision)\\n\");\n              int decide; // decide what to do\n              scanf(\"%d\", \u0026decide);\n              switch (decide)\n              {\n              case 1:                                        // use potion of swiftness\n                  if (hero-\u003ethings.potion_of_swiftness == 0) // check if you have it\n                  {\n                      printf(\"You don't have it.\\n\");\n                      return 1;\n                  }\n                  hero-\u003ethings.potion_of_swiftness--;                                                    // use potion of swiftness\n                  hero-\u003eeffect.potion_of_swiftness++;                                                    // get effect for potion of swiftness\n                  hero-\u003eboot *= 2;                                                                       // travel two times speed\n                  printf(\"Now you have %d potion(s) of swiftness\", hero-\u003ethings.potion_of_swiftness);    // show stats\n                  printf(\"Nice! Now you can 2 times speed, but only cost half the amount of hunger.\\n\"); // description\n                  return 1;\n              case 2:                                     // use totem of undying\n                  if (hero-\u003ethings.totem_of_undying == 0) // check if you have it\n                  {\n                      printf(\"You don't have it.\\n\");\n                      return 1;\n                  }\n                  hero-\u003ethings.totem_of_undying--;                                               // use totem of undying\n                  hero-\u003eeffect.totem_of_undying++;                                               // get effect for totem of undying\n                  printf(\"Now you have %d totem(s) of undying\", hero-\u003ethings.totem_of_undying);  // show stats\n                  printf(\"Nice! Now if you are strike to death, you will have 5 more blood.\\n\"); // description\n                  return 1;\n              case 3:\n                  if (hero-\u003ethings.golden_apple == 0) // check if you have it\n                  {\n                      printf(\"You don't have it.\\n\");\n                      return 1;\n                  }\n                  if (hero-\u003eblood \u003e 5)\n                  {\n                      printf(\"you have %d blood now, do you still want to use it [0]No [1]Yes:\\n\", hero-\u003eblood);\n                      int decide;\n                      scanf(\"%d\", \u0026decide);\n                      if (!decide)\n                          return 1;\n                  }\n                  hero-\u003ethings.golden_apple--;            // use golden apple\n                  hero-\u003eblood += 5;                       // get effect for golden apple\n                  if (hero-\u003eblood \u003e= hero-\u003edefault_blood) // add to healthy\n                      hero-\u003eblood = hero-\u003edefault_blood;\n                  printf(\"Now you have %d golden apple(s)\", hero-\u003ethings.golden_apple); // show stats\n                  printf(\"Nice! Now you have %d blood\\n\", hero-\u003eblood);                 // description\n                  return 1;\n              case 4:                                          // use potion of good vision\n                  if (hero-\u003ethings.potion_of_good_vision == 0) // check if you have it\n                  {\n                      printf(\"You don't have it.\\n\");\n                      return 1;\n                  }\n                  hero-\u003ethings.potion_of_good_vision--;                                                   // use potion of good vision\n                  hero-\u003eeffect.potion_of_good_vision++;                                                   // get effect for potion of good vision\n                  printf(\"Now you have %d potion(s) of good vision\", hero-\u003ethings.potion_of_good_vision); // show stats\n                  printf(\"Nice! Now you can see more when you see the map\\n\");                            // description\n                  return 1;\n              default:\n                  printf(\"Invalid action!\\n\");\n                  return 1;\n              }\n          case 1: // up\n              go_up(map, row, col, hero, village);\n              return 1;\n          case 2: // down\n              go_down(map, row, col, hero, village);\n              return 1;\n          case 3: // right\n              go_right(map, row, col, hero, village);\n              return 1;\n          case 4: // left\n              go_left(map, row, col, hero, village);\n              return 1;\n          case 5: // see map\n              print_map(map, row, col, hero, village);\n              return 1;\n          case 6: // quit game\n              return 0;\n          }\n      }\n      ```\n  * go up (similar coding to down / left / right)\n      ```c\n      void go_up(char **map, int *row, int *col, adventurer *hero, village *village) // up\n      {\n          if (check_boundary(row, col, hero-\u003erp - 1, hero-\u003ecp)) // check if out of range\n              return;\n          hero-\u003ehunger -= (1 / (hero-\u003eeffect.potion_of_swiftness + 1)); // see if there is potion of swiftness effect and minus hunger\n          hero-\u003eboot--;                                                 // time of day++\n          int a = check_hunger(hero);                                   // see if hungry\n          if (check_blood(hero))                                        // see if have blood\n              return;\n          char temp = map[hero-\u003erp][hero-\u003ecp]; // temp for player standing spot\n          if (temp == 'p')                     // if player standing spot is shown 'p', then it must be a normal('.') spot\n              temp = '.';\n          switch (check_move(map, row, col, hero-\u003erp - 1, hero-\u003ecp, hero)) // try next step first(see if it is a special spot)\n          {\n          case 'w': // means player's 'p' can be shown on map\n          {\n              map[--(hero-\u003erp)][hero-\u003ecp] = 'p';\n              map[hero-\u003erp + 1][hero-\u003ecp] = temp;\n              return;\n          }\n          case 'f': // travel back to village\n              --(hero-\u003erp);\n              map[hero-\u003erp + 1][hero-\u003ecp] = temp;\n              hero-\u003erp = hero-\u003erv;\n              hero-\u003ecp = hero-\u003ecv;\n              printf(\"You are now back in the village\\n\");\n              in_village(hero);\n              return;\n          case 'l': // means player's 'p' can't be shown on map because it is a special spot\n              --(hero-\u003erp);\n              map[hero-\u003erp + 1][hero-\u003ecp] = temp;\n              return;\n          case 'D': // your dead\n              return;\n          }\n\n          map[--(hero-\u003erp)][hero-\u003ecp] = 'p';       // move p to the next spot\n          map[hero-\u003erp + 1][hero-\u003ecp] = temp;      // original standing spot is recovered\n          print_map(map, row, col, hero, village); // print out map\n      }\n      ```\n  * Check if it's a special spot (special spot means every spot that is not '.')\n      ```c\n    char check_move(char **map, int *row, int *col, int rp, int cp, adventurer *hero) // check if special spot (map[r][c]!='.')\n    {\n        if (map[rp][cp] != '.') // special spot\n        {\n            if (map[rp][cp] == 'v') // village\n            {\n                printf(\"you are now in the village\\nWelcome!!!\\n\");\n                in_village(hero); // go to village\n                return 'l';\n            }\n            else if (map[rp][cp] == 'm') // monster\n            {\n                printf(\"you are fighting a monster\\n\");\n                char res = encounter_monster(hero); // fight monster\n                return res;\n            }\n            else if (map[rp][cp] == 'g') // gun\n            {\n                encounter_gun(hero); // get gun\n                return 'w';\n            }\n            else if (map[rp][cp] == 't') // trap\n            {\n                encounter_trap(hero); // encounter trap\n                return 'w';\n            }\n            else if (map[rp][cp] == 'd') // dealer's shop\n            {\n                encounter_dealer(hero); // go to dealer's shop\n                return 'w';\n            }\n            else if (map[rp][cp] == 'c') // food\n            {\n                char res = encounter_food(hero); // get food\n                return res;\n            }\n            else if (map[rp][cp] == 's') // shield\n            {\n                encounter_shield(hero); // get shield\n                return 'w';\n            }\n            else if (map[rp][cp] == 'f') // fast travel station\n            {\n                return encounter_station(hero); // go to station\n            }\n            else if (map[rp][cp] == 'h') // health station\n            {\n                return encounter_clinic(hero); // go to station\n            }\n        }\n        else\n            return 'n'; // normal spot\n    }\n    ```\n## Print out map / important stats \nsee [after_movement_interface](#after-movement-interface) for more info\n```c\nvoid print_map(char **arr, int *row, int *col, adventurer *hero, village *village)\n{\n    // village stat\n    printf(\"\\n\\nYour village's stats:\\n\");\n    printf(\"Blood: %d\\tStrength: %d\\tLevel: %d\\n\\n\", village-\u003eblood, village-\u003estrength, village-\u003elevel);\n\n    // player stat\n    printf(\"Your stats:\\n\");\n    printf(\"Blood: %d\\tStrength: %d\\tHunger: %lf\\tCoins: %d\\tLevel: %d\\n\\n\", hero-\u003eblood, hero-\u003estrength, hero-\u003ehunger, hero-\u003ecoins, hero-\u003elevel);\n\n    // what's in your inventory\n    printf(\"Your Inventory:\\n\");\n    printf(\"Potion of  swiftness: %d\\tTotem of undying: %d\\tGolden apple: %d\\tPotion of good vision: %d\\n\\n\", hero-\u003ethings.potion_of_swiftness, hero-\u003ethings.totem_of_undying, hero-\u003ethings.golden_apple, hero-\u003ethings.potion_of_good_vision);\n\n    // effects on you\n    printf(\"Your effects:(1: means has effect, 0: means no effect)\\n\");\n    printf(\"Potion of  swiftness: %d\\tTotem of undying: %d\\tPotion of good vision: %d\\n\\n\", hero-\u003eeffect.potion_of_swiftness, hero-\u003eeffect.totem_of_undying, hero-\u003eeffect.potion_of_good_vision);\n\n    // show map\n    printf(\"== MAP ==\\n\");\n    for (int i = hero-\u003erp - 2 - hero-\u003eeffect.potion_of_good_vision; i \u003c= hero-\u003erp + 2 + hero-\u003eeffect.potion_of_good_vision; i++)\n    {\n        for (int j = hero-\u003ecp - 2 - hero-\u003eeffect.potion_of_good_vision; j \u003c= hero-\u003ecp + 2 + hero-\u003eeffect.potion_of_good_vision; j++)\n        {\n            if (i \u003c 0 || i \u003e= *row)\n                continue;\n            if (j \u003c 0 || j \u003e= *col)\n                continue;\n            if (arr[i][j] != 'p' \u0026\u0026 arr[i][j] != 'v' \u0026\u0026 arr[i][j] != 'd' \u0026\u0026 arr[i][j] != 'c' \u0026\u0026 arr[i][j] != 'm' \u0026\u0026 arr[i][j] != 'f' \u0026\u0026 arr[i][j] != 'h')\n                printf(\"%c\", '.');\n            else\n                printf(\"%c\", arr[i][j]);\n        }\n        printf(\"\\n\");\n    }\n    // reminder\n    printf(\"You are the center of the map\\n\");\n    printf(\"== MAP ==\\n\\n\");\n\n    // coordinates\n    printf(\"(1 indexed)Your coordinates are (%d, %d)\\n\", hero-\u003ecp + 1, hero-\u003erp + 1);\n    printf(\"(1 indexed)Your village's coordinates are (%d, %d)\\n\\n\", hero-\u003ecv + 1, hero-\u003erv + 1);\n\n    // time\n    printf(\"Time of the day: %d:00\\n\", 24 - (hero-\u003eboot / (hero-\u003eeffect.potion_of_swiftness + 1)));\n}\n```\n# Version\nv. 1.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewhsugithub%2F2d-open-world-game","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewhsugithub%2F2d-open-world-game","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewhsugithub%2F2d-open-world-game/lists"}