/*****************************************************************************/
/********************************Funkce.h*************************************/
/*****************************************************************************/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <windows.h>
void vymaz();
void gotoxy(int, int);
void barva(int);
int MyGetch (void);
/* Vycisti obraz */
void vymaz()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
/* Funkce GotoXY pro souradnice */
void gotoxy(int x, int y)
{
COORD point;
point.X = x; point.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point);
}
/* Funkce MyGetch pro pouziti sipkovych klaves */
int MyGetch (void)
{
int Ret = getch();
if ((!Ret || Ret == 0xE0) && kbhit())
Ret = 256 + getch();
return Ret;
}
/* Funkce barev */
void barva(int color)
{
switch (color)
{
case -3: /* Zluta na Sedem */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
BACKGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
break;
case -2: /* Seda na Sedem */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
BACKGROUND_INTENSITY);
break;
case -1: /* Cerna na Cernem */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0);
break;
case 0: /* Bila na Cerne */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
break;
case 1: /* Cervena na Cerne */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED);
break;
case 2: /* Zelena na Cerne */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_GREEN);
break;
case 3: /* Zluta na Cerne */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN);
break;
case 4: /* Modra na Cerne */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_BLUE);
break;
case 5: /* Purpurova na Cerne */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_BLUE);
break;
case 6: /* Azurova na Cerne */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_GREEN | FOREGROUND_BLUE);
break;
case 7: /* Cerna na Sede */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |
BACKGROUND_INTENSITY);
break;
case 8: /* Cerna na Bile */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |
FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
break;
case 9: /* Cervena na Bile */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |
FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
FOREGROUND_RED);
break;
case 10: /* Zelena na Bile */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |
FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
FOREGROUND_GREEN);
break;
case 11: /* Zluta na Bile */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |
FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
FOREGROUND_RED | FOREGROUND_GREEN);
break;
case 12: /* Modra na Bile */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |
FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
FOREGROUND_BLUE);
break;
case 13: /* Purpurova na Bile */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |
FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
FOREGROUND_RED | FOREGROUND_BLUE);
break;
case 14: /* Azurova na Bile */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |
FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
FOREGROUND_GREEN | FOREGROUND_BLUE);
break;
case 15: /* Bila na Bile */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |
FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
break;
default : /* Bila na Cerne */
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
break;
}
}
/*****************************************************************************/
/********************************Konec****************************************/
/*****************************************************************************/
tady prikladam cely soubor funkce.h
btw : porad se tu bavime jen o tom jak to vykreslit ja taky potrebuju vedet co mam napsat "kdyz prikaz bude poloz" bla bla
a zde prikladam main.c ktery mam na test toho putu cihel
#include <stdio.h>
#include "funkce.h"
int x = 0,y = 0; /* souradnice karla */
int i,j; /* promenne cyklu */
int karel = 16;
char prikazy[0];
int pole[10][10];
int main()
{
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
pole[i][j] = 0;
}
}
for(;;)
{
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
if (pole[i][j]) {
barva(2);
putc(219,stdout);
}
else {
barva(-1);
putc(219,stdout);
}
}
}
barva(2);
gotoxy(x,y);
putc(karel,stdout);
barva(1);
gotoxy(1,1);
printf("zadej prikaz: ");
scanf("%s", &prikazy);
if(!strcmp("krok", prikazy))
{
x +=1 ;
gotoxy(x-1,y);
barva(-1);
putc(219,stdout);
}
else if(!strcmp("poloz", prikazy))
{
pole[x][y]= 1;
}
}
return 0;
}
zkus mi to prosim upravit tak aby to fungovalo myslim ze uz do toho chybi jen malicko jen nevim co a kdyz to napisu tak ty se bavis o5 o vykreslovani a ne o tom kde mam chybu:D