How to make guessing number game in matlab?
조회 수: 58 (최근 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!