2048-Shooter/Main Scenes/GameOver.tscn
2024-02-29 21:53:12 +01:00

132 lines
3.5 KiB
Plaintext

[gd_scene load_steps=4 format=2]
[ext_resource path="res://Font/super-legend-boy-font/SuperLegendBoy-4w8Y.ttf" type="DynamicFontData" id=1]
[sub_resource type="GDScript" id=1]
script/source = "extends Control
# Declare member variables here. Examples:
# var a = 2
# var b = \"text\"
var timer = Timer.new()
# Called when the node enters the scene tree for the first time.
func _ready():
$HTTPRequest.connect(\"request_completed\", self, \"_on_HTTPRequest_request_completed\")
$VBoxContainer2/Label.text = str(Globals.score)
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Button_pressed():
$VBoxContainer/Button.text = 'wait'
var player = $VBoxContainer2/LineEdit
var score = $VBoxContainer2/Label
if player.text != \"Player\":
send_create_score_request(player.text, \"game1\", score.text.to_int())
pass # Replace with function body.
func send_create_score_request(player: String, game: String, score: int):
var url := \"https://schmidti.digital/create_score/\"
# Überprüfen, ob sich das Spiel im Debug-Modus befindet
#if OS.is_debug_build():
#url = \"http://localhost:8000/create_score/\"
var request_data := {
\"player\": player,
\"game\": game,
\"score\": score
}
var headers := [\"Content-Type: application/json\"]
# Konvertieren der Daten in einen JSON-String
var json_data := to_json(request_data)
# Senden der POST-Anfrage mit den Daten und Headern
var error = $HTTPRequest.request(url, headers, true, HTTPClient.METHOD_POST, json_data)
if error != OK:
print(\"Fehler beim Senden der Anfrage: \", error)
else:
print(\"Anfrage gesendet\")
func _on_HTTPRequest_request_completed(result, response_code, headers, body):
# Diese Funktion wird aufgerufen, wenn die Anfrage abgeschlossen ist
var response = parse_json(body.get_string_from_utf8())
print(\"Antwort: \", response)
get_tree().change_scene(\"res://Main Scenes/MainMenu.tscn\")
"
[sub_resource type="DynamicFont" id=2]
size = 40
font_data = ExtResource( 1 )
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = SubResource( 1 )
__meta__ = {
"_edit_vertical_guides_": [ -240.0 ]
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -64.0
margin_top = -24.0
margin_right = 64.0
margin_bottom = 40.0
[node name="Button" type="Button" parent="VBoxContainer"]
margin_right = 128.0
margin_bottom = 64.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Restart"
icon_align = 1
[node name="VBoxContainer2" type="VBoxContainer" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -200.0
margin_top = -336.0
margin_right = 200.0
margin_bottom = -152.0
[node name="LineEdit" type="LineEdit" parent="VBoxContainer2"]
margin_right = 400.0
margin_bottom = 90.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
custom_fonts/font = SubResource( 2 )
text = "Player"
align = 1
[node name="Label" type="Label" parent="VBoxContainer2"]
margin_top = 116.0
margin_right = 400.0
margin_bottom = 161.0
size_flags_horizontal = 3
size_flags_vertical = 6
custom_fonts/font = SubResource( 2 )
text = "10"
align = 1
uppercase = true
[node name="HTTPRequest" type="HTTPRequest" parent="."]
[connection signal="pressed" from="VBoxContainer/Button" to="." method="_on_Button_pressed"]
[connection signal="request_completed" from="HTTPRequest" to="." method="_on_HTTPRequest_request_completed"]