Skip to content

Instantly share code, notes, and snippets.

@albionbrown
Last active April 27, 2022 16:39
Show Gist options
  • Select an option

  • Save albionbrown/045002da6ac9ce78e9dbdb8ed7b8fcda to your computer and use it in GitHub Desktop.

Select an option

Save albionbrown/045002da6ac9ce78e9dbdb8ed7b8fcda to your computer and use it in GitHub Desktop.
#! /bin/python
import turtle
print("Let's play Battleships!")
columns = 8
rows = 8
line_length = 300
your_ships = []
all_cells = []
def print_grid():
#screen_turtle = turtle.Turtle()
#screen_turtle.bgcolor('blue')
grid_turtle = turtle.Turtle()
grid_turtle.penup()
grid_turtle.speed("fastest")
# Draw rows
grid_turtle.setx(-100)
grid_turtle.sety(100)
grid_turtle.pendown()
for i in range(0, rows):
grid_turtle.forward(line_length)
grid_turtle.penup()
grid_turtle.back(line_length)
grid_turtle.right(90)
grid_turtle.forward(42)
grid_turtle.left(90)
grid_turtle.pendown()
# Draw columns
grid_turtle.setx(-100)
grid_turtle.sety(100)
grid_turtle.pendown()
grid_turtle.right(90)
for i in range(0, columns):
grid_turtle.forward(line_length)
grid_turtle.penup()
grid_turtle.back(line_length)
grid_turtle.left(90)
grid_turtle.forward(42)
grid_turtle.right(90)
grid_turtle.pendown()
# Set up the game
print_grid()
print("Your turn to place your battleships")
column = input("Enter the column: ")
row = input("Enter the row: ")
orientation = input("Enter the orientation. H for horizontal and V for vertical")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment