I am writing a tic tac toe game using a graph. I used dialog boxes to prompt each user to input their move. I added a button to the graph that can be pressed to clear the board and restart the game. However, the button cannot be pressed while a dialog box is open, and as soon as one user inputs their move a new dialog box pops up for the next move. Essentially, I cannot press the button until all the moves have been made and there are no more dialog boxes. Is there any way to allow the button to be pressed while there is a dialog box open?

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 14 Mär. 2017

0 Stimmen

If you are using inputdlg() then you can use the option 'WindowStyle', 'normal' instead of the default 'modal'. However, if you do that then inputdlg() returns immediately and you have to take special care to wait for the user to answer the question.
You should reconsider using inputdlg()
For example you could use a radio button located in each square. Clicking it would change the color of the square and disable the radio button.
Or you could add the letter 'Q' to indicate 'Quit' or 'R' for 'Replay', instead of using a push button.

3 Kommentare

Carolina Binns
Carolina Binns am 14 Mär. 2017
I tried to figure out how to use a keypress instead of a button, but I couldn't figure out the syntax (kept getting a lot of errors, my textbook doesn't cover it). Any advice on how to do the same thing my button does:
function ExitCallback(ButtonH, EventData)
clf
tictactoe
end
Except using a keypress?
I'll definitely look into using radio buttons too. Thanks!
Walter Roberson
Walter Roberson am 14 Mär. 2017
Currently you have an inputdlg() call. Skip the button and just check whether the user entered 'Q' (quit) or 'R' (replay) in the same place you check for 'A' to 'I' already.
Carolina Binns
Carolina Binns am 14 Mär. 2017
Got it! Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

ES
ES am 14 Mär. 2017

0 Stimmen

Please check if you have used modal property in the dialog box?
%An example which blocks execution until the user responds:
uiwait(msgbox('String','Title','modal'));

1 Kommentar

Walter Roberson
Walter Roberson am 14 Mär. 2017
It looks to me that they are using inputdlg(), which defaults to 'WindowStyle', 'modal'

Melden Sie sich an, um zu kommentieren.

Image Analyst
Image Analyst am 14 Mär. 2017

0 Stimmen

Why not simply have 9 pushbuttons instead of a graph? It would be so much easier. When you press the button, simply change the String on the button from blank to X or O depending on whose turn it is.

Kategorien

Mehr zu Strategy & Logic finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by