fix: refine game mode state tracking and turn handling
* Centralize ball state generation in `BaseMode` * Track turn count, player, and ball state consistently * Prevent 8-ball, 9-ball, and colored snooker balls from being marked valid when reaped/sunk * Update mode initialization and ball-state assignment * Normalize Free Ball mode node name to `freeball`
This commit is contained in:
@@ -1,16 +1,51 @@
|
||||
class_name Snooker extends BaseMode
|
||||
|
||||
|
||||
# NOTE: The game is sometimes played with fewer red balls- commonly 6 or 10.
|
||||
# Normally, 15 red balls (1 point) and 6 balls of different colors:
|
||||
# yellow (2 points), green (3), brown (4), blue (5), pink (6), black (7).
|
||||
|
||||
|
||||
var COLORED_BALLS: Array[String] = [
|
||||
"yellow_ball", "green_ball", "brown_ball",
|
||||
"blue_ball", "pink_ball", "black_ball"
|
||||
]
|
||||
|
||||
var COLORED_BALLS_POINTS: Array[int] = [
|
||||
2, 3, 4,
|
||||
5, 6, 7
|
||||
]
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
pass
|
||||
|
||||
func generate_ball_state() -> Dictionary:
|
||||
var state: Dictionary = {}
|
||||
|
||||
for i in COLORED_BALLS.size():
|
||||
var ball_name = COLORED_BALLS[i]
|
||||
var points = COLORED_BALLS_POINTS[i]
|
||||
|
||||
state[ball_name] = BALL_STATE.duplicate_deep()
|
||||
state[ball_name]["points"] = points
|
||||
|
||||
# NOTE: Red balls
|
||||
for i: int in range(1, 16):
|
||||
var ball_name = "%02d_ball" % i
|
||||
state[ball_name] = BALL_STATE.duplicate_deep()
|
||||
state[ball_name]["points"] = 1
|
||||
|
||||
ball_state = state
|
||||
return state
|
||||
|
||||
func is_colored_ball(ball_name: String) -> bool:
|
||||
return ball_name in COLORED_BALLS
|
||||
|
||||
func reap_ball(ball: Node3D) -> void:
|
||||
super(ball)
|
||||
|
||||
if is_colored_ball(ball.name):
|
||||
# TODO: Colored ball must not be be destroyed. Handle rule...
|
||||
ball_state[ball.name]["valid_end"] = false
|
||||
pass
|
||||
|
||||
func process_ball(ball: Node3D) -> void:
|
||||
@@ -19,6 +54,9 @@ func process_ball(ball: Node3D) -> void:
|
||||
if is_colored_ball(ball.name):
|
||||
# TODO: Colored ball must not be be processed before red ball sunk.
|
||||
# Handle rule...
|
||||
var red_ball_sunk = true
|
||||
if not red_ball_sunk:
|
||||
pass
|
||||
pass
|
||||
|
||||
func handle_switch_user() -> void:
|
||||
@@ -31,9 +69,11 @@ func handle_switch_user() -> void:
|
||||
|
||||
if balls_sunk.is_empty():
|
||||
Globals.game_state.switch_active_player()
|
||||
turn_count += 1
|
||||
return
|
||||
|
||||
# TODO: Handle points, etc
|
||||
# Globals.multiplayer_data.current_turn_player_id
|
||||
|
||||
balls_sunk.clear()
|
||||
turn_count += 1
|
||||
|
||||
Reference in New Issue
Block a user