[問題]matlab畫五子棋棋子

作者: clh960524 (CLH)   2015-05-28 21:00:42
最近在做程式語言期末專題,我選的主題是五子棋
不過我在畫棋子的的時候遇到一點困難
我先貼棋子的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"?請問修正方式?
作者: physbook (路克)   2015-05-29 11:57:00
會是沒有輸出嗎? f = chess(a, b)
作者: clh960524 (CLH)   2015-05-29 15:03:00
對,不會出現棋子,並出現error
作者: physbook (路克)   2015-05-29 22:08:00
呃,我的意思是你在主程式裡並沒有給chess一個輸出的變數,不過這好像不影響…

Links booklink

Contact Us: admin [ a t ] ucptt.com