Matrix - Python

0

I'm doing a college job that requires me to play the Space Invaders game. I was able to make the matrix of the game and now I need to put the ships inside it, for now it is like this:

Ineedtoprinttheshipssotheylooklikethis:

VVVV

VVVV

Note:Iassign'V'totheship.

CouldsomeonegivemeanideahowIcoulddothis?

Matrix:

matriz=[]foriinrange(LINHA_MAXIMA+1):matriz.append(['']*(COLUNA_MAXIMA+1))

MatrixPrinting:

forlinhainmatriz:print("|", end="")
    for posicao in linha:
        print(posicao, end="")
    print("|", end="")
    print("")
    
asked by anonymous 18.05.2018 / 23:25

1 answer

0

Let's suppose you have a list of tuples that indicates the position of each ship

pos_naves = [(4,3), (5,3), (6,3)]

Where pos_naves [1] = (4,3) gives the position of the nave 1 (x = 4, y = 3), as you already have the matrix, simply put change the characters by 'V'

for x, y in pos_naves:
  matriz[x][y] = 'V'

Then, just draw the array again, it would be good to put the code snippet that does this in a function, since every time you update the game state, you need to update the interface (this design pattern is known as MVC: link )

For the ships to stay in the formation you want:

0..1..2.3

04.09.2018 / 19:36