Ruszanie obiektem w konsoli
Ostatnio zmodyfikowano 2017-01-20 21:38
Hashiyan Temat założony przez niniejszego użytkownika |
Ruszanie obiektem w konsoli » 2017-01-19 15:23:09 Cześć, robię prosty (zdawałoby się) program, który ma za zadanie wypisać w konsoli X, a potem zmieniać jego rozmiar oraz przesuwać po konsoli. Ze zmianą rozmiaru sobie poradziłem, ale totalnie utknąłem na zmianie pozycji. include < iostream > #include <conio.h>
void Intro(); void Draw();
const int Esc = 27;
int main() { Intro(); Draw(); return 0; }
void Draw() { int Size; char AsciiChar; char Tab[ 50 ][ 80 ]; int AsciiCharPosX = 10; int AsciiCharPosY = 10; char Key; system( "cls" ); std::cout << "Enter the size: "; std::cin >> Size; std::cout << std::endl; std::cout << "Enter the ASCII char from the keyboard: "; std::cin >> AsciiChar; std::cout << std::endl; for( int i = 0; i < Size; i++ ) { for( int j = 0; j < Size; j++ ) { Tab[ i ][ j ] = 'e'; } } Tab[ AsciiCharPosX ][ AsciiCharPosY ] = 'f'; do { system( "cls" ); for( int Rows = 1; Rows <= Size; Rows++ ) { for( int Cols = 1; Cols <= Size; Cols++ ) { if( Rows == Cols || Cols ==( Size + 1 ) - Rows ) { Tab[ Rows ][ Cols ] = 'f'; if( Tab[ Rows ][ Cols ] == 'f' ) { std::cout << AsciiChar; } } else { Tab[ Rows ][ Cols ] = 'e'; if( Tab[ Rows ][ Cols ] == 'e' ) { std::cout << " "; } } } std::cout << std::endl; } Key = _getch(); switch( Key ) { case '+': { Size = Size + 2; break; } case '-': { Size = Size - 2; break; } case 's': { AsciiCharPosY++; break; } case 'w': { AsciiCharPosY--; break; } case 'a': { AsciiCharPosX--; break; } case 'd': { AsciiCharPosX++; break; } } } while( Key != Esc ); return; }
|
|
M28DMW |
» 2017-01-20 21:38:07 Co to jest nieważne Intro ();? |
|
« 1 » |