Dino Direct

Visite nosso Grupo de Compras!
Votação DingooBR!!!

VOTE NO NOSSO SITE

Contamos com sua ajuda!

Buscar
 
 

Resultados por:
 


Rechercher Busca avançada

Maio 2013
DomSegTerQuaQuiSexSab
   1234
567891011
12131415161718
19202122232425
262728293031 

Calendário Calendário

Últimos assuntos
» O que anda jogando
por gilplay3000 Hoje à(s) 12:31 pm

» Qual foi o jogo(s) mais díficil que você já terminou?
por scorpion Hoje à(s) 12:14 pm

» emulador de nes para android
por waguinao333 Hoje à(s) 10:29 am

» Unboxing Revo GBA K101
por mrdisco Hoje à(s) 9:58 am

» Novo Portátil - Droid X360
por italo Hoje à(s) 9:32 am

» Duvida ? Paypal
por lakers20 Hoje à(s) 8:34 am

» JXD S5110B Dual Core 1.5GHz android 4.1.1 1GB Ram, pré-venda na willgoo
por felipeROx Hoje à(s) 3:55 am

» [CUSTOM FIRMWARE] TheXSample-SXELROM v3.5 para JXD S7300B [Update 18/05/2013]
por Deen0X Hoje à(s) 3:27 am

» JXD S5110 com tela touch screen com defeito.
por Ludio_Ludius Ontem à(s) 3:09 pm

» Poste Aqui a sua Compra da DinoDirect
por paulo*recife Ontem à(s) 12:22 pm

» [VENDO] Portátil Android - JXD S5110
por jonas453 Ontem à(s) 12:21 pm

» [UPDATE] PocketSNES v1.0 for Gemei A330
por italo Ontem à(s) 9:46 am

» JXD S7300 em ação
por alissonmano Dom 19 Maio 2013, 9:45 pm

» Bug com os botões do JXD
por mrdisco Dom 19 Maio 2013, 9:06 pm

» Problema na usb.
por leilton_sfc Dom 19 Maio 2013, 11:23 am


Minhas primeiras criações em PASCAL

Ver o tópico anterior Ver o tópico seguinte Ir em baixo

Minhas primeiras criações em PASCAL

Mensagem por italo em Qui 31 Maio 2012, 5:31 pm

Olá gente, já faz um tempo que eu começei a estudar no CEFET aqui do meu estado e já comeicei a fazer umas exeperiênciaszinhas com a linguagem PASCAL. Por enquanto é só um mas vou amentar essa lista...

4shared.com 4shared.com/file/mkBEf2Tl/OPERACOE.html

Programa da tabuada:

4shared.com 4shared.com/rar/hXXBzamV/TABUADA.html

Trata-se de um programa que recebe dois valores e após isso, o usuário escolhe alguma operação a ser feita.

Bem é isso, oque acharam? To muito ansioso pra aprender mais e criar um joguinho Very Happy
-----------------------------------------------------------------------------------------------
ATUALIZADO

PS: Refiz o programa da tabuada com a estrutura FOR, podem ver que ficou muito menor do que com WHILE.

Spoiler:
Program Tabuada ;
var x, i: integer;
Begin
writeln ('TABUADA - 1 a 9');
for x:= 1 to 9 do
begin
writeln;
for i:= 1 to 9 do
begin
writeln (x,' x ',i,' = ', i *x);
end;
end;
End.


Pois eh, to gostando de programar mas num é fácil não...


Última edição por italo em Sex 06 Jul 2012, 2:34 pm, editado 3 vez(es)

_________________
tutorial de instalação de ítens no dingux:
http://dingoobr.forumeiros.com/t1937-tutorial-instalando-coisas-no-gmenu2x
---------------------------------------------------------------------------------------------------------------
Equipe Dingoo From The Past
Spoiler:

Dingoo From The Past #5 Megaman Battle Network [GBA] Por Italo
http://dingoobr.forumeiros.com/t2483-dingoo-from-the-past-5-megaman-battle-network-gba
Dingoo From The Past #14 Adventure Island 4 [NES] por Italo
http://dingoobr.forumeiros.com/t2580-dingoo-from-the-past-14-adventure-island-4-nes
Dingoo From The Past #19 - Megaman 2 [NES] por Italo
http://dingoobr.forumeiros.com/t2689-dingoo-from-the-past-19-megaman-2-nes#42565
Dingoo From The Past # 22 - Star Fox [SNES] por Italo
http://dingoobr.forumeiros.com/t2738-dingoo-from-the-past-22-star-fox-snes#43255

italo
Moderador
Moderador

Avisos:
0 / 1000 / 100

Mensagens: 1858
Data de inscrição: 06/06/2011
Idade: 16
Localização: Aracaju-SE

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por Patrick em Qui 31 Maio 2012, 6:12 pm

Parabéns cara, trabalho como programador a quase 2 anos mas nunca nem cheguei perto de pascal, programei apenas em C,C++,C# e agora estou programando em uma linguagem desenvolvida pela empresa em que trabalho é uma linguagem baseada em workflow e dedicada a industria.

Se pretende seguir a carreira deve ter em mente que não é um trabalho fácil... é um aprendizado constante tu nunca vai parar de estudar pois por mais que tu saiba sempre tem mais para aprender! mas por outro lado é extremamente gratificante ver algo que saiu de tuas linhas funcionando!

Boa sorte nas tuas aplicações!


ps: não costumo postar muito no fórum mas estou sempre acompanhando os acontecimentos do mundo dos portáteis "alternativos"...

Patrick
User Level II
User Level II

Avisos:
0 / 1000 / 100

Mensagens: 95
Data de inscrição: 19/10/2011
Idade: 24
Localização: Canoas-rs

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por Favato em Qui 31 Maio 2012, 6:13 pm

Depois se quiser eu te passo dois jogos que baixei, um TD e um snake, linguagem em pascal é fácil e talz.. mas é meio inútil hoje em dia, eu particularmente gostaria de estar aprendendo outra linguagem mais difícil de cara... Jaja você começa usar units, modularizar etc...

ps: não abri o código

Favato
User Level III
User Level III

Avisos:
0 / 1000 / 100

Mensagens: 194
Data de inscrição: 10/05/2012
Idade: 21

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por flpstr em Qui 31 Maio 2012, 6:33 pm

Bacana cara! Continue assim Smile

flpstr
Developer
Developer

Avisos:
0 / 1000 / 100

Mensagens: 2660
Data de inscrição: 19/05/2011
Idade: 15
Localização: No pc

http://flpstr.blogspot.com

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por Favato em Sab 02 Jun 2012, 10:47 am

Alguém com conhecimento em pascal poderia me ajudar a descobrir um erro no meu código? Já revisei varias vezes e não encontro, ele sempre retorna o menor número digitado, ao invés do Maior divisor comum dos números... ;s

Código:
Program CalculaMaximoDivisorNoveNumeros;
Uses CRT;

   procedure CalculaMDC (var A,B,C:integer ; var MDC:integer);

    function Menor(X,Y,Z:integer):integer;
     begin
       if (X<Y) and (X<Z) then
         Menor:=X
       else
         if (Y<X) and (Y<Z) then
      Menor:=Y
         else
      Menor:=Z
     end;

   begin
   MDC:=Menor(A,B,C);

     while
       ((A mod MDC)<>0) and ((B mod MDC)<>0) and ((C mod MDC)<>0) do
       MDC:= MDC-1;

   end;


Var A,B,C,D,E,F,G,H,I,
    W,X,Y,
    Z:integer;

Begin
ClrScr;
   Writeln('-------------------------------------------------------------------------');
   Writeln('-  Turma E3  -  Nome: Humberto Garrido Favato  -  Matr¡cula 2011078363  -');
   Writeln('-------------------------------------------------------------------------');
   Writeln('Este programa mostrar  o Maior Divisor Comum dos nove n£meros digitados.');
   Writeln('');
   Writeln('');


readln(A,B,C,D,E,F,G,H,I);
CalculaMDC(A,B,C,W);
CalculaMDC(D,E,F,X);
CalculaMDC(G,H,I,Y);
CalculaMDC(W,X,Y,Z);
Writeln(Z);

readkey;
end.


Favato
User Level III
User Level III

Avisos:
0 / 1000 / 100

Mensagens: 194
Data de inscrição: 10/05/2012
Idade: 21

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por Favato em Sab 02 Jun 2012, 10:52 am

italo escreveu:

Bem é isso, oque acharam? To muito ansioso pra aprender mais e criar um joguinho Very Happy



Vou colocar o código de 2jogos pra você, você abre o BN compila e executa o .EXE...


Snake
Código:
program snake;

uses CRT;

Type
  ptpos = ^posicao; { ponteiro para lista circular }
  posicao = record
      ant: ptpos;
      x: integer;
      y: integer;
      prox: ptpos;
  end;

  cab = record
      apont: ptpos;
      corpo: string;
  end;

var
  opc: char;
  opaux: char;
  h, v, cont, apagax, apagay: integer;
  prim, p, pultimo: ptpos;
  comidaX, comidaY, opx, opy, opz: integer;
  tamanhoc: integer;
  vidas: integer;
  dificuldade: integer;
  pontos: integer;
  jogador: string;
  cabeca: cab;
  velocidade: integer; { tempo de dalay }

procedure ListaCircular;
begin
{Cria uma lista circular duplamente encadada com 15 elementos
que o tamanho m'e1ximo da cobra cada elemento comtem uma
cordenada (x,y) de onde a cobra esta passando}
  new(prim);
  prim^.x := 2;
  prim^.y := 4;
  p := prim;
  for cont := 1 to 200 do
  begin
      new(pultimo);
      pultimo^.x := 2;
      pultimo^.y := 4;
      p^.prox := pultimo;
      pultimo^.ant := p;
      p := pultimo;
  end;
  pultimo^.prox := prim;
  prim^.ant := pultimo;
  cabeca.apont := prim;
end;

procedure PreencheCorpo;
var i, a, b: integer;
  aux: string;
begin
  aux := '';
  a := length(jogador);
  if (dificuldade = 1) and (a = 12) then
      dificuldade := 2;
  if (dificuldade = 2) and (a = 25) then
      dificuldade := 3;
  if a < 200 then
      for i := a to 200 do
      begin
        aux := aux + 'O';
      end;
  cabeca.corpo := '@OO' + aux;
end;

procedure Inicializa;
begin
  delay(1000);
  clrscr;
  pontos := 0;
  dificuldade := 1;
  vidas := 3;
  { jogador := 'Orivaldo'; }
  preenchecorpo;
  tamanhoc := 3;
  velocidade := 110;
  opc := 'a';
  opx := 0;
  opy := 80;
end;


procedure AtualizaVariaveis;
begin
  textcolor(14);
  gotoxy(18,2); write(pontos);
  gotoxy(45,2); write(dificuldade);
  gotoxy(67,2); write(vidas);
end;

procedure linhaH(posicaox, posicaoy, tamanho: integer);
var a: integer;
begin
  a := posicaox;
  while a < (posicaox + tamanho) do
  begin
      gotoxy(a,posicaoy);
      write('#');
      a := a + 1;
  end;
end;

