Tictactoe游戏意外结束输入期待IF MySQL

时间:2015-11-28 03:51:27

标签: mysql syntax triggers tic-tac-toe

我正在创建一个tic-tac-toe游戏的触发器,用于检查玩家或计算机是否赢了。我认为它编码正确,但最后它说“语法错误,意外的end_of_input,期待IF”我的分隔符编码正确,但这似乎是问题。这是代码:

 delimiter //
create trigger check_winner
after update on grid
for each row

begin
declare message varchar(100);

select A into @A1 from grid where ttt = 1;
select A into @A2 from grid where ttt = 2;
select A into @A3 from grid where ttt = 3;
select B into @B1 from grid where ttt = 1;
select B into @B2 from grid where ttt = 2;
select B into @B3 from grid where ttt = 3;
select C into @C1 from grid where ttt = 1;
select C into @C2 from grid where ttt = 2;
select C into @C3 from grid where ttt = 3;


-- Horizontal wins
    if @A1 = @B1 and @B1 = @C1 then     
        set message = concat('Player ', @A1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;


   else if @A2 = @B2 and @B2 = @C2 then     
        set message = concat('Player ', @A2, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;


   else if @A3 = @B3 and @B3 = @C3 then     
        set message = concat('Player ', @A3, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;


-- Vertical wins
    else if @A1 = @A2 and @A2 = @A3 then     
        set message = concat('Player ', @A1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

    else if @B1 = @B2 and @B2 = @B3 then     
        set message = concat('Player ', @B1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

    else if @C1 = @C2 and @C2 = @C3 then     
        set message = concat('Player ', @C1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

-- Diagonal wins
    else if @A1 = @B2 and @B2 = @C3 then     
        set message = concat('Player ', @A1, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

    else if @A3 = @B2 and @B2 = @C1 then     
        set message = concat('Player ', @A3, ' is victorious!');
        signal sqlstate '42000'
        set message_text = message;

-- Game continues
    else 
        set message = 'Game is still ongoing';
        signal sqlstate '42000'
        set message_text = message;

end if;

end// -- error is right here

给予的任何帮助都会有所帮助!

1 个答案:

答案 0 :(得分:1)

更改您的

else if 

elseif

即。删除else和if之间的空格。