battleships.rb
## CARRIES OUT ACTION AND RETURNS OUTCOME TO USER.  RETURNS GAME BOARD ARRAY AFTER ACTION HAS FINISHED ##

CARRIES OUT ACTION AND RETURNS OUTCOME TO USER.  RETURNS GAME BOARD ARRAY AFTER ACTION HAS FINISHED
CARRIES OUT ACTION AND RETURNS OUTCOME TO USER . RETURNS GAME BOARD ARRAY AFTER ACTION HAS FINISHED
def shoot(column,row,board)
	puts "----------------------------------------------------------------------------"
	puts "  RESULTS".white.on_black
	puts ""
	case board[row][column]
	when 0  
		board[row][column] = 6
		@numTurns += 1
		print "  "
		print "It's just empty water at at #{column}, #{row}!".white.on_blue
		if nearMissCheck(board,row,column)
			print "  ||  "
			puts "That was a near miss though!".cyan
			puts ""
		else
			print "  ||"
		end
		@outcome = "Hit empty water :("
	when 1  
		board[row][column] = 7
		@numTurns += 1
		ship1LeftToHit = 0 
		board.each do |column|
			ship1LeftToHit += column.count(1)
		end
		print "  "
		print "You hit Ship #1 at #{column}, #{row}!".cyan.on_red
		print "  ||  "
		ship1LeftToHit.times {print "S".white.on_red}  
		(5-ship1LeftToHit).times {print "X".red.on_red}
		if ship1LeftToHit == 0
			print "  ||  "
			puts "YOU HAVE DESTROYED THE AIRCRAFT CARRIER!\n".red
			@outcome = "DESTROYED Aircraft Carrier (Ship #1)!"
		else
			print "  ||"
			@outcome = "Hit Ship #1!"
		end
	when 2  
		board[row][column] = 7
		@numTurns += 1
		ship2LeftToHit = 0 
		board.each do |column|
			ship2LeftToHit += column.count(2)
		end
		print "  "
		print "You hit Ship #2 at #{column}, #{row}!".cyan.on_red
		print "  ||  "
		ship2LeftToHit.times {print "S".white.on_red}  
		(4-ship2LeftToHit).times {print "X".red.on_red}
		if ship2LeftToHit == 0
			print "  ||  "
			puts "YOU HAVE DESTROYED THE CRUISER!\n".red
			@outcome = "DESTROYED Cruiser (Ship #2)!"
		else
			print "  ||"
			@outcome = "Hit Ship #2!"
		end
	when 3  
		board[row][column] = 7
		@numTurns += 1
		ship3LeftToHit = 0 
		board.each do |column|
			ship3LeftToHit += column.count(3)
		end
		print "  "
		print "You hit Ship #3 at #{column}, #{row}!".cyan.on_red
		print "  ||  "
		ship3LeftToHit.times {print "S".white.on_red}  
		(3-ship3LeftToHit).times {print "X".red.on_red}
		if ship3LeftToHit == 0
			print "  ||  "
			puts "YOU HAVE DESTROYED A DESTROYER!\n".red
			@outcome = "DESTROYED DESTROYER (Ship #3)!"
		else
			print "  ||"
			@outcome = "Hit Ship #3!"
		end
	when 4  
		board[row][column] = 7
		@numTurns += 1
		ship4LeftToHit = 0 
		board.each do |column|
			ship4LeftToHit += column.count(4)
		end
		print "  "
		print "You hit Ship #4 at #{column}, #{row}!".cyan.on_red
		print "  ||  "
		ship4LeftToHit.times {print "S".white.on_red}  
		(3-ship4LeftToHit).times {print "X".red.on_red}
		if ship4LeftToHit == 0
			print "  ||  "
			puts "YOU HAVE DESTROYED A DESTROYER!\n".red
			@outcome = "DESTROYED Destroyer (Ship #4)!"
		else
			print "  ||"
			@outcome = "Hit Ship #4!"
		end
	when 5  
		board[row][column] = 7
		@numTurns += 1
		ship5LeftToHit = 0 
		board.each do |column|
			ship5LeftToHit += column.count(5)
		end
		print "  "
		print "You hit Ship #5 at #{column}, #{row}!".cyan.on_red
		print "  ||  "
		ship5LeftToHit.times {print "S".white.on_red}  
		(2-ship5LeftToHit).times {print "X".red.on_red}
		if ship5LeftToHit == 0
			print "  ||  "
			puts "YOU HAVE DESTROYED THE SUBMARINE!\n".red
			@outcome = "DESTROYED Submarine (Ship #5)!"
		else
			print "  ||"
			@outcome = "Hit Ship #5!"
		end
	else
		print "\n  You've already shot there! Try again.".red
		@outcome = "Already hit here"
	end
	return board
