- create game board
- while loop
- play game
- update game board
Can't Stop program
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 !!
0 comentarios
Respuestas (1)
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
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).
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!