سلام
کسی هست که با C++ اشنایی داشته باشه؟
کد یک ستاره رو میخوام که با کلید های up / down / left / right روی صفحه کلید حرکت کنه:
سلام
کسی هست که با C++ اشنایی داشته باشه؟
کد یک ستاره رو میخوام که با کلید های up / down / left / right روی صفحه کلید حرکت کنه:
واسه سوال های برنامه نویسی به این سایت مراجعه کنید
barnamenevis.org
کتاب آموزش c++ عین اله جعفرنژاد قمی هم مرجع خوبی واسه اموزش زبان سی پلاس پلاس هست
من کد C++ حرکت یک شکلک با فشار دادن کلید های U D L R دارم...
اگه خواستی بگو بدم
به رزبلاگ مربوط نیست ها !
من با سی پلاس پلاس آشنایی دارم
ولی طول میکشه بتونم همچین کدی بنویسم
همونطور که دوستمون بالا گفتن بهترین مرجع کتاب آموزش c++ عین اله جعفرنژاد قمی هست که حتی تو یه نسخش همین چیزی که شما گفتینو تا جایی که یادمه دیدم.
بفرما اینم کد:
//This program demonstrates ELSE…IF statement
#include <iostream>
#include <conio.h>
using namespace std;
#include <windows.h>
void gotoxy(int, int); //prototype
void clrscr(); //prototype
int main()
{
//move ? in 4 corners of the screen.
clrscr(); //function call
gotoxy(0,25);//move to first of last line
char U=24,D=25,R=26,L=27;//ASCII code of 4 vector
cout<<"Use these keys for move:\t"
<<"U="<<U<<"\tD="<<D<<"\tR="<<R<<"\tL="<<L;
char sg=1,ch=0;//sg have ASCII code of ?
int x=39,y=11;//x and y store position of cursor.
gotoxy(x,y);//move to meddle of screen.
cout.put(sg);
gotoxy(x,y);//return to previous position.
while((ch=getch())!=27)
{//start getting command of user.
if((ch=='U'||ch=='u') && y>1)
{
cout.put(' ');
gotoxy(x,--y);
cout.put(sg);
gotoxy(x,y);
}
else if((ch=='D'||ch=='d') && y<24)
{
cout.put(' ');
gotoxy(x,++y);
cout.put(sg);
gotoxy(x,y);
}
else if((ch=='R' || ch=='r') && x<79)
{
cout.put(' ');
gotoxy(++x,y);
cout.put(sg);
gotoxy(x,y);
}
else if((ch=='L'||ch=='l') && x>0)
{
cout.put(' ');
gotoxy(--x,y);
cout.put(sg);
gotoxy(x,y);
}
}//end of while
clrscr();
return 0;
}
// function definition -- requires windows.h
void gotoxy(int x, int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
cout.flush();
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
//function definition-in some compiler requires process.h
void clrscr()
{
system("cls");
}
اگه کار کرد تشکر فراموش نشه! :)