procedure TForm1.Edit1Change(Sender: TObject); begin if flag=false then //得到控制权,计算机开始自动报数 begin temp1:=s+1; temp2:=s+2; if (temp1 mod 3)=0 then //你报的最后的数字与3取模,若为1,则计算机加2 begin s:=temp1; j:=1; end else if (temp2 mod 3)=0 then //你报的最后的数字与3取模,若为2,则计算机加1 begin s:=temp2; j:=2; end else //否则计算机随机报一个数字或两个数字 begin randomize(); j:=random(2)+1; s:=s+j; end; Button2.Enabled :=true; //计算机报数完毕后把报数按钮设为可用 Button3.Enabled :=true; Button2.Caption :=IntToStr(s+1); //并把报数按钮的Caption设为将要选择的数字 Button3.Caption :=IntToStr(s+2); Edit2.Text :=IntToStr(j); //显示计算机报的个数 ListBox1.Items.Add(计算机报的个数: +IntToStr(j));//写入到历史记录 flag:=true; //交出控制权 Edit1.Text :=IntToStr(s); //显示计算机实际报的数字 if s>=30 then //判断游戏是否结束 begin Button2.Enabled :=false; Button3.Enabled :=false; ShowMessage(嘿嘿,想赢我?动动脑筋再来吧!); end; end; end;