This program is a microservice designed for RPG dungeon crawls. It takes in two parameters and returns a balanced enemy back to the user. It communicates between programs via shared memory. This code only functions on a linux machine.
- You must be able to use shared memory on whatever computer you are running the code on.
- You must run the code on a linux machine
- You must compile with the
enemysharelib.o
object - You MUST run the
enemymicroservice &
command BEFORE you attempt to use thegenerate_enemy
function provided.- Not following this instructions will generate undefined behavior and may crash your program.
- If the
enemymicroservice
process is not running in the background the code will not work
- Clone the github repo
- You may need to fix the bash scripts permissions. Run the command
chmod 777 compile.sh
- Compile by running the bash script. Use the command
./compile.sh
- The microservice is now installed and compiled.
- Ensure you have followed the above steps.
- Run the microservice process in the background using the command
enemymicroservice &
- This is a critical step. Follow these instructions in this order.
- You can use the provided function "generate_enemy" by including the
enemysharelib.h
library. At the top of your code put the line#include enemysharelib.h
- When you compile your code make sure you include the
enemysharelib.o
object. An example can be found in thecompile.sh
file. - You may now run
generate_enemy()
- To kill the microservice you have two options
- A
- Run the
jobs
command - Type
fg job_id
where job_id is the microservices job id. - The microservice should be running in the foreground now.
- press
Ctrl + C
- Run the
- B
- Run the
ps
command - Type
kill -9 PID
where PID is the microservices process ID (usually a six digit number).
- Run the
- A
- The prototype for the function is as follows:
struct enemy* generate_enemy(int floor, int difficulty)
- The function returns a dynamically allocated enemy with a generated health, attack, and rarity. It will return a name in the future.
- The first parameter is an integer representing the floor that the user is on. It is expected to be an integer above 0 and below INT_MAX.
- The second parameter is an integer representing the difficulty the user selected. It is expected to be an integer between 1 and 3.
- After compiling using
compile.sh
run the microprocess in the background usingenemymicroprocess &
- Run the
runexample
executable - Input the desired values
- Watch an enemy struct be printed