| Đoạn code sau chỉ chạy được trên C thôi nhé, còn bạn nào muốn chạy được trên C++ thì phải add thêm thư viện graphics.h vào
#include <graphics.h> #include <stdio.h> #include <dos.h> #include <ctype.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define n 300 #define lu 600 #define gx getmaxx()/2 #define gy getmaxy()/2 void GOC()//hien luc vao... { setcolor(14); settextstyle(0,0,2); outtextxy(gx-88,50,"INH LA OI !"); settextstyle(0,0,1); setcolor(15); outtextxy(gx-96,80,"Inh la oi . Sao noong oi ."); outtextxy(gx-128,95,"Khap nuong rung tay bac sang ngoi ."); outtextxy(gx-120,110,"Mua xuan toi ngan hoa he cuoi ."); outtextxy(gx-96,125,"Inh la oi . Sao noong oi ."); } void am_thanh(int DL, int tan_so) { if(kbhit()) { char c=getch(); if(c==27) exit(1); } sound(tan_so); delay(DL); nosound(); } int tan_so(char ch) { switch(ch) { case 'd': return(440);break; case 'r': return(494);break; case 'm': return(523);break; case 'f': return(587);break; case 's': return(659);break; case 'l': return(698);break; case 'S': return(784);break; case '0': return(0) ;break; } } main() { int mh=DETECT , k , i=0,j=0,x=96,y=80,Chay=0,tt=0; // inh la oi sao nog oi kha nuo rug tay bac sg ng mua xua den nga hoa he cui inh la oi sao nog oi int a[]={600,660,900,200,600,660,800,n,700,300,550,500,580,lu,lu,n,680,250,550,550,550,500,600,n,500,600,800,n,800,800,1000,n}; char b[]={"lml0smr0lmrmlsm0rmlmsmr0lml0sms0"}; char Tex[]="Inh la oi . Sao noong oi . Khap nuong rung tay bac sang ngoi . Mua xuan toi ngan hoa he cuoi . Inh la oi . Sao noong oi . "; char TG[]=" "; initgraph(&mh,&k,"c:\\tc\\bgi"); cleardevice(); setcolor(14); rectangle(1,1,2*gx-1,2*gy-1); GOC();// hien luc vao while(i<strlen(Tex)&&!kbhit()) { if(i==27){x=128;y=95;j=0;} if(i==63){x=120;y=110;j=0;} if(i==95){x=96;y=125;j=0;} while(Tex[i+tt]!=32) { TG[0] = Tex[i+tt]; setcolor(2); outtextxy(gx-x+8*(j+tt),y,TG); tt++; } am_thanh(a[Chay],tan_so(b[Chay])); j+=tt+1; i+=tt+1; tt=0; Chay++; } getch(); } | |