📄 umain.pas
字号:
WindowColor := Ini.ReadInteger('Setting','WindowColor',clBlack);
LeftKey := Ini.ReadInteger('Setting','LeftKey',VK_LEFT);
RightKey := Ini.ReadInteger('Setting','RightKey',VK_RIGHT);
DownKey := Ini.ReadInteger('Setting','DownKey',VK_DOWN);
ChangeKey := Ini.ReadInteger('Setting','ChangeKey',VK_UP);
DirectDownKey := Ini.ReadInteger('Setting','DirectDownKey',VK_SHIFT);
frmGame.Width := Ini.ReadInteger('Setting','Width',0);
frmGame.Height := Ini.ReadInteger('Setting','Height',0); //这里会触发 OnResize事件,在那里调整窗口大小
UseImgBlock := Ini.ReadBool('Setting','UseImageBlock',true);
end;
procedure TfrmGame.SaveSetting;
var
Ini: TIniFile;
Path: String;
begin
Path := ExtractFilePath(Application.ExeName);
Ini := TIniFile.Create(Path+IniFile);
Ini.WriteString('Setting','DefaultMusic',DefaultMusic);
Ini.WriteString('Setting','BackImage',BackImagePath);
Ini.WriteBool('Setting','FullScreen',MenuFull.Checked);
Ini.WriteBool('Setting','SoundOpen',MenuSound.Checked);
Ini.WriteBool('Setting','ShowBkImage',MenuShowBack.Checked);
Ini.WriteInteger('Setting','GameBkColor',BkColor);
Ini.WriteInteger('Setting','WindowColor',WindowColor);
Ini.WriteInteger('Setting','LeftKey',LeftKey);
Ini.WriteInteger('Setting','RightKey',RightKey);
Ini.WriteInteger('Setting','DownKey',DownKey);
Ini.WriteInteger('Setting','ChangeKey',ChangeKey);
Ini.WriteInteger('Setting','DirectDownKey',DirectDownKey);
Ini.WriteInteger('Setting','Width',frmGame.Width);
Ini.WriteInteger('Setting','Height',frmGame.Height); //这里会触发 OnResize事件,在那里调整窗口大小
Ini.WriteBool('Setting','UseImageBlock',UseImgBlock);
end;
function TfrmGame.RandomColor:TColor; //随机颜色
begin
Result := RGB(Random(205)+50,Random(205)+50,Random(205)+50);
end;
procedure TfrmGame.PlaySound(Filename: String);
begin
if (not FileExists(Filename)) or (not MenuSound.Checked) then exit;
Sound.FileName := Filename;
Sound.Open;
Sound.Play;
end;
procedure TfrmGame.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if MainTimer.Enabled = false then exit;
StopTimer.Enabled := false;
if Key = LeftKey then
begin
if CanGo(CurX-1,CurY,Block) then
begin
BoxMoveTo(PaintBox.Canvas,CurX-1,CurY,Block);
LasX := CurX - 1;
CurX := LasX;
end;
end else
if Key = RightKey then
begin
if CanGo(CurX+1,CurY,Block) then
begin
BoxMoveTo(PaintBox.Canvas,CurX+1,CurY,Block);
LasX := CurX + 1;
CurX := LasX;
end;
end else
if Key = ChangeKey then
begin
Change(PaintBox.Canvas,Block,CurX,CurY);
end else
if Key = DownKey then
begin
if CanGo(CurX,CurY+1,Block) then
begin
BoxMoveTo(PaintBox.Canvas,CurX,CurY+1,Block);
LasY := CurY + 1;
CurY := LasY;
end
else
StopTimerTimer(Sender); {2001.5.11日修改此处}
end else
if Key = DirectDownKey then
begin
while(CanGo(CurX,CurY+1,Block))do
CurY := CurY + 1;
BoxMoveTo(PaintBox.Canvas,CurX,CurY,Block);
StopTimerTimer(Sender);
end;
end;
procedure TfrmGame.MenuExitClick(Sender: TObject);
begin
Close;
end;
procedure TfrmGame.MainTimerTimer(Sender: TObject);
begin
if Level< 4 then
MainTimer.Interval := 450 - 100 * Level
else
if Level <= 8 then
MainTimer.Interval := 200 - 25 * Level + 1
else
MainTimer.Interval := 1;
LabelScore.Caption := '得分: '+IntToStr(Score);
if CanGo(CurX,CurY+1,Block) then
begin
BoxMoveTo(PaintBox.Canvas,CurX,CurY+1,Block);
LasY := CurY + 1;
CurY := LasY;
end
else
StopTimer.Enabled := true;
LabelLevel.Caption := IntToStr(Level);
LabelLevel.Font.Color := RandomColor;
end;
procedure TfrmGame.StopTimerTimer(Sender: TObject);
var
i : Integer;
begin
Randomize;
MainTimer.Enabled := false;
MoveToMap(CurX,CurY,Block);
LabelScore.Caption := '得分: '+IntToStr(Score);
PlaySound(GamePath+'Sound\Stop.wav');
if CurY<3 then
begin
StopTimer.Enabled := false;
MainTimer.Enabled := false;
MenuStart.Enabled := true;
MenuPause.Enabled := false;
MenuReplay.Enabled := false;
case Level of
1: LabelMess.Caption := '同志,工夫不到家,回去修炼几年再说吧!';
2: LabelMess.Caption := '乖乖,不要灰心慢慢来!';
3: LabelMess.Caption := '你已经很不错了嘛,祝贺你哟……请客……';
4: LabelMess.Caption := '你怎么现在才死呀,你早该死了……(偷着乐,哈哈哈哈~)';
else
LabelMess.Caption := '你已经无药可救了~~!下次不要在来了啦,烦不烦啊!';
end;
PlaySound(GamePath+'Sound\Lough.wav');
MessageBox(Handle,PChar('失败呀!典型的失败!'+LabelMess.Caption),'香蕉你个疤瘌',64);
Level := 1;
CheckScore(Score);
Exit;
end;
ScanEmptyLine(PaintBox.Canvas,EmptyLine);
if (EmptyLine[1]<>0) or (EmptyLine[2]<>0) or
(EmptyLine[3]<>0) or (EmptyLine[4]<>0) then
PlaySound(GamePath+'Sound\Delaline.wav');
FreshMap(PaintBox.Canvas,EmptyLine);
for i := 1 to 4 do EmptyLine[i] := 0;
BColor := RandomColor;
BlockId := NextId;
CopyBox(Block,Box[BlockId]);
SetBlockColor(Block,BColor);
NextId := Random(7)+1;
ShowNext(PaintBox.Canvas);
CurX := 10;
CurY := 1;
LasX := 10;
LasY := 1;
Score := Score + 15;
CurLevelScore := CurLevelScore + 15;
//if Score > Level * 10000 then
if CurLevelScore > 10000 then
begin
case Level of
1: LabelMess.Caption := '小伙子(姑娘),不错嘛!祝贺你过了第'+IntToStr(Level)+'关!';
2: LabelMess.Caption := '哇噻!有进步!祝贺你过了第'+IntToStr(Level)+'关!';
3: LabelMess.Caption := '又拿好成绩了呵呵!快谢谢我的鼓励!祝贺你过了第'+IntToStr(Level)+'关!';
4: LabelMess.Caption := '你已经成仙了,可以升天了。祝贺你过了第'+IntToStr(Level)+'关!';
else
LabelMess.Caption := '哎,你这个人已经无药可救了。祝贺你过了第'+IntToStr(Level)+'关!';
end;
Level := Level + 1;
CurLevelScore := 0;
PlaySound(GamePath+'Sound\LevelOut.Wav');
end;
StopTimer.Enabled := false;
MainTimer.Enabled := true;
LabelScore.Caption := '得分: '+IntToStr(Score);
end;
procedure TfrmGame.MenuStartClick(Sender: TObject);
begin
MemoShow.Hide;
InitBoxes;
DrawMap(PaintBox.Canvas);
if not (Sender=MenuReplay) then
LabelMess.Caption := '开始游戏,有什么不满可以提!';
CurX := 10;
CurY := 1;
LasX := 10;
LasY := 1;
Score := 0;
CurLevelScore := 0;
SilentClose := false;
Randomize;
BColor := RandomColor;
BlockId := Random(7)+1;
CopyBox(Block,Box[BlockId]);
SetBlockColor(Block,BColor);
NextId := Random(7)+1;
ShowNext(PaintBox.Canvas);
MainTimer.Enabled := true;
StopTimer.Enabled := false;
MenuStart.Enabled := false;
MenuPause.Enabled := true;
MenuReplay.Enabled := true;
end;
procedure TfrmGame.MenuPauseClick(Sender: TObject);
begin
MemoShow.Show;
MainTimer.Enabled := false;
MenuPause.Enabled := false;
MenuContinue.Enabled := true;
LabelMess.Caption := '暂停,按F2继续。你想干什么???';
end;
procedure TfrmGame.MenuContinueClick(Sender: TObject);
begin
MemoShow.Hide;
MainTimer.Enabled := true;
MenuPause.Enabled := true;
MenuContinue.Enabled := false;
LabelMess.Caption := '继续……用心一点好不好!!!';
end;
procedure TfrmGame.FormCreate(Sender: TObject);
var
SplashFrm: TSplashForm;
begin
Self.Hide;
SplashFrm := TSplashForm.Create(Application);
SplashFrm.Show;
Delay(400);
// 获取用户设置
LoadSetting;
MenuReplay.Enabled := false;
MenuPause.Enabled := false;
MenuContinue.Enabled := false;
PanelBack.Top := 0 ;//Round((frmGame.Height - PanelBack.Height)/2);
PanelBack.Left:= 0 ;//Round((frmGame.Width - PanelBack.Width)/2);
PanelBack.Color := clBlack;
frmGame.Caption := '搞笑俄罗斯方块' + Version;
ImgBlock.Hide;
MenuShowBack.Checked := BackImage.Visible;
DateLabel1.Caption := BuildDate;
DateLabel2.Caption := BuildDate;
StopClick := false;
SilentClose := true;
Level := 1;
NextId := Random(7)+1;
LabelMess.Caption := '';
LabelLevel.Caption := IntToStr(Level);
LabelMess.Caption := '欢迎来到搞笑俄罗斯方块的游戏世界!请按F3开始游戏';
GamePath := ExtractFilePath(Application.ExeName);
CheckRegistry;
//从注册表里提取分数信息
LoadScore;
SplashFrm.Hide;
SplashFrm.Free;
Self.Show;
end;
procedure TfrmGame.MenuSpeedClick(Sender: TObject);
var
ChgLevForm : TLevelForm;
begin
ChgLevForm := TLevelForm.Create(Owner);
MenuPause.Click;
ChgLevForm.ShowModal;
ChgLevForm.Free;
end;
procedure TfrmGame.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
Res: Integer;
begin
MenuPause.Click;
if not SilentClose then
begin
Res := MessageBox(Handle,'怎么回事呀,你这个人也太不用心了,玩个游戏都坐不住。怎么样?给我个面子好不好!玩完他同意吗?','气呼呼的问:',48+MB_YESNO);
if Res=IDNO then
MessageBox(Handle,'什么还要走啊?我可真是舍不得你……~5555@_*看,眼睛都哭肿了,既然如此我就不强留了,下次记得来啊!','恋恋不舍的',64)
else
CanClose := false;
end;
end;
procedure TfrmGame.MenuKeyboardClick(Sender: TObject);
var
ChgKeyForm: TSelectKeyForm;
begin
ChgKeyForm := TSelectKeyForm.Create(Owner);
MenuPause.Click;
ChgKeyForm.ShowModal;
ChgKeyForm.Free;
end;
procedure TfrmGame.LabelHomepageClick(Sender: TObject);
begin
ShellExecute(Handle,'open',PChar('http://yousp.yeah.net'),'','',SW_SHOWNORMAL);
end;
procedure TfrmGame.ItemOpenMusicClick(Sender: TObject);
begin
MenuPauseClick(Sender);
OpenDialog.Filter := '所有音乐文件|*.mp3;*.wav;*.mid;';
if OpenDialog.Execute then
begin
Audio.Close;
ChangingFileName := true;
Audio.FileName := OpenDialog.FileName;
DefaultMusic := OpenDialog.FileName;
ChangingFileName := false;
Audio.Open;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -