【发布时间】:2014-06-04 09:37:42
【问题描述】:
我正在进行一个项目,其中某些部分与井字游戏有关。我有 tictactoe.m 文件并想更改代码,以便玩家的选择将通过函数的输出应用,例如,RESULT 参数,而不是用户自己点击屏幕。我的代码的 uicontrol 部分如下。如何通过另一个函数的输出而不是按钮样式来控制游戏?
function B = buttons
% Initialize push buttons and text.
clf
shg
B = zeros(3,3);
M = magic(3); % strategical approach and equivalent game for TicTacToe game.
for k = 1:9
[i,j] = find(k == M);
B(i,j) = uicontrol('style','pushbutton','units','normal', ...
'fontsize',16,'callback','tictactoe(''green'')');
end
uicontrol('style','text','units','normal','pos',[0.30 0.82 0.40 0.10], ...
'fontsize',20,'background',get(gcf,'color'),'tag','toptext');
uicontrol('style','text','units','normal','pos',[0.20 0.72 0.60 0.10], ...
'fontsize',10,'background',get(gcf,'color'),'tag','toptext','string', ...
['Pick single digit numbers. Each digit can be chosen only once. ' ...
'Generate a total of 15 using exactly three digits.'])
uicontrol('style','pushbutton','units','normal','string','Game', ...
'fontsize',12,'position',[.23 .12 .15 .07], ...
'callback','tictactoe(''game'')');
uicontrol('style','pushbutton','units','normal','string','Start', ...
'fontsize',12,'position',[.43 .12 .15 .07], ...
'callback','tictactoe(''start'')');
uicontrol('style','pushbutton','units','normal','string','Exit', ...
'fontsize',12,'position',[.63 .12 .15 .07], ...
'callback','tictactoe(''exit'')');
【问题讨论】:
标签: matlab user-interface