major refactor(game-modes): centralize scoring and turn handling
* Move common ball recording, scoring, and turn-switching logic into `BaseMode` * Add hooks for mode-specific ball handling and turn behavior * Simplify 8-ball and 9-ball modes to use `LastBallMode` * Update Snooker to use the new ball-processing hooks * Remove duplicated scoring and turn-management code
This commit is contained in:
@@ -1,54 +1,5 @@
|
||||
class_name Ball9 extends BaseMode
|
||||
class_name Ball9 extends LastBallMode
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
pass
|
||||
|
||||
func reap_ball(ball: Node3D) -> void:
|
||||
super(ball)
|
||||
|
||||
if ball.name == "09_ball":
|
||||
# TODO: 9 ball must not be be destroyed. Handle rule...
|
||||
ball_states[ball.name]["is_foul"] = true
|
||||
|
||||
func process_ball(ball: Node3D) -> void:
|
||||
super(ball)
|
||||
|
||||
if ball.name == "09_ball":
|
||||
# TODO: 9 ball must be sunk last. Handle rule...
|
||||
ball_states[ball.name]["is_foul"] = true
|
||||
|
||||
func handle_switch_user() -> void:
|
||||
push_warning("Balls reaped: ", balls_reaped.size() )
|
||||
push_warning("Balls sunk: ", balls_sunk.size() )
|
||||
var is_player_1: bool = "Player 1" == get_player()
|
||||
var switch_player: bool = true
|
||||
|
||||
if not balls_reaped.is_empty():
|
||||
for ball_name in balls_reaped:
|
||||
if is_player_1:
|
||||
player_1_points -= ball_states[ball_name]["points"]
|
||||
else:
|
||||
player_2_points -= ball_states[ball_name]["points"]
|
||||
|
||||
balls_reaped.clear()
|
||||
|
||||
if not balls_sunk.is_empty():
|
||||
# TODO: Handle points, etc, insure 9-ball not sunk unless last.
|
||||
# Insure we process stripped vs solid ball and apropriate points accordingly.
|
||||
# ball_states[ball.name]["is_foul"] = true
|
||||
|
||||
switch_player = false
|
||||
balls_sunk.clear()
|
||||
|
||||
if ball_states_finalized():
|
||||
process_win_condition()
|
||||
return
|
||||
|
||||
if switch_player:
|
||||
Globals.game_state.switch_active_player()
|
||||
|
||||
turn_count += 1
|
||||
|
||||
func process_win_condition() -> void:
|
||||
pass
|
||||
func _init() -> void:
|
||||
final_ball_name = "09_ball"
|
||||
|
||||
Reference in New Issue
Block a user