How to make guessing number game in matlab?
52 次查看(过去 30 天)
显示 更早的评论
my professor ask us to create a game like guessing number, there's a time limit for the guest to guess the number that show up in the screen for like 1-3 seconds and if they failed 3 times then the game is over, and there must be a level up feature as well. How do i start? if you know please give me a guide :(
ps: i am really new to Matlab and barely know a thing
1 个评论
Jan
2022-6-4
Hint: This is not twitter. No # before the tags. Thanks.
Please ask more specifically than "How do i start?". Otherwise the best answer is: Get a computer and switch it on. Install Matlab. Read "Matlab Onramp" to learn the basics. Then try to implement the code and ask a specific question.
回答(1 个)
Manas Shivakumar
2022-8-9
All you need to understand is the requirements of the game and the paradigm/methods needed to code it.
You will need some kind of loop to stay inside untill the user gets the correct answer. You will have to quit if he fails to provide the right answer within the time limit. you might need a mix of timer object and pause command to achive it. To monitor the levels you can maintain a variable that keeps track of your score. Based on the score you can calculte the level. ex: after every 10 points you level up.
Here is a sample code that does something similar:
r = randi([1,10]);
numb = 0;
n = 0;
Numb=[];
while numb ~= r
numb = input('Guess the number between 1 and 10: ');
if ~ismember(numb,Numb)
n = n+1;
Numb=[Numb,numb];
end
if numb < r
fprintf('Your guess (%i) is below the actual number \n', numb)
elseif numb > r
fprintf('Your guess (%i) is above the actual number \n', numb)
else
fprintf('Congratulations, you guessed the right number %d!\n', r)
end
end
Now it's your turn to complete the rest. You can' expect people to hand out answers to assignments :) .
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!