May 2019
Beginner to intermediate
466 pages
10h 44m
English
The player has read the starting article and clicked on a link within the content. We need to add the logic for rendering the linked article. We'll have to fetch the article (or read it from the database if it was already fetched), display it, and update the game's state.
Here is the code:
const articlepage = HTTP.HandlerFunction() do req
uri_parts = parseuri(req.target)
game = gamesession(uri_parts[1])
article_uri = "/wiki/$(uri_parts[end])" existing_articles = Articles.find(article_uri)
article = isempty(existing_articles) ?
persistedarticle(fetchpage(article_uri)...) :
existing_articles[1] push!(game.history, article)
game.steps_taken += 1 puzzlesolved(game, article) && destroygamesession(game.id) ...Read now
Unlock full access