- create game board
- while loop
- play game
- update game board
Can't Stop program
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Geoff Hayes
le 20 Jan 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 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!