save difficulty in prefs and apply it
This commit is contained in:
parent
0c905be6fc
commit
6d788465ab
3 changed files with 68 additions and 17 deletions
|
@ -71,10 +71,10 @@ func _ready() -> void:
|
|||
$Background.rect_size.y = height
|
||||
|
||||
rng.randomize()
|
||||
var piece_size: int = compute_piece_size()
|
||||
padding = compute_padding(piece_size)
|
||||
print("piece size: ", piece_size)
|
||||
print("padding: ", padding)
|
||||
# var piece_size: int = compute_piece_size()
|
||||
# padding = compute_padding(piece_size)
|
||||
# print("piece size: ", piece_size)
|
||||
# print("padding: ", padding)
|
||||
var pieces_order: Array = []
|
||||
for order in range(1, rows * columns + 1):
|
||||
pieces_order.append(order)
|
||||
|
@ -338,8 +338,8 @@ func init(pieces_order: Array, hidden_piece: int) -> void:
|
|||
print("padding: ", padding)
|
||||
|
||||
if pieces.size() > 0:
|
||||
for c in range(columns):
|
||||
for r in range(rows):
|
||||
for c in range(pieces.size()):
|
||||
for r in range(pieces[0].size()):
|
||||
var piece: Piece = pieces[c][r]
|
||||
$Background.remove_child(piece)
|
||||
piece.queue_free()
|
||||
|
@ -358,7 +358,7 @@ func init(pieces_order: Array, hidden_piece: int) -> void:
|
|||
# 4 5 6
|
||||
# 7 8 9
|
||||
piece.order = pieces_order[r + c * rows]
|
||||
print("piece at ", c, ", ", r, " -> order: ", piece.order)
|
||||
# print("piece at ", c, ", ", r, " -> order: ", piece.order)
|
||||
|
||||
# place inside the taquin as indices (i, j)
|
||||
piece.taquin_index = Vector2(c, r)
|
||||
|
@ -395,5 +395,29 @@ func _on_AnimationPlayer_animation_finished(anim_name):
|
|||
update()
|
||||
check_solved()
|
||||
|
||||
func _on_NewGamePanel_start_triggered(config):
|
||||
pass # Replace with function body.
|
||||
func _on_NewGamePanel_start_triggered(preferences):
|
||||
var difficulty = preferences.get_value("game", "difficulty", "normal")
|
||||
match difficulty:
|
||||
"easy":
|
||||
rows = 3
|
||||
columns = 3
|
||||
difficulty = 4
|
||||
"normal":
|
||||
rows = 4
|
||||
columns = 4
|
||||
difficulty = 10
|
||||
"hard":
|
||||
rows = 5
|
||||
columns = 5
|
||||
difficulty = 30
|
||||
_:
|
||||
rows = 4
|
||||
columns = 4
|
||||
difficulty = 10
|
||||
|
||||
var pieces_order: Array = []
|
||||
for order in range(1, rows * columns + 1):
|
||||
pieces_order.append(order)
|
||||
var hidden_piece = rows * columns # Last piece is hidden
|
||||
init(pieces_order, hidden_piece)
|
||||
shuffle(difficulty)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue