Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h> //für _getch()
- #include <iostream> //für in- output
- #include <clocale> //für setlocale
- #include <windows.h> //u.a. für SetConsoleTitleA()
- #include <vector> //für std::vektoren
- #include <array> //für std::arrays
- using namespace std;
- #define PLAYER true
- #define ENEMY false
- bool CheatMode = false, SaveOptions = false;
- int counter, columns = 17, lines = 8;
- enum Colors { //Farbcodes definieren
- BLACK,
- DARKBLUE,
- DARKGREEN,
- DARKTURQUOIS,
- DARKRED,
- PURPLE,
- GOLD,
- GRAY,
- DARKGRAY,
- BLUE,
- GREEN,
- TURQUOIS,
- RED,
- PINK,
- YELLOW,
- WHITE
- };
- void CursorVisibility(bool x) { //Cursor sichtbar oder unsichtbar machen
- CONSOLE_CURSOR_INFO info;
- HANDLE out;
- info.bVisible = x;
- info.dwSize = 1;
- out = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorInfo(out, &info);
- }
- int getKey() { //Tastenabfrage, welche Taste gedrückt wurde
- int result = _getch();
- if (result == 0) {
- result = 256 + _getch();
- }
- else if (result == 224) {
- result = 512 + _getch();
- }
- return result;
- /*Pfeil oben = 584
- Pfeil rechts = 589
- Pfeil unten = 592
- Pfeil links = 587*/
- }
- void gotoxy(int x, int y) { //Konsolencursor an eine bestimmte Position setzen
- HANDLE hConsole;
- COORD cursorLoc;
- cout.flush();
- cursorLoc.X = x;
- cursorLoc.Y = y;
- hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorPosition(hConsole, cursorLoc);
- }
- void Color(WORD color) { //Text farbig machen
- SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), color);
- }
- vector<int> CoordsConverting() {
- vector<int> retval;
- retval.push_back(1);
- retval.push_back(2);
- return retval;
- }
- struct Pair { //damit ihn retval ohne arrays zwei werte gespeichert sind und an andere Funktionen übergeben werden können
- int One, Two;
- };
- Pair CoordsConverting(int x, int y) { //Koordinaten werden in integers konvertiert, um sie mit PlaceSth platzieren zu können
- Pair retval;
- if (tolower(x) >= 'a' && tolower(x) <= 'q') {
- retval.One = 20 + (tolower(x) - 'a') * 10;
- }
- else {
- retval.One = 0;
- }
- if (y >= '1' && y <= '8') {
- retval.Two = 10 + (y - '1') * 6;
- }
- else {
- retval.Two = 0;
- }
- return retval;
- }
- void PlaceSth(int x, int y, WORD color) { //etwas im Feld platzieren
- Color(color);
- for (int i = -2; i <= 2; i++) {
- gotoxy(x - 4, y + i);
- cout << "XXXXXXXXX";
- }
- }
- void Legend(int x) { //Legende zum Feld hinzufügen
- gotoxy(10, 64);
- Color(WHITE);
- cout << "Legende:";
- if (x == 1) {
- gotoxy(10, 65);
- Color(YELLOW);
- cout << "X";
- Color(WHITE);
- cout << " = Deine Schiffe";
- }
- if (x == 2) {
- gotoxy(10, 65);
- Color(BLUE);
- cout << "X";
- Color(WHITE);
- cout << " = Wasser-Treffer";
- gotoxy(10, 66);
- Color(DARKRED);
- cout << "X";
- Color(WHITE);
- cout << " = Schiff-Treffer";
- }
- if (x == 3) {
- gotoxy(10, 65);
- Color(YELLOW);
- cout << "X";
- Color(WHITE);
- cout << " = Deine Schiffe";
- gotoxy(10, 66);
- Color(BLUE);
- cout << "X";
- Color(WHITE);
- cout << " = feindliche Wasser-Treffer";
- gotoxy(10, 67);
- Color(DARKRED);
- cout << "X";
- Color(WHITE);
- cout << " = feindliche Schiff-Treffer";
- }
- if (x == 4) {
- gotoxy(10, 67);
- Color(TURQUOIS);
- cout << "X";
- Color(WHITE);
- cout << " = feindliche Schiffe";
- }
- }
- void Field(bool x) { //Spielfeld mit Legende erstellen
- int i, k = 1;
- char character = 'A';
- if (x == PLAYER) {
- gotoxy(94, 0);
- Color(RED);
- cout << "DEIN FELD";
- }
- else {
- gotoxy(90, 0);
- Color(RED);
- cout << "GEGNERISCHES FELD";
- }
- Color(TURQUOIS);
- for (i = 20; i <= columns * 10 + 10; i += 10) {
- gotoxy(i, 4);
- cout << character;
- character++;
- }
- for (i = 10; i <= lines * 6 + 4; i += 6) {
- gotoxy(10, i);
- cout << k;
- k++;
- }
- Color(WHITE);
- for (i = 15; i <= columns * 10 + 15; i += 10) {
- for (k = 4; k <= lines * 6 + 7; k++) {
- gotoxy(i, k);
- cout << "#";
- }
- }
- for (i = 7; i <= lines * 6 + 7; i += 6) {
- for (k = 10; k <= columns * 10 + 15; k++) {
- gotoxy(k, i);
- cout << "#";
- }
- }
- if (x == PLAYER && counter == 0) {
- Legend(1);
- }
- else if (x == ENEMY) {
- Legend(2);
- }
- else {
- Legend(3);
- }
- if (CheatMode == true && counter != 0 && x == ENEMY) {
- Legend(4);
- }
- if (x == PLAYER) {
- for (i = 0; i <= 3; i++) {
- if (Schiffe[i][0] != 0) {
- PlaceSth(Schiffe[i][0], Schiffe[i][1], YELLOW);
- }
- }
- for (i = 0; i <= columns * lines - 1; i++) {
- if (SchüsseKI[i][0] != 0) {
- PlaceSth(SchüsseKI[i][0], SchüsseKI[i][1], BLUE);
- }
- }
- for (i = 0; i <= 3; i++) {
- if (TrefferKI[i][0] != 0) {
- PlaceSth(TrefferKI[i][0], TrefferKI[i][1], DARKRED);
- }
- }
- }
- else if (x == ENEMY) {
- if (CheatMode == true) {
- for (i = 0; i <= 3; i++) {
- PlaceSth(SchiffeKI[i][0], SchiffeKI[i][1], TURQUOIS);
- }
- }
- for (i = 0; i <= columns * lines - 1; i++) {
- if (Schüsse[i][0] != 0) {
- PlaceSth(Schüsse[i][0], Schüsse[i][1], BLUE);
- }
- }
- for (i = 0; i <= 3; i++) {
- if (Treffer[i][0] != 0) {
- PlaceSth(Treffer[i][0], Treffer[i][1], DARKRED);
- }
- }
- }
- counter++;
- }
- void PlayerPlaceFlattop() { //Flugzeugträger mit Pfeiltasten platzieren
- int x = 20, y = 10, Key, i, A = 0, B = 0;
- CursorVisibility(false);
- i = y;
- do {
- do {
- i = y;
- for (i; i <= 28 + y; i += 6) {
- PlaceSth(x, i, YELLOW);
- }
- Key = getKey();
- i = y;
- for (i; i <= 28 + y; i += 6) {
- PlaceSth(x, i, BLACK);
- }
- if (Key == 589) {
- if (x < 180) {
- x += 10;
- }
- }
- else if (Key == 587) {
- if (x > 20) {
- x -= 10;
- }
- }
- else if (Key == 584) {
- if (y > 10) {
- y -= 6;
- }
- }
- else if (Key == 592) {
- if (y < 26) {
- y += 6;
- }
- }
- } while (Key != 32);
- y += 12;
- x -= 20;
- do {
- i = x;
- for (i; i <= 40 + x; i += 10) {
- PlaceSth(i, y, YELLOW);
- }
- Key = getKey();
- i = x;
- for (i; i <= 40 + x; i += 10) {
- PlaceSth(i, y, BLACK);
- }
- if (Key == 589) {
- if (x < 140) {
- x += 10;
- }
- }
- else if (Key == 587) {
- if (x > 20) {
- x -= 10;
- }
- }
- else if (Key == 584) {
- if (y > 10) {
- y -= 6;
- }
- }
- else if (Key == 592) {
- if (y < 52) {
- y += 6;
- }
- }
- } while (Key != 32);
- y -= 12;
- x += 20;
- } while (true);
- }
Advertisement
Add Comment
Please, Sign In to add comment