2026-08-07 02:50:54 -05:00
|
|
|
class_name Snooker extends BaseMode
|
2026-08-10 21:22:52 -05:00
|
|
|
# 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).
|
|
|
|
|
|
|
|
|
|
|
2026-08-11 23:59:30 -05:00
|
|
|
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
|
|
|
|
|
|
2026-08-12 22:14:03 -05:00
|
|
|
func generate_ball_states() -> Dictionary:
|
2026-08-11 23:59:30 -05:00
|
|
|
var state: Dictionary = {}
|
|
|
|
|
|
|
|
|
|
for i in COLORED_BALLS.size():
|
|
|
|
|
var ball_name = COLORED_BALLS[i]
|
|
|
|
|
var points = COLORED_BALLS_POINTS[i]
|
|
|
|
|
|
2026-08-12 22:14:03 -05:00
|
|
|
state[ball_name] = ball_states.duplicate_deep()
|
2026-08-11 23:59:30 -05:00
|
|
|
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
|
|
|
|
|
|
2026-08-12 22:14:03 -05:00
|
|
|
ball_states = state
|
2026-08-11 23:59:30 -05:00
|
|
|
return state
|
|
|
|
|
|
|
|
|
|
func is_colored_ball(ball_name: String) -> bool:
|
|
|
|
|
return ball_name in COLORED_BALLS
|
|
|
|
|
|
2026-08-07 02:50:54 -05:00
|
|
|
func reap_ball(ball: Node3D) -> void:
|
2026-08-10 21:22:52 -05:00
|
|
|
super(ball)
|
2026-08-07 02:50:54 -05:00
|
|
|
|
2026-08-10 21:22:52 -05:00
|
|
|
if is_colored_ball(ball.name):
|
|
|
|
|
# TODO: Colored ball must not be be destroyed. Handle rule...
|
2026-08-12 22:14:03 -05:00
|
|
|
ball_states[ball.name]["is_foul"] = true
|
2026-08-07 02:50:54 -05:00
|
|
|
|
|
|
|
|
func process_ball(ball: Node3D) -> void:
|
2026-08-10 21:22:52 -05:00
|
|
|
super(ball)
|
2026-08-07 02:50:54 -05:00
|
|
|
|
2026-08-10 21:22:52 -05:00
|
|
|
if is_colored_ball(ball.name):
|
|
|
|
|
# TODO: Colored ball must not be be processed before red ball sunk.
|
|
|
|
|
# Handle rule...
|
2026-08-11 23:59:30 -05:00
|
|
|
var red_ball_sunk = true
|
|
|
|
|
if not red_ball_sunk:
|
2026-08-12 22:14:03 -05:00
|
|
|
ball_states[ball.name]["is_foul"] = true
|
2026-08-07 02:50:54 -05:00
|
|
|
|
|
|
|
|
func handle_switch_user() -> void:
|
2026-08-10 21:22:52 -05:00
|
|
|
push_warning("Balls reaped: ", balls_reaped.size() )
|
|
|
|
|
push_warning("Balls sunk: ", balls_sunk.size() )
|
2026-08-12 22:14:03 -05:00
|
|
|
var switch_player: bool = true
|
2026-08-07 02:50:54 -05:00
|
|
|
|
|
|
|
|
if not balls_reaped.is_empty():
|
2026-08-12 22:14:03 -05:00
|
|
|
for ball_name in balls_reaped:
|
|
|
|
|
ball_states[ball_name]["points"] = -ball_states[ball_name]["points"]
|
|
|
|
|
|
2026-08-07 02:50:54 -05:00
|
|
|
balls_reaped.clear()
|
|
|
|
|
|
2026-08-12 22:14:03 -05:00
|
|
|
if not balls_sunk.is_empty():
|
|
|
|
|
# TODO: Handle points, etc, insure color ball not sunk before red ball
|
|
|
|
|
|
|
|
|
|
switch_player = false
|
|
|
|
|
balls_sunk.clear()
|
|
|
|
|
|
|
|
|
|
if ball_states_finalized():
|
|
|
|
|
process_win_condition()
|
2026-08-07 02:50:54 -05:00
|
|
|
return
|
|
|
|
|
|
2026-08-12 22:14:03 -05:00
|
|
|
if switch_player:
|
|
|
|
|
Globals.game_state.switch_active_player()
|
|
|
|
|
turn_count += 1
|
|
|
|
|
else:
|
|
|
|
|
turn_count += 1
|
2026-08-07 02:50:54 -05:00
|
|
|
|
2026-08-12 22:14:03 -05:00
|
|
|
func process_win_condition() -> void:
|
|
|
|
|
pass
|