📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "colorform.h"
#include "setpaishuform.h"
#include "speedform.h"
#include "saveunit.h"
#include "diffunit.h"
#include "nameform.h"
#include "aboutmj.h"
#include <Registry.hpp>
#include <assert.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
name[0]="小明";
name[1]="周润发";
name[2]="赵钟祥";
name[3]="冯巩";//姓名 0下 1左 2上 3右
paishu[0]=10; paishu[1]=15; //一条龙 0
paishu[2]=10;paishu[3]=15; //清一色 2
paishu[4]=5;paishu[5]=10; //混一色 (凑一色) 4
paishu[6]=10;paishu[7]=15; //七对 6
paishu[8]=10;paishu[9]=15; //碰碰和 8
paishu[10]=4;paishu[11]=7; //红旗飘飘 10
paishu[12]=10; //杠上开花 12
paishu[13]=1; //炮 13
paishu[14]=2; //自摸 14
paishu[15]=2; //抢杠和 15
paishu[16]=1; //发 16
paishu[17]=1; //字明刻 17
paishu[18]=2; //字暗刻 18
paishu[19]=3; //字明杠 19
paishu[20]=4; //字暗杠 20
paishu[21]=1; //明杠 21
paishu[22]=2; //暗杠 22
paishu[23]=1; //独听(砍张、边张、吊将) 23
paishu[24]=1; //门清 24
avepaishu=0;
for(int i=0;i<25;i++)
avepaishu+=paishu[i];
avepaishu/=25;
moneyperpai=-1.0;
begin =false;
numofgames=0;
imagetype=1;
setbkcolor();
m_sound=true;
imdownming1=imdownming2=imdownan1=imdownan2=NULL;
Randomize();
zhuangjia=random(4);
#ifndef NDEBUG
gamespeed=500;
#else
gamespeed=1000;
#endif
difficult=2;
downsc=leftsc=upsc=rightsc=100;
clearanddrawname();
}
//---------------------------------------------------------------------------
void TForm1::leftclick(int X,int Y)
{
int i;
switch(gamestat)
{
case PlayerWaitForSelectBtn:
i=downplayer.getindex(X,Y);
if(i==102&&(playerPGflag&btPeng))
{
if(laststat==LeftWaitForMo)
{
if(leftcom.wanttohu(false))
{
gamestat=LeftWaitForHu;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=2;
timer->Enabled=true;
break;
}
if(rightcom.wanttohu(false))
{
gamestat=RightWaitForHu;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=2;
timer->Enabled=true;
break;
}
}
else
{
if(rightcom.wanttohu(false)&&laststat!=UpWaitForMo)
{
gamestat=RightWaitForHu;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=1;
timer->Enabled=true;
break;
}
if(upcom.wanttohu(false))
{
gamestat=UpWaitForHu;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=(laststat==UpWaitForMo)?3:1;
timer->Enabled=true;
break;
}
if(leftcom.wanttohu(false)&&laststat!=PlayerWaitForChu)
{
gamestat=LeftWaitForHu;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=3;
timer->Enabled=true;
break;
}
}
downplayer.peng();
gang=false;
clearform(Rect(153,454,648,502));
downplayer.resetbegin();
downplayer.draw(imagetype);
//clearmjot();
//mjot.draw(imagetype);
clearform(Rect(278,120,528,400));
mjots.draw(imagetype);
playerPGflag=btNo;
drawbt(playerPGflag);
gamestat=PlayerWaitForChu;
}
if(i==103&&(playerPGflag&btGang))
{
if(laststat==LeftWaitForMo&&!flag_bugang)
{
if(leftcom.wanttohu(false))
{
gamestat=LeftWaitForHu;
downplayerwanttogang=true;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=2;
timer->Enabled=true;
break;
}
if(rightcom.wanttohu(false))
{
gamestat=RightWaitForHu;
downplayerwanttogang=true;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=2;
timer->Enabled=true;
break;
}
}
else if(!flag_bugang)
{
if(rightcom.wanttohu(false)&&laststat!=UpWaitForMo)
{
gamestat=RightWaitForHu;
downplayerwanttogang=true;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=1;
timer->Enabled=true;
break;
}
if(upcom.wanttohu(false))
{
gamestat=UpWaitForHu;
downplayerwanttogang=true;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=(laststat==UpWaitForMo)?3:1;
timer->Enabled=true;
break;
}
if(leftcom.wanttohu(false)&&laststat!=PlayerWaitForChu)
{
gamestat=LeftWaitForHu;
downplayerwanttogang=true;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=3;
timer->Enabled=true;
break;
}
}
if(!flag_bugang)
downplayer.gang();
else
{
downplayer.bugang();
flag_bugang=false;
}
gang=true;
playerPGflag=btNo;
if(downplayer.canbugang())
{
flag_bugang=true;
playerPGflag=btGang;
}
if(downplayer.canhu(true))
{
flag_zimo=true;
playerPGflag=(btstat)(playerPGflag|btHu);
}
if(playerPGflag!=0)
{
laststat=PlayerWaitForChu;
gamestat=PlayerWaitForSelectBtn;
}
else
gamestat=PlayerWaitForChu;
clearform(Rect(153,454,648,502));
downplayer.resetbegin();
downplayer.draw(imagetype);
clearmjot();
mjot.draw(imagetype);
if(!flag_bugang)
{
clearform(Rect(278,120,528,400));
mjots.draw(imagetype);
}
drawbt(playerPGflag);
}
if(i==104&&(playerPGflag&btHu))
{
if(laststat==LeftWaitForMo&&!flag_zimo)
{
if(leftcom.wanttohu(false))
{
gamestat=LeftWaitForHu;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=2;
timer->Enabled=true;
break;
}
}
if(laststat==UpWaitForMo&&!flag_zimo)
{
if(upcom.wanttohu(false))
{
gamestat=UpWaitForHu;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=3;
timer->Enabled=true;
break;
}
if(leftcom.wanttohu(false))
{
gamestat=LeftWaitForHu;
playerPGflag=btNo;
drawbt(playerPGflag);
loser=3;
timer->Enabled=true;
break;
}
}
int flag_qghu=false;
if(!flag_zimo)
if(rightcom.wanttogang()||leftcom.wanttogang()||upcom.wanttogang())
flag_qghu=true;
if(!flag_zimo)downplayer.painewget=mjots.getnewest();
/*upcom.painewget=11; //另3人补一张其实只是为了不让红旗飘飘函数检测
leftcom.painewget=11;//painewget时出错,此牌对输的'人'来说已经无用
rightcom.painewget=11; */
int loser;
switch(laststat)
{
case LeftWaitForMo:
loser=2;
break;
case PlayerWaitForChu:
loser=1;
break;
case UpWaitForMo:
loser=3;
break;
}
int sc[4];
soundhu();
hupaiform=new Thupai(this,downplayer,leftcom,upcom,rightcom,gang,
flag_qghu,flag_zimo,0,loser,zhuangjia,name,paishu,imagetype);
assert(hupaiform);
hupaiform->calculate(sc);
hupaiform->ShowModal();
begin=false;
delete hupaiform;
downsc+=sc[0];
leftsc+=sc[1];
upsc+=sc[2];
rightsc+=sc[3];
zhuangjia=0;
clearanddrawname();
N3->Enabled=true;
N4->Enabled=true;
N11->Enabled=true;
start->Visible=true;
}
break;
case PlayerWaitForChu:
i=downplayer.getindex(X,Y);
assert(i==50||i==100||(i>=101&&i<=104)||(i>=0&&i<downplayer.getcount()));
if(i<=50)
{
downplayer.select(i,imagetype);
playerPGflag=btChu;
drawbt(playerPGflag);
}
if(i==101&&(playerPGflag&btChu))
{
downplayer.chu();
clearform(Rect(153,454,648,502));
downplayer.resetbegin();
downplayer.draw(imagetype);
clearform(Rect(278,120,528,400));
mjots.draw(imagetype);
playerPGflag=btNo;
drawbt(playerPGflag);
if(rightcom.wanttohu(false))
{
gamestat=RightWaitForHu;
flag_zimo=false;
loser=0;
timer->Enabled=true;
break;
}
if(upcom.wanttohu(false))
{
gamestat=UpWaitForHu;
flag_zimo=false;
loser=0;
timer->Enabled=true;
break;
}
if(leftcom.wanttohu(false))
{
gamestat=LeftWaitForHu;
flag_zimo=false;
loser=0;
timer->Enabled=true;
break;
}
if(leftcom.wanttopeng())
{
gamestat=LeftWaitForPG;
flag_pg=1;
timer->Enabled=true;
break;
}
if(leftcom.wanttogang())
{
gamestat=LeftWaitForPG;
flag_pg=2;
timer->Enabled=true;
break;
}
if(rightcom.wanttopeng())
{
gamestat=RightWaitForPG;
flag_pg=1;
timer->Enabled=true;
break;
}
if(rightcom.wanttogang())
{
gamestat=RightWaitForPG;
flag_pg=2;
timer->Enabled=true;
break;
}
if(upcom.wanttopeng())
{
gamestat=UpWaitForPG;
flag_pg=1;
timer->Enabled=true;
break;
}
if(upcom.wanttogang())
{
gamestat=UpWaitForPG;
flag_pg=2;
timer->Enabled=true;
break;
}
timer->Enabled=true;
gamestat=RightWaitForMo;
}
break;
}
}
void TForm1::clearanddrawname()
{
Label1->Caption=name[0];
Label2->Caption=name[1];
Label3->Caption=name[2];
Label4->Caption=name[3];
switch(zhuangjia)
{
case 0:
Label1->Caption=Label1->Caption+"(庄家)";
break;
case 1:
Label2->Caption=Label2->Caption+"(庄家)";
break;
case 2:
Label3->Caption=Label3->Caption+"(庄家)";
break;
case 3:
Label4->Caption=Label4->Caption+"(庄家)";
break;
}
if(moneyperpai<=0.0)
{
Label1->Caption=Label1->Caption+"\n"+downsc;
Label2->Caption=Label2->Caption+"\n"+leftsc;
Label3->Caption=Label3->Caption+"\n"+upsc;
Label4->Caption=Label4->Caption+"\n"+rightsc;
}
else
{
AnsiString ls;
ls=(AnsiString(downsc*moneyperpai).Pos(".")>0)?AnsiString(downsc*moneyperpai):AnsiString(downsc*moneyperpai)+".";
Label1->Caption=Label1->Caption+"\n¥"+ls.SubString(1,ls.Pos(".")+2);
ls=(AnsiString(leftsc*moneyperpai).Pos(".")>0)?AnsiString(leftsc*moneyperpai):AnsiString(leftsc*moneyperpai)+".";
Label2->Caption=Label2->Caption+"\n¥"+ls.SubString(1,ls.Pos(".")+2);
ls=(AnsiString(upsc*moneyperpai).Pos(".")>0)?AnsiString(upsc*moneyperpai):AnsiString(upsc*moneyperpai)+".";
Label3->Caption=Label3->Caption+"\n¥"+ls.SubString(1,ls.Pos(".")+2);
ls=(AnsiString(rightsc*moneyperpai).Pos(".")>0)?AnsiString(rightsc*moneyperpai):AnsiString(rightsc*moneyperpai)+".";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -