How to make guessing number game in matlab?
15 views (last 30 days)
Show older comments
koo91 on 4 Jun 2022
Answered: Manas Shivakumar on 9 Aug 2022
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
Jan on 4 Jun 2022
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.
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 :) .
Find more on Conway's Game of Life in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!