📄 unit6.pas
字号:
begin
case game_fangkuai[i].fangkuai of
1: begin
glcube1.Position.X:= get_x(i);
glcube1.Position.Y:= get_y(i);
end;
2: begin
glcube2.Position.X:= get_x(i);
glcube2.Position.Y:= get_y(i);
end;
3: begin
glcube3.Position.X:= get_x(i);
glcube3.Position.Y:= get_y(i);
end;
4: begin
glcube4.Position.X:= get_x(i);
glcube4.Position.Y:= get_y(i);
end;
5: begin
glcube5.Position.X:= get_x(i);
glcube5.Position.Y:= get_y(i);
end;
6: begin
glcube6.Position.X:= get_x(i);
glcube6.Position.Y:= get_y(i);
end;
7: begin
glcube7.Position.X:= get_x(i);
glcube7.Position.Y:= get_y(i);
end;
8: begin
glcube8.Position.X:= get_x(i);
glcube8.Position.Y:= get_y(i);
end;
end;
end;
end;
procedure TForm6.darw_word;
var i: integer;
bmp: Tbitmap;
begin
label1.Caption:= get_chinese(game_fangkuai[0].word_index);
label2.Caption:= get_chinese(game_fangkuai[1].word_index);
label3.Caption:= get_chinese(game_fangkuai[2].word_index);
label4.Caption:= get_chinese(game_fangkuai[3].word_index);
label5.Caption:= get_chinese(game_fangkuai[4].word_index);
label6.Caption:= get_chinese(game_fangkuai[5].word_index);
label7.Caption:= get_chinese(game_fangkuai[6].word_index);
label8.Caption:= get_chinese(game_fangkuai[7].word_index);
bmp:=TBitmap.Create;
bmp.PixelFormat:=pf24bit;
bmp.Canvas.Font.Name:='宋体';
bmp.Canvas.Font.Height:=16;
bmp.Canvas.Brush.Style:= bsClear;
for i:= 0 to 7 do
begin
bmp.LoadFromFile(pic_name);
bmp.Width:=128;
bmp.Height:=84;
bmp.Canvas.TextOut(25, 35,get_english(game_fangkuai[i].word_index));
//GLMaterialLibrary1.Materials.Items[game_fangkuai[i].fangkuai-1].Material.Texture.image.Assign(bmp);
GLMaterialLibrary1.Materials.Items[i].Material.Texture.image.Assign(bmp);
{相应编号的内容设为对应的英文}
end;
bmp.Free;
end;
function TForm6.get_space: integer;
var i: integer;
begin
result:= 8;
for i:= 0 to 8 do
begin
if game_fangkuai[i].fangkuai= 0 then
begin
result:= i+1;
break;
end;
end;
end;
function TForm6.can_move(c: TGLCube): boolean;
var cube_i,i,j: integer;
begin
result:= false;
{获取控件的编号}
cube_i:= get_cube_pstion(c);
j:= cube_i-1;
{确定其位置}
for i:= 0 to 8 do
begin
if game_fangkuai[i].fangkuai= cube_i then
begin
cube_i:= i+1;
break;
end;
end;
//cube_i 的值指向了具体的位置编号
case cube_i of
1: if get_space in[2,4] then
result:= true;
2: if get_space in[1,3,5] then
result:= true;
3: if get_space in[2,6] then
result:= true;
4: if get_space in[1,5,7] then
result:= true;
5: if get_space in[2,4,6,8] then
result:= true;
6: if get_space in[3,5,9] then
result:= true;
7: if get_space in[4,8] then
result:= true;
8: if get_space in[7,5,9] then
result:= true;
9: if get_space in[6,8] then
result:= true;
end;
if result then
GLMaterialLibrary1.Materials.Items[j].Material.FrontProperties.Emission.Color:=clrFirebrick;
end;
procedure TForm6.resume_color(c: TGLCube);
var cube_i: integer;
begin
cube_i:= get_cube_pstion(c)-1;
GLMaterialLibrary1.Materials.Items[cube_i].Material.FrontProperties.Emission.Color:=clrGray50;
end;
function TForm6.get_chinese(index: integer): string;
begin
result:= Form1.get_word_to_form6(index);
delete(result,1,pos('=',result));
end;
function TForm6.get_english(index: integer): string;
begin
result:= Form1.get_word_to_form6(index);
result:= copy(result,1,pos('=',result)-1);
end;
procedure TForm6.move_cube(c: tglcube);
begin
if can_move(c) then
begin
c.Position.X:= getspace_at_xy.fangkuai;
c.Position.y:= getspace_at_xy.word_index;
set_space(get_cube_pstion(c));
end;
end;
function TForm6.getspace_at_xy: jit_sz;
begin
case get_space of
1: begin
result.fangkuai:= -4;
result.word_index:= 3;
end;
2: begin
result.fangkuai:= 0;
result.word_index:= 3;
end;
3: begin
result.fangkuai:= 4;
result.word_index:= 3;
end;
4: begin
result.fangkuai:= -4;
result.word_index:= 0;
end;
5: begin
result.fangkuai:= 0;
result.word_index:= 0;
end;
6: begin
result.fangkuai:= 4;
result.word_index:= 0;
end;
7: begin
result.fangkuai:= -4;
result.word_index:= -3;
end;
8: begin
result.fangkuai:= 0;
result.word_index:= -3;
end;
9: begin
result.fangkuai:= 4;
result.word_index:= -3;
end;
end;
end;
function TForm6.get_cube_pstion(c: tglcube): integer;
begin
result:= 1;
if c= glcube1 then
result:= 1
else if c= glcube2 then
result:= 2
else if c= glcube3 then
result:= 3
else if c= glcube4 then
result:= 4
else if c= glcube5 then
result:= 5
else if c= glcube6 then
result:= 6
else if c= glcube7 then
result:= 7
else if c= glcube8 then
result:= 8;
end;
procedure TForm6.set_space(i: integer);
var j: integer;
b: boolean;
begin
inc(game_step_count);
stringgrid1.Cells[1,1]:= inttostr(game_step_count);
for j:= 0 to 8 do
begin
if game_fangkuai[j].fangkuai= 0 then
game_fangkuai[j].fangkuai:= i
else if game_fangkuai[j].fangkuai= i then
game_fangkuai[j].fangkuai:= 0;
end;
b:= true;
for j:= 0 to 7 do
begin
if game_fangkuai[j].fangkuai<> j+1 then
b:= false;
end;
if b then
begin
jit_isgame:= false;
button3.Enabled:= false;
button4.Enabled:= false;
GLFireFXManager1.Disabled:= true;
GLCadencer1.Enabled:= true;
timer2.Enabled:= true;
jit_time:= 0;
stringgrid1.Cells[1,3]:= inttostr(game_time_count div 50)+' 分';
game_time_count:= 0;
stringgrid1.Cells[1,6]:= '游戏已过关。';
if stringgrid1.Cells[1,2]= '扣除金币:5000' then
begin
stringgrid1.Cells[1,2]:= '扣除了金币5000'
end else begin
Form1.add_money(1000);
stringgrid1.Cells[1,2]:= '奖励金币:1000';
end;
PlaySound(pchar(extractfilepath(application.ExeName)+'Joy118.wav'),0,SND_FILENAME or SND_ASYNC);
GetOrCreateSourcePFX(GLDummyCube2).RingExplosion(GLCadencer1.CurrentTime, 1, 1.2, 150);
end else begin
if game_fangkuai[0].fangkuai= 1 then
if game_fangkuai[1].fangkuai= 2 then
if game_fangkuai[2].fangkuai= 3 then
if game_fangkuai[3].fangkuai= 4 then
if game_fangkuai[4].fangkuai= 5 then
if game_fangkuai[5].fangkuai= 6 then
if game_fangkuai[6].fangkuai= 8 then
if game_fangkuai[7].fangkuai= 7 then
begin
if messagebox(handle,'此题无解,点击“是”开始新游戏,点击“否”继续尝试。','提示', mb_yesno or MB_ICONINFORMATION)= mryes then
begin
jit_isgame:= false;
button1click(button1);
end;
end;
end;
end;
procedure TForm6.msg_from_form1(var Message: TMessage);
begin
case Message.LParam of
cn_jit_game_star: button1click(form6);
cn_jit_game_up: move_updown(cn_jit_game_up);
cn_jit_game_down: move_updown(cn_jit_game_down);
cn_jit_game_left: move_updown(cn_jit_game_left);
cn_jit_game_right:move_updown(cn_jit_game_right);
end;
end;
procedure TForm6.move_updown(up: integer);
begin
if game_is_amt then
exit;
if not jit_isgame then
begin
if messagebox(handle,'游戏尚未开局,是否立即开始?','提示',mb_yesno or MB_ICONWARNING)= mryes then
button1click(glsceneviewer1);
exit;
end;
case up of
cn_jit_game_up: move_to_up;
cn_jit_game_down: move_to_down;
cn_jit_game_left: move_to_left;
cn_jit_game_right:move_to_right;
end;
end;
procedure TForm6.create_pic_name;
begin
pic_name:= ExtractFilePath(application.ExeName)+ 'Lib\tu'+inttostr(random(pic_file_count))+'.bmp';
end;
procedure TForm6.Button4Click(Sender: TObject);
begin
if not jit_isgame then
exit;
create_pic_name;
darw_word; //显示单词
end;
procedure TForm6.Button3Click(Sender: TObject);
begin
//初始化单词在单词本的随机位置
instl_game_index;
darw_word; //显示单词
end;
procedure TForm6.chinese_bold;
begin
if not(currentPick is tglcube) then
exit;
if not can_move(currentPick as tglcube) then
exit;
case get_cube_pstion(currentPick as tglcube) of
1: label1.Font.Color:= clred;
2: label2.Font.Color:= clred;
3: label3.Font.Color:= clred;
4: label4.Font.Color:= clred;
5: label5.Font.Color:= clred;
6: label6.Font.Color:= clred;
7: label7.Font.Color:= clred;
8: label8.Font.Color:= clred;
end;
end;
procedure TForm6.chinese_not_bold;
begin
if not(oldpick is tglcube) then
exit;
case get_cube_pstion(oldpick as tglcube) of
1: label1.Font.Color:= clWindow;
2: label2.Font.Color:= clWindow;
3: label3.Font.Color:= clWindow;
4: label4.Font.Color:= clWindow;
5: label5.Font.Color:= clWindow;
6: label6.Font.Color:= clWindow;
7: label7.Font.Color:= clWindow;
8: label8.Font.Color:= clWindow;
end;
end;
procedure TForm6.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
timer2.Enabled:= false;
Form1.button13.Enabled:= true;
end;
procedure TForm6.FormShow(Sender: TObject);
begin
timer2.Enabled:= true;
end;
procedure TForm6.move_to_up;
begin
case get_space of
1: move_cube2(get_cube_from_index(3));
2: move_cube2(get_cube_from_index(4));
3: move_cube2(get_cube_from_index(5));
4: move_cube2(get_cube_from_index(6));
5: move_cube2(get_cube_from_index(7));
6: move_cube2(get_cube_from_index(8));
{7: if get_space in[4,8] then
result:= true;
8: if get_space in[7,5,9] then
result:= true;
9: if get_space in[6,8] then
result:= true; }
end;
end;
function TForm6.get_cube_from_index(index: integer): tglcube;
begin
case game_fangkuai[index].fangkuai of
1: result:= glcube1;
2: result:= glcube2;
3: result:= glcube3;
4: result:= glcube4;
5: result:= glcube5;
6: result:= glcube6;
7: result:= glcube7;
8: result:= glcube8;
else
result:= glcube1;
end;
end;
procedure TForm6.move_to_down;
begin
case get_space of
{ 1: move_cube(get_cube_from_index(3));
2: move_cube(get_cube_from_index(4));
3: move_cube(get_cube_from_index(5)); }
4: move_cube2(get_cube_from_index(0));
5: move_cube2(get_cube_from_index(1));
6: move_cube2(get_cube_from_index(2));
7: move_cube2(get_cube_from_index(3));
8: move_cube2(get_cube_from_index(4));
9: move_cube2(get_cube_from_index(5));
end;
end;
procedure TForm6.move_to_left;
begin
case get_space of
1: move_cube2(get_cube_from_index(1));
2: move_cube2(get_cube_from_index(2));
// 3: move_cube(get_cube_from_index(5));
4: move_cube2(get_cube_from_index(4));
5: move_cube2(get_cube_from_index(5));
//6: move_cube(get_cube_from_index(2));
7: move_cube2(get_cube_from_index(7));
8: move_cube2(get_cube_from_index(8));
// 9: move_cube(get_cube_from_index(5));
end;
end;
procedure TForm6.move_to_right;
begin
case get_space of
//1: move_cube(get_cube_from_index(3));
2: move_cube2(get_cube_from_index(0));
3: move_cube2(get_cube_from_index(1));
// 4: move_cube(get_cube_from_index(0));
5: move_cube2(get_cube_from_index(3));
6: move_cube2(get_cube_from_index(4));
// 7: move_cube(get_cube_from_index(3));
8: move_cube2(get_cube_from_index(6));
9: move_cube2(get_cube_from_index(7));
end;
end;
procedure TForm6.move_cube2(c: tglcube);
begin
c.Position.X:= getspace_at_xy.fangkuai;
c.Position.y:= getspace_at_xy.word_index;
set_space(get_cube_pstion(c));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -