Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
idontknow
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
#include <windows.h> #include <iostream> #include <stdlib.h> #include <stdio.h> #define ROWS 15 #define COLUMNS 25 #define SIGN '|' #define SELECTED 'O' char cSelect = ' '; char cSigns[ROWS*COLUMNS]; int iField; int main() { for(int i = 0; i < ROWS; i++) { for(int i2 = 0; i2 < COLUMNS; i2++) { cSigns[i * i2] = SIGN; } } iField = 1; cSigns[1] = SELECTED; // cSelect = cSigns[ROWS * COLUMNS]; while(1) { // zeichnen... std::cin.clear(); //std::cin.ignore(std::numeric_limits<int>::max(),'\n'); for(int i = 1; i < ROWS; i++) { for(int i2 = 1; i2 < COLUMNS; i2++) { if(iField != i * i2) std::cout << cSigns[i * i2]; else std::cout << SELECTED; } std::cout << std::endl; } //Debug, Feld position! std::cout << iField; // Clear screen: system("cls"); // Exit.... by pressing 0; if(GetAsyncKeyState(48)) break; if(GetAsyncKeyState(65)) // a { iField = iField - 1; } if(GetAsyncKeyState(68)) // d { iField = iField + 1; } if(GetAsyncKeyState(83)) // s { iField = iField + COLUMNS; } if(GetAsyncKeyState(87)) // w { iField = iField - COLUMNS; } // Crash' vermeiden! if(iField < 1) iField = 1; if(iField > ROWS * COLUMNS) iField = ROWS * COLUMNS; } return 0; }; |
idontknow
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
#include <windows.h> #include <iostream> #include <stdlib.h> #include <stdio.h> #define ROWS 15 #define COLUMNS 25 #define SIGN '|' #define SELECTED 'O' char cSigns[ROWS*COLUMNS]; int iField; int main() { for(int i = 0; i < ROWS; i++) { for(int i2 = 0; i2 < COLUMNS; i2++) { cSigns[i * COLUMNS + i2] = SIGN; } } iField = 0; while(1) { // zeichnen... std::cin.clear(); for(int i = 0; i < ROWS; i++) { for(int i2 = 0; i2 < COLUMNS; i2++) { if(iField != i * COLUMNS + i2) std::cout << cSigns[i * COLUMNS + i2]; else std::cout << SELECTED; } std::cout << std::endl; } //Debug, Feld position! std::cout << iField; // Clear screen: system("cls"); // Exit.... by pressing 0; if(GetAsyncKeyState(48)) break; if(GetAsyncKeyState(65)) // a { iField = iField - 1; } if(GetAsyncKeyState(68)) // d { iField = iField + 1; } if(GetAsyncKeyState(83)) // s { iField = iField + COLUMNS; } if(GetAsyncKeyState(87)) // w { iField = iField - COLUMNS; } // Crash' vermeiden! if(iField < 0) iField = 0; if(iField > (ROWS * COLUMNS) -1) iField = ROWS * COLUMNS -1; } return 0; }; |
idontknow
unregistriert
idontknow
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#include <windows.h> #include <iostream> #include <stdlib.h> #include <stdio.h> #define ROWS 15 #define COLUMNS 25 #define SIGN '|' #define SELECTED 'O' char cSigns[ROWS*COLUMNS]; int iField; int main() { for(int i = 0; i < ROWS; i++) { for(int i2 = 0; i2 < COLUMNS; i2++) { cSigns[i * COLUMNS + i2] = SIGN; } } iField = 0; while(1) { // zeichnen... std::cin.clear(); for(int i = 0; i < ROWS; i++) { for(int i2 = 0; i2 < COLUMNS; i2++) { if(iField != i * COLUMNS + i2) std::cout << cSigns[i * COLUMNS + i2]; else std::cout << SELECTED; } std::cout << std::endl; } //Debug, Feld position! std::cout << iField; // Clear screen: system("cls"); // Exit.... by pressing 0; if(GetAsyncKeyState(48)) break; if(GetAsyncKeyState(65)) // a { if(iField % COLUMNS != 0) iField = iField - 1; } if(GetAsyncKeyState(68)) // d { if(iField % COLUMNS != COLUMNS -1) iField = iField + 1; } if(GetAsyncKeyState(83)) // s { iField = iField + COLUMNS; } if(GetAsyncKeyState(87)) // w { iField = iField - COLUMNS; } // Crash' vermeiden! if(iField < 0) iField += COLUMNS; if(iField > (ROWS * COLUMNS) -1) iField -= COLUMNS; } return 0; }; |
idontknow
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 |
if(iField - COLUMNS < 0) iField = iField; else iField = iField - COLUMNS; |
C-/C++-Quelltext |
|
1 2 3 4 |
if(iField + COLUMNS > ROWS * COLUMNS - 1) iField = iField; else iField = iField + COLUMNS; |
Zitat
eine alternativ Funktion für system("cls")?
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
void clrscr() { COORD coordScreen = { 0, 0 }; /* here's where we'll home the cursor */ BOOL bSuccess; DWORD cCharsWritten; CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ DWORD dwConSize; /* number of character cells in the current buffer */ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); /* get the number of character cells in the current buffer */ bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi); dwConSize = csbi.dwSize.X * csbi.dwSize.Y; /* fill the entire screen with blanks */ bSuccess = FillConsoleOutputCharacter(hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten); /* get the current text attribute */ bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi); /* now set the buffer's attributes accordingly */ bSuccess = FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten); /* put the cursor at (0, 0) */ bSuccess = SetConsoleCursorPosition(hConsole, coordScreen); return; } |
Werbeanzeige