Recent

Author Topic: Glyph de botões em jogo de memória  (Read 1961 times)

zerowin

  • New member
  • *
  • Posts: 8
Glyph de botões em jogo de memória
« on: May 09, 2019, 01:31:44 am »
Olá, estou com um problema na hora de passar a imagem da imagelist para o glyph dos meus botões do jogo da memória. ( talvez o código esteja "enrolado", mas ainda estou otimizando).

A parte em questão:
Code: Pascal  [Select][+][-]
  1. ImageList1.GetBitmap(I, TSpeedButton[I].Glyph);  


Todo o código:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode Delphi}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  9.   Buttons;
  10.  
  11. type
  12.  
  13. { TForm1 }
  14.  
  15. TForm1 = class(TForm)
  16.   Button1: TButton;
  17.   ImageList1: TImageList;
  18.   Label1: TLabel;
  19.   Label2: TLabel;
  20.   reiniciar: TButton;
  21.   RadioGroup1: TRadioGroup;
  22.   SpeedButton1: TSpeedButton;
  23.  
  24.  
  25.  
  26. procedure buttonClick(Sender: TObject);
  27. procedure SpeedButton1Click(Sender: TObject);
  28.  
  29.  
  30.  
  31.  
  32.  
  33. private
  34.  
  35. public
  36.  
  37. end;
  38.  
  39. var
  40.   Form1 : TForm1;
  41.   CartaVirada1 : TSpeedButton;
  42.   CartaVirada2 : TSpeedButton;
  43.   ViradasJogador : Integer;
  44.   ViradasIa : Integer;
  45.   jogadaJogador : integer;
  46.   guardado: array[0..15] of TSpeedbutton;
  47.   I : Integer;
  48.   botao : TSpeedButton;
  49.  
  50.  
  51. implementation
  52.  
  53. {$R *.lfm}
  54.  
  55. procedure TForm1.SpeedButton1Click(Sender: TObject);
  56.  var
  57.  
  58.  
  59. cont : Integer;
  60. num : Integer;
  61. linha : Integer;
  62. coluna : Integer;
  63.  
  64. capBotao : array[0..7] of  String = ('A','B', 'C', 'D', 'E', 'F','G','H');
  65. capBotao2 : array[0..7] of String = ('A','B', 'C', 'D', 'E', 'F','G','H');
  66.  
  67. capBotaoRandom : array[0..7] of String = ('.','.', '.', '.', '.', '.','.','.');
  68. Resultado : array[0..15] of String = ('.', '.', '.', '.', '.', '.',  '.',  '.',  '.',
  69. '.', '.', '.',  '.',  '.',  '.',  '.');
  70.  
  71.  
  72. begin
  73.  
  74.  
  75. label2.caption := 'Jogando:';
  76. RadioGroup1.Visible := false;
  77. reiniciar.visible := true;
  78. reiniciar.enabled := true;
  79.  
  80.  
  81. Randomize;
  82.  
  83. cont := 0;
  84. linha := 30;
  85. coluna := 30;
  86.  
  87.  
  88.  
  89.  
  90.             for I := 0 to 7 do
  91. begin
  92. cont := Random(8);
  93. capBotaoRandom[I] := capBotao[cont];
  94.  
  95.  
  96.  
  97.                    while capBotao[cont] = '.' do
  98. begin
  99. cont := Random(8);
  100. capBotaoRandom[I] := capBotao[cont];
  101. end;
  102. capBotao[cont] := '.';
  103.  
  104.  
  105.  
  106.  
  107.                for num := 0 to 7 do
  108. begin
  109. Resultado[num] := capBotaoRandom[num];
  110. end;
  111. end;
  112.  
  113.  
  114.  
  115.             for I := 0 to 7 do
  116. begin
  117. cont := Random(8);
  118. capBotaoRandom[I] := capBotao2 [cont];
  119.  
  120.  
  121.  
  122.                    while capBotao2 [cont] = '.' do
  123. begin
  124. cont := Random(8);
  125. capBotaoRandom[I] := capBotao2 [cont];
  126. end;
  127. capBotao2[cont] := '.';
  128. end;
  129.  
  130.  
  131.  
  132.                 for num := 0 to 7 do
  133. begin
  134. resultado[num + 8] := capBotaoRandom[num];
  135. end;
  136.  
  137.  
  138.  
  139.                 for I := 0 to 15 do
  140. begin
  141.  
  142. botao := TSpeedButton.Create(Self);
  143. botao.Parent := Form1;
  144. botao.Height := 150;
  145. botao.Width  := 150;
  146. botao.Top    := coluna;
  147. botao.Left   := linha;
  148. botao.Hint := resultado[I];
  149. botao.Name := 'btn' + IntToStr(I);
  150. botao.Caption := '';
  151. botao.OnClick := buttonClick();
  152. guardado[I] := botao;
  153. ImageList1.GetBitmap(I, TSpeedButton[I].Glyph);
  154.  
  155.  
  156.                  if ((I+1) mod 4 = 0) then
  157. begin
  158. coluna := coluna + 150;
  159. linha := 30;
  160. end
  161. else
  162. linha := linha + 150;
  163. end;
  164.  
  165.  
  166.  
  167.                 end;
  168.  
  169.  
  170.  
  171. procedure TForm1.buttonClick(Sender: TObject);
  172.   begin
  173.  
  174.  
  175.         if(Sender as TSpeedButton).Caption = '' then
  176. (Sender as TSpeedButton).Caption := (Sender as TSpeedButton).Hint
  177.  
  178.  
  179.  
  180.                             else
  181. (Sender as TSpeedButton).Caption := '';
  182.         Application.ProcessMessages;
  183. ViradasJogador := ViradasJogador + 1;
  184.  
  185.  
  186.  
  187.            if(ViradasJogador mod 2 = 1)then
  188. CartaVirada1 := (Sender as TSpeedButton);
  189.  
  190.             CartaVirada1.Enabled := false;
  191.  
  192.  
  193.                if(ViradasJogador mod 2 = 0) then
  194. begin
  195. CartaVirada2 := (Sender as TSpeedButton);
  196. CartaVirada1.Enabled := true;
  197.  
  198.  
  199.  
  200.  
  201.        if(CartaVirada1.Name = CartaVirada2.Name) then
  202. begin
  203. CartaVirada1.Caption := '';
  204. CartaVirada2.Caption := '';
  205. end
  206.  
  207.  
  208.  
  209.        else if(CartaVirada2.Caption = CartaVirada1.Caption) then
  210. begin
  211. CartaVirada1.Visible := false;
  212. CartaVirada2.Visible := false;
  213. end;
  214.  
  215.  
  216.  
  217.        if (CartaVirada2.Caption <> CartaVirada1.Caption) then
  218. begin
  219. label1.caption := 'PC';
  220. Sleep(900);
  221. CartaVirada1.Caption := '';
  222. CartaVirada2.Caption := '';
  223.  
  224. end;
  225. CartaVirada1 := Nil;
  226. CartaVirada2 := Nil;
  227. jogadaJogador := 1;
  228. end;
  229.  
  230.       if label1.caption = 'PC' then
  231.                    begin
  232.  
  233.                    end;
  234.  
  235.  
  236.  
  237.  
  238.  
  239. end;
  240. end.
  241.              
                     

 

TinyPortal © 2005-2018