Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ as long as the multiplier lasts.

Note that the score resets at the start of each level, alongside the board.

When a run ends, the score it finished on is reported in the obituary that both UIs
show, alongside the all-time best in the chronicle printed beneath it.

## Controls
Key | Action
------------ | -------------
Expand Down
12 changes: 10 additions & 2 deletions src/progression/obituary.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ def formatObituaryLines(obituary):
level = obituary.get("level", 1)
length = obituary.get("length", 0)
ticks = obituary.get("ticksSurvived", 0)
# obituaries written before score was recorded have no "score" key
score = obituary.get("score", 0)
cause = causeOfDeathPhrase(obituary.get("causeOfDeath"))

return [
"== Obituary ==",
"The ophidian {name} lived to level {level}, reaching a length of "
"{length}, surviving {ticks} ticks, before {cause}.".format(
name=name, level=level, length=length, ticks=ticks, cause=cause
"{length} and a score of {score}, surviving {ticks} ticks, before "
"{cause}.".format(
name=name,
level=level,
length=length,
score=score,
ticks=ticks,
cause=cause,
),
]

Expand Down
23 changes: 23 additions & 0 deletions tests/progression/test_obituary.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_format_obituary_lines_interpolates_fields_for_collision():
assert "Noodle" in narrative
assert "level 3" in narrative
assert "length of 12" in narrative
assert "score of 789" in narrative
assert "surviving 456 ticks" in narrative
assert "colliding with itself" in narrative

Expand All @@ -82,10 +83,23 @@ def test_format_obituary_lines_falls_back_when_name_missing():
assert "Unnamed Ophidian" in lines[1]


def test_format_obituary_lines_reports_the_score_of_the_run_that_just_ended():
lines = formatObituaryLines(sampleObituary(score=1234))
assert "score of 1234" in lines[1]


def test_format_obituary_lines_defaults_score_for_records_predating_it():
stale = sampleObituary()
del stale["score"]
lines = formatObituaryLines(stale)
assert "score of 0" in lines[1]


def test_format_obituary_lines_handles_empty_dict():
lines = formatObituaryLines({})
assert lines[0] == "== Obituary =="
assert "Unnamed Ophidian" in lines[1]
assert "score of 0" in lines[1]
assert "unknown causes" in lines[1]


Expand Down Expand Up @@ -115,3 +129,12 @@ def test_format_obituary_screen_combines_both_sections_with_separator():
joined = "\n".join(lines)
assert "Noodle" in joined
assert "Total runs: 7" in joined


def test_format_obituary_screen_distinguishes_run_score_from_lifetime_best():
lines = formatObituaryScreen(
sampleObituary(score=789), sampleLifetimeStats(highestScore=999)
)
joined = "\n".join(lines)
assert "score of 789" in joined
assert "Highest score ever: 999" in joined
22 changes: 22 additions & 0 deletions tests/test_ophidian_run_lifecycle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time

from progression.obituary import formatObituaryScreen
from textui.textrenderer import TextRenderer

from ophidian import Ophidian
Expand Down Expand Up @@ -197,3 +198,24 @@ def test_restart_still_reinitializes_and_signals_restart(tmp_path, monkeypatch):

assert calls == ["reinit"]
assert result == "restart"


def test_ending_a_run_shows_that_run_s_score_on_the_obituary_screen(
tmp_path, monkeypatch
):
# regression test: the screen reported the lifetime best and never the
# score of the run just played (see issue #136). The lifetime best is
# seeded above the run's score so the run's number can't be satisfied by
# the chronicle line.
game = _makeGame(monkeypatch, tmp_path)
game.saveManager.data["lifetimeStats"]["highestScore"] = 9999
game.score = 4242

game.recordCurrentRun("collision")
lines = formatObituaryScreen(
game.lastObituary, game.saveManager.data["lifetimeStats"]
)

joined = "\n".join(lines)
assert "score of 4242" in joined
assert "Highest score ever: 9999" in joined