Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program CelebrityDogs;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- type TDogs = record //Calls a record called TDogs which will store all 30 cards
- Name: String;
- Exercise, Intelligence, Friendliness, Drool: Integer; //Assigning variables for the characteristics that the dogs have
- end;
- type TPlayerHand = record //Calls a record TPlayerHand which will be linked to an array to store the player's hand
- Name: String;
- Exercise, Intelligence, Friendliness, Drool: Integer; //Assigning variables for the characteristics that the dogs have
- end;
- type TComputerHand = record //Calls a record TComputerHand which will be linked to an array to store the computer's hand
- Name: String;
- Exercise, Intelligence, Friendliness, Drool: Integer; //Assigning variables for the characteristics that the dogs have
- end;
- var
- DogsArray: Array [1..30] of String; //String array that will store the names of the dogs when imported from the text file
- DogRecord: Array [1..30] of TDogs; //Array linked to record TDogs to access and use all 30 cards
- 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
- 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
- TotalCards, PlayerScore, ComputerScore: Integer; //Variables called for use in various processes
- PlayerWin: Boolean;
- procedure StartGame; //Procedure for main menu
- var
- Answer: Char;
- begin
- repeat
- Writeln('Do you want to play the game? Y/N ');
- Readln(Answer);
- if Answer = 'N' then //If statement that determines what to do depending on the output of either 'Y', 'N' or an invalid input
- begin
- Write('Game end');
- Readln;
- Halt; //Stops the program
- end
- else
- if Answer = 'Y' then //Nested if statement so that a third decision can be made in the case of an invalid input
- begin
- Write('Game start');
- Writeln;
- Readln;
- end
- else
- begin
- Write('Invalid input');
- Readln;
- end;
- until Answer = 'Y'; //Repeat loop ensures that the program only continues if 'Y' is inputted. Inputting 'N' will close the program.
- end;
- 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
- begin
- repeat
- Write('Enter total number of cards: ');
- Readln(TotalCards);
- if (TotalCards < 4) OR (TotalCards > 30) OR (TotalCards MOD 2 <> 0) then
- //If statement that asks the user to reinput a value if the value inputted is not even or in between 4 and 30
- begin
- Writeln('Value is outside of acceptable range. Please enter an even number between 4 and 30.');
- Readln;
- end;
- until (TotalCards >= 4) AND (TotalCards <= 30) AND (TotalCards MOD 2 = 0)
- //Repeat loop only allows the program to continue if the value of TotalCards meets the requirements
- end;
- procedure DogList; //Procedure to import dog names from text file
- var
- DogFile: TextFile;
- i: Integer;
- begin
- assignFile(DogFile, 'C:\Users\Baldeep\Desktop\test\dogs.txt'); //Assigns the text file to be imported to variable 'DogFile'
- reset(DogFile); //Opens the text document
- for i := 1 to 30 do
- Readln(DogFile, DogsArray[i]); //For loop assigns all 30 names into the string array 'DogsArray'
- for i := 1 to 30 do
- 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
- end;
- procedure Assigning; //Procedure to assign randomised values to each dog card for that game
- var
- i: Integer;
- begin
- Randomize; //Initializes the randomize function
- for i := 1 to 30 do //For loop assigns random number values for each dog characteristic
- begin
- DogRecord[i].Exercise := Random(5) + 1;
- DogRecord[i].Intelligence := Random(100) + 1;
- DogRecord[i].Friendliness := Random(10) + 1;
- DogRecord[i].Drool := Random(10) + 1;
- end;
- end;
- procedure DealingCards; //Procedure for giving out the cards between the two players
- var
- i, Ticker: Integer;
- begin
- Ticker := 1;
- for i := 1 to (TotalCards DIV 2) do
- begin
- PlayerHand[i].Name := DogRecord[i].Name;
- PlayerHand[i].Exercise := DogRecord[i].Exercise;
- PlayerHand[i].Intelligence := DogRecord[i].Intelligence;
- PlayerHand[i].Friendliness := DogRecord[i].Friendliness;
- PlayerHand[i].Drool := DogRecord[i].Drool;
- end;
- for i := ((TotalCards DIV 2) + 1) to TotalCards do
- begin
- ComputerHand[Ticker].Name := DogRecord[i].Name;
- ComputerHand[Ticker].Exercise := DogRecord[i].Exercise;
- ComputerHand[Ticker].Intelligence := DogRecord[i].Intelligence;
- ComputerHand[Ticker].Friendliness := DogRecord[i].Friendliness;
- ComputerHand[Ticker].Drool := DogRecord[i].Drool;
- Ticker := Ticker + 1;
- end;
- end;
- procedure ShiftingLikeABoss;
- var
- i: integer;
- begin
- if PlayerWin = true then
- begin
- PlayerHand[PlayerScore + 1].Name := PlayerHand[1].Name;
- PlayerHand[PlayerScore + 1].Exercise := PlayerHand[1].Exercise;
- PlayerHand[PlayerScore + 1].Intelligence := PlayerHand[1].Intelligence;
- PlayerHand[PlayerScore + 1].Friendliness := PlayerHand[1].Friendliness;
- PlayerHand[PlayerScore + 1].Drool := PlayerHand[1].Drool;
- for i := 1 to (PlayerScore - 1) do
- begin
- PlayerHand[i].Name := Playerhand[i + 1].Name;
- PlayerHand[i].Exercise := PlayerHand[i + 1].Exercise;
- PlayerHand[i].Intelligence := PlayerHand[i + 1].Intelligence;
- PlayerHand[i].Friendliness := PlayerHand[i + 1].Friendliness;
- PlayerHand[i].Drool := PlayerHand[i + 1].Drool;
- end;
- PlayerHand[PlayerScore].Name := ComputerHand[1].Name;
- PlayerHand[PlayerScore].Exercise := ComputerHand[1].Exercise;
- PlayerHand[PlayerScore].Intelligence := ComputerHand[1].Intelligence;
- PlayerHand[PlayerScore].Friendliness := ComputerHand[1].Friendliness;
- PlayerHand[PlayerScore].Drool := ComputerHand[1].Drool;
- for i := 1 to ComputerScore do
- begin
- ComputerHand[i].Name := ComputerHand[i + 1].Name;
- ComputerHand[i].Exercise := ComputerHand[i + 1].Exercise;
- ComputerHand[i].Intelligence := ComputerHand[i + 1].Intelligence;
- ComputerHand[i].Friendliness := ComputerHand[i + 1].Friendliness;
- ComputerHand[i].Drool := ComputerHand[i + 1].Drool;
- end;
- PlayerScore := PlayerScore + 1;
- ComputerScore := ComputerScore - 1;
- end
- else
- begin
- ComputerHand[ComputerScore + 1].Name := ComputerHand[1].Name;
- ComputerHand[ComputerScore + 1].Exercise := ComputerHand[1].Exercise;
- ComputerHand[ComputerScore + 1].Intelligence := ComputerHand[1].Intelligence;
- ComputerHand[ComputerScore + 1].Friendliness := ComputerHand[1].Friendliness;
- ComputerHand[ComputerScore + 1].Drool := ComputerHand[1].Drool;
- for i := 1 to (ComputerScore - 1) do
- begin
- ComputerHand[i].Name := PlayerHand[i + 1].Name;
- ComputerHand[i].Exercise := PlayerHand[i + 1].Exercise;
- ComputerHand[i].Intelligence := PlayerHand[i + 1].Intelligence;
- ComputerHand[i].Friendliness := PlayerHand[i + 1].Friendliness;
- ComputerHand[i].Drool := PlayerHand[i + 1].Drool;
- end;
- ComputerHand[ComputerScore].Name := PlayerHand[1].Name;
- ComputerHand[ComputerScore].Exercise := PlayerHand[1].Exercise;
- ComputerHand[ComputerScore].Intelligence := PlayerHand[1].Intelligence;
- ComputerHand[ComputerScore].Friendliness := PlayerHand[1].Friendliness;
- ComputerHand[ComputerScore].Drool := PlayerHand[1].Drool;
- for i := 1 to PlayerScore do
- begin
- PlayerHand[i].Name := PlayerHand[i + 1].Name;
- PlayerHand[i].Exercise := PlayerHand[i + 1].Exercise;
- PlayerHand[i].Intelligence := PlayerHand[i + 1].Intelligence;
- PlayerHand[i].Friendliness := PlayerHand[i + 1].Friendliness;
- PlayerHand[i].Drool := PlayerHand[i + 1].Drool;
- end;
- PlayerScore := PlayerScore - 1;
- ComputerScore := ComputerScore + 1;
- end;
- end;
- procedure Compare;
- var
- ChosenCategory: String;
- begin
- Writeln;
- Writeln('This is your card: ');
- Writeln;
- Writeln('Name: ', PlayerHand[1].Name);
- Writeln('Exercise: ', PlayerHand[1].Exercise, '/10');
- Writeln('Intelligence: ', PlayerHand[1].Intelligence, '/100');
- Writeln('Friendliness: ', PlayerHand[1].Friendliness, '/10');
- Writeln('Drool: ', PlayerHand[1].Drool, '/10');
- Writeln;
- Write('Enter a category: ');
- Readln(ChosenCategory);
- Writeln('Computers card is: ');
- Writeln;
- Writeln('Name: ', ComputerHand[1].Name);
- Writeln('Exercise: ', ComputerHand[1].Exercise, '/10');
- Writeln('Intelligence: ', ComputerHand[1].Intelligence, '/100');
- Writeln('Friendliness: ', ComputerHand[1].Friendliness, '/10');
- Writeln('Drool: ', ComputerHand[1].Drool, '/10');
- Writeln;
- Readln;
- if ChosenCategory = 'Exercise' then
- begin
- if PlayerHand[1].Exercise > ComputerHand[1].Exercise then
- begin
- Writeln('Player wins the round!');
- PlayerWin := true;
- end
- else
- if ComputerHand[1].Exercise > PlayerHand[1].Exercise then
- begin
- Writeln('Computer wins this round!');
- PlayerWin := false;
- end
- else
- Writeln('Draw')
- end
- else
- if ChosenCategory = 'Intelligence' then
- begin
- if PlayerHand[1].Intelligence > ComputerHand[1].Intelligence then
- begin
- Writeln('Player wins this round!');
- PlayerWin := true;
- end
- else
- if ComputerHand[1].Intelligence > PlayerHand[1].Intelligence then
- begin
- Writeln('Computer wins this round!');
- PlayerWin := false;
- end
- else
- Writeln('Draw');
- end
- else
- if ChosenCategory = 'Friendliness' then
- begin
- if PlayerHand[1].Friendliness > ComputerHand[1].Friendliness then
- begin
- Writeln('Player wins this round!');
- PlayerWin := true;
- end
- else
- if ComputerHand[1].Friendliness > PlayerHand[1].Friendliness then
- begin
- Writeln('Computer wins this round!');
- PlayerWin := false;
- end
- else
- Writeln('Draw');
- end
- else
- if ChosenCategory = 'Drool' then
- begin
- if PlayerHand[1].Drool < ComputerHand[1].Drool then
- begin
- Writeln('Player wins this round!');
- PlayerWin := true;
- end
- else
- if ComputerHand[1].Drool < PlayerHand[1].Drool then
- begin
- Writeln('Computer wins this round!');
- PlayerWin := false;
- end
- else
- begin
- Writeln('Draw');
- PlayerWin := true;
- end
- end
- else
- Writeln('Invalid category');
- Readln;
- ShiftingLikeABoss;
- end;
- procedure ContinueCompare;
- var
- ChosenCategory: String;
- Item: Integer;
- begin
- if PlayerWin = false then
- begin
- Item := Random(4);
- if Item = 0 then
- ChosenCategory := 'Exercise';
- if Item = 1 then
- ChosenCategory := 'Intelligence';
- if Item = 2 then
- ChosenCategory := 'Friendliness';
- if Item = 3 then
- ChosenCategory := 'Drool';
- Writeln;
- Writeln('This is your card: ');
- Writeln;
- Writeln('Name: ', PlayerHand[1].Name);
- Writeln('Exercise: ', PlayerHand[1].Exercise, '/10');
- Writeln('Intelligence: ', PlayerHand[1].Intelligence, '/100');
- Writeln('Friendliness: ', PlayerHand[1].Friendliness, '/10');
- Writeln('Drool: ', PlayerHand[1].Drool, '/10');
- Writeln;
- Readln;
- Writeln('Computer is choosing a category... ');
- Writeln('Computer chose ', ChosenCategory, '!');
- Writeln;
- Writeln('Computers card is: ');
- Writeln;
- Writeln('Name: ', ComputerHand[1].Name);
- Writeln('Exercise: ', ComputerHand[1].Exercise, '/10');
- Writeln('Intelligence: ', ComputerHand[1].Intelligence, '/100');
- Writeln('Friendliness: ', ComputerHand[1].Friendliness, '/10');
- Writeln('Drool: ', ComputerHand[1].Drool, '/10');
- Writeln;
- Readln;
- if ChosenCategory = 'Exercise' then
- begin
- if PlayerHand[1].Exercise > ComputerHand[1].Exercise then
- begin
- Writeln('Player wins the round!');
- PlayerWin := true;
- end
- else
- if ComputerHand[1].Exercise > PlayerHand[1].Exercise then
- begin
- Writeln('Computer wins this round!');
- PlayerWin := false;
- end
- else
- Writeln('Draw')
- end
- else
- if ChosenCategory = 'Intelligence' then
- begin
- if PlayerHand[1].Intelligence > ComputerHand[1].Intelligence then
- begin
- Writeln('Player wins this round!');
- PlayerWin := true;
- end
- else
- if ComputerHand[1].Intelligence > PlayerHand[1].Intelligence then
- begin
- Writeln('Computer wins this round!');
- PlayerWin := false;
- end
- else
- Writeln('Draw');
- end
- else
- if ChosenCategory = 'Friendliness' then
- begin
- if PlayerHand[1].Friendliness > ComputerHand[1].Friendliness then
- begin
- Writeln('Player wins this round!');
- PlayerWin := true;
- end
- else
- if ComputerHand[1].Friendliness > PlayerHand[1].Friendliness then
- begin
- Writeln('Computer wins this round!');
- PlayerWin := false;
- end
- else
- Writeln('Draw');
- end
- else
- if ChosenCategory = 'Drool' then
- begin
- if PlayerHand[1].Drool < ComputerHand[1].Drool then
- begin
- Writeln('Player wins this round!');
- PlayerWin := true;
- end
- else
- if ComputerHand[1].Drool < PlayerHand[1].Drool then
- begin
- Writeln('Computer wins this round!');
- PlayerWin := false;
- end
- else
- begin
- Writeln('Draw');
- PlayerWin := true;
- end
- end
- else
- Writeln('Invalid category');
- Readln;
- ShiftingLikeABoss;
- end;
- end;
- begin
- Randomize;
- StartGame;
- CardCheck;
- PlayerScore := TotalCards DIV 2;
- ComputerScore := TotalCards DIV 2;
- DogList;
- Assigning;
- DealingCards;
- repeat
- Compare;
- ContinueCompare;
- Readln;
- until (PlayerScore = TotalCards) OR (ComputerScore = TotalCards);
- if PlayerScore = TotalCards then
- begin
- Writeln('Player wins!');
- Writeln('Thank you for playing Celebrity dogs!');
- end
- else
- begin
- Writeln('Computer wins!');
- Writeln('Unlucky! Play again?');
- end;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement