Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Video Game Spawner

video_game_spawner.livemd

Video Game Spawner

Mix.install([
  {:kino, github: "livebook-dev/kino", override: true},
  {:kino_lab, "~> 0.1.0-dev", github: "jonatanklosko/kino_lab"},
  {:vega_lite, "~> 0.1.4"},
  {:kino_vega_lite, "~> 0.1.1"},
  {:benchee, "~> 0.1"},
  {:ecto, "~> 3.7"},
  {:math, "~> 0.7.0"},
  {:faker, "~> 0.17.0"},
  {:utils, path: "#{__DIR__}/../utils"},
  {:tested_cell, git: "https://github.com/BrooklinJazz/tested_cell"}
])

Navigation

Return Home Report An Issue

Setup

Ensure you type the ea keyboard shortcut to evaluate all Elixir cells before starting. Alternatively you can evaluate the Elixir cells as you read.

Video Game Spawner

It’s classic in video games for a spawner to spawn enemy creatures. Typically the spawner has a limit for how many enemy creatures it can spawn. If a creature dies, the spawner then re-spawns that creature.

You’re going to create a Spawner application to simulate a game with enemy spawns.

This project aims to help you learn about supervisors and fault tolerance.

A SpawnerSupervisor will supervise three Creature GenServerss.

flowchart
  S[Spawner]
  C1[Creature]
  C2[Creature]
  C3[Creature]

  S --> C1
  S --> C2
  S --> C3
  S --> C4

When a Creature process dies, the Spawner supervisor will automatically restart it.

Create A New Mix Project

Using the command line, create a new supervised project in the projects folder called spawner.

mix new spawner --sup

Create the Creature GenServer

Create a Creature GenServer. It should start as a minimal GenServer with no additional functionality for now.

Configure the Spawner

Configure the Spawner to start in application.ex.

(Optional) Use :observer to View Your Spawner and Creature

Start your project

iex -S mix

Then start the observer.

:observer.start()

Use the observer to kill a Creature process. It should be automatically restarted by the Spawner supervisor.

:kill

A Creature process should be killed when it receives a :kill message. Create a Spawner.kill/1 which accepts the pid of a Creature process and sends it the :kill message.

Upon terminating, the Spawner supervisor should automatically restart the Creature process.

Commit Your Progress

Run the following in your command line from the project folder to track and save your progress in a Git commit.

$ git add .
$ git commit -m "finish video game spawner exercise"