حرکت در صفحه با کليد هاي جها نما
اين يه برنامه هستش که تقريبا مثل نقاشي مي مونه.البته کد زياد جالبي براي افراد پيشرفته نيست ولي واسه اونهايي که تازه شروع به برنامه نويسي کردن خوبه.
مي توني جواب سئوالت رو درمورد کار با کليد ها بگيري.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#define rx10;
#include<process.h>
main()
{
int flag=0,x=40,y=12;
char key;
clrscr();
textcolor(4);
gotoxy(3,22);
cprintf(" ");
gotoxy(3,23);
cprintf(" R ");
gotoxy(3,24);
cprintf(" ");
textcolor(2);
gotoxy(10,22);
cprintf("");
gotoxy(10,23);
cprintf(" g ");
gotoxy(10,24);
cprintf("");
textcolor(15);
gotoxy(17,22);
cprintf("");
gotoxy(17,23);
cprintf(" w ");
gotoxy(17,24);
cprintf("");
textcolor(9);
gotoxy(24,22);
cprintf("");
gotoxy(24,23);
cprintf(" b ");
gotoxy(24,24);
cprintf("");
textcolor(14);
gotoxy(31,22);
cprintf("");
gotoxy(31,23);
cprintf(" y ");
gotoxy(31,24);
cprintf("");
textcolor(13);
gotoxy(38,22);
cprintf("");
gotoxy(38,23);
cprintf(" m ");
gotoxy(38,24);
cprintf("");
textcolor(12);
gotoxy(45,22);
cprintf("");
gotoxy(45,23);
cprintf(" z ");
gotoxy(45,24);
cprintf("");
textcolor(7);
gotoxy(60,22);
cprintf("");
gotoxy(60,23);
cprintf(" exit ");
gotoxy(60,24);
cprintf("");
while(1)
{
key=getch();
if(key==72)
{
if(y>1)
y--;
}
if(key==80)
{
if(y!=21)
y++;
}
if(key==77)
{
if(x!=80)
x++;
}
if(key==75)
{
if(x!=1)
x--;
}
if(key=='b'|| key=='B')
textcolor(BLUE);
if(key=='w'|| key=='W')
textcolor(WHITE);
if(key=='g'|| key=='G')
textcolor(GREEN);
if(key=='r'|| key=='R')
textcolor(RED);
if(key=='y'|| key=='Y')
textcolor(YELLOW);
if(key=='m'|| key=='M')
textcolor(13);
if(key=='z'|| key=='Z')
textcolor(12);
if(flag==0)
{
gotoxy(x,y);
cprintf("");
}
if(key==9)
{
if(flag==0)
flag=1;
else
flag=0;
}
// if(flag==1)
// { gotoxy(x,y);
// cprintf(" ");}
if(key==13)
exit(0);
}
// return 0;
}
متغير flag براي اينه که اگه بزني چيزي چاپ نمي کنه و اگه دوباره بزني از يه جاي ديگه مي توني شروع به کار کني.
من براي حرکت در صفحه کد کليد هاي جهت نما رو دادم.
مي شه به جاي اين کليدها از هر عدد ديگري استفاده کنيد.
مثلابنويسيد : اگر کليد 1 را زدم چاپ کن hello .