unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, LazLogger, Unit2, Unit3;
{ 美眉杀游戏策划
游戏的玩法类似于三国杀。
//'1.游戏说明:美腿代表[杀],美胸代表[桃],美臀代表[闪],美脸代表[拆]。'
游戏初期只设计了四张卡牌,分别为,杀,桃,闪和拆。分别以美腿牌,美胸牌,美臀牌
和美脸牌代表。^-^
}
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Edit1: TEdit;
Edit2: TEdit;
Image1: TImage;
Image2: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
ListBox1: TListBox;
ListBox2: TListBox;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
procedure Initial2();
procedure InitialDValue();
procedure AddTest(str1: string);
procedure InitialGame();
procedure IARun();
procedure MeiXiong(str1:string);
procedure MeiTui(str1:string);
procedure MeiLian(str1:string);
procedure updateDLife(int1:Integer);
procedure updateWLife(int1:Integer);
procedure updateDKYPS(int1:Integer);
procedure updateWKYPS(int1:Integer);
function checkDP():boolean;
function checkWP():boolean;
procedure checkWdied();
procedure checkAdied();
public
{ public declarations }
end;
MyRec = record
i1:integer;
s1:string;
r1:Real;
end;
var
Form1: TForm1;
i1,i2,iWLife,iDLife:Integer;
strA1:Array[0..10] of String;
strD1:Array[0..10] of String;
strP1:Array[0..50] of String;
strMTui,strMX,strMTun,strMLian:String;
bool1,boolWMeiTuiA:boolean;
Rec1:MyRec;
procedure getCard(strTmp1:String);
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.checkWdied();
begin
if iWLife = 0 then
begin
showmessage('玩家已经死亡');
self.Button1Click(Form1);
end;
end;
procedure TForm1.checkAdied();
begin
//检查电脑AI是否死亡
if iDLife=0 then
begin
showmessage('电脑已经死亡');
end;
end;
procedure TForm1.updateDKYPS(int1:Integer);
var
str1:String;
begin
str1:='可用牌数: ';
self.Label5.Caption:=str1+inttostr(int1);
end;
procedure TForm1.updateWKYPS(int1:Integer);
var
str1:String;
begin
str1:='可用牌数: ';
self.Label3.Caption:=str1+inttostr(int1);
end;
procedure TForm1.updateWLife(int1:Integer);
var
strTmp1:String;
intTmp1:integer;
begin
{ 我方伤加血 }
intTmp1:= int1 + 1;
//strTmp1:=self.Label1.Caption;
self.Label1.Caption:='Player Life is '+inttostr(int1)+'/3';
end;
function TForm1.checkWP():boolean;
var
str1:string;
ii1,ii2,ii3:integer;
begin
{ 检查玩家手中,是否有牌可以抵挡美腿的攻击 }
ii1:=self.ListBox1.Count;
if ii1=-1 then
begin
showmessage('玩家没有手牌了');
checkWP:=true;
exit
end;
for ii2:=0 to ii1-1 do
begin
str1:=self.ListBox1.Items.Strings[ii2];
if str1='美臀' then
begin
if MessageDlg('提示:是否用手牌中美臀抵挡电脑的美腿?',
mtConfirmation,[mbYes,mbNo],0)=mrYes then
begin
AddTest('玩家出了张美臀牌(闪)');
self.ListBox1.Items.Delete(ii2);
checkWP:=false;
ii3:=self.ListBox1.Items.Count;
self.updateWKYPS(ii3);
exit;
end
else
begin
checkWP:=true;
end;
end;
end;
end;
procedure getCard(strTmp1:String);
var
ii1,ii2,ib1:integer;
str1:string;
begin
//
case strTmp1 of
'A':
begin
for ii2:=0 to 2 do
begin
ii1:=random(4);
case ii1 of
1:
str1:=strMTui;
2:
str1:=strMX;
3:
str1:=strMTun;
else
str1:=strMLian;
end;
Form1.ListBox2.Items.Add(str1);
end;
ib1:=Form1.ListBox2.Items.Count;
Form1.updateDKYPS(ib1);
end;
'Z':
begin
for ii2:=0 to 2 do
begin
ii1:=random(4);
case ii1 of
1:
str1:=strMTui;
2:
str1:=strMX;
3:
str1:=strMTun;
else
str1:=strMLian;
end;
Form1.ListBox1.Items.Add(str1);
end;
ib1:=Form1.ListBox1.Items.Count;
Form1.updateWKYPS(ib1);
end;
end;
end;
procedure TForm1.MeiLian(str1:string);
var
ii1,ii2,ii3:integer;
strTmp1:string;
begin
if str1='zi' then
begin
addTest('玩家出了张美脸牌(拆)');
ii1:=self.ListBox2.Count;
if ii1=-1 then
begin
showmessage('电脑没有牌了');
exit
end;
for ii2:=0 to ii1-1 do
begin
strTmp1:=self.ListBox2.items.strings[ii2];
addTest('电脑手牌:'+strTmp1+' 被拆掉了');
self.ListBox2.Items.Delete(ii2);
ii3:=self.ListBox2.Items.Count;
self.updateDKYPS(ii3);
break;
end;
bool1:=true;
end
else if str1='A' then
begin
addTest('电脑出了张美脸牌(拆)');
ii1:=self.ListBox1.Count;
if ii1=-1 then
begin
showmessage('玩家手中没有牌了');
exit
end;
for ii2:=0 to ii1-1 do
begin
strTmp1:=self.ListBox1.Items.Strings[ii2];
addTest('玩家手牌: '+strTmp1+' 被拆掉了');
self.ListBox1.Items.Delete(ii2);
ii3:=self.ListBox1.Items.Count;
self.updateWKYPS(ii3);
break;
end;
i1:=100;
end;
end;
function TForm1.checkDP():boolean;
var
str1:string;
ii1,ii2,ib1:integer;
begin
ii1:=self.ListBox2.Count;
//showmessage(inttostr(i1));
bool1:=true;
if ii1=-1 then
begin
showmessage('电脑没有手牌');
result:=true;
exit
end;
for ii2:=0 to ii1-1 do
begin
str1:=self.ListBox2.Items.Strings[ii2];
if str1 ='美臀' then
begin
addtest('电脑出了张美臀(闪)');
self.ListBox2.Items.Delete(ii2);
checkDP:=false;
ib1:=self.ListBox2.Items.Count;
self.updateDKYPS(ib1);
exit
//break
end;
end;
checkDP:=true;
//result:=false;
end;
procedure TForm1.InitialDValue();
var
ii1:Integer;
ii2:Integer;
str2,strTmp1:String;
strA1:array of String;
begin
for ii1:=LOW(strD1) to HIGH(strD1) do
begin
ii2:=random(4);
str2:=str2+inttostr(ii2)+',';
case ii2 of
0:
strTmp1:='';
1:
strTmp1:='';
2:
strTmp1:='';
3:
strTmp1:='';
else
strTmp1:='';
end;
strTmp1:='';
end;
str2:=leftstr(str2,length(str2)-1);
self.Edit2.Text:=str2;
end;
procedure TForm1.Initial2();
var
ii1:integer;
str1:string;
begin
str1:='';
for ii1:=low(strp1) to high(strp1) do
begin
strp1[ii1] := inttostr(random(4));
str1 :=str1 + strp1[ii1] + ',';
end;
self.Edit1.Text:=str1;
end;
procedure TForm1.updateDLife(int1:Integer);
var
strTmp1:String;
intTmp1:integer;
begin
{ 电脑加伤血 }
if int1=0 then
begin
end;
//strTmp1
intTmp1:= int1 + 1;
strTmp1:=self.Label2.Caption;
self.Label2.Caption:='AI Life is '+inttostr(int1)+'/3';
end;
procedure TForm1.MeiXiong(str1:string);
begin
if str1='zi' then
begin
if iWLife <3 then
begin
iWLife:=iWLife+1;
addTest('玩家出了张美胸牌(桃)');
self.updateWLife(iWLife);
addTest('玩家生命值加一');
bool1:=true;
end;
end
else if str1='A' then
begin
end;
end;
procedure TForm1.MeiTui(str1:string);
begin
if str1 = 'zi' then
begin
addTest('玩家出了张美腿牌(杀)');
bool1:=true;
boolWMeiTuiA:=false;
//showmessage(booltostr(checkDP()));
if checkDP()=true then
begin
idlife:=idlife -1;
//showmessage(inttostr(idlife));
self.updateDLife(idlife);
self.AddTest('敌方生命值减一');
end;
end
else if str1='A' then
begin
addTest('电脑出了张美腿牌(杀)');
if self.checkWP()=true then
begin
iWLife:=iWLife-1;
self.updateWLife(iWLife);
self.AddTest('玩家生命值减一');
self.checkWdied();
end;
end;
end;
procedure TForm1.IARun();
var
ii1,ii2,ii3,ib1:integer;
intA1:Array[0..10] of integer;
strS1:Array[0..10] of String;
str1:string;
boolT1:boolean;
begin
//电脑开始行动
getCard('A');
boolT1:=true;
ii1:=self.ListBox2.Items.Count;
for ii3:=0 to high(intA1) do
intA1[ii3]:= -1;
for ii3:=0 to high(strS1) do
strS1[ii3]:='-1';
ii3:=0;
for ii2:=0 to ii1-1 do
begin
str1:=self.ListBox2.Items.Strings[ii2];
//showmessage(str1);
if iDLife<3 then
begin
showmessage('电脑尝试自动补血');
if str1 = strMX then
begin
iDLife:=idlife+1;
addTest('电脑出了张美胸牌(桃)');
updateDlife(idlife);
addTest('电脑生命值加一');
intA1[ii3]:=ii2;
ii3:=ii3+1;
end;
end;
//showmessage(booltostr(boolT1));
if booltostr(boolT1)='-1' then
begin
if str1=strMTui then
begin
showmessage('电脑出美腿(杀)攻击玩家');
self.MeiTui('A');
boolT1:=false;
continue
end;
end;
if str1=strMLian then
begin
i1:=0;
showmessage('电脑出美脸(拆)拆玩家手中的牌');
self.MeiLian('A');
if i1=100 then
begin
//self.ListBox2.Items.Delete(ii2);
//showmessage(inttostr(ii2));
intA1[ii3]:=ii2;
strS1[ii3]:=str1;
ii3:=ii3+1;
i1:=0;
end;
continue
end;
end;
//showmessage(inttostr(high(intA1)));
for ii3:=high(intA1) downto 0 do
begin
//showmessage(inttostr(intA1[ii3]));
if intA1[ii3] <> -1 then
begin
//showmessage(inttostr(intA1[ii3]));
self.ListBox2.Items.Delete(intA1[ii3]);
end;
end;
self.Button2.Enabled:=true;
self.Button3.Enabled:=true;
self.Button4.Enabled:=true;
ib1:=self.ListBox2.Items.Count;
self.updateDKYPS(ib1);
getCard('Z');
end;
procedure TForm1.InitialGame();
var
ii2,ii3,ii1,ib1,ib2:Integer;
str1,strWP1,strAP2:String;
begin
iWLife:=3;
iDLife:=3;
strMTui:='美腿';
strMX:='美胸';
strMTun:='美臀';
strMLian:='美脸';
for i1:=LOW(strA1) to HIGH(strA1) do
begin
//Randomize;
ii2:=Random(4);
// showmessage(inttostr(ii2));
//self.Memo1.Lines.Add(inttostr(ii2));
if ii2=3 then
begin
ii3:=0;
str1:=strMTui;
end
else if ii2=2 then
begin
ii3:=0;
str1:=strMX;
end
else if ii2=1 then
begin
ii3:=0;
str1:=strMTun;
end
else
str1:=strMLian;
strA1[i1]:=str1;
end;
for i2:=0 to 6 do
begin
self.ListBox1.Items.Add(strA1[i2]);
//self.ListBox1.Items.Add(strMTui);
end;
self.Label3.Caption:='可用牌数';
for ii1:= 0 to 6 do
begin
ii2:= Random(4);
case ii2 of
1:
str1:=strMTui;
2:
str1:=strMX;
3:
str1:=strMTun;
else
str1:=strMLian;
end;
self.ListBox2.Items.Add(str1);
end;
self.Button6.Enabled:=false;
//AddTest('abc');
self.Memo1.Lines.Add('开始游戏');
addtest('请选择你要出的牌');
self.Label1.Caption:='PLAYER1 Life is '+inttostr(iWLife);
self.Label2.Caption:='AI Life is '+inttostr(iDLife);
ib1:=self.ListBox1.Items.Count;
//showmessage(inttostr(ib1));
strWP1:=self.Label3.Caption;
self.Label3.Caption:=strWP1+': '+inttostr(ib1);
ib2:=self.ListBox2.Items.Count;
strAP2:=self.Label5.Caption;
self.Label5.Caption:=strAP2+': '+inttostr(ib2);
end;
procedure TForm1.AddTest(str1: string);
begin
//self.ListBox1.Items.Add(str1);
//self.memo1.lines.add(str1);
self.Memo1.Lines.Insert(0,str1);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
str1,str2:String;
ii1,ii2:integer;
begin
//确定
ii1:=self.ListBox1.ItemIndex;
//str1:=self.ListBox1.Items[self.ListBox1.ItemIndex];
str1:=self.ListBox1.Items[ii1];
//showmessage(str1);
case str1 of
'美腿':
//showmessage('1');
begin
if boolWMeiTuiA = true then
begin
self.MeiTui('zi');
end
else
begin
showmessage('提示美腿牌,每回合只能出一张');
end;
//bool1:=true;
end;
'美胸':
//showmessage('2');
begin
self.MeiXiong('zi');
end;
'美臀':
showmessage('3');
else
//showmessage('4');
begin
self.MeiLian('zi');
end;
end;
//bool1:=true;
str2:=booltostr(bool1);
//showmessage(str2);
//showmessage(booltostr(bool1));
if booltostr(bool1) ='-1' then
begin
//showmessage(inttostr(ii1));
self.ListBox1.items.Delete(ii1);
ii2:=self.ListBox1.Items.Count;
self.updateWKYPS(ii2);
bool1:=false;
end;
{if bool1 then
showmessage('ok');}
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
//
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
//弃牌
self.Button2.Enabled:=false;
self.button3.Enabled:=false;
self.Button4.Enabled:=false;
boolWMeiTuiA:=true;
self.IARun();
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
//Test1
{self.Memo1.Lines.Add('abc');
i1:=1;
self.AddTest('abc');}
showmessage(inttostr(i2));
end;
procedure TForm1.Button6Click(Sender: TObject);
var
i2:Integer;
begin
//开始游戏
//showmessage(inttostr(i1));
bool1:=false;
boolWMeiTuiA:=true;
self.Initial2();
self.InitialDValue();
self.InitialGame();
self.Button2.Enabled:=true;
self.Button3.Enabled:=true;
self.Button4.Enabled:=true;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
//
Form2.Show;
end;
procedure TForm1.Button8Click(Sender: TObject);
var
i1:Integer;
begin
{DebugLn ('************abc**************');
i1:=Random(100);
showmessage(inttostr(i1)); }
self.Image2.Picture:=Form3.Image1.Picture;
end;
procedure TForm1.Button9Click(Sender: TObject);
var
strlist1:tstringList;
i1:integer;
begin
// Test3
//i2:=2;
//Application.MessageBox('abc','aaa',17 );
strlist1:=TStringList.create;
strlist1.Delimiter:=',';
strlist1.DelimitedText:='aa,bb,cc,dd';
i1:=strlist1.Count;
showmessage(inttostr(i1));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//初始化数据
//i1:=2;
//self.Label6.Caption:='游戏说明:美腿代表[杀],';
//bool1:=false;
boolWMeiTuiA:=false;
Randomize
end;
end.