{                   Chris Goodno and Matt Michie  }
{                   Pascal, pd. 4                 }
{                   Filename: ch3/gamech3         }
{                   Due Date: January 21, 1994    }
{Program description:                             }
{*************************************************}
{  Grading Criteria:                              }
{                                 Header ______   }
{                                                 }
{                    Program Description ______   }
{                                                 }
{                           Presentation ______   }
{                                                 }
{                         Run of Program ______   }
{                                                 }
{                            Final Grade ______   }
{                                                 }
{*************************************************}
program blackjacktwentyone (output, input);
  uses crt;
  var
    cardnum, computer, cwon, clost, pwon, plost, twon : integer;
    number, counterc, counterp, x, y: real;
    playagain : char;
  begin {main}
    clrscr;
    playagain := 'y';
    cwon := 0;
        pwon := 0;
        twon := 0;
        clost := 0;
        plost := 0;

      while playagain = 'y' do
      begin {Game loop}
        counterc := 0;
        counterp := 0;
        clrscr;
        randomize;
        {$I-}
          write ('How many cards do you want? ');
          textcolor(random(14)+1);
          readln (cardnum);
        {$I+}
        while ((IOresult <> 0) or (cardnum >= 5) or (cardnum >= maxint)) or (cardnum < 0) do
          begin {while loop to get good number of cards}
            writeln ('Bad card value, has to be less than 5, try again: ');
            {$I-}
              write ('How many cards do you want? ');
              readln (cardnum);
            {$I+}
          end;  {while loop to get good number of cards}
        while cardnum < 5 do
          begin {while loop}
            writeln;
            textcolor (random(14)+1);
            write ('Computer draws: ');
            for computer := 1 to cardnum do
              begin {for loop}
                number := random(11) + 1;
                delay (100);
                textcolor ((random(14)+1));
                write (number:2:0,' ');
                counterc := counterc + number;
              end;  {for loop}
            writeln;
            textcolor (random(14)+1);
            write ('Player draws:   ');
            for computer := 1 to cardnum do
              begin {for loop}
                number := random(11) + 1;
                delay (100);
                textcolor (random(14)+1);
                write (number:2:0,' ');
                counterp := counterp + number;
                cardnum := 5;
             end;  {for loop}
          end; {while loop}
        writeln;
        writeln;
        textcolor (random(14)+1);
        write ('Computer gets: ');
        textcolor (random(14)+1);
        writeln (counterc:2:0);
        textcolor (random(14)+1);
        write ('Player gets  : ');
        textcolor (random(14)+1);
        writeln (counterp:2:0);
        if (counterc > counterp) and (counterc < 22) or (counterc = 21 ) then
          begin {if then to get total won}
            cwon := cwon + 1;
            plost := plost + 1;
          end   {if then to get total won}
        else
        if (counterp > counterc) and (counterp < 22) or (counterp = 21) then
          begin {If then to get total won}
            pwon := pwon + 1;
            clost := clost + 1;
          end   {if then to get total won}
        else
        if (counterc > 21) and (counterp > 21) then
          twon := twon +1
        else
        if (counterc < counterp) and (counterp > 21) and (counterc < 22) then
          begin {if then to get total won}
            cwon := cwon + 1;
            plost := plost + 1;
          end   {if then to get total won}
        else
        if (counterp < counterc) and (counterc > 21) and (counterp < 22) then
          begin {if then to get total won}
            pwon := pwon + 1;
            clost := clost + 1;
          end   {if then to get total won}
        else
        if counterc = counterp then
          twon := twon + 1;
        writeln;
        textcolor (random(14)+1);
        write ('Computer:  ');
        textcolor (random(14)+1);
        write ('won:');
        textcolor (random(14)+1);
        write (cwon:3);
        textcolor (random(14)+1);
        write ('  lost:');
        textcolor (random(14)+1);
        writeln (clost:3);
        textcolor (random(14)+1);
        write ('Player  :');
        textcolor (random(14)+1);
        write ('  won:');
        textcolor (random(14)+1);
        write (pwon:3);
        textcolor (random(14)+1);
        write ('  lost:');
        textcolor (random(14)+1);
        writeln (plost:3);
        textcolor (random(14)+1);
        write ('Ties    :  ');
        textcolor (random(14)+1);
        writeln (twon);
        writeln;
        textcolor (random(14)+1);
        write ('Would You like to play again? ');
        readln (playagain);
        if playagain = 'Y' then
          playagain := 'y';
        end;  {Game loop}
    clrscr;
    number := random(6)+1;
    if cwon > pwon then
      begin {if then to get ending}
        textcolor (random(14)+1);
        if number = 1 then
          writeln ('Happy, Happy, Joy, Joy, I won ... Happy, Happy, etc.')
        else
        if number = 2 then
          writeln ('Huh, Huh, Hum, You stink, You lose, don''t play again.')
        else
        if number = 3 then
          writeln ('Me being arogant and all, I say I had a good game!!!')
        else
        if number = 4 then
          begin {losing words}
            writeln ('Ode to my Winnings   By: C.P.U.');
            writeln;
            writeln ('On the outside I look like a sad little computer.');
            writeln ('But only if you could see the inside of me....');
            writeln ('I would be laughing at your lost....');
          end   {losing words}
        else
        if number = 5 then
          writeln ('Cash can be paid up front to the disk drive, thank you')
        else
        if number = 6 then
          begin {losing words}
            writeln ('It was a really good game....');
            writeln (' If I were to look at it backwards!!!');
          end   {losing words}
        end   {if then to get ending}
    else
    if pwon > cwon then
      begin {if then to get ending}
        textcolor (random(14)+1);
        If number = 1 then
          writeln ('Good Job, now go away so that I may cheat in peace...')
        else
        if number = 2 then
          writeln ('Huh, huh, he thinks he''s cool just cause he won, cool!')
        else
        if number = 3 then
          begin {winning words}
            writeln ('If you look at it from a different perspective....');
            writeln (' I believe you cheated...');
          end  {winning words}
        else
        if number = 4 then
          begin {winning words}
            writeln ('Don''t flatter yourself for winning a game...');
            writeln ('  I let you win!!!!');
          end   {winning words}
        else
        if number = 5 then
          begin {winning words}
            writeln ('Don''t worry, I will beat you next time..');
            writeln ('Sure you don''t want to play again???!!');
          end   {winning words}
        else
        if number = 6 then
          writeln ('Go Away, Don''t come again another day!!!');
        end   {if then to get ending}                      else
    if pwon = cwon then
      begin {if then to get ending}
        textcolor (random(14)+1);
        writeln ('HEY, It''s A Tie...');
      end;  {if then to get ending}
    writeln;
    textcolor (random(14)+1);
    write ('T');    delay (200);
    textcolor (random(14)+1);
    write ('h');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    write ('n');    delay (200);
    textcolor (random(14)+1);
    write ('k');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('Y');    delay (200);
    textcolor (random(14)+1);
    write ('o');    delay (200);
    textcolor (random(14)+1);
    write ('u');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('F');    delay (200);
    textcolor (random(14)+1);
    write ('o');    delay (200);
    textcolor (random(14)+1);
    write ('r');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('P');    delay (200);
    textcolor (random(14)+1);
    write ('l');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    write ('y');    delay (200);
    textcolor (random(14)+1);
    write ('i');    delay (200);
    textcolor (random(14)+1);
    write ('n');    delay (200);
    textcolor (random(14)+1);
    write ('g');    delay (200);
    textcolor (random(14)+1);
    write ('.');    delay (200);
    textcolor (random(14)+1);
    write ('.');    delay (200);
    textcolor (random(14)+1);
    writeln ('.');  delay (200);
    writeln;

    window (9, 10, 80, 24);
    clrscr;
    gotoxy(random(60)+1, random(10)+1);
    textcolor (random(14)+1);
    write ('A');    delay (200);
    textcolor (random(14)+1);
    write ('u');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('R');    delay (200);
    textcolor (random(14)+1);
    write ('e');    delay (200);
    textcolor (random(14)+1);
    write ('v');    delay (200);
    textcolor (random(14)+1);
    write ('o');    delay (200);
    textcolor (random(14)+1);
    write ('i');    delay (200);
    textcolor (random(14)+1);
    write ('r');    delay (200);
    textcolor (random(14)+1);
    writeln ('e');  delay (200);

    gotoxy (random(60)+1, random(10)+1);
    textcolor (random(14)+1);
    write ('C');    delay (200);
    textcolor (random(14)+1);
    write ('h');    delay (200);
    textcolor (random(14)+1);
    write ('o');    delay (200);
    textcolor (random(14)+1);
    write ('w');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('B');    delay (200);
    textcolor (random(14)+1);
    write ('o');    delay (200);
    textcolor (random(14)+1);
    write ('m');    delay (200);
    textcolor (random(14)+1);
    write ('b');    delay (200);
    textcolor (random(14)+1);
    write ('i');    delay (200);
    textcolor (random(14)+1);
    write ('n');    delay (200);
    textcolor (random(14)+1);
    writeln ('o');  delay (200);

    gotoxy (random(60)+1, random(10)+1);
    textcolor (random(14)+1);
    write ('A');    delay (200);
    textcolor (random(14)+1);
    write ('d');    delay (200);
    textcolor (random(14)+1);
    write ('i');    delay (200);
    textcolor (random(14)+1);
    write ('o');    delay (200);
    textcolor (random(14)+1);
    writeln ('s');  delay (200);

    gotoxy (random(60)+1, random(10)+1);
    textcolor (random(14)+1);
    write ('H');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    write ('s');    delay (200);
    textcolor (random(14)+1);
    write ('t');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('L');    delay (200);
    textcolor (random(14)+1);
    write ('u');    delay (200);
    textcolor (random(14)+1);
    write ('e');    delay (200);
    textcolor (random(14)+1);
    write ('g');    delay (200);
    textcolor (random(14)+1);
    writeln ('o');  delay (200);

    gotoxy (random(60)+1, random(10)+1);
    textcolor (random(14)+1);
    write ('H');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    write ('s');    delay (200);
    textcolor (random(14)+1);
    write ('t');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('L');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('B');    delay (200);
    textcolor (random(14)+1);
    write ('y');    delay (200);
    textcolor (random(14)+1);
    write ('e');    delay (200);
    textcolor (random(14)+1);
    write ('-');    delay (200);
    textcolor (random(14)+1);
    write ('b');    delay (200);
    textcolor (random(14)+1);
    write ('y');    delay (200);
    textcolor (random(14)+1);
    writeln ('e');  delay (200);

    gotoxy (random(60)+1, random(10)+1);
    textcolor (random(14)+1);
    write ('S');    delay (200);
    textcolor (random(14)+1);
    write ('y');    delay (200);
    textcolor (random(14)+1);
    write ('o');    delay (200);
    textcolor (random(14)+1);
    write ('n');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    write ('r');    delay (200);
    textcolor (random(14)+1);
    writeln ('a');  delay (200);

    gotoxy (random(60)+1, random(10)+1);
    textcolor (random(14)+1);
    write ('G');    delay (200);
    textcolor (random(14)+1);
    write ('r');    delay (200);
    textcolor (random(14)+1);
    write ('u');    delay (200);
    textcolor (random(14)+1);
    write ('s');    delay (200);
    textcolor (random(14)+1);
    write ('s');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('D');    delay (200);
    textcolor (random(14)+1);
    write ('i');    delay (200);
    textcolor (random(14)+1);
    writeln ('s');  delay (200);

    gotoxy (random(60)+1, random(10)+1);
    textcolor (random(14)+1);
    write ('G');    delay (200);
    textcolor (random(14)+1);
    write ('u');    delay (200);
    textcolor (random(14)+1);
    write ('t');    delay (200);
    textcolor (random(14)+1);
    write ('t');    delay (200);
    textcolor (random(14)+1);
    write ('e');    delay (200);
    textcolor (random(14)+1);
    write ('n');    delay (200);
    textcolor (random(14)+1);
    write (' ');    delay (200);
    textcolor (random(14)+1);
    write ('T');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    writeln ('g');  delay (200);

    gotoxy (random(60)+1, random(10)+1);
    textcolor (random(14)+1);
    write ('S');    delay (200);
    textcolor (random(14)+1);
    write ('a');    delay (200);
    textcolor (random(14)+1);
    write ('l');    delay (200);
    textcolor (random(14)+1);
    write ('u');    delay (200);
    textcolor (random(14)+1);
    writeln ('t');  delay (200);

    readln;
    end. {main}
