Dear ALL,

I have tried to demonstrate the card game problem by myself. The card game is come together with 52 cards. It has Spade, Heart, Club and Diamond - Spade > Heart > Club > Diamond. It has the integers and chars 2,3,4,5,6,7,8,9,10,J,Q,K,A. Could you tell me how can I code this program if we only play for 5 times. We choose 1 card in every time randomly.

Cheers,

turbomen

Recommended Answers

All 2 Replies

i had a little time to continue the card game....

program solution;

var lapok:array[1..12]of string[1];{the cards,2,3,4,5...J,Q,K,A}
    kezd:byte;{who begins the game}
    lapszam:byte;{the numbers of the card }
    i,num:byte;
    s:string[1];
    you,computer,draw:byte;
    lapyou,lapcomputer:array[1..4]of string[1];
    temp:byte;

procedure stars;
var x:byte;
begin
   writeln;
   for x:=1 to 20 do write('*-');
   writeln;
end;

begin
     lapszam:=52;
     you:=0;
     computer:=0;
     draw:=0;
     randomize;
     stars;
     writeln('Welcome to my card game!');
     writeln('There are 52 cards.');
     write('The available cards are: ');
     {fill up the array}
     for i:=1 to 12 do begin
        case (i) of
             9:lapok[i]:='J';
            10:lapok[i]:='Q';
            11:lapok[i]:='K';
            12:lapok[i]:='A';
        else begin
              num:=i+1;
              str(num,s); {converts number to string,built in procedure}
              lapok[i]:=s;
             end;
        end;{of case}
     write(lapok[i],' ');
     end;{of for}
     stars;
     {now the program adds to you four cards}
     write('Your cards are :  ');
     for i:=1 to 4 do begin
        temp:=random(12)+1;
        lapyou[i]:=lapok[temp];
        write(lapyou[i],' ');
     end;
     writeln;
     write('Computer cards are : ');
     for i:=1 to 4 do begin
        temp:=random(12)+1;
        lapcomputer[i]:=lapok[temp];
        write(lapcomputer[i],' ');
     end;
     stars;
     for i:=1 to 5 do begin
        {let's see,who begins the game...}
        kezd:=random(2);
        temp:=random(5);
        readln;
        writeln(i,'. round.');
        if temp = 0 then temp:=1;
        if kezd=0 then begin
           writeln('You begins the game!');

           write('you: ',lapyou[temp],'  ');
           writeln('computer: ',lapcomputer[temp]);
           if lapyou[temp]>lapcomputer[temp] then
           begin
              you:=you+1;
              writeln('you win.');
           end;
           if lapyou[temp]<lapcomputer[temp] then
           begin
              computer:=computer+1;
              writeln('computer win.');
           end;
           if lapyou[temp]=lapcomputer[temp] then
           begin
              draw:=draw+1;
              writeln('draw.');
           end;
        end
        else begin
           writeln('Coputer begins the game!');

           write('computer: ',lapcomputer[temp],' ');
           writeln('you: ',lapyou[temp]);
           if lapyou[temp]>lapcomputer[temp] then
           begin
              you:=you+1;
              writeln('you win.');
           end;
           if lapyou[temp]<lapcomputer[temp] then
           begin
              computer:=computer+1;
              writeln('computer win.');
           end;
           if lapyou[temp]=lapcomputer[temp] then
           begin
              draw:=draw+1;
              writeln('draw.');
           end;
           end;
     end;{of for}
     stars;
     write('YOU: ',you,'   COMPUTER: ',computer,'   DRAW: ',draw);
     readln;
end.
{
created by FlamingClaw 2009.08.29.
}

of course my little program do not cares about the spade or diamond,etc
this program demonstrates a simple card game ,you against the computer.you gain 4 cards and the computer too,then the program determines that who will begin the game,then you randomly select a card and the computer too,then the program determines again,and the winner gains point..... :D

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.