vendredi 3 décembre 2021

How to hide Value in array for Battleship game?

I'm on my way to create an Battleship game however i'm not sure on how to change the 1 in the first players grid to a 0, so that the player can not see where the ship is.

import random

# formatt to access certain grid point print (grid_1[1][2])

grid_1 = [[0, 0, 0, 0],
          [0, 0, 0, 0],
          [0, 0, 0, 0],
          [0, 0, 0, 0]]

row_random = random.randint(0,3)
column_random = random.randint(0,3)
ship_1 = grid_1[row_random][column_random] = 1 
# creates a random spot in the grid where the ship will be 







def Player_1():
 
  for i in grid_1:
    print (i)
    #loops through grid so the output is in row and column form 
  x = int(input("Enter row:"))
  y = int(input("Enter column:"))
  co_ordinates_1 = (grid_1[x][y])
  # user guses where the ship will be
  if co_ordinates_1 == 1:
    print("BATTLESHIP HIT")
  elif co_ordinates_1 != 1:
    print("You missed!")
  # shows the user if they hit the target or not
Player_1()



Aucun commentaire:

Enregistrer un commentaire