Dear Sir,
Could you please give me some of the ideas of making the hotSeat game in pascal?
The following is the simple mode of my coding:-
Program yeungkt1;
{$APPTYPE CONSOLE}
{
Who wants to be a millionaire.
Author: Chris Yeung
Version 1
}
uses
SysUtils,
OurCrt;
Type
hotSeat_record=record
lastname:string[12];
firstname:string[12];
phone: string[12];
End;
Var User_Choice:Integer;
hotSeat_file:file of hotSeat_record;
hotSeat:array[1..100]of hotSeat_record;
numberRecords:integer;
numbers: array[1..10] of integer;
generate: boolean;
Procedure load;
Var
count:integer;
begin
assign(hotSeat_file,'hotSeat.dat');
reset(hotSeat_file);
numberRecords:= filesize(hotSeat_file);
for count:= 1 to numberRecords do
Begin
read(hotSeat_file,hotSeat[count]);
end;
end;
Procedure ContestantsList;
Var
count:integer;
Begin
numberRecords:= filesize(hotSeat_file);
WriteLn;
for count:= 1 to (filesize(hotSeat_file)) do
Begin
WriteLn(hotSeat[count].firstname:12,hotSeat[count].lastname:12,
hotSeat[count].phone:20);
sleep(100);
End;
readln;
end;
Procedure Generate10finalists;
var
count,temp:integer;
begin
writeln('Here are the 10 finalist''s numbers');
randomize;
for count:= 1 to 10 do
begin
temp:=random(numberRecords)+1;
while(temp=numbers[1])
or (temp=numbers[2])
or (temp=numbers[3])
or (temp=numbers[4])
or (temp=numbers[5])
or (temp=numbers[6])
or (temp=numbers[7])
or (temp=numbers [8])
or (temp=numbers [9])
or (temp=numbers [10]) do
begin
temp:=random(numberRecords)+1;
end;
numbers[count]:=temp;
generate := true;
end;
for count := 1 to 10 do
begin
writeln;
writeln(' ***<$$$$$>**** ' ,(numbers[count]), ' ****<$$$$>****');
writeln;
sleep(100);
end;
writeln(' GOOD LUCK !!!!!!!');
readln;
clrscr;
end;
Procedure ShowFinalists;
var
count: integer;
Begin
if (generate = true) then
begin
WriteLn('3 pressed,finding and listing the finalists...');
WriteLn;
for count:=1 to 10 do
begin
writeln(hotSeat[numbers[count]].firstname:12,
hotSeat[numbers[count]].lastname:12, hotSeat[numbers[count]].phone:20);
writeln;
sleep(200);
end
end
else
writeln('Please generate finalist number first!');
readln;
End;
Procedure save;
var
count: integer;
Begin
reset(hotSeat_file);
for count:=1 to filesize(hotSeat_file) do
begin
write(hotSeat_file,hotSeat[count]);
end;
end;
Procedure ChangeDetails;
var
count: integer;
firstname,lastname,newphone: string[12];
name: boolean;
Begin
name:=false;
WriteLn('4 pressed,changing the phone a friend details...');
WriteLn('Please enter your first name.');
readln(firstname);
WriteLn('Please enter your last name.');
readln(lastname);
for count:=1 to filesize(hotSeat_file) do
begin
if (hotSeat[count].lastname=lastname) and
(hotSeat[count].firstname=firstname) then
begin
writeln('Well. We''ve found your records.');
writeln('Please enter your new phone number < 03 ###-####>');
readln(newphone);
hotSeat[count].phone:=newphone;
name:=true
end;
end;
if name=false then
begin
writeln('Sorry! We do not have your records from your database.');
end;
writeln;
write('Press <ENTER> to save changes and return to the main menu.');
save;
readln;
end;
Procedure EnrolContestant;
var lastname:string[12];
firstname :string[12];
phone:string[12];
count :integer;
name :boolean;
Begin
name:=false;
writeln('Please enter your first name - if you''re new.');
readln(firstname);
writeln('Please enter your last name.');
readln(lastname);
writeln('Lastly, please enter your phone number.');
readln(phone);
writeln('Please press <ENTER>');
for count:=1 to filesize(hotSeat_file) do
begin
if (hotSeat[count].lastname=lastname) and
(hotSeat[count].firstname=firstname) then
begin
name:=true;
writeln('You''re a contestant already.');
end;
end;
if (name = false) then
begin
numberRecords:= numberRecords+ 1;
hotSeat[filesize(hotSeat_file)].firstname:=firstname;
hotSeat[filesize(hotSeat_file)].lastname:=lastname;
hotSeat[filesize(hotSeat_file)].phone:=phone;
writeln('Please press <ENTER> to save your details and return to main menu.');
readln;
save;
end;
end;
Procedure GetOutOfHere;
Begin
WriteLn('0 pressed,exiting...');
Sleep(5000);
clrscr;
End;
Procedure Menu;
Begin
Writeln(' M E N U');
WriteLn('Please enter an integer in the range 1...5');
WriteLn;
WriteLn(' 1 List all the contestants');
WriteLn(' 2 Generate the 10 finalist''s numbers');
WriteLn(' 3 Find and list the finalists');
WriteLn(' 4 Change the phone a friend details');
WriteLn(' 5 Enrol a new contestant');
WriteLn(' 0 Exit');
Readln(User_Choice);
Case (User_Choice) of
1:ContestantsList;
2:Generate10finalists;
3:ShowFinalists;
4:ChangeDetails;
5:EnrolContestant;
0:GetOutOfHere;
end;
end;
begin //main body
Load;
repeat
menu; {Shows the Menu on the screen}
until User_Choice = 0; {Allows program user to Exit program}
end.