procedure linhaV(posicaox, posicaoy, tamanho: integer);
var a: integer;
begin
  for a := posicaoy to (posicaoy + tamanho) do
  begin
      gotoxy(posicaox,a);
      write('#');
  end;
end;

procedure GeraTela;
begin
  opx := 0;  {ope'e7'f5es x e y que fazem a cobra se movimentar para baixo}
  opy := 80;
  h := 2;
  v := 4;
  clrscr;

  AtualizaVariaveis;

  textcolor(15);
  gotoxy(10,2); write('Pontos:');
  gotoxy(32,2); write('Dificuldade:');
  gotoxy(60,2); write('Vidas:');
  gotoxy(1,4);

  textcolor(11);
  linhaH(1,4,79);
  linhaH(1,24,79);
  linhaV(1,5,19);
  linhaV(79,5,19);
end;


procedure Apaga;
var papaga: ptpos;
begin
  textcolor(10);
  papaga := pultimo;
  gotoxy(papaga^.x,papaga^.y);
  write('*');
  textcolor(0);
  papaga := pultimo;
  papaga := pultimo^.ant;
  apagax := papaga^.x;
  apagay := papaga^.y;
  gotoxy(apagax,apagay);
  write('*');
  textcolor(10);
end;

procedure TamanhoCobra (tam : integer);
begin
  pultimo := cabeca.apont; {faz o final da cobra amumentar}
  for cont := 1 to tam do
    pultimo := pultimo^.ant;
end;


procedure Telainicial;
var
  posx, posy: integer;
begin
  posx := 20;
  posy := 2;
  clrscr;

  textcolor(12);
  gotoxy(posx+13,posy);  writeln('JOGO DA COBRINHA');

  textcolor(15);
  gotoxy(posx+7,posy+8); writeln('Pressione ENTER para comecar');

  textcolor(11);
  linhaH(1,  posy+14, 80);
  linhaH(1,  posy+22, 80);
  linhaV(1,  posy+15, 6);
  linhaV(80, posy+15, 6);

  textcolor(12);
  gotoxy(3,posy+16); writeln('COMANDOS:');
  textcolor(15);
  gotoxy(5,posy+18); writeln('SETAS movimentam a cobra');
  gotoxy(5,posy+19); writeln('ESC para Sair');
  gotoxy(5,posy+20); writeln('P para Pausa');
  textcolor(7);
  gotoxy(posx+30,posy+11);
  readkey;
end;

procedure ComecarNovamente;
var i: integer;

 procedure gameover;
 var posx,posy: integer;
 begin
 posx := 22;
 posy := 5;
 gotoxy(posx+15,posy+10);
 writeln('GAME OVER');

{ gotoxy(posx-2,posy+16); writeln('Pressione qualquer tecla para CONTINUAR ',i);}
 end;


begin
{ reseta a posi'e7'e3o da cobra para o canto superior esquerdo}
 p := pultimo;
 for i := 1 to 15 do begin
 p^.x := 2;
 p^.y := 4;
 p := p^.prox;
 end;

 tamanhoC := 3;

 tamanhoCobra(tamanhoC); {coloca a cobra com o tamanho 3}


 textcolor(7);
 gotoxy(67,2); write(vidas);
 if vidas = 0 then begin

 i := 9;  {quantidade de seguntos restante}
 while (i >= 0)  do begin
 textcolor(red);
 gameover;
 delay(400);
 textcolor(7); {cinza claro}
 gameover;
 delay(600);
 i := i -1;
 if keypressed then
 i := -1;
 end;
 inicializa;
 end;
 geratela;
end;

procedure verificaPosicao; { verifca a posica'e3o de colisa'e3o }
begin
  if (cabeca.apont^.x > 77) or (cabeca.apont^.x < 2) or (cabeca.apont^.y > 23) or (cabeca.apont^.y < 5) then
  begin
      vidas := vidas -1;
      comecarnovamente;
  end;
end;


procedure criaComida;
begin
  comidaX := 2 +  random(77);
  comidaY := 5 +  random(19);
  textcolor(12);
  {indica o caracter que representarar a comida}
  gotoxy(comidaX,comidaY); write(cabeca.corpo[tamanhoc+1]);
end;

procedure atualizaComida; {mostra a comida na tela}
begin
  textcolor(12);
  {indica o caracter que representarar a comida}
  gotoxy(comidaX,comidaY); write(cabeca.corpo[tamanhoC+1]);
end;

procedure mudaDificuldade;
begin
  Dificuldade := Dificuldade +1;
  velocidade := velocidade - 20 div dificuldade; { imprime na tela no intervalo que 'e9 10 milisegundo menor que o anterior;}
end;

procedure verificacomida;
begin
  if (cabeca.apont^.x = comidax) and (cabeca.apont^.y = comiday) then
  begin
      CriaComida;
      tamanhoc := tamanhoc +1;
      TamanhoCobra(tamanhoc);
      pontos := pontos + 10;
      if tamanhoc = 15  then
        MudaDificuldade;
  end;
end;

procedure mover(a,b: integer); {faz a cobra se mover para norte(0,1),}
var i: integer;  {sul(0,-1), leste(-1,0) e oeste(1,0)}
 q: ptpos;
begin
  cabeca.apont := cabeca.apont^.prox;
  h := h + a;
  v := v + b;
  cabeca.apont^.x := h;
  cabeca.apont^.y := v;
  verificaposicao;
  i := tamanhoc;
  q := cabeca.apont;
  atualizaComida;
  textcolor(10); {cor azul claro da cobra}
  for i := 1 to tamanhoc do
  begin {cria a cobra na tela}
      gotoxy(q^.x,q^.y);
      q := q^.ant;
      write(cabeca.corpo[i]);
  end;
  pultimo := pultimo^.prox;
  verificacomida;
  apaga;
  atualizaVariaveis;
end;

Begin
  TelaInicial;
  Inicializa;
  Geratela;
  CriaComida;
  {esta lista circular comtem os caracteres e a posicao da cobra}
  Listacircular;
  TamanhoCobra(tamanhoc);

  {este e o laco principal do jogo usado para identificar quais sao as teclas usada pelo jogador}
  opc := 'a';
  while (opc <> 's') do
  begin
      if keypressed then
      begin
        opc := readkey;
        {a funcao ord nos fornece qual o codigo ascii da tecla, mas tem um
        problema quando o jogador usa teclas especias tipo as setas do teclado.
        Tem que usar duas variaveis para guardar o codigo dessas teclas
        especias, observando que a primeira variavel sempre fica com o valor 0}
        opz := ord(opc);
        if opz = 0 then
        begin
            opx := opz;
            opc := readkey;
            opz := ord(opc);
            if (opz = 75) or (opz = 77) or (opz = 72) or (opz = 80) then
              opy := opz;
            end;
            {para quando aperta 'p' ficar em pausa}
            if opz = 112 then begin
              opc := 'a';
              opy := 111;
              while (opz <> 112) do
                  if keypressed then
                  begin
                    opc := readkey;
                    opz := ord(opc);
                    if opz = 0 then
                        opz := ord(opc)
                    end;
                  end;
                  if opz = 27 then {para usar ESC quando quiser sair do programa}
                    opc := 's';
                  end
                  else begin
                    if opx = 0 then
                    begin
                        case opy of
                          75: mover(-1,0); { movimentra para esquerda }
                          77: mover(1,0);  { movimenta para direita}
                          72: mover(0,-1); { para cima }
                          80: mover(0,1);  { para baixo }
                            1: comecarnovamente;
                            2: telainicial;
                    end;
                    delay(velocidade);
                end;
              end;
          end;
          gotoxy(1,40);
          clrscr;
end.


Tower Defense
Código:
Program TowerDefense;
{**********************************************************}
uses crt;
{**********************************************************}
const hor = #205; ver = #186; Sesq = #201;
      Sdir = #187; Iesq = #200; Idir = #188;
{**********************************************************}
type
{Matrizes que armazenam a cor e o caracter de cada ponto da interface}
matrizNum = array [1..80,1..25] of longint;
matrizCar = array [1..80,1..25] of char;
{Matriz com a rota dos monstros na tela}
matrizRota = array [1..80,1..25] of char;

{Posi‡Æo no mapa}
tipo_posicao = record
          x: integer;{linha}
          y: integer;{coluna}
          end;

{Monstro}
tipo_monster = record
            vida: longint;
            posicao: tipo_posicao;
            primeiro: boolean;
            destruido: boolean;
          end;

{Wave: as configuracoes que definem um n¡vel}
tipo_wave = record
                monstro: array [1..20] of tipo_monster;
                skin: char;
                cor: longint;
                velocidade: longint;
                dinheiro: longint;
                iniciado: boolean;
            end;
{Torre: configuracoes da torre}
tipo_torre = record
                ataque: integer;
                posicao: tipo_posicao;
                skin_ataque: char;
                cor: integer;
                tipo: integer;
                vel: integer;
                atacou: boolean;
            end;

tipo_jogador = record
                vida: integer;
                dinheiro: longint;
              end;

tipo_wave2 = array [1..10] of tipo_wave;
{Formato Tipo 1}
{  < O > } {ataque = o }

{Formato Tipo 2}
{  \^/
  /V\  } {ataque = . }

{Formato Tipo 3}
{  <<*>>  } {ataque = * }
{**********************************************************}
var mapa: matrizCar;
    corMapa, mapaTorre: matrizNum;
    mapaRota: matrizRota;
    wave: tipo_wave2;
    cur: tipo_posicao;
    torre: array [1..1000] of tipo_torre;
    ind_tor, i, erro: integer;
    jogador: tipo_jogador;
    k: string;
{**********************************************************}

Procedure alerta(s: string);
Begin
        window(63,10,79,15);
        textcolor(7);
        textbackground(0);
        clrscr;
        write(s);
        window(1,1,80,25);
end;

Procedure statusJogador;
Begin
        window(63,17,79,21);
        textbackground(0);
        clrscr;
        textcolor(yellow);
        writeln('    JOGADOR');
        writeln;
        textcolor(7);
        writeln(' Vidas: ',jogador.vida);
        writeln(' Money: $',jogador.dinheiro);
        window(1,1,80,25);
end;

Procedure ImpPos(x, y: integer; s: char; corMapa: matrizNum; cor: integer);
begin
   gotoxy(y,x);
        textbackground(corMapa[y,x]);
        textcolor(cor);
        write(s);
end;

Procedure InsereTorre1(x,y: integer);
Begin
        if (corMapa[y-1,x]=2) and (corMapa[y+1,x]=2) and
          (mapaTorre[y-1,x]=0) and (mapaTorre[y+1,x]=0) and
          (jogador.dinheiro>=20) then
        begin
                inc(ind_tor);
                torre[ind_tor].ataque:=1;
                torre[ind_tor].posicao.x:=x;
                torre[ind_tor].posicao.y:=y;
                torre[ind_tor].skin_ataque:='o';
                torre[ind_tor].cor:=0;
                torre[ind_tor].tipo:=1;
                torre[ind_tor].vel:=20;
                mapa[y,x]:='O';
                mapa[y-1,x]:=#17;
                mapa[y+1,x]:=#16;
                ImpPos(x,y,mapa[y,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_tor].cor);
                mapaTorre[y,x]:=ind_tor;
                mapaTorre[y+1,x]:=ind_tor;
                mapaTorre[y-1,x]:=ind_tor;
                dec(jogador.dinheiro,20);
                StatusJogador;
        end
        else
        begin
                if jogador.dinheiro<20 then alerta('Vocˆ nÆo possui dinheiro suficiente para comprar essa torre.')
                else
                alerta('NÆo ‚ poss¡vel colocar uma torre do tipo 1 nesse local.');
        end;
end;

Procedure InsereTorre2(x,y: integer);
Begin
        if (corMapa[y-1,x]=2) and (corMapa[y+1,x]=2) and
          (corMapa[y-1,x-1]=2) and (corMapa[y+1,x-1]=2) and
          (mapaTorre[y-1,x]=0) and (mapaTorre[y+1,x]=0) and
          (mapaTorre[y-1,x-1]=0) and (mapaTorre[y+1,x-1]=0) and
          (jogador.dinheiro>=400) then
        begin
                inc(ind_tor);
                torre[ind_tor].ataque:=50;
                torre[ind_tor].posicao.x:=x;
                torre[ind_tor].posicao.y:=y;
                torre[ind_tor].skin_ataque:=#250;
                torre[ind_tor].cor:=9;
                torre[ind_tor].tipo:=2;
                torre[ind_tor].vel:=30;
                mapa[y,x]:=#31;
                mapa[y-1,x]:='/';
                mapa[y+1,x]:='\';
                mapa[y,x-1]:=#30;
                mapa[y-1,x-1]:='\';
                mapa[y+1,x-1]:='/';
                ImpPos(x,y,mapa[y,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_tor].cor);
                ImpPos(x-1,y,mapa[y,x-1],corMapa,torre[ind_tor].cor);
                ImpPos(x-1,y-1,mapa[y-1,x-1],corMapa,torre[ind_tor].cor);
                ImpPos(x-1,y+1,mapa[y+1,x-1],corMapa,torre[ind_tor].cor);
                mapaTorre[y,x]:=ind_tor;
                mapaTorre[y+1,x]:=ind_tor;
                mapaTorre[y-1,x]:=ind_tor;
                mapaTorre[y,x-1]:=ind_tor;
                mapaTorre[y+1,x-1]:=ind_tor;
                mapaTorre[y-1,x-1]:=ind_tor;
                dec(jogador.dinheiro,400);
                StatusJogador;
        end
        else
        begin
                if jogador.dinheiro<400 then alerta('Vocˆ nÆo possui dinheiro suficiente para comprar essa torre.')
                else
                alerta('NÆo ‚ poss¡vel colocar uma torre do tipo 1 nesse local.');
        end;
end;

Procedure InsereTorre3(x,y: integer);
Begin
        if (corMapa[y-1,x]=2) and (corMapa[y+1,x]=2) and
          (mapaTorre[y-1,x]=0) and (mapaTorre[y+1,x]=0) and
          (jogador.dinheiro>=700) then
        begin
                inc(ind_tor);
                torre[ind_tor].ataque:=50;
                torre[ind_tor].posicao.x:=x;
                torre[ind_tor].posicao.y:=y;
                torre[ind_tor].skin_ataque:='*';
                torre[ind_tor].cor:=12;
                torre[ind_tor].tipo:=3;
                torre[ind_tor].vel:=30;
                mapa[y,x]:=#15;
                mapa[y-1,x]:=#174;
                mapa[y+1,x]:=#175;
                ImpPos(x,y,mapa[y,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_tor].cor);
                mapaTorre[y,x]:=ind_tor;
                mapaTorre[y+1,x]:=ind_tor;
                mapaTorre[y-1,x]:=ind_tor;
                dec(jogador.dinheiro,700);
                StatusJogador;
        end
        else
        begin
                if jogador.dinheiro<700 then alerta('Vocˆ nÆo possui dinheiro suficiente para comprar essa torre.')
                else
                alerta('NÆo ‚ poss¡vel colocar uma torre do tipo 1 nesse local.');
        end;
end;

Procedure ExcluirTorre13(x,y,ind_t: integer);
var i, x1, y1: integer;
Begin
        mapa[y,x]:=' ';
        mapa[y-1,x]:=' ';
        mapa[y+1,x]:=' ';
        mapaTorre[y,x]:=0;
        mapaTorre[y+1,x]:=0;
        mapaTorre[y-1,x]:=0;
        ImpPos(x,y,mapa[y,x],corMapa,torre[ind_t].cor);
        ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_t].cor);
        ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_t].cor);
        if torre[ind_t].tipo=1 then inc(jogador.dinheiro,10)
        else inc(jogador.dinheiro,350);
        StatusJogador;
        for i:=ind_t to ind_tor-1 do
        begin
                torre[i].ataque:=torre[i+1].ataque;
                torre[i].posicao.x:=torre[i+1].posicao.x;
                torre[i].posicao.y:=torre[i+1].posicao.y;
                torre[i].skin_ataque:=torre[i+1].skin_ataque;
                torre[i].cor:=torre[i+1].cor;
                torre[i].tipo:=torre[i+1].tipo;
                torre[i].vel:=torre[i+1].vel;
                x1:=torre[i].posicao.x;
                y1:=torre[i].posicao.y;
                if torre[i].tipo=2 then
                begin
                        mapaTorre[y1,x1-1]:=i;
                        mapaTorre[y1+1,x1-1]:=i;
                        mapaTorre[y1-1,x1-1]:=i;
                end;
                mapaTorre[y1,x1]:=i;
                mapaTorre[y1+1,x1]:=i;
                mapaTorre[y1-1,x1]:=i;
        end;
        ind_tor:=ind_tor-1;
end;

Procedure ExcluirTorre2(x,y,ind_t: integer);
var i, x1, y1: integer;
Begin
        mapa[y,x]:=' ';
        mapa[y-1,x]:=' ';
        mapa[y+1,x]:=' ';
        mapa[y,x-1]:=' ';
        mapa[y-1,x-1]:=' ';
        mapa[y+1,x-1]:=' ';
        mapaTorre[y,x]:=0;
        mapaTorre[y+1,x]:=0;
        mapaTorre[y-1,x]:=0;
        mapaTorre[y,x-1]:=0;
        mapaTorre[y+1,x-1]:=0;
        mapaTorre[y-1,x-1]:=0;
        ImpPos(x,y,mapa[y,x],corMapa,torre[ind_t].cor);
        ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_t].cor);
        ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_t].cor);
        ImpPos(x-1,y,mapa[y,x-1],corMapa,torre[ind_t].cor);
        ImpPos(x-1,y-1,mapa[y-1,x-1],corMapa,torre[ind_t].cor);
        ImpPos(x-1,y+1,mapa[y+1,x-1],corMapa,torre[ind_t].cor);
        inc(jogador.dinheiro,200);
        Statusjogador;
        for i:=ind_t to ind_tor-1 do
        begin
                torre[i].ataque:=torre[i+1].ataque;
                torre[i].posicao.x:=torre[i+1].posicao.x;
                torre[i].posicao.y:=torre[i+1].posicao.y;
                torre[i].skin_ataque:=torre[i+1].skin_ataque;
                torre[i].cor:=torre[i+1].cor;
                torre[i].tipo:=torre[i+1].tipo;
                torre[i].vel:=torre[i+1].vel;
                x1:=torre[i].posicao.x;
                y1:=torre[i].posicao.y;
                if torre[i].tipo=2 then
                begin
                        mapaTorre[y1,x1-1]:=i;
                        mapaTorre[y1+1,x1-1]:=i;
                        mapaTorre[y1-1,x1-1]:=i;
                end;
                mapaTorre[y1,x1]:=i;
                mapaTorre[y1+1,x1]:=i;
                mapaTorre[y1-1,x1]:=i;
        end;
        ind_tor:=ind_tor-1;
end;

{Define as configura‡äes da wave}
Procedure CriarWave(var wave: tipo_wave; vida, vel, din, cor: longint; skin: char);
var i, h: integer;
Begin
        wave.velocidade:=vel;
        wave.dinheiro:=din;
        wave.skin:=skin;
        wave.cor:=cor;
        for i:=1 to 20 do
        begin
                wave.monstro[i].vida:=vida;
                wave.monstro[i].posicao.x:=5;
                wave.monstro[i].posicao.y:=2;
                wave.monstro[i].primeiro:=true;
                wave.monstro[i].destruido:=false;
        end;
end;

