How to make guessing number game in matlab?
75 views (last 30 days)
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
Manas Shivakumar on 9 Aug 2022
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;
while numb ~= r
numb = input('Guess the number between 1 and 10: ');
n = n+1;
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)
fprintf('Congratulations, you guessed the right number %d!\n', r)
Now it's your turn to complete the rest. You can' expect people to hand out answers to assignments :) .