003
20.06.2009, 15:06 Uhr
~JOe
Gast
|
meine funktionen:
C++: |
#include "allgFkt.h"
static int _foreground = LIGHTGRAY; static int _background = BLACK;
static int save_attr;
void SetXY (int x, int y) // SetXY() setzt den Cursor { // COORD CPos = {x,y}; // auf Position X horizontal (Zählung 0 .. 79) und Y vertikal (0 .. 24) COORD CurPos; CurPos.X = x; // Element der Struktur COORD CurPos.Y = y; SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), CurPos); }
void GetXY (int *x, int*y) { CONSOLE_SCREEN_BUFFER_INFO Scr_Buf_info; GetConsoleScreenBufferInfo(GetStdHandle (STD_OUTPUT_HANDLE), &Scr_Buf_info); *x = Scr_Buf_info.dwCursorPosition.X; *y = Scr_Buf_info.dwCursorPosition.Y; }
void set_textattr(int attr) { if (!save_attr) save_attr = (_background<<4) | _foreground;
_background = attr>>4;
_foreground = attr & 0x0f;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (WORD) attr); }
int get_textattr(int x, int y) { unsigned short attr; unsigned long n;
COORD gc = {(short)x,(short)y}; ReadConsoleOutputAttribute(GetStdHandle (STD_OUTPUT_HANDLE), &attr, 1, gc, &n); return attr; }
void highvideo() { if (_foreground <= BROWN) textcolor (_foreground + 9);
if (_background <= BROWN) textbackground (_background + 9); }
void textbackground(int color) { if (!save_attr) save_attr=(_background<<4)|_foreground;
if (color == BLINK) color = WHITE;
_background = color;
set_textattr (_foreground | (color << 4)); }
void textcolor(int color) { if (!save_attr) save_attr = (_background<<4)|_foreground;
if(color == BLINK) color = WHITE;
_foreground = color;
set_textattr(color | (_background<<4)); }
void set_cursortype(int type) { CONSOLE_CURSOR_INFO Info; Info.bVisible = TRUE;
if (type == NOCURSOR) Info.bVisible = FALSE; else if (type == SOLIDCURSOR) Info.dwSize = 100; else if (type == NORMALCURSOR) Info.dwSize = 1;
SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &Info); }
int get_cursortype(void) { CONSOLE_CURSOR_INFO Info; GetConsoleCursorInfo(GetStdHandle (STD_OUTPUT_HANDLE), &Info);
if (Info.dwSize == 1) return NORMALCURSOR; if (Info.dwSize == 100) return SOLIDCURSOR; if (Info.bVisible==FALSE) return NOCURSOR;
return NORMALCURSOR; }
int gewinnpruefung(char matrix[][8], char symbol, int spalte, int zeile) { int i, j, win;
/* senkrecht */ win=1; for(j=zeile-1; j>= 0 && matrix[spalte][j]==symbol; --j, ++win); if(win==GEWONNEN) return 1;
/* waagerecht */ win=1; for(i=spalte-1; i>= 0 && matrix[i][zeile]==symbol; --i, ++win); for(i=spalte+1; i<BREITE && matrix[i][zeile]==symbol; ++i, ++win); if(win>=GEWONNEN) return 1;
/* diagonal / */ win=1; for(i=spalte-1, j=zeile-1; i>= 0 && j>= 0 && matrix[i][j]==symbol; --i, --j, ++win); for(i=spalte+1, j=zeile+1; i<BREITE && j<HOEHE && matrix[i][j]==symbol; ++i, ++j, ++win); if(win>=GEWONNEN) return 1;
/* diagonal \ */ win=1; for(i=spalte-1, j=zeile+1; i>= 0 && j<HOEHE && matrix[i][j]==symbol; --i, ++j, ++win); for(i=spalte+1, j=zeile-1; i<BREITE && j>= 0 && matrix[i][j]==symbol; ++i, --j, ++win); if(win >= GEWONNEN) return 1;
return 0; }
int FeldVoll(char matrix[][8]) { int spalte=0, zeile=7, i=0;
while(spalte<=7) { if(matrix[spalte][zeile]=='X' || matrix[spalte][zeile]=='O') ++i; ++spalte; } return i; }
int ZeileSuchen(char matrix[][8], int spalte) {
int zl=0; while(matrix[spalte-1][zl]=='X' && zl<8 || matrix[spalte-1][zl]=='O' && zl<8) ++zl;
return zl; }
void spielfeld(char matrix[][8]) {
int zl, ausrichtung, sp, i;
textcolor(LIGHTGRAY); SetXY (32, 5); printf(" 1 2 3 4 5 6 7 8 \n"); SetXY (32, 6); for(i=0; i<=16; ++i) printf("%c", 205); printf("\n");
for(zl=7, ausrichtung=7; zl>=0; --zl) { SetXY(32, ausrichtung); for(sp=0 ; sp<8; ++sp) { if(matrix[sp][zl]=='X') { textcolor(LIGHTGREEN); printf(" %c", matrix[sp][zl]); if(sp==7) ++ausrichtung; } else if(matrix[sp][zl]=='O') { textcolor(YELLOW); printf(" %c", matrix[sp][zl]); if(sp==7) ++ausrichtung; } else { textcolor(LIGHTGRAY); printf(" %c", matrix[sp][zl]); if(sp==7) ++ausrichtung; } } if(ausrichtung>14) ausrichtung=7; } }
void statistik(int gruen[], int gelb[]) {
textcolor(LIGHTGRAY); SetXY(2, 1); printf("Stat.: W | D | L "); SetXY(2, 2); textcolor(LIGHTGREEN); printf("Gruen: "); textcolor(LIGHTGRAY); printf("%i | %i | %i ", gruen[0], gruen[1], gruen[2]); SetXY(2, 3); textcolor(YELLOW); printf("Gelb : "); textcolor(LIGHTGRAY); printf("%i | %i | %i ", gelb[0], gelb[1], gelb[2]); }
|
|