mirror of
				https://github.com/JohnBreaux/Boat-Battle.git
				synced 2025-02-04 12:28:35 +00:00 
			
		
		
		
	Partial implementation of the player class
This commit is contained in:
		@@ -14,19 +14,28 @@ func _ready():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Member functions:
 | 
					# Member functions:
 | 
				
			||||||
#   hit: Called when opponent fires on us.
 | 
					#   hit: Called when opponent fires on us.
 | 
				
			||||||
#     Update internal state, and return bool hit/miss
 | 
					#     Update internal state, and return bool hit/miss, hit = true, miss = false
 | 
				
			||||||
func hit():
 | 
					func hit(pos):
 | 
				
			||||||
 | 
						var res = board.hit(pos)
 | 
				
			||||||
 | 
						if res == -1:
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						else:
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
	pass
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#   place_ship: called when ships are placed.
 | 
					#   place_ship: called when ships are placed.
 | 
				
			||||||
#     forwards Ship locations to the Board, so that it may construct a ship
 | 
					#     forwards Ship locations to the Board, so that it may construct a ship
 | 
				
			||||||
#     ship: a list of ship properties {position, orientation, size}
 | 
					#     ship: a list of ship properties {position, orientation, size}
 | 
				
			||||||
 | 
					#		NOTE: Variant? Assuming _ship is an array of lists of ship properties
 | 
				
			||||||
func place_ship(_ship):
 | 
					func place_ship(_ship):
 | 
				
			||||||
 | 
						for i in _ship:
 | 
				
			||||||
 | 
							board.place_ship(i)
 | 
				
			||||||
	pass
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#   setUp: set up the board given the placed ship locations
 | 
					#   setUp: set up the board given the placed ship locations
 | 
				
			||||||
#     translates the ship positions in the Setup UI to board-space, then places each ship
 | 
					#     translates the ship positions in the Setup UI to board-space, then places each ship
 | 
				
			||||||
#     ships: a list of lists of ship properties {{position, orientation, size}, ...}
 | 
					#     ships: a list of lists of ship properties {{position, orientation, size}, ...}
 | 
				
			||||||
 | 
					#		NOTE: What is the difference place_ship() and set_up()
 | 
				
			||||||
func set_up(_ships):
 | 
					func set_up(_ships):
 | 
				
			||||||
	pass
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -46,10 +55,18 @@ func getBoard():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#   forfeit: ends game for player
 | 
					#   forfeit: ends game for player
 | 
				
			||||||
#     Sinks all ships
 | 
					#     Sinks all ships
 | 
				
			||||||
 | 
					#		hits every single board tile
 | 
				
			||||||
func forfeit():
 | 
					func forfeit():
 | 
				
			||||||
	pass
 | 
						for i in 10:
 | 
				
			||||||
 | 
							for j in 10:
 | 
				
			||||||
 | 
								var pos
 | 
				
			||||||
 | 
								pos.x = i
 | 
				
			||||||
 | 
								pos.y = j
 | 
				
			||||||
 | 
								hit(pos)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#   getShipCount: get the number of ships the player has left alive
 | 
					#   getShipCount: get the number of ships the player has left alive
 | 
				
			||||||
func getShipCount():
 | 
					func getShipCount():
 | 
				
			||||||
 | 
						var count = board.get_ship_count()
 | 
				
			||||||
 | 
						return count
 | 
				
			||||||
	pass
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user