Ir para conteúdo
Faça parte da equipe! (2024) ×

[Delphi]Criando um Jogo da Velha XD


' Extasy
 Compartilhar

Posts Recomendados

begin;

 

Você precisara dos seguntes itens:

 

9 TButtons: 33x33 de preferencia;

*4 TPanels: Para fazer as barras;

*1 TXPManifest: Para melhorar o grafico;

 

* = Opcional;

 

Alinhe-os formando um quadrado, assim.

Se quiser, use os panels para fazer as barras:

Se quiser colocar um XPMan para melhorar o grafic, pode colocar.

 

Após isso, abra a unit.pas

 

declare os procedimentos JogoNovo e Verfificar

 

unit form1;

 

interface

 

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, XPMan, StdCtrls, ExtCtrls;

 

type

TfrmJogo = class(TForm)

Panel1: TPanel;

Panel2: TPanel;

Panel3: TPanel;

Panel4: TPanel;

Button1: TButton;

Button2: TButton;

Button3: TButton;

Button4: TButton;

Button5: TButton;

Button6: TButton;

Button7: TButton;

Button8: TButton;

Button9: TButton;

XPManifest1: TXPManifest;

procedure JogoNovo; // <---| Declare esses 2 procedimentos

procedure Verificar; // <--|

 

private

{ Private declarations }

public

{ Public declarations }

end;

 

Logo apos isso, declare a variavel Botao \/

 

Botao: array [1..9] of T Button;

 

Volte ao form1 e de 2 clicks no evento OnCreate do form1

 

e escreva isso \/

 

Randomize;

Botao[1]:= Button1;

Botao[2]:= Button2;

Botao[3]:= Button3;

Botao[4]:= Button4;

Botao[5]:= Button5;

Botao[6]:= Button6;

Botao[7]:= Button7;

Botao[8]:= Button8;

Botao[9]:= Button9;

JogoNovo;

 

Se quiser salvar agora salve

pois não esta nem na metade

 

Agora declare a var

 

intNumeroVezes:Integer;

 

Agora va ate onde vc digitou os 2 procedimentos e de um "CTRL + SHIFT + C" e

coloque este comando \/

 

procedure TfrmJogo.JogoNovo;

var

intM,i: Integer;

begin

for i:= 1 to 9 do

Botao.Caption:='';

intM:= Trunc(Random * 10);

intNumeroVezes:=0;

 

Agora no procedure do button 1 a 9, coloque o seguinte comando \/

 

intNumeroVezes:= intNumeroVezes + 1;

Button1.Caption:='x';

Verificar;

 

Agora na procedure verificar, coloque este pequeno comando \/

 

 

label 1,2;

var

intResposta: Integer;

i: Integer;

begin

if (Button1.Caption='x') and (Button2.Caption='x')

and (Button3.Caption='x') then goto 1;

if (Button4.Caption='x') and (Button5.Caption='x')

and (Button6.Caption='x') then goto 1;

if (Button7.Caption='x') and (Button8.Caption='x')

and (Button9.Caption='x') then goto 1;

if (Button1.Caption='x') and (Button4.Caption='x')

and (Button7.Caption='x') then goto 1;

if (Button2.Caption='x') and (Button5.Caption='x')

and (Button8.Caption='x') then goto 1;

if (Button3.Caption='x') and (Button6.Caption='x')

and (Button9.Caption='x') then goto 1;

if (Button1.Caption='x') and (Button5.Caption='x')

and (Button9.Caption='x') then goto 1;

if (Button3.Caption='x') and (Button5.Caption='x')

and (Button7.Caption='x') then goto 1;

 

repeat i:=Trunc (Random * 10) until Botao.Caption='';

Botao.Caption:='o';

 

if (Button1.Caption='o') and (Button2.Caption='o')

and (Button3.Caption='o') then goto 2;

if (Button4.Caption='o') and (Button5.Caption='o')

and (Button6.Caption='o') then goto 2;

if (Button7.Caption='o') and (Button8.Caption='o')

and (Button9.Caption='o') then goto 2;

if (Button1.Caption='o') and (Button4.Caption='o')

and (Button7.Caption='o') then goto 2;

if (Button2.Caption='o') and (Button5.Caption='o')

and (Button8.Caption='o') then goto 2;

if (Button3.Caption='o') and (Button6.Caption='o')

and (Button9.Caption='o') then goto 2;

if (Button1.Caption='o') and (Button5.Caption='o')

and (Button9.Caption='o') then goto 2;

if (Button3.Caption='o') and (Button5.Caption='o')

and (Button7.Caption='o') then goto 2;

if intNumeroVezes= 4 then

begin

Showmessage('Partida Empatada');

JogoNovo;

exit;

end;

exit;

 

1:

begin

intResposta:=Application.MessageBox

('Você ganhou, quer jogar novamente?','Vencedor',36);

if intResposta = 7 then Close;

JogoNovo;

exit;

end;

 

2:

begin

intResposta:=Application.MessageBox

('Eu Ganhei, quer jogar novamente?','Vencedor',36);

if intResposta = 7 then Close;

JogoNovo;

exit;

end;

 

Salve tudo e Pronto, Divirta-se

Se der algum erro é so me avisar OK

Ele tem alguns bugs + é assim mesmo.

 

end.

Link para o comentário
Compartilhar em outros sites

Este tópico está impedido de receber novos posts.
 Compartilhar

  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...

Informação Importante

Nós fazemos uso de cookies no seu dispositivo para ajudar a tornar este site melhor. Você pode ajustar suas configurações de cookies , caso contrário, vamos supor que você está bem para continuar.