home *** CD-ROM | disk | FTP | other *** search
- program demo; {to show some of the capabilities of Pascal Magic}
- uses crt,graph,magic;
- (***********************************************************************)
- procedure showcode;
- begin
- vgahivideo; {switch to VGA 640 x 480 graphics}
- mainback := red;
- xclear; {clear the screen to all red}
- ntext(200,100,'Let''s look at the code so far:');
- ntext(180,152,'uses graph,magic;');
- ntext(180,168,'begin');
- ntext(204,184,'putpcx(''earth'');');
- ntext(204,200,'outtextxy(94,124,''Copyright 1992'');');
- ntext(204,216,'outtextxy(92,135,''Another Company'');');
- ntext(204,232,'triplex;');
- ntext(204,248,'setrgbpalette(255,63,63,0);');
- ntext(204,264,'outtextxy(101,30,''Pascal'');');
- ntext(204,280,'outtextxy(107,58,''Magic'');');
- ntext(204,296,'outtextxy(107,86,''Demo'');');
- ntext(204,312,'waitforuser;');
- setlinestyle(0,0,3);
- setcolor(yellow);
- line(194,118,440,118);
- circle(320,220,200);
- triplex; {engage Triplex font}
- settextjustify(lefttext,toptext); {restore normal justification}
- setcolor(black); {make a black shadow to emphasize text}
- outtextxy(162,432,'It''s just that simple!');
- setcolor(lightgreen); {the shadowed text itself}
- outtextxy(160,430,'It''s just that simple!');
- end; {procedure showcode}
- (***********************************************************************)
- procedure demonstratemouse;
- begin
- centerjustify := false; {No centering of strings in pop-up box}
- pile('An arrow will appear.');
- pile('You can move it whether');
- pile('or not you have a mouse,');
- pile('because you can also');
- pile('use the arrow keys,');
- pile('[Page Up], [Page Down],');
- pile('[Home], [End] or the');
- pile('number keys. Try it!');
- pile('Press [Enter] or a');
- pile('mouse button when done.');
- present.init(-1,40); {Pops a text box onto the screen}
- bugle; {sound effect}
- px := 50;
- py := 80;
- pointertoxy; {move cursor position to 50,80}
- pointeron; {show cursor - "mouse" arrow}
- repeat poll; until left or right; {wait until user clicks button}
- {or presses [Enter] or [Esc]}
- pointeroff; {turn off cursor}
- present.done; {get rid of pop up text box}
- centerjustify := true; {restore center justification of strings}
- waste; {wait until user is not pressing mouse}
- {button or keyboard key and clear key-}
- {board buffer}
- end; {procedure demonstratemouse}
- (***********************************************************************)
- procedure extkey; {shows ASCII codes when a key is pressed}
- var
- tempstr : string[3];
- begin
- XClear; {clear screen to current background color}
- sent[1] := 'Press any key to see it''s extended code';
- sent[2] := 'Press [Esc] when done.';
- present.init(18,3); {pop up a text box on screen}
- sent[1] := ' ';
- sent[2] := '';
- repeat
- present.getanykey(-1,-1); {wait for user to press a key}
- if keydetect = 2 then sent[1] := '#0 + ';
- case u of
- #13,#8,#10,#7 : answer := ' '; {don't try to print unprintables}
- else answer := u;
- end; {case}
- str(ord(u),tempstr); {make a string of it's ASCII value}
- sent[1] := sent[1] + answer + ' (#' + tempstr + ')';
- until u = #27; {fall through if user presses [Esc]}
- present.done; {Get rid of pop up text box}
- waste; {Wait for user to let go of keys}
- {and clear the buffer}
- end; {procedure ExtKey}
- (***********************************************************************)
- procedure asciichart; {makes a chart of the ASCII codes}
- var
- x,y : byte;
- temp : integer;
- begin
- textcolor(white); textbackground(blue);
- x := 1;
- y := 1;
- clrscr;
- for temp := 0 to 255 do
- begin
- u := chr(temp); {get the character equivalent of "temp"}
- gotoxy(x,y);
- write(' ');
- if temp < 10 then write(' ');
- if temp < 100 then write(' ');
- if (temp <> 7) and (temp <> 8) and (temp <> 10)
- and (temp <> 13) and (temp <> 27)
- then write(temp,'=',u,' ')
- else write(temp,'=');
- inc(y);
- if y > 25 then
- begin
- y := 1;
- x := x + 7;
- end;
- end; {end of for 0 to 255 loop}
- waitforuser; {show the chart until user presses any key}
- waste; {wait for user to let go of keyboard and}
- {clear the buffer.}
- end; {procedure Asciichart}
- (***********************************************************************)
- procedure typotrap;
- begin
- centerjustify := false; {does not center text in pop-up boxes}
- mainback := green;
- boxback := blue;
- xclear; {clears background to MainBack - green}
- pile('This procedure reads a Pascal source code file from disk,');
- pile('and looks for lines containing literal strings. It then');
- pile('prints only those lines to a disk file named "RESULTS.DOC."');
- pile(' This is very helpful in finding typographical errors');
- pile('which your compiler will not be able to catch but which');
- pile('your end users would notice.');
- pile(' Press any key to begin...');
- present.getanykey(-1,-1); {pops a text box on screen, wait for user}
- centerjustify := true; {lines of text will be centered in pop-ups}
- pile('Type the name of a source code file to check:');
- present.dialog(-1,-1); {get an answer from user}
- if answer = '' then exit;
- if pos('.',answer) = 0 then answer := answer + '.PAS';
- nameinfile(answer); {input file named as user's answer}
- nameoutfile('results.doc'); {output file named "results.doc"}
- mainback := blue;
- xclear; {background cleared to MainBack - blue}
- sent[1] := '*************** String literals from file: ' + answer + '****************';
- fileecholn(sent[1]); {print sent[1] to screen and file}
- repeat
- answer := filereadln; {string "Answer" read from input file}
- if pos('''',answer) > 0 then fileecholn(answer);
- {If there is a quote mark in string,}
- {then print it to file and screen.}
- until problem > 0; {Problem is 1 when end of file}
- filewriteln(''); {write a blank line to file}
- boxback := magenta; {make pop-up boxes in magenta}
- pile('Results written to disk file: RESULTS.DOC');
- pile('');
- pile('Press any key to continue...');
- present.getanykey(-1,-1); {pop up text box, and wait for user}
- boxback := blue;
- mainback := green;
- waste; {clear keyboard buffer (and mouse)}
- end; {procedure typotrap}
- (***********************************************************************)
- procedure tools; {Programmer's Toolkit}
- begin
- textvideo; {get rid of graphics mode screen}
- mc := 1;
- centerjustify := true; {text will be centered in pop-up boxes}
- repeat
- mainback := green;
- xclear; {clears background to green}
- BoxBack := red;
- sent[1] := 'Programmer''s Tools';
- sent[2] := 'Copyright 1991, Another Company';
- present.init(-1,2); {pops up a text box}
- BoxBack := blue;
- sent[1] := 'ASCII Chart';
- sent[2] := 'Extended Keys';
- sent[3] := 'Typo Trap';
- sent[4] := 'Quit';
- present.menu(-1,-1,'AETQ'); {pops up a menu which will fall}
- {through when end user presses}
- {[Enter], [Esc], left or right}
- {mouse buttons, or [A],[E],[T],}
- {or [Q] in upper or lower case.}
-
- present.done; {Get rid of original pop-up box}
- case u of
- 'A' : asciichart;
- 'E' : extkey; {if user selected from menu by}
- 'T' : typotrap; {pressing an alphanumeric key}
- 'Q' : right := true;
- end;
- if left then case mc of
- 1 : asciichart; {if user seleted from menu by}
- 2 : extkey; {highlighting and pressing left}
- 3 : typotrap; {mouse button or [Enter]}
- 4 : right := true;
- end;
- until right; {falls through if user presses}
- {[Esc] or right mouse button}
- waste; {clears keyboard buffer and mouse}
- showcode;
- end; {procedure tools}
- (***********************************************************************)
- procedure saveearth; {Demonstrates how to build a video game}
- var
- holdsize,oldx,oldy : word;
- hold : pointer;
- begin
- egalovideo; {switch to EGA 640 x 200, 16-color mode}
- centerjustify := false; {strings will not be centered in pop-up box}
- pile('This demonstrates a very (very!) simple');
- pile('video game. Try it, look at how small');
- pile('and straight-forward the source code is');
- pile('(Procedure SaveEarth within DEMO.PAS).');
- pile('Then imagine adding more rules, timer,');
- pile('function, sound effects, and perhaps');
- pile('some adversary action...');
- present.getanykey(-1,-1); {pops up a text box and waits for user}
- pile('The earth is suffering from pollution.');
- pile('Only YOU can reverse it. Change the');
- pile('black spots to white. Do this by ');
- pile('clicking the left mouse button or');
- pile('pressing [Enter]. When done, click');
- pile('the right button or press [Esc].');
- pile('');
- pile(' Press any key to begin...');
- present.getanykey(-1,-1); {pops up a text box and waits for user}
- putpcx('Earth',true); {displays a .PCX file called "Earth"}
- setrgbpalette(255,53,53,53); {customize color #255}
- setcolor(255);
- settextjustify(centertext,bottomtext); {Text justification}
- if mouseinstalled then
- outtextxy(160,199,'Left = Fill spot | Right = Quit')
- else outtextxy(160,199,'Enter = Fill spot | Esc = Quit');
- {puts a note at bottom of screen}
- holdsize := imagesize(0,0,20,20);
- getmem(hold,holdsize); {gets a chunk of RAM to hold a}
- {portion of video image}
- waste; {clears keyboard buffer and mouse}
- px := 160;
- py := 100;
- pointertoxy; {position cursor at 160,100}
- repeat
- getimage(px - 10,py - 10,px + 10,py + 10,hold^); {store portion of}
- {screen to RAM}
- line(px - 1,py,px - 10,py);
- line(px + 1,py,px + 10,py); {make + shaped cursor}
- line(px,py - 1,px,py - 10); {with a small hole in}
- line(px,py + 1,px,py + 10); {the middle}
- oldx := px;
- oldy := py;
- repeat
- poll; {get of mouse position & status}
- if px < 10 then px := 10;
- if px > 307 then px := 307;
- if py < 10 then py := 10; {keep cursor location on screen}
- if py > 188 then py := 188;
- until (px <> oldx) or (py <> oldy) {keep polling until action is}
- or left or right; {detected}
- putimage(oldx - 10, oldy - 10, hold^,copyput); {replace screen image}
- if left then putpixel(px,py,255); {draw a dot on screen}
- until right; {done when user presses right}
- {mouse button or [Esc] key}
- freemem(hold,holdsize); {release RAM held for image}
- waste;
- centerjustify := true;
- showcode;
- end; {procedure saveearth}
- (***********************************************************************)
- procedure fixsound; {if sound effects are on, turn them off, & visa versa}
- begin
- if musicon then
- begin
- musicon := false;
- pile('Sound Turned OFF')
- end else begin
- musicon := true;
- pile('Sound turned ON');
- end;
- present.init(-1,-1); {pop a line of text on screen in small box}
- delay(500); {wait 1/2 second}
- present.done; {get rid of pop-up box}
- end; {procedure fixsound}
- (***********************************************************************)
- begin {main}
- putpcx('earth',true); {display .PCX file}
- setcolor(yellow);
- outtextxy(94,124,'Copyright 1992');
- outtextxy(92,135,'Another Company');
- triplex; {Engage Triplex font}
- setrgbpalette(255,63,63,0);
- outtextxy(101,30,'Pascal');
- outtextxy(107,58,'Magic');
- outtextxy(107,86,'Demo');
- waitforuser; {wait for user to press something}
- showcode; {procedure at top of this file}
- waitforuser;
- mc := 1; {first menu item to highlight}
- centerjustify := true; {text will be centered in boxes}
- repeat
- pile('Mouse Interface');
- pile('Programmer''s Tools');
- pile('Save The Earth');
- if musicon then pile('Turn Off Sound Effects')
- else pile('Turn On Sound Effects');
- pile('Quit');
- present.menu(-1,150,'MPQST'); {a menu will pop up which will}
- {drop out when the user presses}
- {[Enter], [Esc] a mouse button,}
- {[M], [P], [Q], [S] or [T].}
- case u of
- 'M' : demonstratemouse;
- 'P' : tools;
- 'S' : saveearth;
- 'T' : fixsound; {if user selected by pressing}
- 'Q' : right := true; {a key}
- end;
- if left then case mc of
- 1 : demonstratemouse;
- 2 : tools;
- 3 : saveearth; {if user selected by hilighting}
- 4 : fixsound;
- 5 : right := true;
- end;
- until right; {if user pressed right mouse button}
- {or [Esc] key, we're done}
-
- textvideo;
- mainback := green;
- xclear;
- clearsents;
- centerjustify := true;
- pile('Pascal Magic - Demo');
- pile('');
- pile('For use with Turbo Pascal, Version 7.0');
- pile('');
- pile('Copyright 1992, Another Company');
- pile('P.O. Box 298');
- pile('Applegate, OR 97530, USA');
- pile('phone 503-846-7884');
- present.getanykey(-1,-1);
- cleanup;
- end.