Clock game,how to set parameters

5 ビュー (過去 30 日間)
Braeden McKeown
Braeden McKeown 2021 年 3 月 13 日
回答済み: Asvin Kumar 2021 年 3 月 15 日
I'm given a problem which states this Write a program that will function as a simple clock game. The program will determine a random target between 5 and 15 seconds. The player gets to set the direction of the clock either as up (1) or down (2). The player may pause (3) the clock and may end (4) the game. Any invalid input will be indicated by the program. If the player is able to stop the clock within 0.25 seconds of the target, the program will praise the player. An example of the game is shown below.
Your target is 9.06 seconds
Menu:
1. Up 2. Down 3. Pause 4. End
Please choose an action: 1
Total time is 0.00. The target time is 9.06.
Please choose an action: 3
Total time is 7.77. The target time is 9.06.
Please choose an action: 1
Total time is 7.77. The target time is 9.06.
Please choose an action: 3
Total time is 10.26. The target time is 9.06.
Please choose an action: 2
Total time is 10.26. The target time is 9.06.
Please choose an action: 3
Total time is 8.74. The target time is 9.06.
Please choose an action: 1
Total time is 8.74. The target time is 9.06.
Please choose an action: 3
Total time is 9.29. The target time is 9.06.
Please choose an action: 4
Total time is 9.29. The target time is 9.06.
Your time is 9.29 with 9 commands.
Winner! Winner! Chicken Dinner!
You are free to tailor the prompts and the game play.
Your program must do the following 
Provide the original clock target 
Use inputs 1, 2, 3, 4 as described 
Indicate an invalid entry 
Update the user as to the time that is on the clock 
Display the clock and the number of commands when the player stops the clock I however do not know how I would set up the 5-15 seconds with all the times for example 6.34 seconds If I could get help with how to set that up ,I could set the rest of the performs up from there Any help would be appreciated Thank you!!

回答 (1 件)

Asvin Kumar
Asvin Kumar 2021 年 3 月 15 日
This is fun. Since this seems ilke a HW problem, I'm just going to list out what functions I think you might find useful:
  1. randi
  2. or rand or randn
  3. rng for reproducibility/debugging
  4. tic and toc
  5. and input
Have a look at MATLAB Onramp (free) if you're looking to quickly learn some MATLAB basics.

カテゴリ

Help Center および File ExchangeClocks and Timers についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by