mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-20 16:20:18 +01:00
Can only play cards until energy is used up
This commit is contained in:
parent
3c19740994
commit
01bc31b210
4 changed files with 67 additions and 18 deletions
19
card.gd
19
card.gd
|
@ -62,11 +62,9 @@ func _unhandled_input(event):
|
|||
game.dragged_object = null
|
||||
modulate.a = 1
|
||||
|
||||
|
||||
if get_viewport().get_mouse_position().y < get_viewport().size.y/3*2:
|
||||
if arg_number == 0 :
|
||||
$"../../..".terminal.send_command($Label.text)
|
||||
buuurn()
|
||||
try_play($Label.text)
|
||||
else:
|
||||
move_back()
|
||||
else:
|
||||
|
@ -99,8 +97,8 @@ func move_back():
|
|||
|
||||
func buuurn():
|
||||
queue_free()
|
||||
$"..".draw_rand_card()
|
||||
#$"..".arrange_cards()
|
||||
#$"..".draw_rand_card()
|
||||
$"..".arrange_cards()
|
||||
|
||||
func dropped_on(other):
|
||||
var full_command = ""
|
||||
|
@ -110,8 +108,7 @@ func dropped_on(other):
|
|||
if ($Label.text.begins_with("git checkout") or $Label.text.begins_with("git rebase")) and other.id.begins_with("refs/heads"):
|
||||
argument = Array(other.id.split("/")).pop_back()
|
||||
full_command = $Label.text + " " + argument
|
||||
$"../../..".terminal.send_command(full_command)
|
||||
buuurn()
|
||||
try_play(full_command)
|
||||
# 2:
|
||||
# if _first_argument:
|
||||
# full_command = $Label.text + " " + _first_argument + " " + other.id
|
||||
|
@ -119,3 +116,11 @@ func dropped_on(other):
|
|||
# buuurn()
|
||||
# else:
|
||||
# _first_argument = other.id
|
||||
|
||||
func try_play(command):
|
||||
if game.energy >= energy:
|
||||
$"../../..".terminal.send_command(command)
|
||||
buuurn()
|
||||
game.energy -= energy
|
||||
else:
|
||||
move_back()
|
||||
|
|
34
cardgame.gd
34
cardgame.gd
|
@ -2,9 +2,9 @@ extends Control
|
|||
|
||||
var cards = [
|
||||
{
|
||||
"command": 'git add .',
|
||||
"command": 'git commit --allow-empty -m "$RANDOM"',
|
||||
"arg_number": 0,
|
||||
"description": "Add all files in the working directory to the index.",
|
||||
"description": "Add a new commit under HEAD.",
|
||||
"energy": 1
|
||||
},
|
||||
{
|
||||
|
@ -13,18 +13,19 @@ var cards = [
|
|||
"description": "Point HEAD to a branch or commit, and update the index and the working directory.",
|
||||
"energy": 1
|
||||
},
|
||||
{
|
||||
"command": 'git add .',
|
||||
"arg_number": 0,
|
||||
"description": "Add all files in the working directory to the index.",
|
||||
"energy": 1
|
||||
},
|
||||
|
||||
{
|
||||
"command": 'touch "file$RANDOM"',
|
||||
"arg_number": 0,
|
||||
"description": "Create a new file.",
|
||||
"energy": 2
|
||||
},
|
||||
{
|
||||
"command": 'git commit --allow-empty -m "$RANDOM"',
|
||||
"arg_number": 0,
|
||||
"description": "Add a new commit under HEAD.",
|
||||
"energy": 1
|
||||
},
|
||||
{
|
||||
"command": 'git checkout -b "$RANDOM"',
|
||||
"arg_number": 0,
|
||||
|
@ -92,13 +93,27 @@ func _ready():
|
|||
redraw_all_cards()
|
||||
arrange_cards()
|
||||
|
||||
func _process(delta):
|
||||
if $Energy:
|
||||
$Energy.text = str(game.energy)
|
||||
|
||||
#func _update_repo():
|
||||
# $Repository.update_everything()
|
||||
# $RepositoryRemote.update_everything()
|
||||
|
||||
func draw_rand_card():
|
||||
var deck = []
|
||||
|
||||
for card in cards:
|
||||
deck.push_back(card)
|
||||
|
||||
# We want a lot of commit and checkout cards!
|
||||
for i in range(5):
|
||||
deck.push_back(cards[0])
|
||||
deck.push_back(cards[1])
|
||||
|
||||
var new_card = preload("res://card.tscn").instance()
|
||||
var card = cards[randi() % cards.size()]
|
||||
var card = deck[randi() % deck.size()]
|
||||
new_card.command = card.command
|
||||
new_card.arg_number = card.arg_number
|
||||
new_card.description = card.description
|
||||
|
@ -137,6 +152,7 @@ func arrange_cards():
|
|||
tween.start()
|
||||
|
||||
func redraw_all_cards():
|
||||
game.energy = 5
|
||||
for card in get_tree().get_nodes_in_group("cards"):
|
||||
card.queue_free()
|
||||
for i in range(7):
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]
|
||||
[ext_resource path="res://drop_area.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://repository.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://cardgame.gd" type="Script" id=4]
|
||||
[ext_resource path="res://terminal.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://fonts/big.tres" type="DynamicFont" id=6]
|
||||
|
||||
[node name="Cardgame" type="Node2D"]
|
||||
script = ExtResource( 4 )
|
||||
|
@ -49,5 +50,18 @@ text = "Draw new cards"
|
|||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Energy" type="Label" parent="."]
|
||||
modulate = Color( 0.431373, 0.792157, 0.423529, 1 )
|
||||
margin_left = 35.3364
|
||||
margin_top = 796.429
|
||||
margin_right = 75.3364
|
||||
margin_bottom = 845.429
|
||||
rect_scale = Vector2( 2, 2 )
|
||||
custom_fonts/font = ExtResource( 6 )
|
||||
text = "3"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="command_done" from="Terminal" to="." method="_update_repo"]
|
||||
[connection signal="pressed" from="Button" to="." method="redraw_all_cards"]
|
||||
|
|
16
cards.tscn
16
cards.tscn
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]
|
||||
[ext_resource path="res://fonts/big.tres" type="DynamicFont" id=2]
|
||||
[ext_resource path="res://cardgame.gd" type="Script" id=3]
|
||||
|
||||
[node name="Cards" type="Control"]
|
||||
|
@ -24,4 +25,17 @@ text = "Draw new cards"
|
|||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Energy" type="Label" parent="."]
|
||||
modulate = Color( 0.431373, 0.792157, 0.423529, 1 )
|
||||
margin_left = 28.2219
|
||||
margin_top = 16.6766
|
||||
margin_right = 68.2219
|
||||
margin_bottom = 65.6766
|
||||
rect_scale = Vector2( 2, 2 )
|
||||
custom_fonts/font = ExtResource( 2 )
|
||||
text = "3"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="pressed" from="Button" to="." method="redraw_all_cards"]
|
||||
|
|
Loading…
Reference in a new issue