added math mechanics
This commit is contained in:
parent
0f4083a263
commit
0f691de97c
@ -86,14 +86,24 @@ layout_mode = 2
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="UI/PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="question" type="Label" parent="UI/PanelContainer/VBoxContainer/HBoxContainer"]
|
||||
[node name="QUESTION" type="Label" parent="UI/PanelContainer/VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("9_im5ls")
|
||||
theme_override_font_sizes/font_size = 100
|
||||
text = "x * y = "
|
||||
|
||||
[node name="answer" type="LineEdit" parent="UI/PanelContainer/VBoxContainer/HBoxContainer"]
|
||||
[node name="ANSWER" type="LineEdit" parent="UI/PanelContainer/VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("9_im5ls")
|
||||
theme_override_font_sizes/font_size = 100
|
||||
placeholder_text = "?"
|
||||
max_length = 5
|
||||
context_menu_enabled = false
|
||||
emoji_menu_enabled = false
|
||||
shortcut_keys_enabled = false
|
||||
middle_mouse_paste_enabled = false
|
||||
drag_and_drop_selection_enabled = false
|
||||
|
||||
[connection signal="text_submitted" from="UI/PanelContainer/VBoxContainer/HBoxContainer/ANSWER" to="." method="_on_answer_text_submitted"]
|
||||
|
1
godot/scripts/ai.gd
Normal file
1
godot/scripts/ai.gd
Normal file
@ -0,0 +1 @@
|
||||
extends Node
|
1
godot/scripts/ai.gd.uid
Normal file
1
godot/scripts/ai.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dutkdqg1nwysf
|
@ -6,14 +6,66 @@ func _determine_seconds_left() -> float:
|
||||
var difficulty_calc:float = 20/float(GLOBALVARS.difficulty)
|
||||
return difficulty_calc if difficulty_calc >= 3.0 else 3.0
|
||||
|
||||
func _unhandled_key_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("enter"):
|
||||
func _on_answer_text_submitted(_new_text: String) -> void:
|
||||
if GLOBALVARS.selected_player == 0:
|
||||
pass # SUBMIT ANSWER
|
||||
if GLOBALVARS.current_solution == (%ANSWER.text).to_int():
|
||||
GLOBALVARS.selected_player = (GLOBALVARS.selected_player+1)%4
|
||||
GLOBALVARS.difficulty+=1
|
||||
_determine_seconds_left()
|
||||
_generate_question()
|
||||
%ANSWER.text = ""
|
||||
else:
|
||||
%RULE_ENFORCEMENT.explode()
|
||||
cooldown = 120
|
||||
GLOBALVARS.rotation_paused = true
|
||||
GLOBALVARS.players_remaining.erase(0)
|
||||
get_node("players/player_0").queue_free()
|
||||
|
||||
|
||||
func _generate_question() -> void:
|
||||
# 0 - add
|
||||
# 1 - subtract
|
||||
# 2 - multiply
|
||||
# 3 - divide
|
||||
|
||||
var x:int = randi_range(1,100)
|
||||
var y:int = randi_range(1,100)
|
||||
var rand_int:int = randi_range(0,3)
|
||||
var operand:String
|
||||
|
||||
if rand_int == 0:
|
||||
GLOBALVARS.current_solution = x+y
|
||||
operand = "+"
|
||||
elif rand_int == 1:
|
||||
GLOBALVARS.current_solution = x-y
|
||||
operand = "-"
|
||||
elif rand_int == 2:
|
||||
x = randi_range(0,10) # simplify multiplication
|
||||
y = randi_range(0,10)
|
||||
GLOBALVARS.current_solution = x*y
|
||||
operand = "*"
|
||||
elif rand_int == 3:
|
||||
operand = "/"
|
||||
while x%y != 0: # keep going til the remainder is 0
|
||||
x = randi_range(0,100)
|
||||
y = randi_range(1,100)
|
||||
|
||||
@warning_ignore('integer_division')
|
||||
GLOBALVARS.current_solution = x/y
|
||||
|
||||
%QUESTION.text = "%s %s %s = " % [x,operand,y]
|
||||
|
||||
func _ready() -> void:
|
||||
_determine_seconds_left()
|
||||
_generate_question()
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if not GLOBALVARS.rotation_paused:
|
||||
GLOBALVARS.seconds_left -= 0.01666666667
|
||||
if GLOBALVARS.selected_player == 0:
|
||||
%ANSWER.editable = true
|
||||
else:
|
||||
%ANSWER.editable = false
|
||||
|
||||
if GLOBALVARS.seconds_left <= 0:
|
||||
%RULE_ENFORCEMENT.explode()
|
||||
@ -28,10 +80,11 @@ func _physics_process(_delta: float) -> void:
|
||||
if len(GLOBALVARS.players_remaining) > 1 and 0 in GLOBALVARS.players_remaining:
|
||||
while GLOBALVARS.selected_player not in GLOBALVARS.players_remaining:
|
||||
GLOBALVARS.selected_player = (GLOBALVARS.selected_player+1)%4
|
||||
_generate_question()
|
||||
elif 0 in GLOBALVARS.players_remaining:
|
||||
pass # WIN CONDITION
|
||||
else:
|
||||
pass # LOSE CONDITION
|
||||
get_tree().change_scene_to_file("res://main_scenes/menu.tscn")
|
||||
|
||||
GLOBALVARS.rotation_paused = false
|
||||
%RULE_ENFORCEMENT.reset_rule_enforcement_device()
|
||||
|
@ -5,10 +5,11 @@ var seconds_left:float = 0.0
|
||||
var difficulty:int = 1
|
||||
var rotation_paused:bool = false
|
||||
var players_remaining:Array = [0,1,2,3]
|
||||
var current_solution:int
|
||||
|
||||
func reset_variables() -> void:
|
||||
selected_player = 0
|
||||
seconds_left = 5.0
|
||||
seconds_left = 20.0
|
||||
difficulty = 1
|
||||
rotation_paused = false
|
||||
players_remaining = [0,1,2,3]
|
||||
|
Reference in New Issue
Block a user