Skip to content

Commit

Permalink
Merge pull request #161 from joshuafolkken/160-refactoring
Browse files Browse the repository at this point in the history
160 refactoring
  • Loading branch information
joshuafolkken authored Sep 25, 2024
2 parents b4dd03f + 0ddb751 commit f257937
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/cell.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ signal button_clicked(board_position: BoardPosition)

@export var button_index := 0

var button_visible: bool:
get:
return _cell_button.visible
set(value):
_cell_button.visible = value

@onready var _cell_button: Button = $CellButton
@onready var _click_sound: ClickSound = $ClickSound
@onready var _cross: Node2D = $Cross
Expand All @@ -21,10 +27,14 @@ func set_button_visibility(value: bool) -> void:
_cell_button.visible = value


func is_button_visible() -> bool:
return _cell_button.visible


func _show_mark(cell_status: CellStatus) -> void:
_cross.visible = cell_status.is_x()
_circle.visible = cell_status.is_o()
set_button_visibility(cell_status.is_empty())
_cell_button.visible = cell_status.is_empty()
fade(false)


Expand Down
74 changes: 74 additions & 0 deletions src/lib/cell_collection_test.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# # gdlint: disable=unused-argument
# # gdlint: disable=private-method-call
# # GdUnit generated TestSuite
# class_name CellCollectionTest
# extends GdUnitTestSuite

# func test_init() -> void:
# await assert_error(func() -> void: CellCollection.new()).is_success()

# @warning_ignore("unused_parameter")

# func test_add(
# position: BoardPosition,
# cell: Cell,
# test_parameters := [
# [BoardPosition.new(0, 0), Cell.new()],
# [BoardPosition.new(1, 1), Cell.new()],
# ]
# ) -> void:
# var collection := CellCollection.new()
# collection.add(position, cell)

# var actual := collection.get_element(position)
# assert_that(actual).is_equal(cell)

# func test_end_game() -> void:
# var collection := CellCollection.new()
# var cell1 := Cell.new()
# var cell2 := Cell.new()
# collection.add(BoardPosition.new(0, 0), cell1)
# collection.add(BoardPosition.new(1, 1), cell2)

# collection.end_game()

# assert_bool(cell1.button_visible).is_false()
# assert_bool(cell2.button_visible).is_false()

# cell1.free()
# cell2.free()

# func test_reset_all() -> void:
# var collection := CellCollection.new()
# var cell1 := Cell.new()
# var cell2 := Cell.new()

# collection.add(BoardPosition.new(0, 0), cell1)
# collection.add(BoardPosition.new(1, 1), cell2)
# collection.reset_all()

# assert_bool(cell1.button_visible).is_true()
# assert_bool(cell2.button_visible).is_true()

# cell1.free()
# cell2.free()

# func test_clear() -> void:
# var collection := CellCollection.new()
# var cell := Cell.new()
# var position := BoardPosition.new(0, 0)

# collection.add(position, cell)
# collection.clear(position)

# assert_bool(cell.button_visible).is_true()

# func test_fade() -> void:
# var collection := CellCollection.new()
# var cell := Cell.new()
# var position := BoardPosition.new(0, 0)

# collection.add(position, cell)
# collection.fade(position)

# assert_bool(cell.button_visible).is_false()
6 changes: 1 addition & 5 deletions src/lib/cell_status_collection.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
class_name CellStatusCollection

var _elements: Array[CellStatus]


func _init() -> void:
_elements = []
var _elements: Array[CellStatus] = []


func append(status: CellStatus) -> void:
Expand Down
1 change: 0 additions & 1 deletion src/lib/game_player_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func test_get_value(
id: GamePlayer.Id,
expected: GamePlayer.Id,
test_parameters := [
[null, GamePlayer.Id.X],
[GamePlayer.Id.X, GamePlayer.Id.X],
[GamePlayer.Id.O, GamePlayer.Id.O],
]
Expand Down
1 change: 0 additions & 1 deletion src/lib/game_status_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ func test_init(
state: GameStatus.State,
is_success: bool,
test_parameters := [
[null, true],
[GameStatus.State.PLAYING, true],
[GameStatus.State.X_WIN, true],
[GameStatus.State.O_WIN, true],
Expand Down

0 comments on commit f257937

Please sign in to comment.