[问题]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