在我的AS级计算课程中,我们使用Turbo Pascal,对于扩展工作,我的任务是制作二十一点/21风格的纸牌游戏。我决定为一般的纸牌游戏数据结构做一个单元:
unit CardLib;
interface
type
CardSuite = (clubs, diamonds, hearts, spades);
Card = record
name:String;
value:Integer;
suite:CardSuite;
end;
CardDeck = object
cards: Array[0..51] of Card;
freeIndex: Integer;
constructor init;
procedure addNewCard(suite:CardSuite, name:String, value:Integer);
procedure addCard(c:Card);
function drawCard:Card;
destructor done;
end;
CardHand = object
cards: Array[0..51] of Card;
freeIndex: Integer;
constructor init(deck:CardDeck, size:Integer);
function getLowestTotal:Integer; {Aces are worth 1}
function getHighestTotal:Integer; {Aces are worth 11}
procedure addCard(c:Card);
destructor done;
end;
...
我正在 Turbo Pascal 兼容模式下使用 Free Pascal 编译此代码,但出现以下错误:
CardLib.pas(18,39) Fatal: Syntax error, ")" expected but "," found
Fatal: Compilation aborted
Error: /usr/bin/ppcarm returned an error exitcode (normal if you did not specify a source file to be compiled)
如果我注释掉 addNewCard 过程,我会在 CardHand 构造函数中得到同样的错误。知道是什么原因造成的吗?
使用分号分隔参数。
procedure addNewCard(suite:CardSuite; name:String; value:Integer);