based on rules from http://www.hasbro.com/common/instruct/battleship.pdf
- start_game
-
grid_value = 8
-
computer_squares = an empty hash
-
player_squares = an empty hash
-
grid_letter = a
-
grid_number = 1
-
square_status = 'no_ship'
-
hit = 'hit'
###set contender to be player || computer #later can be adapted easily to allow more than 2 players. for now, contender & not_contender.
- setup contender_squares hashes, which requires you to pass in contender
- unless grid_value is 0
- create a two char key of square_name (aka square_name) with a value of square_status
- push the item into the #{contender}_squares hash
- add/increment 1 grid_letter to grid_letter
- add 1 grid_number to grid_number
- decrease grid_value by 1
- end
- unless grid_value is 0
- end
-
ships = {'carrier' => 5, 'battleship' => 4, 'cruiser' => 3, 'submarine' => 3, 'destroyer' => 2}
-
create hashes for ship sets: #{contender}_ships = ships, and then #{not_contender}_ships = ships
- for each ship
- randomly find a placement, which is #rules out diagonal && non-connecting squares from being played
- ship_length computer_squares in the list where either all ship_length grid_letter or
- ship_length grid_numbers are in a row (computer will need more instructions on this, aka grid_check) and
- each square has a square_status of square_status
- ship_length grid_numbers are in a row (computer will need more instructions on this, aka grid_check) and
- ship_length computer_squares in the list where either all ship_length grid_letter or
- after placement, change each square_status to ship_name
- randomly find a placement, which is #rules out diagonal && non-connecting squares from being played
- end
- make grid graphic that varies based on status of each square
- puts contender.capitalize + ''s ' + 'Ocean'
- arrange the grid from contender + '_' + 'squares' hash with letters incremented horizontally and numbers incremented vertically
- if grid_status == 'no_ship'
- show square_name on each contender + '_' + 'square'
- elsif grid_status like '%_hit'
- show 'x' on each contender + '_' + 'square'
- else
- show ship_name on each contender + '_' + 'square'
- end
- show grid_graphic(player)
- until there are no more player_ships
- show the human their list of player_ships keys
- ask the human to type the name of the ship from player_ships they'd like to place on the board and name it selected_ship
- remove selected_ship from player_ships
- show grid_graphic(player)
- ask the human to type in square_name ship_length number of player_squares
- if grid_check of ship_length player_squares
- change each player_square's square_status to ship_name
- else
- prompt the human to give you ship_length player_squares that will pass a grid check
- end
- end
###set contender #will this interfere w above use of contender?
- randomly select player or computer to be the contender and go first
- contender = player || computer
###game play. need to pass in contender
-
show grid_graphic(not_contender)
-
if contender == 'player'
- ask human to enter square_name they'd like to hit, aka selected_#{not_contender}_square #not_contender is pretty negative!
-
else
- have computer randomly select item from player_squares where square_status is not like '%_hit'
-
end
-
if selected_#{not_contender}_square square_status is like '%_hit'
- puts 'Too bad. You already played that square! Start your turn over.' #this isn't in the rules...
-
else
- if square_status for selected_#{not_contender}_square is like '%no_ship'
- puts 'Miss.'
- else
- puts "Hit. #{square_status}" #this will be ship_name
- change square_status to square_status + '_' + 'hit'
- if #{not_contender}_squares has any value ship_name for ship_length number of times #can you do this on a value?
- puts 'You sunk computer's #{ship_name}' for that computer_ship
- else
- end
- if square_status for selected_#{not_contender}_square is like '%no_ship'
-
if #{not_contender}_squares has any value ship_name for ship_length number of times for all #{not_contender}_ships
- if contender == player
- puts 'Congratulations! You sunk all of #{not_contender.capitalize}'s ships!' #could get fancy and ask name of player and set name of computer
- else
- puts "Sorry, #{not_contender.capitalize} sunk all your ships!"
- end
- show grid_graphic(computer)
- show grid_graphic(player)
- ask player 'Want to play again? Enter Yes or No.'
- if player_input == like '%y' #need to ck on capitalization issues? need to deal with non-alpha chars?
- start_game
- else
- 'Thanks for playing Battleship! Come on back now, ya hear?'
- end
- if player_input == like '%y' #need to ck on capitalization issues? need to deal with non-alpha chars?
- if contender == player
-
else
-
end