/* Problem 8 hetmanów z obsługą pierwszego hetmana / 8quens problems with user-inputable first quen Author: Daniel Skowroński License: GNU GPL v2. You should receive copy of this license, if not google it. */ #include #include #include #include #include #include //obsługa kolorów /* INSTRUKCJA! *{attr} is one of following 0 Reset All Attributes (return to normal mode) 1 Bright (Usually turns on BOLD) 2 Dim 3 Underline 5 Blink 7 Reverse 8 Hidden {fg} is one of the following /CZCIONKA/ 30 Black 31 Red 32 Green 33 Yellow 34 Blue 35 Magenta 36 Cyan 37 White {bg} is one of the following /TLO/ 40 Black 41 Red 42 Green 43 Yellow 44 Blue 45 Magenta 46 Cyan 47 White */ #define RESET 0 #define BRIGHT 1 #define DIM 2 #define UNDERLINE 3 #define BLINK 4 #define REVERSE 7 #define HIDDEN 8 #define BLACK 0 #define RED 1 #define GREEN 2 #define YELLOW 3 #define BLUE 4 #define MAGENTA 5 #define CYAN 6 #define WHITE 7 void textcolor(int attr, int fg, int bg) { char command[13]; /* Command is the control command to the terminal */ sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40); printf("%s", command); } //koniec obslugi kolorow ------------------------------------------------------------------------ using namespace std; //zmienne int hetmany[31]; int wierszPierwszego = 0;//userinput lock for excute - prevents from changing bool ok; int ileWierszy = 8; string wersja = "4f: 4..30, jako-taki final"; //procedury i funkcje void powitanie() { cout << "Hetmaty wersja: "<= 65) && (toupper(humanReadable[0]) <= 72) && (humanReadable[1] >= 49) && (humanReadable[1] <= 56)) { pozycja[0] = toupper(humanReadable[0]) - 65; pozycja[1] = humanReadable[1] - 49; } else pozycja[0] = (-100);//przekazanie błędu return pozycja; } string dlaCzlowieka(int pozycja[]) { stringstream humanReadable;//magic if ( (pozycja[0] >= 0) && (pozycja[0] <= 7) && (pozycja[1] >= 0) && (pozycja[1] <= 7) ) { char pierwszy, drugi; pierwszy = pozycja[0] + 65; drugi = pozycja[1] + 49; humanReadable << pierwszy; humanReadable << drugi; } else humanReadable << "--"; //przekazanie błędu return humanReadable.str();//magic } bool przyjmijPierwszego() { int tablica[2]; string a; cout << "Podaj pozycje pierwszego hetmana: "; cin >> a; tablica[0] = odCzlowieka(a)[0]; tablica[1] = odCzlowieka(a)[1]; if (tablica[0] == (-100)) return false; //interpretacja poprawności else { cout << "Przyjalem: " << dlaCzlowieka(tablica); hetmany[odCzlowieka(a)[1]] = odCzlowieka(a)[0]; wierszPierwszego = (tablica[1]); return true; } } void wypiszHetmany() { cout<<"Wyniki:"<> ileWierszy; if ((ileWierszy>3)&&(ileWierszy<31)){czy_ok = true;}}} if (ileWierszy>12) { textcolor(RESET, RED, BLACK); cout<<"UWAGA: Wykonanie dla wiecej jak 1 wierszy moze trwac ekstermalnie dlugo!"<> poz1; if ((poz1>0) && (poz1<(ileWierszy))) {czy_ok = true;}} czy_ok = false; while (!czy_ok) {cout<< "Podaj WIERSZ pierwszego hetmana: ";cin >> poz2; if ((poz2>0) && (poz2<(ileWierszy))) {czy_ok = true;}} hetmany[(int)poz2-1] = (int)poz1-1; } } void rysujSzachownice() { //cout << "*-"; textcolor(RESET, WHITE, BLACK);//JAKBY DOMYSLNE KOLORKI BYŁY INNE if (ileWierszy == 8) {cout<8){ cout<<(i+1)<<"";} else {cout<<(i+1)<<" ";} } cout<-1; i--)//wiersz od max - kolejnosc logiczna; to takze komorka - wg schematu na kartce { if ((i % 2) == 1) { textcolor(RESET, YELLOW, BLACK); //biale } else { textcolor(RESET, YELLOW, BLACK); //biale textcolor(RESET, WHITE, BLACK);//czarne } if((i+1)>9) cout<<(i+1)<<" "; else cout<<(i+1)<<" "; textcolor(RESET, WHITE, BLACK); for (int k = 0; k (ileWierszy-1)) rysujSzachownice();//wiersz 8 --> rysuj, potem /dosyc nieelegancko/ dozeruje //dupa else if (wiersz==wierszPierwszego) { if ((wiersz == (ileWierszy-1)) && (czyMozna(hetmany[wierszPierwszego], wierszPierwszego))) {} else {wstawHetmana(wiersz+1);} } else { for (int i=0; i