最近在做程式語言期末專題,我選的主題是五子棋
不過我在畫棋子的的時候遇到一點困難
我先貼棋子的code:
function f = chess(color, action)
% CHESS.M
% to draw chess
%color = 1;
switch(action)
case 'start'
set(gcf, 'WindowButtonDownFcn', 'chess down');
case 'down'
set(gcf, 'WindowButtonUpFcn', 'chess up');
[x, y] = ginput(1);
%circle(0.125, x, y);
t = linspace(0, 2*pi, 100);
x1 = 0.125 * cos(t) + x;
y1 = 0.125 * sin(t) + y;
hold on;
plot(x1, y1);
if color == 1
fill (x1, y1, 'r');
color = 0;
elseif color == 0
fill(x1, y1, 'b');
color = 1;
end
case 'up'
set(gcf, 'WindowButtonUpFcn', 'chess start');
fprintf('Mouse up!\n');
otherwise
disp('Error');
% draw circle
end
這個function的目的是畫出棋子,並交替畫出紅、藍、紅、藍...
然後我再上棋盤的code:
clc
grid on
axis([-1.75 1.75 -1.75 1.75])
set(gca,'GridLineStyle','-','XTick',[-1.75:0.25:1.75],'YTick',[-1.75:0.25:1.75])
axis square
color = 1;
chess(color, 'start');
現在問題來了
當我畫出棋盤的之後
我去點任意座標時
會出現以下的error:
Error using chess (line 8)
Not enough input arguments.
Error while evaluating figure WindowButtonDownFcn
請問大大們,我到底出錯在哪?不是'start'之後會call自己嗎?為甚麼會說"not enough
input arguments"?請問修正方式?