Advertisement
Guest User

Computing Finished Program

a guest
Mar 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 16.11 KB | None | 0 0
  1. program CelebrityDogs;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. type TDogs = record   //Calls a record called TDogs which will store all 30 cards
  9.   Name: String;
  10.   Exercise, Intelligence, Friendliness, Drool: Integer;   //Assigning variables for the characteristics that the dogs have
  11. end;
  12.                        
  13. type TPlayerHand = record   //Calls a record TPlayerHand which will be linked to an array to store the player's hand
  14.   Name: String;
  15.   Exercise, Intelligence, Friendliness, Drool: Integer;   //Assigning variables for the characteristics that the dogs have
  16. end;
  17.  
  18. type TComputerHand = record   //Calls a record TComputerHand which will be linked to an array to store the computer's hand
  19.   Name: String;
  20.   Exercise, Intelligence, Friendliness, Drool: Integer;   //Assigning variables for the characteristics that the dogs have
  21. end;
  22.  
  23. var
  24.   DogsArray: Array [1..30] of String;   //String array that will store the names of the dogs when imported from the text file
  25.   DogRecord: Array [1..30] of TDogs;    //Array linked to record TDogs to access and use all 30 cards
  26.   PlayerHand: Array [1..30] of TPlayerHand;   //Array linked to record TPlayerHand that will be used to call the values of the cards in the player's hand
  27.   ComputerHand: Array [1..30] of TComputerHand;   //Array linked to record TComputerHand that will be used to call the vaules of the cards in the computer's hand
  28.   TotalCards, PlayerScore, ComputerScore: Integer;    //Variables called for use in various processes
  29.   PlayerWin: Boolean;
  30.  
  31. procedure StartGame;    //Procedure for main menu
  32. var
  33.   Answer: Char;
  34. begin
  35.   repeat
  36.     Writeln('Do you want to play the game? Y/N ');
  37.     Readln(Answer);
  38.     if Answer = 'N' then    //If statement that determines what to do depending on the output of either 'Y', 'N' or an invalid input
  39.       begin
  40.         Write('Game end');
  41.         Readln;
  42.         Halt;   //Stops the program
  43.       end
  44.     else
  45.       if Answer = 'Y' then    //Nested if statement so that a third decision can be made in the case of an invalid input
  46.         begin
  47.           Write('Game start');
  48.           Writeln;
  49.           Readln;
  50.         end
  51.       else
  52.         begin
  53.           Write('Invalid input');
  54.         Readln;
  55.         end;
  56.   until Answer = 'Y';   //Repeat loop ensures that the program only continues if 'Y' is inputted. Inputting 'N' will close the program.
  57. end;
  58.  
  59. procedure CardCheck;    //Procedure that asks the user how many cards are to be used and ensures that the number is in between 4 and 30 and is even
  60. begin
  61.   repeat
  62.     Write('Enter total number of cards: ');
  63.     Readln(TotalCards);
  64.     if (TotalCards < 4) OR (TotalCards > 30) OR (TotalCards MOD 2 <> 0) then
  65.     //If statement that asks the user to reinput a value if the value inputted is not even or in between 4 and 30
  66.  
  67.       begin
  68.         Writeln('Value is outside of acceptable range. Please enter an even number between 4 and 30.');
  69.         Readln;
  70.       end;
  71.   until (TotalCards >= 4) AND (TotalCards <= 30) AND (TotalCards MOD 2 = 0)
  72.   //Repeat loop only allows the program to continue if the value of TotalCards meets the requirements
  73. end;
  74.  
  75. procedure DogList;    //Procedure to import dog names from text file
  76. var
  77.   DogFile: TextFile;
  78.   i: Integer;
  79. begin
  80.   assignFile(DogFile, 'C:\Users\Baldeep\Desktop\test\dogs.txt');    //Assigns the text file to be imported to variable 'DogFile'
  81.   reset(DogFile);   //Opens the text document
  82.   for i := 1 to 30 do
  83.     Readln(DogFile, DogsArray[i]);    //For loop assigns all 30 names into the string array 'DogsArray'
  84.   for i := 1 to 30 do
  85.     DogRecord[i].Name := DogsArray[i];    //For loop assigns all 30 names from string array into array linked to record that will store all the cards
  86. end;
  87.  
  88. procedure Assigning;    //Procedure to assign randomised values to each dog card for that game
  89. var
  90.   i: Integer;
  91. begin
  92.   Randomize;    //Initializes the randomize function
  93.   for i := 1 to 30 do   //For loop assigns random number values for each dog characteristic
  94.     begin
  95.       DogRecord[i].Exercise := Random(5) + 1;
  96.       DogRecord[i].Intelligence := Random(100) + 1;
  97.       DogRecord[i].Friendliness := Random(10) + 1;
  98.       DogRecord[i].Drool := Random(10) + 1;
  99.     end;
  100. end;
  101.  
  102. procedure DealingCards;   //Procedure for giving out the cards between the two players
  103. var
  104.   i, Ticker: Integer;
  105. begin
  106.   Ticker := 1;
  107.   for i := 1 to (TotalCards DIV 2) do
  108.     begin
  109.       PlayerHand[i].Name := DogRecord[i].Name;
  110.       PlayerHand[i].Exercise := DogRecord[i].Exercise;
  111.       PlayerHand[i].Intelligence := DogRecord[i].Intelligence;
  112.       PlayerHand[i].Friendliness := DogRecord[i].Friendliness;
  113.       PlayerHand[i].Drool := DogRecord[i].Drool;
  114.     end;
  115.  
  116.   for i := ((TotalCards DIV 2) + 1) to TotalCards do
  117.     begin
  118.       ComputerHand[Ticker].Name := DogRecord[i].Name;
  119.       ComputerHand[Ticker].Exercise := DogRecord[i].Exercise;
  120.       ComputerHand[Ticker].Intelligence := DogRecord[i].Intelligence;
  121.       ComputerHand[Ticker].Friendliness := DogRecord[i].Friendliness;
  122.       ComputerHand[Ticker].Drool := DogRecord[i].Drool;
  123.       Ticker := Ticker + 1;
  124.     end;
  125. end;
  126.  
  127. procedure ShiftingLikeABoss;
  128. var
  129.   i: integer;
  130. begin
  131.  
  132.   if PlayerWin = true then
  133.     begin
  134.       PlayerHand[PlayerScore + 1].Name := PlayerHand[1].Name;
  135.       PlayerHand[PlayerScore + 1].Exercise := PlayerHand[1].Exercise;
  136.       PlayerHand[PlayerScore + 1].Intelligence := PlayerHand[1].Intelligence;
  137.       PlayerHand[PlayerScore + 1].Friendliness := PlayerHand[1].Friendliness;
  138.       PlayerHand[PlayerScore + 1].Drool := PlayerHand[1].Drool;
  139.  
  140.       for i := 1 to (PlayerScore - 1) do
  141.         begin
  142.           PlayerHand[i].Name := Playerhand[i + 1].Name;
  143.           PlayerHand[i].Exercise := PlayerHand[i + 1].Exercise;
  144.           PlayerHand[i].Intelligence := PlayerHand[i + 1].Intelligence;
  145.           PlayerHand[i].Friendliness := PlayerHand[i + 1].Friendliness;
  146.           PlayerHand[i].Drool := PlayerHand[i + 1].Drool;
  147.         end;
  148.  
  149.       PlayerHand[PlayerScore].Name := ComputerHand[1].Name;
  150.       PlayerHand[PlayerScore].Exercise := ComputerHand[1].Exercise;
  151.       PlayerHand[PlayerScore].Intelligence := ComputerHand[1].Intelligence;
  152.       PlayerHand[PlayerScore].Friendliness := ComputerHand[1].Friendliness;
  153.       PlayerHand[PlayerScore].Drool := ComputerHand[1].Drool;
  154.  
  155.       for i := 1 to ComputerScore do
  156.         begin
  157.           ComputerHand[i].Name := ComputerHand[i + 1].Name;
  158.           ComputerHand[i].Exercise := ComputerHand[i + 1].Exercise;
  159.           ComputerHand[i].Intelligence := ComputerHand[i + 1].Intelligence;
  160.           ComputerHand[i].Friendliness := ComputerHand[i + 1].Friendliness;
  161.           ComputerHand[i].Drool := ComputerHand[i + 1].Drool;
  162.         end;
  163.  
  164.       PlayerScore := PlayerScore + 1;
  165.       ComputerScore := ComputerScore - 1;
  166.      
  167.     end
  168.   else
  169.     begin
  170.       ComputerHand[ComputerScore + 1].Name := ComputerHand[1].Name;
  171.       ComputerHand[ComputerScore + 1].Exercise := ComputerHand[1].Exercise;
  172.       ComputerHand[ComputerScore + 1].Intelligence := ComputerHand[1].Intelligence;
  173.       ComputerHand[ComputerScore + 1].Friendliness := ComputerHand[1].Friendliness;
  174.       ComputerHand[ComputerScore + 1].Drool := ComputerHand[1].Drool;
  175.  
  176.       for i := 1 to (ComputerScore - 1) do
  177.         begin
  178.           ComputerHand[i].Name := PlayerHand[i + 1].Name;
  179.           ComputerHand[i].Exercise := PlayerHand[i + 1].Exercise;
  180.           ComputerHand[i].Intelligence := PlayerHand[i + 1].Intelligence;
  181.           ComputerHand[i].Friendliness := PlayerHand[i + 1].Friendliness;
  182.           ComputerHand[i].Drool := PlayerHand[i + 1].Drool;
  183.         end;
  184.  
  185.       ComputerHand[ComputerScore].Name := PlayerHand[1].Name;
  186.       ComputerHand[ComputerScore].Exercise := PlayerHand[1].Exercise;
  187.       ComputerHand[ComputerScore].Intelligence := PlayerHand[1].Intelligence;
  188.       ComputerHand[ComputerScore].Friendliness := PlayerHand[1].Friendliness;
  189.       ComputerHand[ComputerScore].Drool := PlayerHand[1].Drool;
  190.  
  191.       for i := 1 to PlayerScore do
  192.         begin
  193.           PlayerHand[i].Name := PlayerHand[i + 1].Name;
  194.           PlayerHand[i].Exercise := PlayerHand[i + 1].Exercise;
  195.           PlayerHand[i].Intelligence := PlayerHand[i + 1].Intelligence;
  196.           PlayerHand[i].Friendliness := PlayerHand[i + 1].Friendliness;
  197.           PlayerHand[i].Drool := PlayerHand[i + 1].Drool;
  198.         end;
  199.  
  200.       PlayerScore := PlayerScore - 1;
  201.       ComputerScore := ComputerScore + 1;
  202.  
  203.     end;
  204. end;
  205.  
  206. procedure Compare;
  207. var
  208.   ChosenCategory: String;
  209.  
  210. begin
  211.   Writeln;
  212.   Writeln('This is your card: ');
  213.   Writeln;
  214.   Writeln('Name: ', PlayerHand[1].Name);
  215.   Writeln('Exercise: ', PlayerHand[1].Exercise, '/10');
  216.   Writeln('Intelligence: ', PlayerHand[1].Intelligence, '/100');
  217.   Writeln('Friendliness: ', PlayerHand[1].Friendliness, '/10');
  218.   Writeln('Drool: ', PlayerHand[1].Drool, '/10');
  219.   Writeln;
  220.   Write('Enter a category: ');
  221.   Readln(ChosenCategory);
  222.   Writeln('Computers card is: ');
  223.   Writeln;
  224.   Writeln('Name: ', ComputerHand[1].Name);
  225.   Writeln('Exercise: ', ComputerHand[1].Exercise, '/10');
  226.   Writeln('Intelligence: ', ComputerHand[1].Intelligence, '/100');
  227.   Writeln('Friendliness: ', ComputerHand[1].Friendliness, '/10');
  228.   Writeln('Drool: ', ComputerHand[1].Drool, '/10');
  229.   Writeln;
  230.   Readln;
  231.   if ChosenCategory = 'Exercise' then
  232.     begin
  233.       if PlayerHand[1].Exercise > ComputerHand[1].Exercise then
  234.         begin
  235.           Writeln('Player wins the round!');
  236.           PlayerWin := true;
  237.         end
  238.       else
  239.         if ComputerHand[1].Exercise > PlayerHand[1].Exercise then
  240.           begin
  241.             Writeln('Computer wins this round!');
  242.             PlayerWin := false;
  243.           end
  244.         else
  245.           Writeln('Draw')
  246.         end
  247.       else
  248.         if ChosenCategory = 'Intelligence' then
  249.           begin
  250.             if PlayerHand[1].Intelligence > ComputerHand[1].Intelligence then
  251.               begin
  252.                 Writeln('Player wins this round!');
  253.                 PlayerWin := true;
  254.               end
  255.             else
  256.               if ComputerHand[1].Intelligence > PlayerHand[1].Intelligence then
  257.                 begin
  258.                   Writeln('Computer wins this round!');
  259.                   PlayerWin := false;
  260.                 end
  261.               else
  262.                 Writeln('Draw');
  263.             end
  264.           else
  265.             if ChosenCategory = 'Friendliness' then
  266.               begin
  267.                 if PlayerHand[1].Friendliness > ComputerHand[1].Friendliness then
  268.                   begin
  269.                     Writeln('Player wins this round!');
  270.                     PlayerWin := true;
  271.                   end
  272.                 else
  273.                   if ComputerHand[1].Friendliness > PlayerHand[1].Friendliness then
  274.                     begin
  275.                       Writeln('Computer wins this round!');
  276.                       PlayerWin := false;
  277.                     end
  278.                   else
  279.                     Writeln('Draw');
  280.                 end
  281.               else
  282.                 if ChosenCategory = 'Drool' then
  283.                   begin
  284.                     if PlayerHand[1].Drool < ComputerHand[1].Drool then
  285.                       begin
  286.                         Writeln('Player wins this round!');
  287.                         PlayerWin := true;
  288.                       end
  289.                     else
  290.                       if ComputerHand[1].Drool < PlayerHand[1].Drool then
  291.                         begin
  292.                           Writeln('Computer wins this round!');
  293.                           PlayerWin := false;
  294.                         end
  295.                       else
  296.                         begin
  297.                           Writeln('Draw');
  298.                           PlayerWin := true;
  299.                         end
  300.                     end
  301.                 else
  302.                   Writeln('Invalid category');
  303.   Readln;
  304.   ShiftingLikeABoss;
  305. end;
  306.  
  307.  
  308. procedure ContinueCompare;
  309. var
  310.   ChosenCategory: String;
  311.   Item: Integer;
  312. begin
  313.   if PlayerWin = false then
  314.   begin
  315.     Item := Random(4);
  316.  
  317.   if Item = 0 then
  318.     ChosenCategory := 'Exercise';
  319.   if Item = 1 then
  320.     ChosenCategory := 'Intelligence';
  321.   if Item = 2 then
  322.     ChosenCategory := 'Friendliness';
  323.   if Item = 3 then
  324.     ChosenCategory := 'Drool';
  325.   Writeln;
  326.   Writeln('This is your card: ');
  327.   Writeln;
  328.   Writeln('Name: ', PlayerHand[1].Name);
  329.   Writeln('Exercise: ', PlayerHand[1].Exercise, '/10');
  330.   Writeln('Intelligence: ', PlayerHand[1].Intelligence, '/100');
  331.   Writeln('Friendliness: ', PlayerHand[1].Friendliness, '/10');
  332.   Writeln('Drool: ', PlayerHand[1].Drool, '/10');
  333.   Writeln;
  334.   Readln;
  335.   Writeln('Computer is choosing a category... ');
  336.   Writeln('Computer chose ', ChosenCategory, '!');
  337.   Writeln;
  338.   Writeln('Computers card is: ');
  339.   Writeln;
  340.   Writeln('Name: ', ComputerHand[1].Name);
  341.   Writeln('Exercise: ', ComputerHand[1].Exercise, '/10');
  342.   Writeln('Intelligence: ', ComputerHand[1].Intelligence, '/100');
  343.   Writeln('Friendliness: ', ComputerHand[1].Friendliness, '/10');
  344.   Writeln('Drool: ', ComputerHand[1].Drool, '/10');
  345.   Writeln;
  346.   Readln;
  347.   if ChosenCategory = 'Exercise' then
  348.     begin
  349.       if PlayerHand[1].Exercise > ComputerHand[1].Exercise then
  350.         begin
  351.           Writeln('Player wins the round!');
  352.           PlayerWin := true;
  353.         end
  354.       else
  355.         if ComputerHand[1].Exercise > PlayerHand[1].Exercise then
  356.           begin
  357.             Writeln('Computer wins this round!');
  358.             PlayerWin := false;
  359.           end
  360.         else
  361.           Writeln('Draw')
  362.         end
  363.       else
  364.         if ChosenCategory = 'Intelligence' then
  365.           begin
  366.             if PlayerHand[1].Intelligence > ComputerHand[1].Intelligence then
  367.               begin
  368.                 Writeln('Player wins this round!');
  369.                 PlayerWin := true;
  370.               end
  371.             else
  372.               if ComputerHand[1].Intelligence > PlayerHand[1].Intelligence then
  373.                 begin
  374.                   Writeln('Computer wins this round!');
  375.                   PlayerWin := false;
  376.                 end
  377.               else
  378.                 Writeln('Draw');
  379.             end
  380.           else
  381.             if ChosenCategory = 'Friendliness' then
  382.               begin
  383.                 if PlayerHand[1].Friendliness > ComputerHand[1].Friendliness then
  384.                   begin
  385.                     Writeln('Player wins this round!');
  386.                     PlayerWin := true;
  387.                   end
  388.                 else
  389.                   if ComputerHand[1].Friendliness > PlayerHand[1].Friendliness then
  390.                     begin
  391.                       Writeln('Computer wins this round!');
  392.                       PlayerWin := false;
  393.                     end
  394.                   else
  395.                     Writeln('Draw');
  396.                 end
  397.               else
  398.                 if ChosenCategory = 'Drool' then
  399.                   begin
  400.                     if PlayerHand[1].Drool < ComputerHand[1].Drool then
  401.                       begin
  402.                         Writeln('Player wins this round!');
  403.                         PlayerWin := true;
  404.                       end
  405.                     else
  406.                       if ComputerHand[1].Drool < PlayerHand[1].Drool then
  407.                         begin
  408.                           Writeln('Computer wins this round!');
  409.                           PlayerWin := false;
  410.                         end
  411.                       else
  412.                         begin
  413.                           Writeln('Draw');
  414.                           PlayerWin := true;
  415.                         end
  416.                     end
  417.                 else
  418.                   Writeln('Invalid category');
  419.     Readln;
  420.     ShiftingLikeABoss;
  421.   end;
  422. end;
  423.  
  424.  
  425.  
  426. begin
  427.   Randomize;
  428.   StartGame;
  429.   CardCheck;
  430.   PlayerScore := TotalCards DIV 2;
  431.   ComputerScore := TotalCards DIV 2;
  432.   DogList;
  433.   Assigning;
  434.   DealingCards;
  435.   repeat
  436.   Compare;
  437.   ContinueCompare;
  438.   Readln;
  439.   until (PlayerScore = TotalCards) OR (ComputerScore = TotalCards);
  440.  
  441.   if PlayerScore = TotalCards then
  442.     begin
  443.       Writeln('Player wins!');
  444.       Writeln('Thank you for playing Celebrity dogs!');
  445.     end
  446.   else
  447.     begin
  448.       Writeln('Computer wins!');
  449.       Writeln('Unlucky! Play again?');
  450.     end;
  451.   Readln;
  452. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement