I want to code a little character fighting game in Pascal, I want to have 2 characters.

They will attack each other, one will be computer and other will be the player.

Each time its your turn a menu will come up saying what type of attack, I will have 3 attacks, stab, kick and punch and each one will have a different value.

The value will be taken from the enemy’s health, and when the health is 0 you have won.

After each of your turn the computer will attack you and the damage will be a random number between 0 and 20.

I just a fellow member to point me in the right direction.

Thanks.

Recommended Answers

All 3 Replies

i have an alternative,of course it is working well :D
i made it with dev-pascal 1.9.2

program sablon;
uses crt;

{"I want to have 2 characters."}
type characters = record
                     health:integer; {health point}
                     attack:byte;   {attack point}
                     speed:byte;    {and the speed point}
                  end;

const stab  = 10;
      punch = 15;
      kick  = 20;

var you,computer:characters;
    temp:byte;

{write  a  line to the screen}
procedure line;
var i:byte;
begin
   for i:=1 to 20 do write('=');
   writeln;
end;

{we test who will begin the fight}
procedure speedtest(var x:characters);
begin
     x.speed:=random(200)+1;
end;

procedure mes (y:byte;var z:characters);
begin
     y:=random(3)+1;
     case (y) of
        1:begin
             writeln('You -> stab: ',stab);
             z.health:=z.health-stab;
          end;
        2:begin
             writeln('You -> punch: ',punch);
             z.health:=z.health-punch;
          end;
        3:begin
             writeln('You -> kick: ',kick);
             z.health:=z.health-kick;
          end;
     end;{of case}
end;

begin
     clrscr;

     randomize;
     line;

     {your data}
     you.health:=120;
     speedtest(you);
     writeln('You     : health: ',you.health:3,' ,speed: ',you.speed:3);

     {computer's data}
     computer.health:=120;
     speedtest(computer);
     writeln('Computer: health: ',computer.health:3,' ,speed: ',computer.speed:3);
     line;
     temp:=0;
     writeln('Fight!');
     repeat
        if you.speed > computer.speed then begin
           mes(temp,computer);
           computer.attack:=random(20)+1;
           writeln('Computer -> ',computer.attack);
           you.health:=you.health-computer.attack;
        end
        else if you.speed = computer.speed then writeln('Draw!')
        else begin
                computer.attack:=random(20)+1;
                writeln('Computer -> ',computer.attack);
                you.health:=you.health-computer.attack;
                mes(temp,computer)
             end;
        delay(1500);
        writeln;
        writeln('Computer: health: ',computer.health);
        writeln('You     : health: ',you.health);
        line;
     until (you.health <= 0) or (computer.health <= 0);


     if computer.health > you.health then writeln('Computer wins!')
     else writeln('Bravo you won this fight!');

     readln;
end.
{created by FlamingClaw 2009}
commented: BRILLIANT GUY! Thanks for all the help - josh48 :) +1

Thanks a bunch again mate :)...will develop this code more for my needs :)

Thanks again! Can you reccomend me any tutorials please so I can practice pacal...I'm using DevPas 1.9.2

learn a lot about the language,and try to practice more and more

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.