mercredi 26 octobre 2016

Random ints with more specific range python

I'm trying to design a basic Battleships style game, where the ship takes up 2 spaces on a 5x5 board.

I am randomly generating one of the co-ordinates and trying to randomly generate 2nd co-ordinate to be within 1 space of the last number. Here is my code

coordinate1x = random.randint(0,4)
coordinate1y = random.randint(0,4)
coordinate1 = [coordinate1x, coordinate1y]

coordinate2x = random.randint(coordinate1x, coordinate1x + 1)
coordinate2y = random.randint(coordinate1y, coordinate1y + 1)
coordinate2 = [coordinate2x, coordinate2y]

battleship_location = [coordinate1, coordinate2]

I am struggling to find the logic to get the correct numbers.

Any help is greatly apprecaited




Aucun commentaire:

Enregistrer un commentaire