필터 지우기
필터 지우기

Can't Stop program

조회 수: 3 (최근 30일)
ziv koren
ziv koren 2021년 1월 7일
답변: Geoff Hayes 2021년 1월 20일
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 !!

답변 (1개)

Geoff Hayes
Geoff Hayes 2021년 1월 20일
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).

카테고리

Help CenterFile Exchange에서 Video games에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by