From 6799746466593c7817e70285c8f9be57b1a11e39 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann <3004405@stud.hs-mannheim.de> Date: Sat, 30 Mar 2024 00:14:49 +0100 Subject: [PATCH] v.0.5.6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit schöneres erkennen des Siegers. Code kürzer gemacht --- board/board.gd | 5 ++++- game.gd | 30 +++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/board/board.gd b/board/board.gd index 938f85a..8802686 100644 --- a/board/board.gd +++ b/board/board.gd @@ -87,7 +87,10 @@ func delete_column(column: int) -> void: if tile_data: var tile_map_cell_source_id = self.get_cell_source_id(tile_map_layer, tile_map_cell_position); var tile_map_cell_atlas_coords = self.get_cell_atlas_coords(tile_map_layer, tile_map_cell_position) - var tile_map_cell_alternative = self.get_cell_alternative_tile(tile_map_layer, tile_map_cell_position) + var tile_map_cell_alternative = self.get_cell_alternative_tile(tile_map_layer, tile_map_cell_position) + print(tile_map_cell_source_id) + print(tile_map_cell_atlas_coords) + print(tile_map_cell_alternative) var new_tile_map_cell_position = Vector2i(i, j + 1) self.set_cell(tile_map_layer, new_tile_map_cell_position, tile_map_cell_source_id, tile_map_cell_atlas_coords, tile_map_cell_alternative) if j == 0: diff --git a/game.gd b/game.gd index ca44e6f..2e63c7f 100644 --- a/game.gd +++ b/game.gd @@ -3,7 +3,9 @@ extends Node2D var current_player: int = 0 var player_states := ["Circle", "Cross"] var won := "" -var five_wins = false +var sequence_needed = 4 +var _sequence = [] + @onready var board := $Board as Board @onready var nextPlayer := $GUI/NextPlayer as Sprite2D @@ -41,6 +43,12 @@ func _process(_delta): else: print("Winner: ", won) wonPlayer.region_rect.position.x = player_states.find(won) * 300 + if won == player_states[0]: + for tile in _sequence: + board.set_cell(1, tile, 1, Vector2i(0, 2), 0) + else: + for tile in _sequence: + board.set_cell(1, tile, 1, Vector2i(3, 2), 0) wonPlayer.show() nextPlayer.hide() board.active = false @@ -61,19 +69,15 @@ var _checks = [ func _check_win() -> String: for cell in board.get_used_cells(board.layer_by_name[board.state_layer]): var state = board.get_state(cell) + _sequence.clear() for check in _checks: for i in range(3): var same = true - if five_wins: - for j in range(5): - if board.get_state(cell + check[0] * (i + j)) != state: - same = false - break - else: - for j in range(4): - if board.get_state(cell + check[0] * (i + j)) != state: - same = false - break + for j in range(sequence_needed): + if board.get_state(cell + check[0] * (i + j)) != state: + same = false + break + _sequence.append(Vector2i(cell + check[0] * (i + j))) if same: return state return "" @@ -137,7 +141,7 @@ func _get_dice_pos_y(result: int) -> int: #Nach dem Glücksradereignis wird die Siegesbedingung auf 5 gewinnt geändert func _five_wins() -> void: print("5 Gewinnt aktiv") #Debug - five_wins = true + sequence_needed = 5 #Nach dem Glücksradereignis tauschen die Spieler die Symbole func _change_symbols(): @@ -162,7 +166,7 @@ func _instant_win(): #Zum Testen der Events func _on_test_pressed(): - board.delete_column(2) + board.delete_column(6) func _spin_the_wheel(result: int) -> void: