program P17; uses wincrt,windos; var wording:array[1..10]of string[10]; ans:array[1..10]of string; code:array[1..10]of string[5]; hints:array[1..10]of string; flagh:array[1..10]of boolean; name:array [1..15]of string; marker:array [1..15] of integer; user:string; i,j,hintno,chance,choice:integer; f1,rankfile:text; select,subselect,oops:integer; control:boolean; h1,h2,m1,m2,s1,s2,hu1,hu2,th,tm,ts:word; marks:integer; procedure assigncha; {to read all the answer and code and hints from file} begin reset(f1); for i:=1 to 10 do begin readln(f1,code[i]); readln(f1,ans[i]); end; for i:=1 to 10 do readln(f1,hints[i]); close(f1) ; end; function LeadingZero(w:word):string; var s:string; begin str(w:0,s); if length(s)=1 then s:='0'+s; leadingzero:=s; end; procedure givehints; {to output hints for the uses to guess} begin writeln('****************** New Game ******************'); writeln('☆☆☆ Your starting time is ',leadingzero(h1),':',leadingzero(m1)); writeln('☆☆☆ You have ',chance,' chance(s) left. You have ',marks,' mark(s).'); writeln('HINTS:'); for i:=1 to 10 do if flagh[i]=false then hints[i]:='>>> * You have answered this hint correctly. * <<<'; {if the user has answered that hint, the hint will not be displayed.} for i:=1 to 10 do writeln(i,'. ',hints[i]); end; procedure inputans; {to accept input from user} var checkinput:boolean; r,c,error,place:integer; begin repeat checkinput:=true; writeln; writeln('Which hint do you want to answer(1-10)?'); readln(hintno); if (hintno>10) or (hintno<0) then begin checkinput:=false; writeln('No such hint.'); end else if flagh[hintno]=false then writeln('You have answered this hint already, choose another hint.'); until (checkinput) and (flagh[hintno]); val(copy(code[hintno],2,2),r,error); val(copy(code[hintno],4,2),c,error); place:=1; if code[hintno][1]='T' then repeat if wording[r][c]='*' then wording[r][c]:='#'; c:=c+1; place:=place+1; until place>length(ans[hintno]); if code[hintno][1]='L' then repeat if wording[r][c]='*' then wording[r][c]:='#'; r:=r+1; place:=place+1; until place>length(ans[hintno]); for i:=1 to 10 do begin for j:=1 to 10 do write(wording[i][j]); writeln; end; writeln('What is your answer for hint[',hintno,']?'); readln(user); end; procedure processinput; {to check whether the user's answer is correct} var r,c,error,place:integer; begin place:=1; {if the user input lower case, change the input back to upper case} for i:=1 to length(user) do if (user[i]>='a') and (user[i]<='z') then user[i]:=chr(ord(user[i])-32); val(copy(code[hintno],2,2),r,error); val(copy(code[hintno],4,2),c,error); if user=ans[hintno] then begin if code[hintno][1]='T' then repeat wording[r][c]:=ans[hintno][place]; c:=c+1; place:=place+1; until place>length(ans[hintno]); if code[hintno][1]='L' then repeat wording[r][c]:=ans[hintno][place]; r:=r+1; place:=place+1; until place>length(ans[hintno]); flagh[hintno]:=false; marks:=marks+10; writeln('You are correct!'); end else begin writeln('You are wrong, try again.') ; chance:=chance-1; end; end; procedure showranking; begin {to read the ranking information from file} assign(rankfile,'rank.dat'); reset(rankfile); for i:=1 to 15 do readln(rankfile, name[i]); for i:=1 to 15 do readln(rankfile, marker[i]); close(rankfile); writeln('****************** Ranking List ******************'); writeln; {to output the ranking information} writeln(' Rank Name Marks'); writeln(' -------------------------'); for i:=1 to 15 do writeln(' ',i:4,' ',name[i],marker[i]:14-length(name[i])); writeln; writeln('Please press to go back to Main Menu.'); readln; clrscr; end; procedure checkranking(a:integer); var new:integer; begin {to read the ranking information from file} assign(rankfile,'rank.dat'); reset(rankfile); for i:=1 to 15 do readln(rankfile, name[i]); for i:=1 to 15 do readln(rankfile, marker[i]); close(rankfile); if (a>marker[15]) then begin for i:=1 to 15 do if a>marker[i] then begin new:=i; i:=15; end; for i:= 15 downto new do {insert the new user top the ranking list} begin name[i]:=name[i-1]; marker[i]:=marker[i-1]; end; writeln('Yeah! You are the top 15 players!!'); writeln('What is your name(at most 10 letters)?'); readln(name[new]); marker[new]:=a; rewrite(rankfile); for i:=1 to 15 do writeln(rankfile,name[i]); for i:=1 to 15 do writeln(rankfile,marker[i]); close(rankfile); end else writeln('Aiyo! You are not the top 15 players.'); writeln('Please press to see the Ranking.'); readln; end; procedure quitgame; begin writeln('****************** Quit Game ******************'); writeln('Thank you for using this Crossword Game!'); writeln('You may press to quit'); control:=false; readln; donewincrt; end; procedure showinstructions; {to give detailed instructions for players} begin writeln('****************** Instructions ******************'); writeln('1.There are many sets of crossword questions.'); writeln(' The computer will randomly choose one for you each time.'); writeln('2.You have 5 chances to complete each crossword game.'); writeln(' You will lose if you answer more than 5 wrong answers.'); writeln('3.The time you used to complete the game will be recorded.'); writeln('4.There is a ranking list in this game.'); writeln(' If you are the top 15 who use the least time to complete the game,'); writeln(' your name will be recorded.'); writeln('5.You can choose the decoration of the crossword in Game Setting.'); writeln('6.You can SAVE your game and LOAD it to continue playing it next time.'); for i:=1 to 8 do writeln; writeln('Please press to go back to Main Menu.'); readln; clrscr; end; procedure showmainmenu; {the first page of the game} var h:integer; begin writeln(' * * * * * * * * * * * * * * *'); writeln(' * * 香 港 中 學 會 考 電 腦 與 資 訊 科 技 科 * * '); writeln(' * * HKCEE Computer and Information and Teachnology* *'); writeln(' * * * * * * * * * * * * * * '); writeln(' * * * * * * * * * * * * * * *'); writeln(' * * * 歡 迎 來 到 縱 橫 式 字 謎 遊 戲 * * * '); writeln(' * * * * * * * * * * * * * * *'); writeln(' * * * Welcome To Crossword Puzzle Game * * * '); writeln(' * * * * * * * * * * * * * * *'); writeln(' * * * * 請選擇以下其中一項。 * * * * '); writeln(' * * * Please choose the following items. * * *'); writeln(' * * * * Main Menu 主菜單 * * * * * '); writeln(' * * * * * 1. Instructions 指示 * * * * *'); writeln(' * * * * 2. New Game 新遊戲 * * * * * '); writeln(' * * * * * 3. Load Game 載入遊戲 * * * *'); writeln(' * * * * 4. Ranking List 排名 * * * * '); writeln(' * * * * * 5. Game Setting 遊戲設定 * * * *'); writeln(' * * * * 6. Quit Game 離開遊戲 * * * * '); writeln(' * * * * * * * * * * * * * * *'); repeat writeln('Enter your selection(1-6) and Press :'); readln(select); if not ((select>=1) and (select<=6)) then writeln('Invalid Selection. Please re-enter.'); until ((select>=1) and (select<=6)); clrscr; end; begin windowsize.x:=780; windowsize.y:=550; windoworg.x:=1; windoworg.y:=1; screensize.x:=80; screensize.y:=100; case random(2) of 0:Assign(f1,'puzzle.dat'); 1:Assign(f1,'puzzle2.dat'); end; assigncha; for i:=1 to 10 do flagh[i]:=true; for i:=1 to 10 do for j:=1 to 10 do wording[i][j]:='*'; control:=true; repeat chance:=5; marks:=0; showmainmenu; case select of 1:showinstructions; 2:begin gettime(h1,m1,s1,hu1); th:=h1; tm:=m1+10; ts:=s1; if tm>=60 then begin tm:=tm-60; th:=th+1; end; if th=24 then th:=0; repeat for i:=1 to 10 do for j:= 1 to 10 do if wording[i][j]='#' then wording[i][j]:='*'; givehints; inputans; processinput; for i:=1 to 10 do begin for j:=1 to 10 do write(wording[i][j]); writeln; end; oops:=0; for i:=1 to 10 do if flagh[i]=false then oops:=oops+1; if (chance=0) then begin writeln('You have used up all the chances. Goodbye!'); writeln('Please press to see your result.'); readln; clrscr; end; if (oops=10) then begin writeln('You have completed the game. Congratulations!'); writeln('Please press to see your result.'); readln; clrscr; end; if (chance>0) and (oops<10) then begin writeln('Please press to continue.'); readln; clrscr; end; gettime(h2,m2,s2,hu2); if (h2=th) and (m2>=tm) then begin ClrScr; writeln('Time is up!!'); end; if (chance=0) or (oops=10) or (h2=th) and (m2>=tm) then begin writeln('Here is you puzzle'); for i:=1 to 10 do begin for j:=1 to 10 do write(wording[i][j]); writeln; end; writeln('You have ',chance,' chances left.'); writeln('You have ',chance*7,' bonus mark.'); writeln('You have ',marks,' mark.'); marks:=marks+chance*7; writeln('Your total mark is ',marks); checkranking(marks); showranking; end; until (chance=0) or (oops=10) or ((h2=th) and (m2>=tm)); end; 4:showranking; 6:quitgame; end; until (control=false); end.