![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|
|
#1
|
|||
|
|||
|
ESTO SERIA EL TATETI, ESPERO QUE SIRVA PARA QUE ME PUEDAN DAR UNA MANO!!!
![]() Código:
unit tateti;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
matriz = record
ficha: integer;
usado: boolean;
end;
TForm1 = class(TForm)
Memo1: TMemo;
GroupBoxjugador1: TGroupBox;
Edit_fila_1: TEdit;
Edit_col_1: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
GroupBoxjugador2: TGroupBox;
Label3: TLabel;
Label4: TLabel;
Edit_fila_2: TEdit;
Edit_col_2: TEdit;
Button2: TButton;
Button_reiciniar: TButton;
Buttonganador: TButton;
Buttonimprimir: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ButtonganadorClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ButtonimprimirClick(Sender: TObject);
procedure Button_reiciniarClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
tate: array [1..3,1..3] of matriz;
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
edit_fila_1.Clear;
edit_col_1.Clear;
edit_fila_2.Clear;
edit_col_2.Clear;
memo1.Clear;
groupboxjugador2.Enabled:=true;
groupboxjugador1.Enabled:=true;
end;
{***********************************************************}
procedure TForm1.Button1Click(Sender: TObject);
var F,C :integer;
begin
if (edit_fila_1.Text='') or (edit_col_1.Text='')
then showmessage ('INGRESE LAS COORDENADAS!!!')
else
begin
F:=strtoint(edit_fila_1.Text);
C:=strtoint(edit_col_1.Text);
if ((F>3) or (C>3) or (F<=0) or (C<=0))
then showmessage ('NO VES QUE ES UN TATETI Y NO UNA BATALLA NAVAL!!!')
else
begin
if (tate[F,C].usado=true)
then showmessage ('CASILLA USADA!!!')
else
begin
tate[F,C].ficha:=1;
tate[F,C].usado:=true;
groupboxjugador1.Enabled:=false;
groupboxjugador2.Enabled:=true;
end;
end;
end;
ButtonimprimirClick(Sender);
ButtonganadorClick(Sender);
edit_fila_1.Clear;
edit_col_1.Clear;
end;
{***********************************************************}
procedure TForm1.Button2Click(Sender: TObject);
var F,C :integer;
begin
if (edit_fila_2.Text='') or (edit_col_2.Text='')
then showmessage ('INGRESE LAS COORDENADAS!!!')
else
begin
F:=strtoint(edit_fila_2.Text);
C:=strtoint(edit_col_2.Text);
if ((F>3) or (C>3) or (F<=0) or (C<=0))
then showmessage ('NO VES QUE ES UN TATETI Y NO UNA BATALLA NAVAL!!!')
else
begin
if (tate[F,C].usado=true)
then showmessage ('CASILLA USADA!!!')
else
begin
tate[F,C].ficha:=2;
tate[F,C].usado:=true;
groupboxjugador2.Enabled:=false;
groupboxjugador1.Enabled:=true;
end;
end;
end;
ButtonimprimirClick(Sender);
ButtonganadorClick(Sender);
edit_fila_2.Clear;
edit_col_2.Clear;
end;
{***********************************************************}
procedure TForm1.ButtonganadorClick(Sender: TObject);
var F,C: integer;
begin
{chequeo fila}
for F:=1 to 3 do
if ((tate[F,1].usado=true)and(tate[F,2].ficha=tate[F,1].ficha) and (tate[F,3].ficha=tate[F,1].ficha))
then
begin
showmessage ('TA TE TI');
groupboxjugador1.Enabled:=false;
groupboxjugador2.Enabled:=false;
end;
for C:=1 to 3 do
if ((tate[1,C].usado=true)and(tate[2,C].ficha=tate[1,C].ficha) and (tate[3,C].ficha=tate[1,C].ficha))
then
begin
showmessage ('TA TE TI');
groupboxjugador1.Enabled:=false;
groupboxjugador2.Enabled:=false;
end;
if ((tate[1,1].usado=true)and(tate[2,2].ficha=tate[1,1].ficha) and (tate[3,3].ficha=tate[1,1].ficha))
then
begin
showmessage ('TA TE TI');
groupboxjugador1.Enabled:=false;
groupboxjugador2.Enabled:=false;
end;
if ((tate[1,3].usado=true)and(tate[2,2].ficha=tate[1,3].ficha) and (tate[3,1].ficha=tate[1,3].ficha))
then
begin
showmessage ('TA TE TI');
groupboxjugador1.Enabled:=false;
groupboxjugador2.Enabled:=false;
end;
end;
{***********************************************************}
procedure TForm1.ButtonimprimirClick(Sender: TObject);
var F,C:integer;
linea,letra: string;
begin
memo1.Clear;
for F:=1 to 3 do
begin
linea:='';
for C:=1 to 3 do
begin
if (tate[F,C].ficha=1)
then letra:='X'
else if tate[F,C].ficha=2
then letra:='O'
else letra:= '* ';
linea:=linea+(letra)+ ' ';
end;
memo1.Lines.Add(linea);
memo1.Lines.Add(#13)
end;
end;
{***********************************************************}
procedure TForm1.Button_reiciniarClick(Sender: TObject);
var F,C:integer;
begin
memo1.Clear;
for F:=1 to 3 do
for C:=1 to 3 do
begin
tate[F,C].ficha:=0;
tate[F,C].usado:=false;
end;
end;
end.
|
|
#2
|
||||
|
||||
|
Vale, no sabía qué era eso de "Ta te ti", hasta que he probado tu código (he tenido que diseñar enteramente el form
) y he visto que es lo que también se conoce como tres en raya ![]() Sigo sin tener claro qué es lo que pedías, para usar este juego con una matriz yo habría hecho...
y faltaría implementar la función comprobar_ganador para ver si después de cada turno alguien ha ganado ![]() Claro que, cada uno tiene su estilo... Saludos. Última edición por ixMike fecha: 14-12-2007 a las 18:28:37. |
|
#3
|
|||
|
|||
|
el ta te ti en si es una matriz de 3 x 3, en cuanto a el algoritmo lo podia haber empleado de otra manera, ahora, lo que yo necesito son ejercicios o juegos que comprendan este tipo de matriz para poder practicar, por eso daba los ejemplos de los que ya hice, como el ta te ti, la batalla naval y el memotest.
Espero haberme explicado bien, de lo contrario te pido disculpas... ![]() |
|
#4
|
||||
|
||||
|
¿Para poder practicar tu programación o tu nivel de juego? ¿Quieres que el ordenador se enfrente a ti?
|
|
#5
|
|||
|
|||
|
Al fin nos vamos entendiendo, lo que necesito ejercitar es mi programacion y en cuanto a los jugadores pueden ser 1 o 2, pero siempre humanos...
Grax nuevamente ![]() |
|
#6
|
||||
|
||||
|
Pues ahí ya sólo decir que pruebes con otro así también facilito, como un Tetris, ahí lo "difícil" está en dibujar la pantalla, pero viene a ser lo mismo, una matriz en la que compruebas si las líneas están llenas o no, y de qué.
Podrías declararte un tipo casilla, o ni siquiera eso, sencillamente una matriz de colores, y tomar el color negro como casilla vacía. Es cuestión de ir probando, no se nace sabiendo ![]() Saludos |
|
#7
|
|||
|
|||
|
Me parece demasiado avanzado ya, pero veo que puedo hacer, muchas gracias!!!
|
![]() |
| Herramientas | Buscar en Tema |
| Desplegado | |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| matrices | finees | Varios | 5 | 15-11-2006 01:52:27 |
| funciones y matrices | anto1178 | Varios | 1 | 28-08-2006 17:29:31 |
| juegos 2d | Flores | Varios | 0 | 30-05-2005 14:44:35 |
| Matrices | sergio_015 | OOP | 3 | 09-03-2005 19:53:07 |
| Matrices | mmtaffarel | OOP | 2 | 15-10-2004 03:19:27 |
|