jessawitzel / battleship Goto Github PK
View Code? Open in Web Editor NEWTerminal battleship game
Terminal battleship game
Edit the game board to use O's for 'Ocean' instead of 'S' for 'Sea'.
Create a function that changes the gameboard to reflect 'X' instead of the current value at the hit site after you have made a guess/attack.
If you hit a ship site it should change the ship value from 'C' or 'U' or 'D' to 'X' but also put into a new list the ship value that you are losing.
hit_ships = []
Use the hit_ships and .count() to create a function that will print "You destroyed my [shipname]" when the count of a certain ship's value == the ship's size.
Use len() to print "Congratulations! You won!" if the length of hit_ships == sum of all of the placed ship's sizes.
Rows should be structured as letters and columns should be real numbers, not indices.
Add tests that test the new attack function. Create variable hit_ships which is referenced in attack.
Create a dictionary of ship types and lengths that can be used when creating your Battleship Board. https://en.wikipedia.org/wiki/Battleship_(game)
Letter Class of ship Size
'C' Carrier 5
'B' Battleship 4
'R' Cruiser 3
'S' Submarine 3
'D' Destroyer 2
Function that allows a player to print his board with his ships and which have been sunk or hit.
Create a function that allows a player to print their opponents board which shows the player's hits and misses.
Currently in the Board
class there is looping logic that is duplicated between place_ship
and collides
.
I recommend we create a method called get_sequence
. This method would take the starting row
, column
, and sequence_size
as well as the direction the sequence should be captured. get_sequence
would return all of the values from that sequence in the board.
For example given the board below, if you wanted to get the sequence of C
, you would call get_sequence(row=1, col=2, seq_sz=3, direction='NS') # NS (NorthSouth)
. Which would return a list of the values from that sequence, ['C', 'C', 'C']
allowing you to easily check for collisions when placing a ship.
SSSSS
SSCSS
SSCSS
SSCSS
SSSSS
If you sank a ship, check to see if all ships have been sank and if they have end the game. You win!
create sank_ships list = []
if sank(ship) == True, check length of sank_ships and if length is 5, end game.
Define a function that receives raw input from the player on where they want to place each ship and uses place_ship to alter the board.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.