1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-14 21:15:58 +00:00

Merge branch 'game-logic' of github.com:StatewideInk/Group12 into game-logic

This commit is contained in:
John 2021-11-11 20:45:56 -06:00
commit 96b5695b12
2 changed files with 86 additions and 5 deletions

View File

@ -43,10 +43,10 @@ anchor_left = 0.912
anchor_top = 0.932
anchor_right = 0.912
anchor_bottom = 0.932
margin_left = 0.319946
margin_top = 0.47998
margin_right = 53.3199
margin_bottom = 20.48
margin_left = -3.68005
margin_top = -4.52002
margin_right = 49.3199
margin_bottom = 15.48
__meta__ = {
"_edit_use_anchors_": false
}
@ -97,5 +97,41 @@ collision_layer = 3
contacts_reported = 1
contact_monitor = true
[node name="Confirm Placement" type="Button" parent="."]
margin_left = 409.0
margin_top = 331.0
margin_right = 543.0
margin_bottom = 351.0
text = "Confirm Placement"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Clear" type="Button" parent="."]
margin_left = 353.0
margin_top = 331.0
margin_right = 406.0
margin_bottom = 351.0
text = "Clear"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AcceptDialog" type="AcceptDialog" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -179.0
margin_top = -29.0
margin_right = 179.0
margin_bottom = 29.0
dialog_text = "You can't confirm placement until all ships are placed"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="VBoxContainer/Forfeit" to="." method="_on_Forfeit_pressed"]
[connection signal="about_to_show" from="ConfirmationDialog" to="." method="_on_ConfirmationDialog_about_to_show"]
[connection signal="pressed" from="Confirm Placement" to="2Ship" method="_on_Confirm_Placement_pressed"]
[connection signal="pressed" from="Clear" to="2Ship" method="_on_Clear_pressed"]

View File

@ -8,11 +8,20 @@ var originalPos # Position before moving the ship
var snapOriginalPos = false # Gets the original position
var vertical = true # Gets ship which is either vertical or horizonal
var startingPos # Starting position of ships before being placed
var TwoShip_StartingPos
var ThreeShipA_StartingPos
var ThreeShipB_StartingPos
var FourShip_StartingPos
var FiveShip_StartingPos
# Called when the node enters the scene tree for the first time.
func _ready():
startingPos = position # Sets the position of ships when game is started to the startingPos variable
pass
TwoShip_StartingPos = get_parent().get_node("2Ship").position
ThreeShipA_StartingPos = get_parent().get_node("3ShipA").position
ThreeShipB_StartingPos = get_parent().get_node("3ShipB").position
FourShip_StartingPos = get_parent().get_node("4Ship").position
FiveShip_StartingPos = get_parent().get_node("5Ship").position
var click_radius = 16
var orient = 0;
@ -217,3 +226,39 @@ func checkOriginalPos(): # Checks whether the position of the ship is the statin
return true
else:
return false
func _on_Clear_pressed():
get_parent().get_node("2Ship").position = TwoShip_StartingPos
get_parent().get_node("2Ship").rotation = 0
get_parent().get_node("3ShipA").position = ThreeShipA_StartingPos
get_parent().get_node("3ShipA").rotation = 0
get_parent().get_node("3ShipB").position = ThreeShipB_StartingPos
get_parent().get_node("3ShipB").rotation = 0
get_parent().get_node("4Ship").position = FourShip_StartingPos
get_parent().get_node("4Ship").rotation = 0
get_parent().get_node("5Ship").position = FiveShip_StartingPos
get_parent().get_node("5Ship").rotation = 0
vertical = true
func check_all_ships_are_on_board():
if !((get_parent().get_node("2Ship").position.x > 17.4 and get_parent().get_node("2Ship").position.x < 335.5) and (get_parent().get_node("2Ship").position.y > 20.2 and get_parent().get_node("2Ship").position.y < 335.5)):
return false
elif !((get_parent().get_node("3ShipA").position.x > 17.4 and get_parent().get_node("3ShipA").position.x < 335.5) and (get_parent().get_node("3ShipA").position.y > 20.2 and get_parent().get_node("3ShipA").position.y < 335.5)):
return false
elif !((get_parent().get_node("3ShipB").position.x > 17.4 and get_parent().get_node("3ShipB").position.x < 335.5) and (get_parent().get_node("3ShipB").position.y > 20.2 and get_parent().get_node("3ShipB").position.y < 335.5)):
return false
elif !((get_parent().get_node("4Ship").position.x > 17.4 and get_parent().get_node("4Ship").position.x < 335.5) and (get_parent().get_node("4Ship").position.y > 20.2 and get_parent().get_node("4Ship").position.y < 335.5)):
return false
elif !((get_parent().get_node("5Ship").position.x > 17.4 and get_parent().get_node("5Ship").position.x < 335.5) and (get_parent().get_node("5Ship").position.y > 20.2 and get_parent().get_node("5Ship").position.y < 335.5)):
return false
else:
return true
func _on_Confirm_Placement_pressed():
if check_all_ships_are_on_board():
print("all ships are on board") # Remove this line
# Convert ships to board pieces
else:
print("You can't confirm placement until all ships are placed")
get_parent().get_node("AcceptDialog").popup()
#OS.alert("You can't confirm placement until all ships are placed", "Confirm Placement")