1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-15 05:25:57 +00:00

Pushing what I've done of the game logic.

This commit is contained in:
John 2021-11-11 14:38:10 -06:00
parent 8c4457a883
commit eaa1617b9a
4 changed files with 35 additions and 10 deletions

View File

@ -1,5 +1,8 @@
extends Node extends Node
# Path to Ship class, for instantiating new Ships in code
onready var Ship = load("res://script/game/Gameplay/Ship.gd")
var bottomBoard # Player board var bottomBoard # Player board
var topBoard # Opponent board var topBoard # Opponent board
var ships # list of Ships var ships # list of Ships
@ -7,17 +10,16 @@ var shipCount # number of 'active' (un-sunk) ships
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. ships = []
shipCount = 0
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
# TODO: What state?
func getState(): func getState():
pass pass
func placeShip(): # Place a ship on the board at board-space coordinates
func placeShip(in_position, in_size, in_orientation):
ships.append(Ship.new(in_position, in_size, in_orientation))
pass pass
func getBottomBoard(): func getBottomBoard():
@ -25,3 +27,18 @@ func getBottomBoard():
func getShipCount(): func getShipCount():
pass pass
func _init():
for i in range(10):
bottomBoard.append([])
for _i in range(0, 10):
bottomBoard[i].resize(10)
for i in range(10):
topBoard.append([])
for _i in range(0, 10):
bottomBoard[i].resize(10)
func worldspace_to_boardspace(coordinate:Vector2):
coordinate -= Vector2(36, 36)
coordinate /= Vector2(32,32)
return coordinate

View File

@ -1,5 +1,8 @@
extends Node extends Node
# Path to Player class, for instantiating new Players in code
var Player = "res://script/game/Gameplay/Player.gd"
var players # = player1, player2, ... var players # = player1, player2, ...
var turnCount = 0 var turnCount = 0
var wasHit = false var wasHit = false
@ -8,7 +11,6 @@ var isMultiplayer = false
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
gameStart() gameStart()
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.

View File

@ -1,5 +1,8 @@
extends Node extends Node
# Path to Board class, for instantiating new Boards in code
var Board = "res://script/game/Gameplay/Board.gd"
var pid var pid
var board var board

View File

@ -1,6 +1,9 @@
extends Node extends Node
# This is the rendered element of a "ship", auto-generated when # This is the rendered element of a "ship", generated when the game transitions from the placing state to the gameplay state
#
enum Orientation {X = 1, Y = 0}
var size = 0 # Size of ship in units var size = 0 # Size of ship in units
var position # Coordinates of ship's center. Ship extends [-(size-1 >> 1), (size/2 >> 1)] var position # Coordinates of ship's center. Ship extends [-(size-1 >> 1), (size/2 >> 1)]
@ -34,7 +37,7 @@ func getSunk():
func setSunk(): func setSunk():
sunk = true sunk = true
func makeShip(in_position, in_size, in_orientation): func _init(in_position = Vector2(0,0), in_size = 2, in_orientation = Orientation.X):
position = in_position position = in_position
size = in_size size = in_size
orientation = in_orientation orientation = in_orientation