Procedure ComprarTorre;
Begin
        window(63,2,79,8);
        textbackground(7);
        textcolor(2);
        clrscr;
        gotoxy(7,2);
        write('TORRE');
        textcolor(0);
        gotoxy(2,4);
        write('*F1');
        gotoxy(2,5);
        write(#17,'O',#16);
        gotoxy(2,7);
        write('$20');
        gotoxy(8,4);
        write('*F2');
        gotoxy(8,5);
        write('\',#30,'/');
        gotoxy(8,6);
        write('/',#31,'\');
        gotoxy(8,7);
        write('$400');
        gotoxy(14,4);
        write('*F3');
        gotoxy(14,5);
        write(#174,#15,#175);
        gotoxy(14,7);
        write('$700');
        window(1,1,80,25);
end;

Procedure ImprimeCursor(cor1, cor2: integer);
Begin
        gotoxy(cur.y,cur.x);
        textbackground(cor1);
        textcolor(cor2);
        write(mapa[cur.y,cur.x]);
end;

Procedure comandos;
Begin
        gotoxy(2,23);
        textcolor(7);
        textbackground(0);
        write('Enter: pausar | ');
        write('F1/F2/F3: criar torre | ');
        write('Delete: excluir torre | ');
        write('Esc: sair');
end;

Procedure destroi(var wave: tipo_wave; h: integer; corMapa: matrizNum; var cont: integer);
Begin
        wave.monstro[h].destruido:=true;
        ImpPos(wave.monstro[h].posicao.x,wave.monstro[h].posicao.y,' ',corMapa,wave.cor);
        dec(cont);
end;

Procedure Perdeu;
Begin
        clrscr;
        gotoxy(35,12);
        textcolor(red);
        writeln('GAME OVER!!');
end;

Procedure Ganhou;
Begin
        clrscr;
        gotoxy(30,12);
        textcolor(yellow);
        writeln('PARABNS, VOCÒ GANHOU!!');
end;

{Inicia um n¡vel com uma determinada wave}
Procedure IniciarNivel(var wave: tipo_wave2; corMapa: matrizNum; mapaRota: matrizRota; n: integer);
var cont, qtd, i, marc, x, y, m: integer;
    t, ind_t, h, ini_cont, marcador: integer;
    s, c: char;
    aux: string;
Begin
      cont:=20;
      qtd:=1;
      marc:=0;
      t:=0;
      m:=0;
      wave[n].iniciado:=false;
      ini_cont:=15;
      marcador:=10;
      while (cont>=1) and (jogador.vida>0) do
      begin
          while (cont>=1) and not(keypressed) and (jogador.vida>0) do
          begin
                if (t mod wave[n].velocidade=0) and (t<>0) then
                begin
                  for i:=1 to qtd do
                  begin
                        x:=wave[n].monstro[i].posicao.x;
                        y:=wave[n].monstro[i].posicao.y;
                        if (mapaRota[y,x]<>' ') and not(wave[n].monstro[i].destruido) then
                        begin
                                if wave[n].monstro[i].primeiro then
                                begin
                                        wave[n].monstro[i].primeiro:=false;
                                        ImpPos(x,y,wave[n].skin,corMapa,wave[n].cor);
                                end
                                else
                                begin
                                        ImpPos(x,y,' ',corMapa,wave[n].cor);
                                        if mapaRota[y,x]='B' then x:=x+1
                                        else
                                        if mapaRota[y,x]='D' then y:=y+1
                                        else
                                        if mapaRota[y,x]='E' then y:=y-1;
                                        ImpPos(x,y,wave[n].skin,corMapa,wave[n].cor);
                                        wave[n].monstro[i].posicao.x:=x;
                                        wave[n].monstro[i].posicao.y:=y;
                                end;
                                if mapaRota[y,x]=' ' then
                                begin
                                        destroi(wave[n],i,corMapa,cont);
                                        dec(jogador.vida);
                                        StatusJogador;
                                end;
                        end;
                  end;
                  inc(marc);
                  if (marc mod 4 = 0) and (qtd<20) then inc(qtd);
                end;
                if wave[n].iniciado then
                for i:=1 to ind_tor do
                begin
                        if t mod torre[i].vel = 0 then
                        begin
                                h:=1;
                                torre[i].atacou:=false;
                                while (h<=qtd) and not(torre[i].atacou) do
                                begin
                                        x:=wave[n].monstro[h].posicao.x;
                                        y:=wave[n].monstro[h].posicao.y;
                                        if (abs(x-torre[i].posicao.x)<=4) and
                                          (abs(y-torre[i].posicao.y)<=6) and
                                          not(wave[n].monstro[h].destruido) then
                                        begin
                                                if x<torre[i].posicao.x then
                                                begin
                                                        ImpPos(x+1,y,torre[i].skin_ataque,corMapa,yellow);
                                                        ImpPos(x+1,y,' ',corMapa,yellow);
                                                end
                                                else
                                                begin
                                                        ImpPos(x-1,y,torre[i].skin_ataque,corMapa,yellow);
                                                        ImpPos(x-1,y,' ',corMapa,yellow);
                                                end;
                                                dec(wave[n].monstro[h].vida,torre[i].ataque);
                                                if wave[n].monstro[h].vida<=0 then
                                                begin
                                                        destroi(wave[n],h,corMapa,cont);
                                                        inc(jogador.dinheiro,wave[n].dinheiro);
                                                        StatusJogador;
                                                end;
                                                torre[i].atacou:=true;
                                        end;
                                        inc(h);
                                end;
                        end;
                end;
                if t = 10000 then t:=0;
                delay(10);
                t:=t+10;
                if not(wave[n].iniciado) then
                begin
                    if marcador mod 400 = 0 then
                    begin
                        dec(ini_cont);
                        str(ini_cont,k);
                        str(n,aux);
                        k:='O n¡vel '+aux+' iniciar  em '+k+' segundos.';
                        alerta(k);
                        if ini_cont=0 then
                        begin
                                k:='N¡vel '+aux+' iniciado.';
                                alerta(k);
                                wave[n].iniciado:=true;
                        end;
                    end;
                    delay(10);
                    t:=0;
                    inc(marcador,10);
                end;
          end;
          if keypressed then
          begin
                c:=readkey;
                if ord(c)=0 then
                begin
                        c:=readkey;
                        if ord(c)=80 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                while (corMapa[y,x+1]<>2) and (x<=20) do inc(x);
                                if x<>21 then
                                begin
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(corMapa[cur.y,cur.x],0)
                                        else ImprimeCursor(corMapa[cur.y,cur.x],torre[mapaTorre[cur.y,cur.x]].cor);
                                        cur.x:=x+1;
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(1,0)
                                        else ImprimeCursor(4,torre[mapaTorre[cur.y,cur.x]].cor);
                                end;
                        end
                        else
                        if ord(c)=72 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                while (corMapa[y,x-1]<>2) and (x>=3) do dec(x);
                                if x<>2 then
                                begin
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(corMapa[cur.y,cur.x],0)
                                        else ImprimeCursor(corMapa[cur.y,cur.x],torre[mapaTorre[cur.y,cur.x]].cor);
                                        cur.x:=x-1;
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(1,0)
                                        else ImprimeCursor(4,torre[mapaTorre[cur.y,cur.x]].cor);
                                end;
                        end
                        else
                        if ord(c)=77 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                while (corMapa[y+1,x]<>2) and (y<=60) do inc(y);
                                if y<>61 then
                                begin
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(corMapa[cur.y,cur.x],0)
                                        else ImprimeCursor(corMapa[cur.y,cur.x],torre[mapaTorre[cur.y,cur.x]].cor);
                                        cur.y:=y+1;
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(1,0)
                                        else ImprimeCursor(4,torre[mapaTorre[cur.y,cur.x]].cor);
                                end;
                        end
                        else
                        if ord(c)=75 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                while (corMapa[y-1,x]<>2) and (y>=3) do dec(y);
                                if y<>2 then
                                begin
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(corMapa[cur.y,cur.x],0)
                                        else ImprimeCursor(corMapa[cur.y,cur.x],torre[mapaTorre[cur.y,cur.x]].cor);
                                        cur.y:=y-1;
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(1,0)
                                        else ImprimeCursor(4,torre[mapaTorre[cur.y,cur.x]].cor);
                                end;
                        end
                        else
                        if ord(c)=59 then InsereTorre1(cur.x,cur.y)
                        else
                        if ord(c)=60 then InsereTorre2(cur.x,cur.y)
                        else
                        if ord(c)=61 then InsereTorre3(cur.x,cur.y)
                        else
                        if ord(c)=83 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                if mapaTorre[y,x]<>0 then
                                begin
                                        ind_t:=mapaTorre[y,x];
                                        if torre[ind_t].tipo in[1,3] then
                                          excluirtorre13(torre[ind_t].posicao.x,torre[ind_t].posicao.y,ind_t)
                                        else excluirtorre2(torre[ind_t].posicao.x,torre[ind_t].posicao.y,ind_t);
                                end;
                        end;
                end
                else
                if ord(c)=13 then
                begin
                        c:=readkey;
                        while ord(c)<>13 do
                        begin
                                delay(10);
                                c:=readkey;
                        end;
                end
                else
                if ord(c)=27 then
                begin
                        inc(m);
                        alerta('Aperte ESC novamente para sair.');
                        c:=readkey;
                        if ord(c)=27 then jogador.vida:=0;
                end;
          end;
      end;
      if jogador.vida<=0 then Perdeu
      else
      if n<10 then IniciarNivel(wave,corMapa,mapaRota,n+1)
      else Ganhou;
end;



{Gera a rota que os monstros farÆo pelo mapa}
Procedure GerarRota(var mapaRota: matrizRota);
var i, h: integer;
Begin
        for i:=1 to 80 do
          for h:=1 to 25 do mapaRota[i,h]:=' ';
        for i:=2 to 54 do mapaRota[i,5]:='D';
        for i:=5 to 10 do mapaRota[55,i]:='B';
        for i:=55 downto 11 do mapaRota[i,11]:='E';
        for i:=11 to 16 do mapaRota[10,i]:='B';
        for i:=10 to 58 do mapaRota[i,17]:='D';
        for i:=17 to 20 do mapaRota[59,i]:='B';
end;

{Preenche um retƒngulo(em matriz) com um caracter "s"}
Procedure PreRet(x1,y1,x2,y2,s: longint; var corGrid: matrizNum);
var i, h: longint;
Begin
        for i:=y1 to y2 do
          for h:=x1 to x2 do corGrid[i,h]:=s;
end;

{Modela o contorno da tela na matriz}
Procedure Contorno(x1,y1,x2,y2: longint; var grid: matrizCar);
var i: longint;
Begin
        for i:=y1 to y2 do
        begin
                grid[i,x1]:=hor;
                grid[i,x2]:=hor;
        end;
        for i:=x1 to x2 do
        begin
                grid[y1,i]:=ver;
                grid[y2,i]:=ver;
        end;
        grid[y1,x1]:=Sesq;
        grid[y1,x2]:=#204;
        grid[y2,x1]:=Sdir;
        grid[y2,x2]:=#185;
        grid[1,24]:=Iesq;
        grid[80,24]:=Idir;
        grid[1,23]:=ver;
        grid[80,23]:=ver;
        for i:=x1+1 to x2-1 do grid[62,i]:=ver;
        grid[62,1]:=#203;
        grid[62,22]:=#202;
        grid[62,9]:=#204;
        grid[80,9]:=#185;
        grid[80,16]:=#185;
        grid[62,16]:=#204;
        for i:=63 to 79 do grid[i,16]:=hor;
        for i:=2 to 79 do grid[i,24]:=hor;
        for i:=63 to 79 do grid[i,9]:=hor;
end;

{Gera o mapa, atribuindo os valores de caracter e de cor a duas matrizes
distintas}
Procedure GerarMapa(var grid: matrizCar; var corGrid: matrizNum);
var i, h: longint;
Begin
        for i:=1 to 80 do
          for h:=1 to 24 do
          begin
                grid[i,h]:=' ';
                corGrid[i,h]:=0;
          end;
        grid[59,11]:='T';
        grid[60,11]:='D';
        PreRet(2,2,3,61,green,corGrid);
        PreRet(4,57,9,61,green,corGrid);
        PreRet(7,2,9,53,green,corGrid);
        PreRet(10,2,18,7,green,corGrid);
        PreRet(13,13,15,61,green,corGrid);
        PreRet(19,2,21,57,green,corGrid);
        PreRet(4,2,6,57,6,corGrid);
        PreRet(7,53,9,57,6,corGrid);
        PreRet(10,8,12,61,6,corGrid);
        PreRet(13,8,15,12,6,corGrid);
        PreRet(16,8,18,61,6,corGrid);
        PreRet(19,57,21,61,6,corGrid);
        PreRet(10,58,12,61,8,corGrid);
        Contorno(1,1,22,80,grid);
end;

{Imprime o mapa com os caracteres com sua respectiva cor de fundo}
Procedure ImprimirMapa(var grid: matrizCar; corGrid: matrizNum);
var i, h: longint;
Begin
        for i:=1 to 80 do
          for h:=1 to 24 do
          begin
                textbackground(corGrid[i,h]);
                gotoxy(i,h);
                write(grid[i,h]);
          end;
end;

Begin
        clrscr;
        cur.x:=2;
        cur.y:=2;
   ind_tor:=0;
   jogador.vida:=20;
   jogador.dinheiro:=200;

   GerarMapa(mapa,corMapa);
        ImprimirMapa(mapa,corMapa);
        GerarRota(mapaRota);
        CriarWave(wave[1],100,100,5,1,#2);
        CriarWave(wave[2],200,50,10,4,#1);
        CriarWave(wave[3],1200,130,50,7,#2);
        CriarWave(wave[4],2000,100,80,9,'@');
        CriarWave(wave[5],5000,130,150,15,'#');
        CriarWave(wave[6],8000,100,250,11,#2);
        CriarWave(wave[7],15000,80,1000,12,#1);
        CriarWave(wave[8],25000,50,3000,13,'$');
        CriarWave(wave[9],50000,80,20000,14,#2);
        CriarWave(wave[10],200000,150,50000,10,'@');
        ComprarTorre;
        Comandos;
        StatusJogador;
        ImprimeCursor(1,0);
        IniciarNivel(wave,corMapa,mapaRota,1);
        readln;
End.

Esse se quiser deixar mais fácil, procura por vida do jogador ou dinheiro e muda, geek

Favato
User Level III
User Level III

Avisos:
0 / 1000 / 100

Mensagens: 194
Data de inscrição: 10/05/2012
Idade: 21

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por italo em Dom 03 Jun 2012, 10:15 pm

Favato escreveu:
italo escreveu:

Bem é isso, oque acharam? To muito ansioso pra aprender mais e criar um joguinho Very Happy



Vou colocar o código de 2jogos pra você, você abre o BN compila e executa o .EXE...


Snake
Código:
program snake;

uses CRT;

Type
  ptpos = ^posicao; { ponteiro para lista circular }
  posicao = record
      ant: ptpos;
      x: integer;
      y: integer;
      prox: ptpos;
  end;

  cab = record
      apont: ptpos;
      corpo: string;
  end;

var
  opc: char;
  opaux: char;
  h, v, cont, apagax, apagay: integer;
  prim, p, pultimo: ptpos;
  comidaX, comidaY, opx, opy, opz: integer;
  tamanhoc: integer;
  vidas: integer;
  dificuldade: integer;
  pontos: integer;
  jogador: string;
  cabeca: cab;
  velocidade: integer; { tempo de dalay }

procedure ListaCircular;
begin
{Cria uma lista circular duplamente encadada com 15 elementos
que o tamanho m'e1ximo da cobra cada elemento comtem uma
cordenada (x,y) de onde a cobra esta passando}
  new(prim);
  prim^.x := 2;
  prim^.y := 4;
  p := prim;
  for cont := 1 to 200 do
  begin
      new(pultimo);
      pultimo^.x := 2;
      pultimo^.y := 4;
      p^.prox := pultimo;
      pultimo^.ant := p;
      p := pultimo;
  end;
  pultimo^.prox := prim;
  prim^.ant := pultimo;
  cabeca.apont := prim;
end;

procedure PreencheCorpo;
var i, a, b: integer;
  aux: string;
begin
  aux := '';
  a := length(jogador);
  if (dificuldade = 1) and (a = 12) then
      dificuldade := 2;
  if (dificuldade = 2) and (a = 25) then
      dificuldade := 3;
  if a < 200 then
      for i := a to 200 do
      begin
        aux := aux + 'O';
      end;
  cabeca.corpo := '@OO' + aux;
end;

procedure Inicializa;
begin
  delay(1000);
  clrscr;
  pontos := 0;
  dificuldade := 1;
  vidas := 3;
  { jogador := 'Orivaldo'; }
  preenchecorpo;
  tamanhoc := 3;
  velocidade := 110;
  opc := 'a';
  opx := 0;
  opy := 80;
end;


procedure AtualizaVariaveis;
begin
  textcolor(14);
  gotoxy(18,2); write(pontos);
  gotoxy(45,2); write(dificuldade);
  gotoxy(67,2); write(vidas);
end;

procedure linhaH(posicaox, posicaoy, tamanho: integer);
var a: integer;
begin
  a := posicaox;
  while a < (posicaox + tamanho) do
  begin
      gotoxy(a,posicaoy);
      write('#');
      a := a + 1;
  end;
end;

procedure linhaV(posicaox, posicaoy, tamanho: integer);
var a: integer;
begin
  for a := posicaoy to (posicaoy + tamanho) do
  begin
      gotoxy(posicaox,a);
      write('#');
  end;
end;

procedure GeraTela;
begin
  opx := 0;  {ope'e7'f5es x e y que fazem a cobra se movimentar para baixo}
  opy := 80;
  h := 2;
  v := 4;
  clrscr;

  AtualizaVariaveis;

  textcolor(15);
  gotoxy(10,2); write('Pontos:');
  gotoxy(32,2); write('Dificuldade:');
  gotoxy(60,2); write('Vidas:');
  gotoxy(1,4);

  textcolor(11);
  linhaH(1,4,79);
  linhaH(1,24,79);
  linhaV(1,5,19);
  linhaV(79,5,19);
end;


procedure Apaga;
var papaga: ptpos;
begin
  textcolor(10);
  papaga := pultimo;
  gotoxy(papaga^.x,papaga^.y);
  write('*');
  textcolor(0);
  papaga := pultimo;
  papaga := pultimo^.ant;
  apagax := papaga^.x;
  apagay := papaga^.y;
  gotoxy(apagax,apagay);
  write('*');
  textcolor(10);
end;

procedure TamanhoCobra (tam : integer);
begin
  pultimo := cabeca.apont; {faz o final da cobra amumentar}
  for cont := 1 to tam do
    pultimo := pultimo^.ant;
end;


procedure Telainicial;
var
  posx, posy: integer;
begin
  posx := 20;
  posy := 2;
  clrscr;

  textcolor(12);
  gotoxy(posx+13,posy);  writeln('JOGO DA COBRINHA');

  textcolor(15);
  gotoxy(posx+7,posy+8); writeln('Pressione ENTER para comecar');

  textcolor(11);
  linhaH(1,  posy+14, 80);
  linhaH(1,  posy+22, 80);
  linhaV(1,  posy+15, 6);
  linhaV(80, posy+15, 6);

  textcolor(12);
  gotoxy(3,posy+16); writeln('COMANDOS:');
  textcolor(15);
  gotoxy(5,posy+18); writeln('SETAS movimentam a cobra');
  gotoxy(5,posy+19); writeln('ESC para Sair');
  gotoxy(5,posy+20); writeln('P para Pausa');
  textcolor(7);
  gotoxy(posx+30,posy+11);
  readkey;
end;

procedure ComecarNovamente;
var i: integer;

 procedure gameover;
 var posx,posy: integer;
 begin
 posx := 22;
 posy := 5;
 gotoxy(posx+15,posy+10);
 writeln('GAME OVER');

{ gotoxy(posx-2,posy+16); writeln('Pressione qualquer tecla para CONTINUAR ',i);}
 end;


begin
{ reseta a posi'e7'e3o da cobra para o canto superior esquerdo}
 p := pultimo;
 for i := 1 to 15 do begin
 p^.x := 2;
 p^.y := 4;
 p := p^.prox;
 end;

 tamanhoC := 3;

 tamanhoCobra(tamanhoC); {coloca a cobra com o tamanho 3}


 textcolor(7);
 gotoxy(67,2); write(vidas);
 if vidas = 0 then begin

 i := 9;  {quantidade de seguntos restante}
 while (i >= 0)  do begin
 textcolor(red);
 gameover;
 delay(400);
 textcolor(7); {cinza claro}
 gameover;
 delay(600);
 i := i -1;
 if keypressed then
 i := -1;
 end;
 inicializa;
 end;
 geratela;
end;

procedure verificaPosicao; { verifca a posica'e3o de colisa'e3o }
begin
  if (cabeca.apont^.x > 77) or (cabeca.apont^.x < 2) or (cabeca.apont^.y > 23) or (cabeca.apont^.y < 5) then
  begin
      vidas := vidas -1;
      comecarnovamente;
  end;
end;


procedure criaComida;
begin
  comidaX := 2 +  random(77);
  comidaY := 5 +  random(19);
  textcolor(12);
  {indica o caracter que representarar a comida}
  gotoxy(comidaX,comidaY); write(cabeca.corpo[tamanhoc+1]);
end;

procedure atualizaComida; {mostra a comida na tela}
begin
  textcolor(12);
  {indica o caracter que representarar a comida}
  gotoxy(comidaX,comidaY); write(cabeca.corpo[tamanhoC+1]);
end;

procedure mudaDificuldade;
begin
  Dificuldade := Dificuldade +1;
  velocidade := velocidade - 20 div dificuldade; { imprime na tela no intervalo que 'e9 10 milisegundo menor que o anterior;}
end;

procedure verificacomida;
begin
  if (cabeca.apont^.x = comidax) and (cabeca.apont^.y = comiday) then
  begin
      CriaComida;
      tamanhoc := tamanhoc +1;
      TamanhoCobra(tamanhoc);
      pontos := pontos + 10;
      if tamanhoc = 15  then
        MudaDificuldade;
  end;
end;

procedure mover(a,b: integer); {faz a cobra se mover para norte(0,1),}
var i: integer;  {sul(0,-1), leste(-1,0) e oeste(1,0)}
 q: ptpos;
begin
  cabeca.apont := cabeca.apont^.prox;
  h := h + a;
  v := v + b;
  cabeca.apont^.x := h;
  cabeca.apont^.y := v;
  verificaposicao;
  i := tamanhoc;
  q := cabeca.apont;
  atualizaComida;
  textcolor(10); {cor azul claro da cobra}
  for i := 1 to tamanhoc do
  begin {cria a cobra na tela}
      gotoxy(q^.x,q^.y);
      q := q^.ant;
      write(cabeca.corpo[i]);
  end;
  pultimo := pultimo^.prox;
  verificacomida;
  apaga;
  atualizaVariaveis;
end;

Begin
  TelaInicial;
  Inicializa;
  Geratela;
  CriaComida;
  {esta lista circular comtem os caracteres e a posicao da cobra}
  Listacircular;
  TamanhoCobra(tamanhoc);

  {este e o laco principal do jogo usado para identificar quais sao as teclas usada pelo jogador}
  opc := 'a';
  while (opc <> 's') do
  begin
      if keypressed then
      begin
        opc := readkey;
        {a funcao ord nos fornece qual o codigo ascii da tecla, mas tem um
        problema quando o jogador usa teclas especias tipo as setas do teclado.
        Tem que usar duas variaveis para guardar o codigo dessas teclas
        especias, observando que a primeira variavel sempre fica com o valor 0}
        opz := ord(opc);
        if opz = 0 then
        begin
            opx := opz;
            opc := readkey;
            opz := ord(opc);
            if (opz = 75) or (opz = 77) or (opz = 72) or (opz = 80) then
              opy := opz;
            end;
            {para quando aperta 'p' ficar em pausa}
            if opz = 112 then begin
              opc := 'a';
              opy := 111;
              while (opz <> 112) do
                  if keypressed then
                  begin
                    opc := readkey;
                    opz := ord(opc);
                    if opz = 0 then
                        opz := ord(opc)
                    end;
                  end;
                  if opz = 27 then {para usar ESC quando quiser sair do programa}
                    opc := 's';
                  end
                  else begin
                    if opx = 0 then
                    begin
                        case opy of
                          75: mover(-1,0); { movimentra para esquerda }
                          77: mover(1,0);  { movimenta para direita}
                          72: mover(0,-1); { para cima }
                          80: mover(0,1);  { para baixo }
                            1: comecarnovamente;
                            2: telainicial;
                    end;
                    delay(velocidade);
                end;
              end;
          end;
          gotoxy(1,40);
          clrscr;
end.


Tower Defense
Código:
Program TowerDefense;
{**********************************************************}
uses crt;
{**********************************************************}
const hor = #205; ver = #186; Sesq = #201;
      Sdir = #187; Iesq = #200; Idir = #188;
{**********************************************************}
type
{Matrizes que armazenam a cor e o caracter de cada ponto da interface}
matrizNum = array [1..80,1..25] of longint;
matrizCar = array [1..80,1..25] of char;
{Matriz com a rota dos monstros na tela}
matrizRota = array [1..80,1..25] of char;

{Posi‡Æo no mapa}
tipo_posicao = record
          x: integer;{linha}
          y: integer;{coluna}
          end;

{Monstro}
tipo_monster = record
            vida: longint;
            posicao: tipo_posicao;
            primeiro: boolean;
            destruido: boolean;
          end;

{Wave: as configuracoes que definem um n¡vel}
tipo_wave = record
                monstro: array [1..20] of tipo_monster;
                skin: char;
                cor: longint;
                velocidade: longint;
                dinheiro: longint;
                iniciado: boolean;
            end;
{Torre: configuracoes da torre}
tipo_torre = record
                ataque: integer;
                posicao: tipo_posicao;
                skin_ataque: char;
                cor: integer;
                tipo: integer;
                vel: integer;
                atacou: boolean;
            end;

tipo_jogador = record
                vida: integer;
                dinheiro: longint;
              end;

tipo_wave2 = array [1..10] of tipo_wave;
{Formato Tipo 1}
{  < O > } {ataque = o }

{Formato Tipo 2}
{  \^/
  /V\  } {ataque = . }

{Formato Tipo 3}
{  <<*>>  } {ataque = * }
{**********************************************************}
var mapa: matrizCar;
    corMapa, mapaTorre: matrizNum;
    mapaRota: matrizRota;
    wave: tipo_wave2;
    cur: tipo_posicao;
    torre: array [1..1000] of tipo_torre;
    ind_tor, i, erro: integer;
    jogador: tipo_jogador;
    k: string;
{**********************************************************}

Procedure alerta(s: string);
Begin
        window(63,10,79,15);
        textcolor(7);
        textbackground(0);
        clrscr;
        write(s);
        window(1,1,80,25);
end;

Procedure statusJogador;
Begin
        window(63,17,79,21);
        textbackground(0);
        clrscr;
        textcolor(yellow);
        writeln('    JOGADOR');
        writeln;
        textcolor(7);
        writeln(' Vidas: ',jogador.vida);
        writeln(' Money: $',jogador.dinheiro);
        window(1,1,80,25);
end;

Procedure ImpPos(x, y: integer; s: char; corMapa: matrizNum; cor: integer);
begin
   gotoxy(y,x);
        textbackground(corMapa[y,x]);
        textcolor(cor);
        write(s);
end;

Procedure InsereTorre1(x,y: integer);
Begin
        if (corMapa[y-1,x]=2) and (corMapa[y+1,x]=2) and
          (mapaTorre[y-1,x]=0) and (mapaTorre[y+1,x]=0) and
          (jogador.dinheiro>=20) then
        begin
                inc(ind_tor);
                torre[ind_tor].ataque:=1;
                torre[ind_tor].posicao.x:=x;
                torre[ind_tor].posicao.y:=y;
                torre[ind_tor].skin_ataque:='o';
                torre[ind_tor].cor:=0;
                torre[ind_tor].tipo:=1;
                torre[ind_tor].vel:=20;
                mapa[y,x]:='O';
                mapa[y-1,x]:=#17;
                mapa[y+1,x]:=#16;
                ImpPos(x,y,mapa[y,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_tor].cor);
                mapaTorre[y,x]:=ind_tor;
                mapaTorre[y+1,x]:=ind_tor;
                mapaTorre[y-1,x]:=ind_tor;
                dec(jogador.dinheiro,20);
                StatusJogador;
        end
        else
        begin
                if jogador.dinheiro<20 then alerta('Vocˆ nÆo possui dinheiro suficiente para comprar essa torre.')
                else
                alerta('NÆo ‚ poss¡vel colocar uma torre do tipo 1 nesse local.');
        end;
end;

Procedure InsereTorre2(x,y: integer);
Begin
        if (corMapa[y-1,x]=2) and (corMapa[y+1,x]=2) and
          (corMapa[y-1,x-1]=2) and (corMapa[y+1,x-1]=2) and
          (mapaTorre[y-1,x]=0) and (mapaTorre[y+1,x]=0) and
          (mapaTorre[y-1,x-1]=0) and (mapaTorre[y+1,x-1]=0) and
          (jogador.dinheiro>=400) then
        begin
                inc(ind_tor);
                torre[ind_tor].ataque:=50;
                torre[ind_tor].posicao.x:=x;
                torre[ind_tor].posicao.y:=y;
                torre[ind_tor].skin_ataque:=#250;
                torre[ind_tor].cor:=9;
                torre[ind_tor].tipo:=2;
                torre[ind_tor].vel:=30;
                mapa[y,x]:=#31;
                mapa[y-1,x]:='/';
                mapa[y+1,x]:='\';
                mapa[y,x-1]:=#30;
                mapa[y-1,x-1]:='\';
                mapa[y+1,x-1]:='/';
                ImpPos(x,y,mapa[y,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_tor].cor);
                ImpPos(x-1,y,mapa[y,x-1],corMapa,torre[ind_tor].cor);
                ImpPos(x-1,y-1,mapa[y-1,x-1],corMapa,torre[ind_tor].cor);
                ImpPos(x-1,y+1,mapa[y+1,x-1],corMapa,torre[ind_tor].cor);
                mapaTorre[y,x]:=ind_tor;
                mapaTorre[y+1,x]:=ind_tor;
                mapaTorre[y-1,x]:=ind_tor;
                mapaTorre[y,x-1]:=ind_tor;
                mapaTorre[y+1,x-1]:=ind_tor;
                mapaTorre[y-1,x-1]:=ind_tor;
                dec(jogador.dinheiro,400);
                StatusJogador;
        end
        else
        begin
                if jogador.dinheiro<400 then alerta('Vocˆ nÆo possui dinheiro suficiente para comprar essa torre.')
                else
                alerta('NÆo ‚ poss¡vel colocar uma torre do tipo 1 nesse local.');
        end;
end;

Procedure InsereTorre3(x,y: integer);
Begin
        if (corMapa[y-1,x]=2) and (corMapa[y+1,x]=2) and
          (mapaTorre[y-1,x]=0) and (mapaTorre[y+1,x]=0) and
          (jogador.dinheiro>=700) then
        begin
                inc(ind_tor);
                torre[ind_tor].ataque:=50;
                torre[ind_tor].posicao.x:=x;
                torre[ind_tor].posicao.y:=y;
                torre[ind_tor].skin_ataque:='*';
                torre[ind_tor].cor:=12;
                torre[ind_tor].tipo:=3;
                torre[ind_tor].vel:=30;
                mapa[y,x]:=#15;
                mapa[y-1,x]:=#174;
                mapa[y+1,x]:=#175;
                ImpPos(x,y,mapa[y,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_tor].cor);
                ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_tor].cor);
                mapaTorre[y,x]:=ind_tor;
                mapaTorre[y+1,x]:=ind_tor;
                mapaTorre[y-1,x]:=ind_tor;
                dec(jogador.dinheiro,700);
                StatusJogador;
        end
        else
        begin
                if jogador.dinheiro<700 then alerta('Vocˆ nÆo possui dinheiro suficiente para comprar essa torre.')
                else
                alerta('NÆo ‚ poss¡vel colocar uma torre do tipo 1 nesse local.');
        end;
end;

Procedure ExcluirTorre13(x,y,ind_t: integer);
var i, x1, y1: integer;
Begin
        mapa[y,x]:=' ';
        mapa[y-1,x]:=' ';
        mapa[y+1,x]:=' ';
        mapaTorre[y,x]:=0;
        mapaTorre[y+1,x]:=0;
        mapaTorre[y-1,x]:=0;
        ImpPos(x,y,mapa[y,x],corMapa,torre[ind_t].cor);
        ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_t].cor);
        ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_t].cor);
        if torre[ind_t].tipo=1 then inc(jogador.dinheiro,10)
        else inc(jogador.dinheiro,350);
        StatusJogador;
        for i:=ind_t to ind_tor-1 do
        begin
                torre[i].ataque:=torre[i+1].ataque;
                torre[i].posicao.x:=torre[i+1].posicao.x;
                torre[i].posicao.y:=torre[i+1].posicao.y;
                torre[i].skin_ataque:=torre[i+1].skin_ataque;
                torre[i].cor:=torre[i+1].cor;
                torre[i].tipo:=torre[i+1].tipo;
                torre[i].vel:=torre[i+1].vel;
                x1:=torre[i].posicao.x;
                y1:=torre[i].posicao.y;
                if torre[i].tipo=2 then
                begin
                        mapaTorre[y1,x1-1]:=i;
                        mapaTorre[y1+1,x1-1]:=i;
                        mapaTorre[y1-1,x1-1]:=i;
                end;
                mapaTorre[y1,x1]:=i;
                mapaTorre[y1+1,x1]:=i;
                mapaTorre[y1-1,x1]:=i;
        end;
        ind_tor:=ind_tor-1;
end;

Procedure ExcluirTorre2(x,y,ind_t: integer);
var i, x1, y1: integer;
Begin
        mapa[y,x]:=' ';
        mapa[y-1,x]:=' ';
        mapa[y+1,x]:=' ';
        mapa[y,x-1]:=' ';
        mapa[y-1,x-1]:=' ';
        mapa[y+1,x-1]:=' ';
        mapaTorre[y,x]:=0;
        mapaTorre[y+1,x]:=0;
        mapaTorre[y-1,x]:=0;
        mapaTorre[y,x-1]:=0;
        mapaTorre[y+1,x-1]:=0;
        mapaTorre[y-1,x-1]:=0;
        ImpPos(x,y,mapa[y,x],corMapa,torre[ind_t].cor);
        ImpPos(x,y-1,mapa[y-1,x],corMapa,torre[ind_t].cor);
        ImpPos(x,y+1,mapa[y+1,x],corMapa,torre[ind_t].cor);
        ImpPos(x-1,y,mapa[y,x-1],corMapa,torre[ind_t].cor);
        ImpPos(x-1,y-1,mapa[y-1,x-1],corMapa,torre[ind_t].cor);
        ImpPos(x-1,y+1,mapa[y+1,x-1],corMapa,torre[ind_t].cor);
        inc(jogador.dinheiro,200);
        Statusjogador;
        for i:=ind_t to ind_tor-1 do
        begin
                torre[i].ataque:=torre[i+1].ataque;
                torre[i].posicao.x:=torre[i+1].posicao.x;
                torre[i].posicao.y:=torre[i+1].posicao.y;
                torre[i].skin_ataque:=torre[i+1].skin_ataque;
                torre[i].cor:=torre[i+1].cor;
                torre[i].tipo:=torre[i+1].tipo;
                torre[i].vel:=torre[i+1].vel;
                x1:=torre[i].posicao.x;
                y1:=torre[i].posicao.y;
                if torre[i].tipo=2 then
                begin
                        mapaTorre[y1,x1-1]:=i;
                        mapaTorre[y1+1,x1-1]:=i;
                        mapaTorre[y1-1,x1-1]:=i;
                end;
                mapaTorre[y1,x1]:=i;
                mapaTorre[y1+1,x1]:=i;
                mapaTorre[y1-1,x1]:=i;
        end;
        ind_tor:=ind_tor-1;
end;

{Define as configura‡äes da wave}
Procedure CriarWave(var wave: tipo_wave; vida, vel, din, cor: longint; skin: char);
var i, h: integer;
Begin
        wave.velocidade:=vel;
        wave.dinheiro:=din;
        wave.skin:=skin;
        wave.cor:=cor;
        for i:=1 to 20 do
        begin
                wave.monstro[i].vida:=vida;
                wave.monstro[i].posicao.x:=5;
                wave.monstro[i].posicao.y:=2;
                wave.monstro[i].primeiro:=true;
                wave.monstro[i].destruido:=false;
        end;
end;

Procedure ComprarTorre;
Begin
        window(63,2,79,8);
        textbackground(7);
        textcolor(2);
        clrscr;
        gotoxy(7,2);
        write('TORRE');
        textcolor(0);
        gotoxy(2,4);
        write('*F1');
        gotoxy(2,5);
        write(#17,'O',#16);
        gotoxy(2,7);
        write('$20');
        gotoxy(8,4);
        write('*F2');
        gotoxy(8,5);
        write('\',#30,'/');
        gotoxy(8,6);
        write('/',#31,'\');
        gotoxy(8,7);
        write('$400');
        gotoxy(14,4);
        write('*F3');
        gotoxy(14,5);
        write(#174,#15,#175);
        gotoxy(14,7);
        write('$700');
        window(1,1,80,25);
end;

Procedure ImprimeCursor(cor1, cor2: integer);
Begin
        gotoxy(cur.y,cur.x);
        textbackground(cor1);
        textcolor(cor2);
        write(mapa[cur.y,cur.x]);
end;

Procedure comandos;
Begin
        gotoxy(2,23);
        textcolor(7);
        textbackground(0);
        write('Enter: pausar | ');
        write('F1/F2/F3: criar torre | ');
        write('Delete: excluir torre | ');
        write('Esc: sair');
end;

Procedure destroi(var wave: tipo_wave; h: integer; corMapa: matrizNum; var cont: integer);
Begin
        wave.monstro[h].destruido:=true;
        ImpPos(wave.monstro[h].posicao.x,wave.monstro[h].posicao.y,' ',corMapa,wave.cor);
        dec(cont);
end;

Procedure Perdeu;
Begin
        clrscr;
        gotoxy(35,12);
        textcolor(red);
        writeln('GAME OVER!!');
end;

Procedure Ganhou;
Begin
        clrscr;
        gotoxy(30,12);
        textcolor(yellow);
        writeln('PARABNS, VOCÒ GANHOU!!');
end;

{Inicia um n¡vel com uma determinada wave}
Procedure IniciarNivel(var wave: tipo_wave2; corMapa: matrizNum; mapaRota: matrizRota; n: integer);
var cont, qtd, i, marc, x, y, m: integer;
    t, ind_t, h, ini_cont, marcador: integer;
    s, c: char;
    aux: string;
Begin
      cont:=20;
      qtd:=1;
      marc:=0;
      t:=0;
      m:=0;
      wave[n].iniciado:=false;
      ini_cont:=15;
      marcador:=10;
      while (cont>=1) and (jogador.vida>0) do
      begin
          while (cont>=1) and not(keypressed) and (jogador.vida>0) do
          begin
                if (t mod wave[n].velocidade=0) and (t<>0) then
                begin
                  for i:=1 to qtd do
                  begin
                        x:=wave[n].monstro[i].posicao.x;
                        y:=wave[n].monstro[i].posicao.y;
                        if (mapaRota[y,x]<>' ') and not(wave[n].monstro[i].destruido) then
                        begin
                                if wave[n].monstro[i].primeiro then
                                begin
                                        wave[n].monstro[i].primeiro:=false;
                                        ImpPos(x,y,wave[n].skin,corMapa,wave[n].cor);
                                end
                                else
                                begin
                                        ImpPos(x,y,' ',corMapa,wave[n].cor);
                                        if mapaRota[y,x]='B' then x:=x+1
                                        else
                                        if mapaRota[y,x]='D' then y:=y+1
                                        else
                                        if mapaRota[y,x]='E' then y:=y-1;
                                        ImpPos(x,y,wave[n].skin,corMapa,wave[n].cor);
                                        wave[n].monstro[i].posicao.x:=x;
                                        wave[n].monstro[i].posicao.y:=y;
                                end;
                                if mapaRota[y,x]=' ' then
                                begin
                                        destroi(wave[n],i,corMapa,cont);
                                        dec(jogador.vida);
                                        StatusJogador;
                                end;
                        end;
                  end;
                  inc(marc);
                  if (marc mod 4 = 0) and (qtd<20) then inc(qtd);
                end;
                if wave[n].iniciado then
                for i:=1 to ind_tor do
                begin
                        if t mod torre[i].vel = 0 then
                        begin
                                h:=1;
                                torre[i].atacou:=false;
                                while (h<=qtd) and not(torre[i].atacou) do
                                begin
                                        x:=wave[n].monstro[h].posicao.x;
                                        y:=wave[n].monstro[h].posicao.y;
                                        if (abs(x-torre[i].posicao.x)<=4) and
                                          (abs(y-torre[i].posicao.y)<=6) and
                                          not(wave[n].monstro[h].destruido) then
                                        begin
                                                if x<torre[i].posicao.x then
                                                begin
                                                        ImpPos(x+1,y,torre[i].skin_ataque,corMapa,yellow);
                                                        ImpPos(x+1,y,' ',corMapa,yellow);
                                                end
                                                else
                                                begin
                                                        ImpPos(x-1,y,torre[i].skin_ataque,corMapa,yellow);
                                                        ImpPos(x-1,y,' ',corMapa,yellow);
                                                end;
                                                dec(wave[n].monstro[h].vida,torre[i].ataque);
                                                if wave[n].monstro[h].vida<=0 then
                                                begin
                                                        destroi(wave[n],h,corMapa,cont);
                                                        inc(jogador.dinheiro,wave[n].dinheiro);
                                                        StatusJogador;
                                                end;
                                                torre[i].atacou:=true;
                                        end;
                                        inc(h);
                                end;
                        end;
                end;
                if t = 10000 then t:=0;
                delay(10);
                t:=t+10;
                if not(wave[n].iniciado) then
                begin
                    if marcador mod 400 = 0 then
                    begin
                        dec(ini_cont);
                        str(ini_cont,k);
                        str(n,aux);
                        k:='O n¡vel '+aux+' iniciar  em '+k+' segundos.';
                        alerta(k);
                        if ini_cont=0 then
                        begin
                                k:='N¡vel '+aux+' iniciado.';
                                alerta(k);
                                wave[n].iniciado:=true;
                        end;
                    end;
                    delay(10);
                    t:=0;
                    inc(marcador,10);
                end;
          end;
          if keypressed then
          begin
                c:=readkey;
                if ord(c)=0 then
                begin
                        c:=readkey;
                        if ord(c)=80 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                while (corMapa[y,x+1]<>2) and (x<=20) do inc(x);
                                if x<>21 then
                                begin
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(corMapa[cur.y,cur.x],0)
                                        else ImprimeCursor(corMapa[cur.y,cur.x],torre[mapaTorre[cur.y,cur.x]].cor);
                                        cur.x:=x+1;
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(1,0)
                                        else ImprimeCursor(4,torre[mapaTorre[cur.y,cur.x]].cor);
                                end;
                        end
                        else
                        if ord(c)=72 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                while (corMapa[y,x-1]<>2) and (x>=3) do dec(x);
                                if x<>2 then
                                begin
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(corMapa[cur.y,cur.x],0)
                                        else ImprimeCursor(corMapa[cur.y,cur.x],torre[mapaTorre[cur.y,cur.x]].cor);
                                        cur.x:=x-1;
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(1,0)
                                        else ImprimeCursor(4,torre[mapaTorre[cur.y,cur.x]].cor);
                                end;
                        end
                        else
                        if ord(c)=77 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                while (corMapa[y+1,x]<>2) and (y<=60) do inc(y);
                                if y<>61 then
                                begin
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(corMapa[cur.y,cur.x],0)
                                        else ImprimeCursor(corMapa[cur.y,cur.x],torre[mapaTorre[cur.y,cur.x]].cor);
                                        cur.y:=y+1;
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(1,0)
                                        else ImprimeCursor(4,torre[mapaTorre[cur.y,cur.x]].cor);
                                end;
                        end
                        else
                        if ord(c)=75 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                while (corMapa[y-1,x]<>2) and (y>=3) do dec(y);
                                if y<>2 then
                                begin
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(corMapa[cur.y,cur.x],0)
                                        else ImprimeCursor(corMapa[cur.y,cur.x],torre[mapaTorre[cur.y,cur.x]].cor);
                                        cur.y:=y-1;
                                        if mapaTorre[cur.y,cur.x]=0 then ImprimeCursor(1,0)
                                        else ImprimeCursor(4,torre[mapaTorre[cur.y,cur.x]].cor);
                                end;
                        end
                        else
                        if ord(c)=59 then InsereTorre1(cur.x,cur.y)
                        else
                        if ord(c)=60 then InsereTorre2(cur.x,cur.y)
                        else
                        if ord(c)=61 then InsereTorre3(cur.x,cur.y)
                        else
                        if ord(c)=83 then
                        begin
                                x:=cur.x;
                                y:=cur.y;
                                if mapaTorre[y,x]<>0 then
                                begin
                                        ind_t:=mapaTorre[y,x];
                                        if torre[ind_t].tipo in[1,3] then
                                          excluirtorre13(torre[ind_t].posicao.x,torre[ind_t].posicao.y,ind_t)
                                        else excluirtorre2(torre[ind_t].posicao.x,torre[ind_t].posicao.y,ind_t);
                                end;
                        end;
                end
                else
                if ord(c)=13 then
                begin
                        c:=readkey;
                        while ord(c)<>13 do
                        begin
                                delay(10);
                                c:=readkey;
                        end;
                end
                else
                if ord(c)=27 then
                begin
                        inc(m);
                        alerta('Aperte ESC novamente para sair.');
                        c:=readkey;
                        if ord(c)=27 then jogador.vida:=0;
                end;
          end;
      end;
      if jogador.vida<=0 then Perdeu
      else
      if n<10 then IniciarNivel(wave,corMapa,mapaRota,n+1)
      else Ganhou;
end;



{Gera a rota que os monstros farÆo pelo mapa}
Procedure GerarRota(var mapaRota: matrizRota);
var i, h: integer;
Begin
        for i:=1 to 80 do
          for h:=1 to 25 do mapaRota[i,h]:=' ';
        for i:=2 to 54 do mapaRota[i,5]:='D';
        for i:=5 to 10 do mapaRota[55,i]:='B';
        for i:=55 downto 11 do mapaRota[i,11]:='E';
        for i:=11 to 16 do mapaRota[10,i]:='B';
        for i:=10 to 58 do mapaRota[i,17]:='D';
        for i:=17 to 20 do mapaRota[59,i]:='B';
end;

{Preenche um retƒngulo(em matriz) com um caracter "s"}
Procedure PreRet(x1,y1,x2,y2,s: longint; var corGrid: matrizNum);
var i, h: longint;
Begin
        for i:=y1 to y2 do
          for h:=x1 to x2 do corGrid[i,h]:=s;
end;

{Modela o contorno da tela na matriz}
Procedure Contorno(x1,y1,x2,y2: longint; var grid: matrizCar);
var i: longint;
Begin
        for i:=y1 to y2 do
        begin
                grid[i,x1]:=hor;
                grid[i,x2]:=hor;
        end;
        for i:=x1 to x2 do
        begin
                grid[y1,i]:=ver;
                grid[y2,i]:=ver;
        end;
        grid[y1,x1]:=Sesq;
        grid[y1,x2]:=#204;
        grid[y2,x1]:=Sdir;
        grid[y2,x2]:=#185;
        grid[1,24]:=Iesq;
        grid[80,24]:=Idir;
        grid[1,23]:=ver;
        grid[80,23]:=ver;
        for i:=x1+1 to x2-1 do grid[62,i]:=ver;
        grid[62,1]:=#203;
        grid[62,22]:=#202;
        grid[62,9]:=#204;
        grid[80,9]:=#185;
        grid[80,16]:=#185;
        grid[62,16]:=#204;
        for i:=63 to 79 do grid[i,16]:=hor;
        for i:=2 to 79 do grid[i,24]:=hor;
        for i:=63 to 79 do grid[i,9]:=hor;
end;

{Gera o mapa, atribuindo os valores de caracter e de cor a duas matrizes
distintas}
Procedure GerarMapa(var grid: matrizCar; var corGrid: matrizNum);
var i, h: longint;
Begin
        for i:=1 to 80 do
          for h:=1 to 24 do
          begin
                grid[i,h]:=' ';
                corGrid[i,h]:=0;
          end;
        grid[59,11]:='T';
        grid[60,11]:='D';
        PreRet(2,2,3,61,green,corGrid);
        PreRet(4,57,9,61,green,corGrid);
        PreRet(7,2,9,53,green,corGrid);
        PreRet(10,2,18,7,green,corGrid);
        PreRet(13,13,15,61,green,corGrid);
        PreRet(19,2,21,57,green,corGrid);
        PreRet(4,2,6,57,6,corGrid);
        PreRet(7,53,9,57,6,corGrid);
        PreRet(10,8,12,61,6,corGrid);
        PreRet(13,8,15,12,6,corGrid);
        PreRet(16,8,18,61,6,corGrid);
        PreRet(19,57,21,61,6,corGrid);
        PreRet(10,58,12,61,8,corGrid);
        Contorno(1,1,22,80,grid);
end;

{Imprime o mapa com os caracteres com sua respectiva cor de fundo}
Procedure ImprimirMapa(var grid: matrizCar; corGrid: matrizNum);
var i, h: longint;
Begin
        for i:=1 to 80 do
          for h:=1 to 24 do
          begin
                textbackground(corGrid[i,h]);
                gotoxy(i,h);
                write(grid[i,h]);
          end;
end;

Begin
        clrscr;
        cur.x:=2;
        cur.y:=2;
   ind_tor:=0;
   jogador.vida:=20;
   jogador.dinheiro:=200;

   GerarMapa(mapa,corMapa);
        ImprimirMapa(mapa,corMapa);
        GerarRota(mapaRota);
        CriarWave(wave[1],100,100,5,1,#2);
        CriarWave(wave[2],200,50,10,4,#1);
        CriarWave(wave[3],1200,130,50,7,#2);
        CriarWave(wave[4],2000,100,80,9,'@');
        CriarWave(wave[5],5000,130,150,15,'#');
        CriarWave(wave[6],8000,100,250,11,#2);
        CriarWave(wave[7],15000,80,1000,12,#1);
        CriarWave(wave[8],25000,50,3000,13,'$');
        CriarWave(wave[9],50000,80,20000,14,#2);
        CriarWave(wave[10],200000,150,50000,10,'@');
        ComprarTorre;
        Comandos;
        StatusJogador;
        ImprimeCursor(1,0);
        IniciarNivel(wave,corMapa,mapaRota,1);
        readln;
End.

Esse se quiser deixar mais fácil, procura por vida do jogador ou dinheiro e muda, geek


Bacana, mas tive problemas com o segundo jogo, ficou dando um erro esquisito no pzim!

Snake ficou meio esquesito (zeros e ums e outros simbolos esquisitos)... Pois eh, os Instituots Federais de Ciência e Tecnologia entrarão em greve aí vou ficar de molho em casa Evil or Very Mad vou aproveitar e mexer um pouco em C++ pra ver como é Wink

_________________
tutorial de instalação de ítens no dingux:
http://dingoobr.forumeiros.com/t1937-tutorial-instalando-coisas-no-gmenu2x
---------------------------------------------------------------------------------------------------------------
Equipe Dingoo From The Past
Spoiler:

Dingoo From The Past #5 Megaman Battle Network [GBA] Por Italo
http://dingoobr.forumeiros.com/t2483-dingoo-from-the-past-5-megaman-battle-network-gba
Dingoo From The Past #14 Adventure Island 4 [NES] por Italo
http://dingoobr.forumeiros.com/t2580-dingoo-from-the-past-14-adventure-island-4-nes
Dingoo From The Past #19 - Megaman 2 [NES] por Italo
http://dingoobr.forumeiros.com/t2689-dingoo-from-the-past-19-megaman-2-nes#42565
Dingoo From The Past # 22 - Star Fox [SNES] por Italo
http://dingoobr.forumeiros.com/t2738-dingoo-from-the-past-22-star-fox-snes#43255

italo
Moderador
Moderador

Avisos:
0 / 1000 / 100

Mensagens: 1858
Data de inscrição: 06/06/2011
Idade: 16
Localização: Aracaju-SE

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por ibm 5155 em Seg 04 Jun 2012, 1:11 pm

tava fazendo um tower defence em sdl/chien2D ¬¬
Linguagem que achei estranha mesma foi lisp, e uma das mais rapidas que eu já entendi kkkk, nunca pencei em uma função que abra ela mesma Oo

ibm 5155
User Level V
User Level V

Avisos:
0 / 1000 / 100

Mensagens: 1424
Data de inscrição: 23/06/2011
Localização: PERFIL_DELETADO

http://ibm5155.site50.net/

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por italo em Qui 28 Jun 2012, 5:32 pm

Fiz um novo programa, confiram aí Razz


Spoiler:

Program tabuada ;
uses CRT;
var n, a, b, c, d, e, f, g, h: integer;
Begin
textbackground (BLUE);
textcolor (WHITE);
clrscr;
writeln ('TABUADA - Italo Vilanova');
writeln ('Copyright - 2012');
writeln ('Loading... ');
delay (1000);
writeln;
write ('Digite um número: ');
readln (n);
writeln ('Please wait... ');
delay (2000);
WHILE (n > 1) do
begin
n:= n * 1;
writeln (n);
a:= n * 2;
writeln (a);
b:= n * 3;
writeln (b);
c:= n * 4;
writeln (c);
d:= n * 5;
writeln (d);
e:= n * 6;
writeln (e);
f:= n * 7;
writeln (f);
g:= n * 8;
writeln (g);
h:= n * 9;
writeln (h);
write ('Digite outro número: ');

readln (n);
end;
readkey;
End.


_________________
tutorial de instalação de ítens no dingux:
http://dingoobr.forumeiros.com/t1937-tutorial-instalando-coisas-no-gmenu2x
---------------------------------------------------------------------------------------------------------------
Equipe Dingoo From The Past
Spoiler:

Dingoo From The Past #5 Megaman Battle Network [GBA] Por Italo
http://dingoobr.forumeiros.com/t2483-dingoo-from-the-past-5-megaman-battle-network-gba
Dingoo From The Past #14 Adventure Island 4 [NES] por Italo
http://dingoobr.forumeiros.com/t2580-dingoo-from-the-past-14-adventure-island-4-nes
Dingoo From The Past #19 - Megaman 2 [NES] por Italo
http://dingoobr.forumeiros.com/t2689-dingoo-from-the-past-19-megaman-2-nes#42565
Dingoo From The Past # 22 - Star Fox [SNES] por Italo
http://dingoobr.forumeiros.com/t2738-dingoo-from-the-past-22-star-fox-snes#43255

italo
Moderador
Moderador

Avisos:
0 / 1000 / 100

Mensagens: 1858
Data de inscrição: 06/06/2011
Idade: 16
Localização: Aracaju-SE

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por omundodogabriel em Qui 28 Jun 2012, 8:58 pm

Se fosse em Visual Basic ou em Delphi até que eu poderia te ajudar, mas Pascal eu nunca mexi...

Eu fiz um RPG recentemente e coloquei aqui:
http://dingoobr.forumeiros.com/t2805-meu-rpg-surreal-adventure

Se quiser coloco o Source. Eu recomendo você tentar desenhar alguma coisa na tela, como alguns sprites para começar, ai vai fazendo uns testes, quando melhorar pode criar uma história e já ir criando o jogo. Um joguinho fácil para começar é Blackjack.

omundodogabriel
User Level IV
User Level IV

Avisos:
0 / 1000 / 100

Mensagens: 468
Data de inscrição: 03/09/2011
Idade: 15
Localização: Unknow

http://gamebots.blogspot.com

Voltar ao Topo Ir em baixo

Re: Minhas primeiras criações em PASCAL

Mensagem por italo em Sex 06 Jul 2012, 2:36 pm

Atualizei o programa da tabuada, dessa vez ficou menor e pra quem não tem o programa pascalzim! pode conferir a versão compilada do meu programa aqui: 4shared.com 4shared.com/rar/hXXBzamV/TABUADA.html

Tem um probleminha, ele não mostra o resto da tabuada (se alguém puder me ajudar eu agradeço)

_________________
tutorial de instalação de ítens no dingux:
http://dingoobr.forumeiros.com/t1937-tutorial-instalando-coisas-no-gmenu2x
---------------------------------------------------------------------------------------------------------------
Equipe Dingoo From The Past
Spoiler:

Dingoo From The Past #5 Megaman Battle Network [GBA] Por Italo
http://dingoobr.forumeiros.com/t2483-dingoo-from-the-past-5-megaman-battle-network-gba
Dingoo From The Past #14 Adventure Island 4 [NES] por Italo
http://dingoobr.forumeiros.com/t2580-dingoo-from-the-past-14-adventure-island-4-nes
Dingoo From The Past #19 - Megaman 2 [NES] por Italo
http://dingoobr.forumeiros.com/t2689-dingoo-from-the-past-19-megaman-2-nes#42565
Dingoo From The Past # 22 - Star Fox [SNES] por Italo
http://dingoobr.forumeiros.com/t2738-dingoo-from-the-past-22-star-fox-snes#43255

italo
Moderador
Moderador

Avisos:
0 / 1000 / 100

Mensagens: 1858
Data de inscrição: 06/06/2011
Idade: 16
Localização: Aracaju-SE

Voltar ao Topo Ir em baixo

Ver o tópico anterior Ver o tópico seguinte Voltar ao Topo

- Tópicos similares

Permissão deste fórum:
Você não pode responder aos tópicos neste fórum