returning to the start of the game
1 次查看(过去 30 天)
显示 更早的评论
i am writting the code for battleships and there is a section that if yuo answer no then it should take you back to the beginging however this does not work for me and it finishes the progam.
the whole code is withing a while loop which works, but for some reasson when i hit no it does not go back to the start.
this is what it looks like
s=input ('would you like to see the game stastics 1,yes 2,no:')
switch s
case 1
num_player = 20;
WLT = zeros(num_player,3);
%disp stastics
if have_a_winner
WLT(winner_index,1) = WLT(winner_index,1) + 1;
WLT(loser_index,2) = WLT(loser_index,2) + 1;
else
WLT(player1_index,3) = WLT(player1_index,3) + 1;
WLT(player2_index,3) = WLT(player2_index,3) + 1;
end
case 2
disp('main menu')
playOn = false;
break
end
case 1 works however case 2 chould go back to the beginging but it does not, any ideas on how to fix this
回答(1 个)
Harikrishnan Balachandran Nair
2022-1-24
Hi,
It is my understanding that you have a switch case inside a while loop , and the loop is being terminated on executing the 'break' statement.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!