How to make guessing number game in matlab?

59 次查看(过去 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
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
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 :) .

类别

Help CenterFile Exchange 中查找有关 Number games 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by