how to combine a GUI timer with battleship game
Show older comments
hi everyone , so i have a .m file that is a battleship game that works fine , and i need to add to this game a timer.
ive successed to create a timer with gui , but the big problem is that i dont know how to combine them ,
i dont know what should i do maybe add an axes option in the GUI and try to plot the game into it
really need your help thx.
5 Comments
Walter Roberson
on 15 Jun 2019
Create a timer object in an accessible place http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F . Configure the callback for the timer to be a "You did not move quickly enough" function.
Under appropriate circumstances, just before permitting the user to start a move, start the timer. In the code that recognizes that the user has made a valid move, stop the timer.
I do not know how you have the user inputting a move. In some input methods, the user might be able to enter invalid data, such as column that is not A to J. In such a case, you do not want to stop the timer until the user enters something valid, so that you do not permit the user to get extra time to think by deliberately entering an invalid move.
elor cohen
on 15 Jun 2019
Walter Roberson
on 15 Jun 2019
In MATLAB, "figure" and "gui" are the same thing.
The timer that is running in the background -- is that just like a game clock to show how long the game has gone on? Or does it affect game play?
elor cohen
on 15 Jun 2019
Walter Roberson
on 15 Jun 2019
https://www.mathworks.com/matlabcentral/fileexchange/12628-stopwatch shows an example of building a clock based upon a timer object. timer objects execute asynchronously, so you can have that running at the same time the GUI is operating.
Answers (1)
Image Analyst
on 17 Jun 2019
0 votes
FYI, the MATLAB Facebook page has an item on Battleship:
Categories
Find more on Board games 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!