Ⅰ 濡備綍鐢╰urbo c鍐欑獥浣撶▼搴
Turbo C2.0鐨勫瓧絎﹀睆騫曞嚱鏁頒富瑕佸寘鎷鏂囨湰紿楀彛澶у皬鐨勮懼畾銆佺獥鍙i滆壊鐨勮劇疆銆
紿楀彛鏂囨湰鐨勬竻闄ゅ拰杈撳叆杈撳嚭絳夊嚱鏁般
1.鏂囨湰紿楀彛鐨勫畾涔
Turbo C2.0榛樿ゅ畾涔夌殑鏂囨湰紿楀彛涓烘暣涓灞忓箷, 鍏辨湁80鍒(鎴40鍒)25琛岀殑鏂囨湰
鍗曞厓, 姣忎釜鍗曞厓鍖呮嫭涓涓瀛楃﹀拰涓涓灞炴, 瀛楃﹀嵆ASCII 鐮佸瓧絎, 灞炴ц勫畾璇ュ瓧
絎︾殑棰滆壊鍜屽己搴︺
Turbo C2.0鍙浠ュ畾涔夊睆騫曚笂鐨勪竴涓鐭╁艦鍩熶綔涓虹獥鍙, 浣跨敤window()鍑芥暟瀹氫箟銆
紿楀彛瀹氫箟涔嬪悗, 鐢ㄦ湁鍏崇獥鍙g殑杈撳叆杈撳嚭鍑芥暟灝卞彲浠ュ彧鍦ㄦょ獥鍙e唴榪涜屾搷浣滆屼笉瓚
鍑虹獥鍙g殑杈圭晫銆
window()鍑芥暟鐨勮皟鐢ㄦ牸寮忎負:
void window(int left, int top, int right, int bottom);
璇ュ嚱鏁扮殑鍘熷瀷鍦╟onio.h 涓 (鍏充簬鏂囨湰紿楀彛鐨勬墍鏈夊嚱鏁板叾澶存枃浠跺潎涓篶onio.h,
鍚庨潰涓嶅啀璇存槑)銆 鍑芥暟涓褰㈠紡鍙傛暟(int left, int top)鏄紿楀彛宸︿笂瑙掔殑鍧愭爣,
(int right, int bottom)鏄紿楀彛鐨勫彸涓嬭掑潗鏍, 鍏朵腑(left, top)鍜(right,
bottom) 鏄鐩稿逛簬鏁翠釜灞忓箷鑰岃█鐨勩 Turbo C 2.0瑙勫畾鏁翠釜灞忓箷鐨勫乏涓婅掑潗鏍囦負
(1, 1), 鍙充笅瑙掑潗鏍囦負(80, 25)銆傚苟瑙勫畾娌挎按騫蟲柟鍚戜負 X杞, 鏂瑰悜鏈濆彸; 娌垮瀭鐩
鏂瑰悜涓 Y杞, 鏂瑰悜鏈濅笅銆傝嫢window()鍑芥暟涓鐨勫潗鏍囪秴榪囦簡灞忓箷鍧愭爣鐨勭晫闄, 鍒欑獥
鍙g殑瀹氫箟灝卞け鍘諱簡鎰忎箟, 涔熷氨鏄璇村畾涔夊皢涓嶈搗浣滅敤, 浣嗙▼搴忕紪璇戦摼鎺ユ椂騫朵笉鍑洪敊銆
鍙﹀, 涓涓灞忓箷鍙浠ュ畾涔夊氫釜紿楀彛, 浣嗙幇琛岀獥鍙e彧鑳芥湁涓涓(鍥犱負DOS涓哄崟浠
鍔℃搷浣滅郴緇), 褰撻渶瑕佺敤鍙︿竴紿楀彛鏃, 鍙灝嗗畾涔夎ョ獥鍙g殑window() 鍑芥暟鍐嶈皟鐢ㄤ竴
嬈, 姝ゆ椂璇ョ獥鍙d究鎴愪負鐜拌岀獥鍙d簡銆
濡傝佸畾涔変竴涓紿楀彛宸︿笂瑙掑湪灞忓箷(20, 5)澶, 澶у皬涓30鍒15琛岀殑紿楀彛鍙鍐欐垚:
window(20, 5, 50, 25);
2. 鏂囨湰紿楀彛棰滆壊鐨勮劇疆
鏂囨湰紿楀彛棰滆壊鐨勮劇疆鍖呮嫭鑳屾櫙棰滆壊鐨勮劇疆鍜屽瓧絎﹂滆壊鐨勮劇疆, 浣跨敤鐨勫嚱鏁板強
鍏惰皟鐢ㄦ牸寮忎負:
璁劇疆鑳屾櫙棰滆壊: void textbackground(int color);
璁劇疆瀛楃﹂滆壊: void textcolor(int color);
鏈夊叧棰滆壊鐨勫畾涔夎佽〃1銆
琛1. 鏈夊叧棰滆壊鐨勫畾涔
鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹
絎﹀彿甯告暟 鏁板 鍚涔 瀛楃︽垨鑳屾櫙
鈥斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺斺
BLACK 0 榛 涓よ呭潎鍙
BLUE 1 鍏 涓よ呭潎鍙
GREEN 2 緇 涓よ呭潎鍙
CYAN 3 闈 涓よ呭潎鍙
RED 4 綰 涓よ呭潎鍙
MAGENTA 5 媧嬬孩 涓よ呭潎鍙
BROWN 6 媯 涓よ呭潎鍙
LIGHTGRAY 7 娣$伆 涓よ呭潎鍙
DARKGRAY 8 娣辯伆 鍙鐢ㄤ簬瀛楃
LIGHTBLUE 9 娣″叞 鍙鐢ㄤ簬瀛楃
LIGHTGREEN 10 娣$豢 鍙鐢ㄤ簬瀛楃
LIGHTCYAN 11 娣¢潚 鍙鐢ㄤ簬瀛楃
LIGHTRED 12 娣$孩 鍙鐢ㄤ簬瀛楃
LIGHTMAGENTA 13 娣℃磱綰 鍙鐢ㄤ簬瀛楃
YELLOW 14 榛 鍙鐢ㄤ簬瀛楃
WHITE 15 鐧 鍙鐢ㄤ簬瀛楃
BLINK 128 闂鐑 鍙鐢ㄤ簬瀛楃
鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹佲攣鈹
涓婅〃涓鐨勭﹀彿甯告暟涓庣浉搴旂殑鏁板肩瓑浠, 浜岃呭彲浠ヤ簰鎹銆備緥濡傝懼畾鍏拌壊鑳屾櫙鍙
浠ヤ嬌鐢╰extbackground(1), 涔熷彲浠ヤ嬌鐢╰extbackground(BLUE), 涓よ呮病鏈変換浣
鍖哄埆, 鍙涓嶈繃鍚庤呮瘮杈冨規槗璁板繂, 涓鐪嬪氨鐭ラ亾鏄鍏拌壊銆
Turbo C鍙﹀栬繕鎻愪緵浜嗕竴涓鍑芥暟, 鍙浠ュ悓鏃惰劇疆鏂囨湰鐨勫瓧絎﹀拰鑳屾櫙棰滆壊, 榪
涓鍑芥暟鐨勮皟鐢ㄦ牸寮忎負:
void textattr(int attr);
鍏朵腑: attr鐨勫艱〃紺洪滆壊褰㈠紡緙栫爜鐨勪俊鎮, 姣忎竴浣嶄唬琛ㄧ殑鍚涔夊備笅:
浣 7 6 5 4 3 2 1 0
B b b b c c c c
鈫 鈹曗攣鈹佲攣鈹 鈹栤斺斺斺斺斺敇
闂鐑 鑳屾櫙棰滆壊 瀛楃﹂滆壊
瀛楄妭浣庡洓浣峜ccc璁劇疆瀛楃﹂滆壊(0鍒15), 4~6涓変綅bbb璁劇疆鑳屾櫙棰滆壊(0鍒7),
絎7浣岯璁劇疆瀛楃︽槸鍚﹂棯鐑併傚亣濡傝佽劇疆涓涓鍏板簳榛勫瓧, 瀹氫箟鏂規硶濡備笅:
textattr(YELLOW+(BLUE<<4));
鑻ュ啀瑕佹眰瀛楃﹂棯鐑, 鍒欏畾涔夊彉涓:
textattr(128+YELLOW+(BLUE<<4);
娉ㄦ剰:
(1) 瀵逛簬鑳屾櫙鍙鏈0 鍒7 鍏卞叓縐嶉滆壊, 鑻ュ彇澶т簬7 灝忎簬15鐨勬暟, 鍒欎唬琛ㄧ殑
棰滆壊涓庡噺 7鍚庣殑鍊煎瑰簲鐨勯滆壊鐩稿悓銆
(2) 鐢╰extbackground()鍜宼extcolor() 鍑芥暟璁劇疆浜嗙獥鍙g殑鑳屾櫙涓庡瓧絎﹂
鑹插悗, 鍦ㄦ病鏈夌敤clrscr()鍑芥暟娓呴櫎紿楀彛涔嬪墠, 棰滆壊涓嶄細鏀瑰彉, 鐩村埌浣跨敤浜嗗嚱鏁
clrscr(), 鏁翠釜紿楀彛鍜岄殢鍚庤緭鍑哄埌紿楀彛涓鐨勬枃鏈瀛楃︽墠浼氬彉鎴愭柊棰滆壊銆
(3) 鐢╰extattr()鍑芥暟鏃惰儗鏅棰滆壊搴斿乏縐4浣, 鎵嶈兘浣3浣嶈儗鏅棰滆壊縐誨埌姝
紜浣嶇疆銆
涓嬮潰榪欎釜紼嬪簭浣跨敤浜嗗叧浜庣獥鍙eぇ灝忕殑瀹氫箟銆侀滆壊鐨勮劇疆絳夊嚱鏁, 鍦ㄤ竴涓灞忓箷
涓婁笉鍚屼綅緗瀹氫箟浜7涓紿楀彛, 鍏惰儗鏅鑹插垎鍒浣跨敤浜7縐嶄笉鍚岀殑棰滆壊銆
渚1.:
#include <stdio.h>
#include <conio.h>
main()
{
int i;
textbackground(0); /* 璁劇疆灞忓箷鑳屾櫙鑹 */
clrscr(); /* 娓呴櫎鏂囨湰灞忓箷 */
for(i=1; i<8; i++)
{
window(10+i*5, 5+i, 30+i*5, 15+i); /* 瀹氫箟鏂囨湰紿楀彛 */
textbackground(i); /* 瀹氫箟紿楀彛鑳屾櫙鑹 */
clrscr(); /* 娓呴櫎紿楀彛 */
}
getch();
}
3. 紿楀彛鍐呮枃鏈鐨勮緭鍏ヨ緭鍑哄嚱鏁
涓銆佺獥鍙e唴鏂囨湰鐨勮緭鍑哄嚱鏁
int cprintf("<鏍煎紡鍖栧瓧絎︿覆>", <鍙橀噺琛>);
int cputs(char *string);
int putch(int ch);
cprintf()鍑芥暟杈撳嚭涓涓鏍煎紡鍖栫殑瀛楃︿覆鎴栨暟鍊煎埌紿楀彛涓銆傚畠涓巔rintf() 鍑
鏁扮殑鐢ㄦ硶瀹屽叏涓鏍, 鍖哄埆鍦ㄤ簬cprintf()鍑芥暟鐨勮緭鍑哄彈紿楀彛闄愬埗, 鑰宲rintf() 鍑
鏁扮殑杈撳嚭涓烘暣涓灞忓箷銆
cputs()鍑芥暟杈撳嚭涓涓瀛楃︿覆鍒板睆騫曚笂, 瀹冧笌puts()鍑芥暟鐢ㄦ硶瀹屽叏涓鏍, 鍙
鏄鍙楃獥鍙eぇ灝忕殑闄愬埗銆
putch()鍑芥暟杈撳嚭涓涓瀛楃﹀埌紿楀彛鍐呫
娉ㄦ剰:
(1) 浣跨敤浠ヤ笂鍑犵嶅嚱鏁, 褰撹緭鍑鴻秴鍑虹獥鍙g殑鍙寵竟鐣屾椂浼氳嚜鍔ㄨ漿鍒頒笅涓琛岀殑
寮濮嬪勭戶緇杈撳嚭銆傚綋紿楀彛鍐呭~婊″唴瀹逛粛娌℃湁緇撴潫杈撳嚭鏃, 紿楀彛灞忓箷灝嗕細鑷鍔ㄩ愯
涓婂嵎鐩村埌杈撳嚭緇撴潫涓烘銆
浜屻佺獥鍙e唴鏂囨湰鐨勮緭鍏ュ嚱鏁
int getche(void);
璇ュ嚱鏁板湪鍓嶉潰宸茬粡璁茶繃, 闇瑕佽存槑鐨勬槸, getche()鍑芥暟浠庨敭鐩樹笂鑾峰緱涓涓瀛
絎, 鍦ㄥ睆騫曚笂鏄劇ず鐨勬椂鍊, 濡傛灉瀛楃﹁秴榪囦簡紿楀彛鍙寵竟鐣, 鍒欎細琚鑷鍔ㄨ漿縐誨埌涓嬩竴
琛岀殑寮濮嬩綅緗銆
涓嬮潰榪欎釜紼嬪簭緇欎緥1.涓鍔犲叆浜嗕竴浜涙枃鏈鐨勮緭鍑哄嚱鏁般
渚2.:
#include <stdio.h>
#include <conio.h>
int main()
{
int i;
char *c[]={"BLACK", "BLUE", "GREEN", "CYAN", "RED",
"MAGENTA", "BROWN", "LIGHTGRAY"};
textbackground(0); /* 璁劇疆灞忓箷鑳屾櫙鑹 */
clrscr(); /* 娓呴櫎鏂囨湰灞忓箷 */
for(i=1; i<8; i++)
{
window(10+i*5, 5+i, 30+i*5, 15+i); /* 瀹氫箟鏂囨湰紿楀彛 */
textbackground(i); /* 瀹氫箟紿楀彛鑳屾櫙鑹 */
clrscr(); /* 娓呴櫎紿楀彛 */
}
getch();
return 0;
}
4. 鏈夊叧灞忓箷鎿嶄綔鐨勫嚱鏁
void clrscr(void); 娓呴櫎褰撳墠紿楀彛涓鐨勬枃鏈鍐呭, 騫舵妸鍏夋爣瀹氫綅鍦ㄧ獥鍙
鐨勫乏涓婅(1, 1)澶勩
void clreol(void); 娓呴櫎褰撳墠紿楀彛涓浠庡厜鏍囦綅緗鍒拌屽熬鐨勬墍鏈夊瓧絎, 鍏
鏍囦綅緗涓嶅彉銆
void gotoxy(x, y); 璇ュ嚱鏁板緢鏈夌敤, 瀹冪敤鏉ュ畾浣嶅厜鏍囧湪褰撳墠紿楀彛涓鐨勪綅
緗銆傝繖閲寈, y鏄鎸囧厜鏍囪佸畾浣嶅勭殑鍧愭爣(鐩稿逛簬紿楀彛
鑰岃█), 褰搙, y瓚呭嚭浜嗙獥鍙g殑澶у皬鏃, 璇ュ嚱鏁板氨涓嶈搗
浣滅敤浜嗐
int gettext(int xl, int yl, int x2, int y2, void *buffer);
int puttext(int x1, int y1, int x2, int y2, void *buffer);
gettext()鍑芥暟鏄灝嗗睆騫曚笂鎸囧畾鐨勭煩褰㈠尯鍩熷唴鏂囨湰鍐呭瑰瓨鍏buffer 鎸囬拡鎸囧悜
鐨勪竴涓鍐呭瓨絀洪棿銆傚唴瀛樼殑澶у皬鐢ㄤ笅寮忚$畻:
鎵鐢ㄥ瓧鑺傚ぇ灝=琛屾暟*鍒楁暟*2
鍏朵腑:
琛屾暟=y2-y1+1 鍒楁暟=x2-x1+1
puttext()鍑芥暟鍒欐槸灝唃ettext()鍑芥暟瀛樺叆鍐呭瓨buffer涓鐨勬枃瀛楀唴瀹規嫹璐濆埌灞
騫曚笂鎸囧畾鐨勪綅緗銆
int movetext(int x1, int x2, int y2, int x3, int y3);
movetext()鍑芥暟灝嗗睆騫曚笂宸︿笂瑙掍負(x1, y1), 鍙充笅瑙掍負(x2, y2)鐨勪竴鐭╁艦紿
鍙e唴鐨勬枃鏈鍐呭規嫹璐濆埌宸︿笂瑙掍負(x3, y3)鐨勬柊鐨勪綅緗銆傝ュ嚱鏁扮殑鍧愭爣涔熸槸鐩稿逛簬
鏁翠釜灞忓箷鑰岃█鐨勩
娉ㄦ剰:
1. gettext()鍑芥暟鍜宲uttext()鍑芥暟涓鐨勫潗鏍囨槸瀵規暣涓灞忓箷鑰岃█鐨, 鍗蟲槸灞
騫曠殑緇濆瑰潗鏍, 鑰屼笉鏄鐩稿圭獥鍙g殑鍧愭爣銆
2. movetext()鍑芥暟鏄鎷瘋礉鑰屼笉鏄縐誨姩紿楀彛鍖哄煙鍐呭, 鍗充嬌鐢ㄨュ嚱鏁板悗, 鍘
浣嶇疆鍖哄煙鐨勬枃鏈鍐呭逛粛鐒跺瓨鍦ㄣ
渚3.
include <conio.h>
main()
{
int i;
char *f[]={"Load F3", "Pick Alt-F3", "New ",
"Save F2", "Write to ", "Directory",
"Change dir", "Os shee ", "Quit Alt-X"};
char buf[9*14*2];
clrscr();
textcolor(YELLOW);
textbackground(BLUE);
clrscr();
gettext(10, 2, 24, 11, buf);
window(10, 2, 24, 11);
textbackground(RED);
textcolor(YELLOW);
clrscr();
for(i=0; i<9; i++)
{
gotoxy(1, i++);
cprintf("%s", f[i]);
}
getch();
movetext(10, 2, 24, 11, 40, 10);
puttext(10, 2, 24, 11, buf);
getch();
}
涓嬮潰鍐嶄粙緇嶄竴浜涘嚱鏁:
void highvideo(void); 璁劇疆鏄劇ず鍣ㄩ珮浜搴︽樉紺哄瓧絎︺
void lowvideo(void); 璁劇疆鏄劇ず鍣ㄤ綆浜搴︽樉紺哄瓧絎︺
void normvideo(void); 浣挎樉紺哄櫒榪斿洖鍒扮▼搴忚繍琛屽墠鐨勬樉紺烘柟寮忋
int wherex(void); 榪欎袱涓鍑芥暟榪斿洖褰撳墠紿楀彛涓嬪厜鏍囩殑x, y鍧愭爣銆
int wherey(void);