end
def shoot ( column , row , board ) puts "----------------------------------------------------------------------------" puts "  RESULTS" . white . on_black puts "" case board [ row ] [ column ] when 0 board [ row ] [ column ] = 6 @numTurns += 1 print "  " print "It's just empty water at at #{column}, #{row}!" . white . on_blue if nearMissCheck ( board , row , column ) print "  ||  " puts "That was a near miss though!" . cyan puts "" else print "  ||" end @outcome = "Hit empty water :(" when 1 board [ row ] [ column ] = 7 @numTurns += 1 ship1LeftToHit = 0 board . each do | column | ship1LeftToHit += column . count ( 1 ) end print "  " print "You hit Ship #1 at #{column}, #{row}!" . cyan . on_red print "  ||  " ship1LeftToHit . times { print "S" . white . on_red } ( 5 - ship1LeftToHit ) . times { print "X" . red . on_red } if ship1LeftToHit == 0 print "  ||  " puts "YOU HAVE DESTROYED THE AIRCRAFT CARRIER!\n" . red @outcome = "DESTROYED Aircraft Carrier (Ship #1)!" else print "  ||" @outcome = "Hit Ship #1!" end when 2 board [ row ] [ column ] = 7 @numTurns += 1 ship2LeftToHit = 0 board . each do | column | ship2LeftToHit += column . count ( 2 ) end print "  " print "You hit Ship #2 at #{column}, #{row}!" . cyan . on_red print "  ||  " ship2LeftToHit . times { print "S" . white . on_red } ( 4 - ship2LeftToHit ) . times { print "X" . red . on_red } if ship2LeftToHit == 0 print "  ||  " puts "YOU HAVE DESTROYED THE CRUISER!\n" . red @outcome = "DESTROYED Cruiser (Ship #2)!" else print "  ||" @outcome = "Hit Ship #2!" end when 3 board [ row ] [ column ] = 7 @numTurns += 1 ship3LeftToHit = 0 board . each do | column | ship3LeftToHit += column . count ( 3 ) end print "  " print "You hit Ship #3 at #{column}, #{row}!" . cyan . on_red print "  ||  " ship3LeftToHit . times { print "S" . white . on_red } ( 3 - ship3LeftToHit ) . times { print "X" . red . on_red } if ship3LeftToHit == 0 print "  ||  " puts "YOU HAVE DESTROYED A DESTROYER!\n" . red @outcome = "DESTROYED DESTROYER (Ship #3)!" else print "  ||" @outcome = "Hit Ship #3!" end when 4 board [ row ] [ column ] = 7 @numTurns += 1 ship4LeftToHit = 0 board . each do | column | ship4LeftToHit += column . count ( 4 ) end print "  " print "You hit Ship #4 at #{column}, #{row}!" . cyan . on_red print "  ||  " ship4LeftToHit . times { print "S" . white . on_red } ( 3 - ship4LeftToHit ) . times { print "X" . red . on_red } if ship4LeftToHit == 0 print "  ||  " puts "YOU HAVE DESTROYED A DESTROYER!\n" . red @outcome = "DESTROYED Destroyer (Ship #4)!" else print "  ||" @outcome = "Hit Ship #4!" end when 5 board [ row ] [ column ] = 7 @numTurns += 1 ship5LeftToHit = 0 board . each do | column | ship5LeftToHit += column . count ( 5 ) end print "  " print "You hit Ship #5 at #{column}, #{row}!" . cyan . on_red print "  ||  " ship5LeftToHit . times { print "S" . white . on_red } ( 2 - ship5LeftToHit ) . times { print "X" . red . on_red } if ship5LeftToHit == 0 print "  ||  " puts "YOU HAVE DESTROYED THE SUBMARINE!\n" . red @outcome = "DESTROYED Submarine (Ship #5)!" else print "  ||" @outcome = "Hit Ship #5!" end else print "\n  You've already shot there! Try again." . red @outcome = "Already hit here" end return board end
CARRIES OUT ACTION AND RETURNS OUTCOME TO USER.
CARRIES OUT ACTION AND RETURNS OUTCOME TO USER .
#Hidden water square
 #Ship #1 hidden
 # Defaults counter value to 0 before count
 # Graphically displays how many parts of this ship are still left to hit.
 #Ship #2 Hidden
 # Defaults counter value to 0 before count
 # Graphically displays how many parts of this ship are still left to hit.
 #Ship #3 Hidden
 # Defaults counter value to 0 before count
 # Graphically displays how many parts of this ship are still left to hit.
 #Ship #4 Hidden
 # Defaults counter value to 0 before count
 # Graphically displays how many parts of this ship are still left to hit.
 #Ship #5 hidden
 # Defaults counter value to 0 before count
 # Graphically displays how many parts of this ship are still left to hit.

column
<not_specific>
row
<not_specific>
board
<not_specific>