Can't Stop program

3 visualizaciones (últimos 30 días)
ziv koren
ziv koren el 7 de En. de 2021
Respondida: Geoff Hayes el 20 de En. de 2021
Hello,
In the code attached to the question I am trying to draw multiple rectangles and erasing them randomly.
My problem occurs when I want the game to end, it seems that the loop keeps on ruuning making a new matrix (even though I didn't order it to do so).
Can you please help me find a way to stop the program from running after this line in the code :
cla; text(Limit/2,Limit/2,'Game Over','HorizontalAlignment','center','fontsize',50); pause(2);
And if you can explain to me why the programm does not stop running it will be even better.
Thanks in advance !!

Respuestas (1)

Geoff Hayes
Geoff Hayes el 20 de En. de 2021
ziv - I think the problem is that you are getting stuck in a loop between two functions: DrawBoard and GamePlay. DrawBoard calls GamePlay and then GamePlay will call DrawBoard, and this pattern will continue. You may want to order your code so that it something more like
  • create game board
  • while loop
  • play game
  • update game board
The condition on the while loop will tell you when you are finished. It may be necessary to keep the update game board call in the GamePlay. I've attached something that might work (it also relies on returning the updated SurfaceMatrix with each call to the functions).

Categorías

Más información sobre Video games en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by