mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-04-29 16:25:35 +00:00
Scoring and Scoreboard implemented
This commit is contained in:
parent
a455d31a69
commit
1ef147cc28
14 changed files with 228 additions and 22 deletions
|
|
@ -21,7 +21,6 @@ func before_each() -> void:
|
|||
_subject = HealthComponent.new()
|
||||
watch_signals(_subject)
|
||||
_subject.max_health = TEST_MAX_HEALTH
|
||||
set_multiplayer_authority(multiplayer.get_unique_id())
|
||||
add_child(_subject)
|
||||
|
||||
func after_each() -> void:
|
||||
|
|
@ -32,16 +31,16 @@ func test_that_it_has_max_health_when_ready() -> void:
|
|||
|
||||
func test_that_it_takes_damage() -> void:
|
||||
var damage_amount : float = 10
|
||||
_subject.damage(damage_amount)
|
||||
_subject.damage(damage_amount, -1)
|
||||
assert_eq(_subject.health, TEST_MAX_HEALTH - damage_amount)
|
||||
|
||||
func test_that_it_emits_health_changed_after_damage() -> void:
|
||||
_subject.damage(1)
|
||||
_subject.damage(1, -1)
|
||||
assert_signal_emitted(_subject, 'health_changed')
|
||||
|
||||
func test_that_it_emits_health_zeroed() -> void:
|
||||
_subject.damage(TEST_MAX_HEALTH)
|
||||
assert_signal_emitted(_subject, 'health_zeroed')
|
||||
_subject.damage(TEST_MAX_HEALTH, -1)
|
||||
assert_signal_emitted_with_parameters(_subject, 'health_zeroed', [-1])
|
||||
|
||||
func test_that_it_heals_fully() -> void:
|
||||
_subject.health = 10
|
||||
|
|
|
|||
57
tests/test_scoreboard.gd
Normal file
57
tests/test_scoreboard.gd
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
extends GutTest
|
||||
|
||||
var PLAYER : PackedScene = preload("res://entities/player/player.tscn")
|
||||
|
||||
var _subject : Scoreboard
|
||||
|
||||
func before_each() -> void:
|
||||
_subject = Scoreboard.new()
|
||||
add_child(_subject)
|
||||
|
||||
func after_each() -> void:
|
||||
_subject.free()
|
||||
|
||||
func test_that_new_scoreboard_is_empty() -> void:
|
||||
assert_eq(_subject.get_entries(), [])
|
||||
|
||||
func test_that_added_entry_is_added_correctly() -> void:
|
||||
var player : Player = PLAYER.instantiate()
|
||||
player.nickname = "test_nickname"
|
||||
_subject.add_entry(player)
|
||||
var entries : Array = _subject.get_entries()
|
||||
assert_eq(1, entries.size())
|
||||
var tested_entry : Scoreboard.ScoreboardEntry = entries[0]
|
||||
assert_eq("test_nickname", tested_entry.nickname)
|
||||
assert_eq(0, tested_entry.kills)
|
||||
assert_eq(0, tested_entry.score)
|
||||
player.free()
|
||||
|
||||
func test_that_scores_are_added_correctly() -> void:
|
||||
var player : Player = PLAYER.instantiate()
|
||||
_subject.add_entry(player)
|
||||
_subject.add_score_to_player(player, 10)
|
||||
var tested_entry : Scoreboard.ScoreboardEntry = _subject.get_entries()[0]
|
||||
assert_eq(10, tested_entry.score)
|
||||
player.free()
|
||||
|
||||
func test_that_kill_counts_are_incremented_correctly() -> void:
|
||||
var player : Player = PLAYER.instantiate()
|
||||
_subject.add_entry(player)
|
||||
_subject.increment_kill_count(player)
|
||||
var tested_entry : Scoreboard.ScoreboardEntry = _subject.get_entries()[0]
|
||||
assert_eq(1, tested_entry.kills)
|
||||
player.free()
|
||||
Loading…
Add table
Add a link
Reference in a new issue