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

Save Game

save_game.livemd

Save Game

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

Save Game

Many games have a Save function, which allows players to save the current state of the game. In some cases, the saved game is stored in a save file.

We’re going to recreate the Save functionality of a video game using the file system.

The game will store some arbitrary Elixir term in a given file name.

game_data = %{
  character_name: "Peter Parker",
  level: 10,
  current_location: "New York"
}

Game.save(game_data, "save file 1")

Then we should be able to retrieve the saved data given the file name.

%{
  character_name: "Peter Parker",
  level: 10,
  current_location: "New York"
} = Game.retrieve("save file 1")

Enter your solution below.

defmodule Game do
  def save(data, filename) do
  end

  def retrieve(filename) do
  end
end

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 save game exercise"