Beispiel #1
0
VALUE
rb_WriteConsoleOutputAttribute(VALUE self, VALUE h, VALUE s,
			       VALUE x, VALUE y)
{

    unsigned short buffer[80*999*sizeof(unsigned short)];
    HANDLE handle = ULongToPtr( NUM2ULONG( h ) );
    DWORD written;
    DWORD towrite;
    unsigned i = 0;
    COORD coords;

	Check_Type( s, T_STRING );
    
    towrite = RSTRING_LEN(s);

    for(i=0; i<towrite; i++) {
        buffer[i] = (unsigned short)(RSTRING_PTR(s)[i]);
    }
    coords.X=NUM2INT( x );
    coords.Y=NUM2INT( y );
    if (WriteConsoleOutputAttribute(handle,(const unsigned short *)&buffer,
				    towrite,coords,&written)) {
       return UINT2NUM( written );
    }
    return rb_getWin32Error();
}
Beispiel #2
0
void Display::updatePos(Position pos_)
{
	if (!m_map.count(pos_))
		return;
    Position CurrentPosition;
    CurrentPosition=pos_;
    const char graphic=m_map[CurrentPosition].getGraphic();
    WORD color=m_map[CurrentPosition].getColor();
    if(m_map[CurrentPosition].getBackground()!=0)
    {
        color=color | m_map[CurrentPosition].getBackground();
    }
	if (isSelected_.count(pos_))
	{
		if (isSelected_[pos_] == true)
		{
			color = S_Box | C_White;
		}
	}
    pos.X=CurrentPosition.getX();
    pos.Y=CurrentPosition.getY();
    //ReadConsoleOutputCharacter(h, &readConsole_, nlength, pos, &output);
    //if (readConsole_ == graphic) return;
    WriteConsoleOutputCharacter(h, &graphic, nlength, pos, &output);
    WriteConsoleOutputAttribute(h, &color, nlength , pos, &output);
}
ThinConsole& ThinConsole::WriteToConsole(string_type const& outputString, console_location_type const& location, console_color_type const& foreground, console_color_type const& background) {
	assert(outputHandle != NULL && "Output Handle Not Initialized");
	std::vector<console_attribute_type> outputAttributes(outputString.size(), foregroundColorMap[foreground] | backgroundColorMap[background]);
	console_information_type charsWritten;
	ExceptionCheck(WriteConsoleOutputCharacter(outputHandle, std::wstring(outputString.begin(), outputString.end()).c_str(), outputString.size(), location, &charsWritten), __FUNCTION__, __LINE__);
	ExceptionCheck(WriteConsoleOutputAttribute(outputHandle, outputAttributes.data(), outputAttributes.size(), location, &charsWritten), __FUNCTION__, __LINE__);
	return *this;
}
Beispiel #4
0
void Display::setPos(Position ipos, WORD color)
{
    pos.X=ipos.getX();
    pos.Y=ipos.getY();

    //ReadConsoleOutputAttribute(h, &readAttribute_, nlength, pos, &output);
    //if(readAttribute_ != color)
        WriteConsoleOutputAttribute(h, &color, nlength, pos, &output);
}
Beispiel #5
0
void Display(void *argv)
{//display memory
    char    MyCell, OldCell;
    WORD    MyAttrib, OldAttrib;
    char    BlankCell = 0x20;//' '
	COORD   Coords = {0,0}, Delta;
    COORD   Old = {0,0};
    DWORD   Dummy;

	address_type disp_addr = MEMORY_DISP_ADDR;

    // Generate update increments and initial 
    // display coordinates.
    MyAttrib = 0x0F;   // force black background 
	size_t count = 0;
	ClearScreen();
	const size_t TOTAL_SIZE = csbiInfo.dwSize.X * MAX_Y;
	csbiInfo.dwSize.Y = MAX_Y;
	bool last_scanf_flag = 0;	//if program ends then refresh for last time

    do{//print every char
		Coords.X = Coords.Y = 0;
		for(size_t i = 0; i <= (TOTAL_SIZE+PAGE_SIZE-1)/PAGE_SIZE ; i++){//for every part
			//get every page's first addr
			WaitForSingleObject(hScreenMutex, INFINITE);
			byte *mem_ptr = GetPageBlock(disp_addr+i*PAGE_SIZE);

			size_t blockSize = PAGE_SIZE;
			if(i == (TOTAL_SIZE+PAGE_SIZE-1)/PAGE_SIZE)
				blockSize = (TOTAL_SIZE - i*PAGE_SIZE) % PAGE_SIZE;//remain

			WriteConsoleOutputCharacter(hConsoleOut, (LPCSTR)mem_ptr, blockSize, Coords, &Dummy);
			WriteConsoleOutputAttribute(hConsoleOut, &MyAttrib, 1, Coords, &Dummy);
			ReleaseMutex(hScreenMutex);//unlock 

			Coords.Y += blockSize / csbiInfo.dwSize.X;
			Coords.X = (Coords.X + blockSize % csbiInfo.dwSize.X) % csbiInfo.dwSize.X;

			// Increment the coordinates for next placement of the block. 
			if(Coords.Y >= MAX_Y){
				if(last_scanf_flag){
					display_finished = true;
					while(1) ;//wait
				}	
				if(prog_finished){//end
					last_scanf_flag = true;
				}
				break;
			}
		}//for every part
	}//end of while
    while (WaitForSingleObject(hRunMutex, 75L) == WAIT_TIMEOUT);
	// Repeat while RunMutex is still taken. 
}
Beispiel #6
0
int Screen::writeColors (int x, int y, const WORD *attrs, int count)
{
    DWORD attrsWritten;
    if (attrs == 0  ||  count <= 0)
	throw AppException (WHERE, ERR_INTERNAL);
    COORD c;
    c.X = (SHORT) x;
    c.Y = (SHORT) y;
    if (WriteConsoleOutputAttribute (mScreenBuf, attrs, count, c, &attrsWritten) != TRUE)
	throw AppException (WHERE, ERR_WINDOWS_FMT, "WriteConsoleOutputAttribute", GetLastError ());
    return attrsWritten;
}
Beispiel #7
0
bool KConsoleDriver::flushAttributes(int fromX,int fromY,int toX,int toY,const CharAttribute *attributes)
{
#ifdef USE_M_API
	coord top = { (SHORT)fromX, (SHORT)fromY };
	dword result;
	if (!WriteConsoleOutputAttribute(hStdOut, attributes, toX * toY, top, &result))
	{
		return false;
	}
#endif
	return true;
}
Beispiel #8
0
														// Here is our function that draws a color string in a DOS window.
														// We just pass in the string, the X and Y position, then the color we desire.
														// The color can be a background color AND a foreground color.  Here are some color examples:
														// FOREGROUND_GREEN; FOREGROUND_RED; FOREGROUND_BLUE; - BACKGROUND_RED; BACKGROUND_BLUE; BACKGROUND_GREEN;
														// You can mix and match these to create other colors.  Look in "Main()" to see how.
void DrawColorString(char *szText, int X, int Y, WORD color)
{
	COORD  screenPos={X, Y};							// Put the X and Y position in a structure.
	WORD   *colorBuf=NULL;								// Create a pointer to a buffer that holds the color for each character.
    DWORD  dwResult=0;									// This holds the amount of characters drawn to the screen. (We don't care about this though...)
	HANDLE OutputH;										// This is an OUTPUT handle.  Think of this as our link to the video card.
	int    length=0;									// This will hold the length of the string passed in.
	int    i=0;											// This is used as a counter.
	
	if(szText == NULL)									// Check if the string is NULL (This makes something was passed in).
      return;											// Quit from the function if no string was passed in.

	OutputH = GetStdHandle(STD_OUTPUT_HANDLE);			// Get an OUTPUT handle to our screen.

	length = strlen(szText);							// strlen() finds the amount of characters in a string.
														// Ok, here is a new concept called "dynamic allocation".  Since we don't
														// know how big the string is that is passed in, we can't just create a colorBuffer like this:
														// WORD colorbuf[I don't know yet];
														// So what we do is just make a pointer, then fill it in on the fly.  This is called "dynamically allocating memory".
														// In, C, we use a function called malloc().  You might notice that it has a weird thing in front of it.  (WORD *).
														// This is called "type-casting".  Since malloc returns a "void *", we need to "cast" the information received into a "WORD *".
														// A "void *" is used so you don't have to have a malloc() for each type of variable, like a WordMalloc(), or an IntMalloc().
														// We can just "cast" the "void *" to what ever variable we are using.  Nifty huh?
														// You can cast anything.  Like, if you want to take a floating point number, and store it into
														// an integer, just say, var1 = (int)var2.  say var2 = 1.2; now var1, being an integer, = 1.  It cuts off the excess.
														// The parameter for malloc() is the number of bytes of memory to allocate.
														// You might say, "But I don't know how many bytes a WORD is..."  That's fine, the sizeof() function does it for you.
														// So, now that we have the bytes of a WORD, we need to figure out how many WORDs we want to allocate.
														// Since we know the length of the string passed in, we just times the amount of bytes by the length.  bytes*length.
	colorBuf = (WORD*)malloc(sizeof(WORD) * length);	// So sizeof(WORD) * length gives us how many bytes of memory we will need to allocate.  Later, we must "free()" the memory.

	for (i=0; i < length; i++)							// Now we go through the color buffer and assign a color for each character.
	{													// A pointer is a one dimensional array.  so we can use the "[]" brackets.
		colorBuf[i] = color;							// Here we assign each cell of colorBuf a color.  The color is what we passed into the function.
	}													// We could say "colorBuf[i] = rand(); and every character in the string would be a random color.
															
														// These bad boys are what draws the text and the text's color to the screen.
														// The first one draws the color to the screen. It's parameters are:
														// "(Output handle, an array to hold the color of each character, the length of the string, the screen position, and the address of a DWORD to hold the number of characters drawn)"
	WriteConsoleOutputAttribute(OutputH, colorBuf, length, screenPos, &dwResult);
														// The next function draws the actual characters to the screen.  It's parameters are:
														// "(Output handle, the string to print, the length of the string, the screen position, and the address of a DWORD to hold the number of characters drawn)"
	WriteConsoleOutputCharacter(OutputH, szText, length, screenPos, &dwResult);
														// The last parameter, we don't care about, we just need it or else the program will crash :)
	free(colorBuf);										// This is how we free memory that we allocated.  There should ALWAYS be a "free()" for every "malloc()".
	colorBuf = NULL;									// After we free a pointer, we should always set it to NULL.  Checking if a pointer equals NULL is the way a pointer is determined if it's "valid" or not.
														// If we didn't set this pointer to NULL it would still point to an address in memory.  However, if we tried to access that memory we'd get a CRASH.  So just set freed pointers to NULL always.
														// You know how you are playing a game, or leave a program running for a while? ... And your computer starts to slow down after a while...?
														// Or when you quit the program, your computer runs slower?  That's not the computer getting tired... that because the programmers
														// didn't free their memory.  If you ask the OS for memory, it locks that memory address so no other program can use it.
														// If you don't free that memory, then the computer still assumes that it's still being used.  You have to restart your computer
														// to get that memory back.  It resets all the permissions you could say.
}
void DisplayKeyVolumeEnvelope::Update(HANDLE hOut)
{
	WORD note_env_attrib[SPECTRUM_WIDTH];
	WORD voice_env_attrib[VOICES];

	memset(note_env_attrib, env_attrib[EnvelopeState::OFF], sizeof(note_env_attrib));
	for (int v = 0; v < VOICES; ++v)
	{
		EnvelopeState::State const state = amp_env_state[v].state;
		WORD const attrib = env_attrib[state];
		if (state != EnvelopeState::OFF)
		{
			int const x = key_pos.X - keyboard_octave * 12 + voice_note[v];
			if (x >= 0 && x < SPECTRUM_WIDTH)
				note_env_attrib[x] = attrib;
		}
		voice_env_attrib[v] = attrib;
	}

	DWORD written;
	WriteConsoleOutputAttribute(hOut, note_env_attrib, SPECTRUM_WIDTH, { 0, key_pos.Y }, &written);
	WriteConsoleOutputAttribute(hOut, voice_env_attrib, VOICES, voice_pos, &written);
}
Beispiel #10
0
void CPlayer::Draw()
{
	char szPlayer[2] = {0};
	DWORD dwResult = 0;

	// Get an output handle for drawing
	HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);

	// Add the player character to a string (We need a string for WriteConsoleOutputCharacter())
	sprintf(szPlayer, "%c", m_image.Char);

	// Finally, we draw our player's character and then draw it's color
	WriteConsoleOutputCharacter(hOutput, szPlayer, 1, m_position, &dwResult);
	WriteConsoleOutputAttribute(hOutput, &m_image.Attributes, 1, m_position, &dwResult);
}
Beispiel #11
0
static void
flash_display(void)
{
    DWORD length = term.cols * term.rows;
    DWORD got;
    WORD *buf1;
    WORD *buf2;

    static COORD origin;

    if ((buf1 = typeallocn(WORD, length)) != 0
	&& (buf2 = typeallocn(WORD, length)) != 0) {
	ReadConsoleOutputAttribute(hConsoleOutput, buf1, length, origin, &got);
	ReadConsoleOutputAttribute(hConsoleOutput, buf2, length, origin, &got);
	for (got = 0; got < length; got++) {
	    buf2[got] ^= (FOREGROUND_INTENSITY | BACKGROUND_INTENSITY);
	}
	WriteConsoleOutputAttribute(hConsoleOutput, buf2, length, origin, &got);
	Sleep(200);
	WriteConsoleOutputAttribute(hConsoleOutput, buf1, length, origin, &got);
	free(buf1);
	free(buf2);
    }
}
Beispiel #12
0
JNIEXPORT void JNICALL Java_com_yifanlu_Josh_Josh_WRITECONSOLEOUTPUTATTRIBUTE
  (JNIEnv *env, jclass jcls, jlong pointer, jintArray data, jint length, jint x, jint y)
{
	HANDLE hConsole = pointerToHandle(pointer);
	COORD coordBufCoord = {x , y};
	WORD *buffer = new WORD[length];
	DWORD numWrote;

	jint *body = env->GetIntArrayElements(data, 0);

	for(int x = 0; x < length; x++)
		buffer[x] = (int)body[x];

	WriteConsoleOutputAttribute(hConsole, buffer, length, coordBufCoord, &numWrote);
}
Beispiel #13
0
void CTextConsoleWin32::UpdateStatus()
{
	COORD coord;
	DWORD dwWritten = 0;
	WORD wAttrib[ 80 ];

	for (int i = 0; i < 80; i++)
	{
		wAttrib[i] = Attrib; // FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY;
	}

	coord.X = coord.Y = 0;

	WriteConsoleOutputAttribute(houtput, wAttrib, 80, coord, &dwWritten);
	WriteConsoleOutputCharacter(houtput, statusline, 80, coord, &dwWritten);
}
/* ************************************
* VOID ChangeUpCaseTextBackgroudColor(HANDLE hStdin, HANDLE hStdout)
* 功能	改变文字背景颜色
* 参数	HANDLE hStdin, HANDLE hStdout,控制台输入输出句柄
**************************************/
VOID ChangeUpCaseTextBackgroudColor(HANDLE hStdin, HANDLE hStdout)
{
	DWORD dwLen, i, dwRead, dwWritten;
	WORD wColors[3];
	BOOL fSuccess;
	COORD coord;
	HANDLE hSreenHandle;
	CONSOLE_SCREEN_BUFFER_INFO csbi;

	PCHAR lpCharacter = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,2048);
	coord.X = 0;	// 起始Cell
	coord.Y = 0;
	// 读取OutputCharacter
	if(!ReadConsoleOutputCharacter(hStdout,lpCharacter,2047,coord,&dwRead))
	{
		MyErrorExit("ReadConsoleOutputCharacter");
	}
	// 获取ScreenBufferInfo
	GetConsoleScreenBufferInfo(hStdout,&csbi);

	dwLen = lstrlen(lpCharacter);
	// 颜色数组
	wColors[0] = BACKGROUND_RED;
	wColors[1] = BACKGROUND_RED | BACKGROUND_GREEN;
	wColors[2] = BACKGROUND_GREEN;

	for (i=0 ;i<dwLen; i++)
	{
		// 查找大写字母
		if(lpCharacter[i]>='A'&& lpCharacter[i]<='Z')
		{
			// 如果是大写字母,则从大写字母开始位置的三个Cell的
			// 文字背景改变成三种不同的颜色
			coord.Y = i/csbi.dwSize.X;
			coord.X = i%csbi.dwSize.X;
			fSuccess = WriteConsoleOutputAttribute(
				hStdout, // handle
				wColors, 3, 
				coord, // 起始位置
				&dwWritten);
			if(!fSuccess)
			{
				MyErrorExit("WriteConsoleOutputAttribute");
			}
		}
	}
}
Beispiel #15
0
void BarConsoleEraseCharacter()
{
    TCHAR buffer[256];
    WORD buffer2[256];
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    COORD coords;
    HANDLE handle = BarConsoleGetStdOut();
    int length, read, write;

    if (!GetConsoleScreenBufferInfo(handle, &csbiInfo))
        return;

    length = csbiInfo.dwSize.X - csbiInfo.dwCursorPosition.X - 1;
    read = csbiInfo.dwCursorPosition.X + 1;
    write = csbiInfo.dwCursorPosition.X;

    while (length >= 0)
    {
        int size = min(length, 256);
        DWORD chRead = 0, chWritten = 0;
        coords = csbiInfo.dwCursorPosition;
        coords.X = read;
        ReadConsoleOutputAttribute(handle, buffer2, size, coords, &chRead);
        ReadConsoleOutputCharacter(handle, buffer, size, coords, &chRead);

        if (chRead == 0)
            break;

        coords.X = write;
        WriteConsoleOutputAttribute(handle, buffer2, chRead, coords, &chWritten);
        WriteConsoleOutputCharacter(handle, buffer, chRead, coords, &chWritten);

        read += chRead;
        write += chRead;
        length -= chRead;
    }
}
Beispiel #16
0
void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool Resize)
{
#ifdef _WIN32
	// Check size
	if (Width < 8 || Height < 12) return;

	bool DBef = true;
	bool DAft = true;
	std::string SLog = "";

	const HWND hWnd = GetConsoleWindow();
	const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

	// Get console info
	CONSOLE_SCREEN_BUFFER_INFO ConInfo;
	GetConsoleScreenBufferInfo(hConsole, &ConInfo);
	DWORD BufferSize = ConInfo.dwSize.X * ConInfo.dwSize.Y;

	// ---------------------------------------------------------------------
	//  Save the current text
	// ------------------------
	DWORD cCharsRead = 0;
	COORD coordScreen = { 0, 0 };

	static const int MAX_BYTES = 1024 * 16;

	std::vector<std::array<CHAR, MAX_BYTES>> Str;
	std::vector<std::array<WORD, MAX_BYTES>> Attr;

	// ReadConsoleOutputAttribute seems to have a limit at this level
	static const int ReadBufferSize = MAX_BYTES - 32;

	DWORD cAttrRead = ReadBufferSize;
	DWORD BytesRead = 0;
	while (BytesRead < BufferSize)
	{
		Str.resize(Str.size() + 1);
		if (!ReadConsoleOutputCharacter(hConsole, Str.back().data(), ReadBufferSize, coordScreen, &cCharsRead))
			SLog += StringFromFormat("WriteConsoleOutputCharacter error");

		Attr.resize(Attr.size() + 1);
		if (!ReadConsoleOutputAttribute(hConsole, Attr.back().data(), ReadBufferSize, coordScreen, &cAttrRead))
			SLog += StringFromFormat("WriteConsoleOutputAttribute error");

		// Break on error
		if (cAttrRead == 0) break;
		BytesRead += cAttrRead;
		coordScreen = GetCoordinates(BytesRead, ConInfo.dwSize.X);
	}
	// Letter space
	int LWidth = (int)(floor((float)Width / 8.0f) - 1.0f);
	int LHeight = (int)(floor((float)Height / 12.0f) - 1.0f);
	int LBufWidth = LWidth + 1;
	int LBufHeight = (int)floor((float)BufferSize / (float)LBufWidth);
	// Change screen buffer size
	LetterSpace(LBufWidth, LBufHeight);


	ClearScreen(true);	
	coordScreen.Y = 0;
	coordScreen.X = 0;
	DWORD cCharsWritten = 0;

	int BytesWritten = 0;
	DWORD cAttrWritten = 0;
	for (size_t i = 0; i < Attr.size(); i++)
	{
		if (!WriteConsoleOutputCharacter(hConsole, Str[i].data(), ReadBufferSize, coordScreen, &cCharsWritten))
			SLog += StringFromFormat("WriteConsoleOutputCharacter error");
		if (!WriteConsoleOutputAttribute(hConsole, Attr[i].data(), ReadBufferSize, coordScreen, &cAttrWritten))
			SLog += StringFromFormat("WriteConsoleOutputAttribute error");

		BytesWritten += cAttrWritten;
		coordScreen = GetCoordinates(BytesWritten, LBufWidth);
	}	

	const int OldCursor = ConInfo.dwCursorPosition.Y * ConInfo.dwSize.X + ConInfo.dwCursorPosition.X;
	COORD Coo = GetCoordinates(OldCursor, LBufWidth);
	SetConsoleCursorPosition(hConsole, Coo);

	if (SLog.length() > 0) Log(LogTypes::LNOTICE, SLog.c_str());

	// Resize the window too
	if (Resize) MoveWindow(GetConsoleWindow(), Left,Top, (Width + 100),Height, true);
#endif
}
Beispiel #17
0
void gra::sprawdzenie()
{
    string outbuf;
    LPWORD buferkoloru;
    buferkoloru = new WORD[outbuf.length()];
    COORD cWhere;
    HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD dwCharsWritten;
    while (true)
    {
        for (int i = 0; i < 22; i++)
        {
            for (int j = 0; j < 40; j++)
            {
                if (MAPA[i][j].zw_typ() == "kamien")
                {
                    kamien k;
                    k.ustaw_wsp(i, j);
                    if (MAPA[i][j].zw_ruch() == true)
                        k.ustaw_ruch(true);
                    KAMIENIE.push_back(k);
                }
            }
        }
        if (wygrana == true || zgnieciony == true || koniec_czasu == true || escape == true || ukaszony == true)
            break;
        for (unsigned i = 0; i < KAMIENIE.size(); i++)
        {
            if (MAPA[KAMIENIE[i].zw_x() + 1][KAMIENIE[i].zw_y()].zw_typ() != "gracz" && MAPA[KAMIENIE[i].zw_x() + 1][KAMIENIE[i].zw_y()].zw_typ() != "kurz")
                KAMIENIE[i].ustaw_ruch(false);
            if (MAPA[KAMIENIE[i].zw_x() + 1][KAMIENIE[i].zw_y()].zw_typ() == "kurz")
            {
                cWhere.X = KAMIENIE[i].zw_y();
                cWhere.Y = KAMIENIE[i].zw_x();
                outbuf = static_cast<char>(95);
                memset(buferkoloru, (CZARNY << 4) + CZARNY, 1);
                WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
                WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
                KAMIENIE[i].ink_wsp_x();
                cWhere.X = KAMIENIE[i].zw_y();
                cWhere.Y = KAMIENIE[i].zw_x();
                outbuf = static_cast<char>(15);
                memset(buferkoloru, (CIEMNOCZERWONY << 4) + JASNOSZARY, 1);
                WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
                WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
                KAMIENIE[i].ustaw_ruch(true);
                MAPA[KAMIENIE[i].zw_x()][KAMIENIE[i].zw_y()] = KAMIENIE[i];
                kurz K;
                MAPA[KAMIENIE[i].zw_x() - 1][KAMIENIE[i].zw_y()] = K;
                Sleep(200);
                if (MAPA[KAMIENIE[i].zw_x() + 1][KAMIENIE[i].zw_y()].zw_typ() == "gracz")
                    zgnieciony = true;
            }
            if (MAPA[KAMIENIE[i].zw_x() + 1][KAMIENIE[i].zw_y()].zw_typ() == "kamien" && MAPA[KAMIENIE[i].zw_x()][KAMIENIE[i].zw_y() + 1].zw_typ() == "kurz" && MAPA[KAMIENIE[i].zw_x() + 1][KAMIENIE[i].zw_y() + 1].zw_typ() == "kurz")
            {
                cWhere.X = KAMIENIE[i].zw_y();
                cWhere.Y = KAMIENIE[i].zw_x();
                outbuf = static_cast<char>(95);
                memset(buferkoloru, (CZARNY << 4) + CZARNY, 1);
                WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
                WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
                KAMIENIE[i].ink_wsp_y();
                cWhere.X = KAMIENIE[i].zw_y();
                cWhere.Y = KAMIENIE[i].zw_x();
                outbuf = static_cast<char>(15);
                memset(buferkoloru, (CIEMNOCZERWONY << 4) + JASNOSZARY, 1);
                WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
                WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
                KAMIENIE[i].ustaw_ruch(true);
                MAPA[KAMIENIE[i].zw_x()][KAMIENIE[i].zw_y()] = KAMIENIE[i];
                kurz K;
                MAPA[KAMIENIE[i].zw_x()][KAMIENIE[i].zw_y() - 1] = K;
                Sleep(200);
            }
            if (MAPA[KAMIENIE[i].zw_x() + 1][KAMIENIE[i].zw_y()].zw_typ() == "kamien" && MAPA[KAMIENIE[i].zw_x()][KAMIENIE[i].zw_y() - 1].zw_typ() == "kurz" && MAPA[KAMIENIE[i].zw_x() + 1][KAMIENIE[i].zw_y() - 1].zw_typ() == "kurz")
            {
                cWhere.X = KAMIENIE[i].zw_y();
                cWhere.Y = KAMIENIE[i].zw_x();
                outbuf = static_cast<char>(95);
                memset(buferkoloru, (CZARNY << 4) + CZARNY, 1);
                WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
                WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
                KAMIENIE[i].dek_wsp_y();
                cWhere.X = KAMIENIE[i].zw_y();
                cWhere.Y = KAMIENIE[i].zw_x();
                outbuf = static_cast<char>(15);
                memset(buferkoloru, (CIEMNOCZERWONY << 4) + JASNOSZARY, 1);
                WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
                WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
                KAMIENIE[i].ustaw_ruch(true);
                MAPA[KAMIENIE[i].zw_x()][KAMIENIE[i].zw_y()] = KAMIENIE[i];
                kurz K;
                MAPA[KAMIENIE[i].zw_x()][KAMIENIE[i].zw_y() + 1] = K;
                Sleep(200);
            }
        }
        KAMIENIE.resize(0);
    }
}
Beispiel #18
0
void gra::robaczki()
{
    string outbuf;
    LPWORD buferkoloru;
    buferkoloru = new WORD[outbuf.length()];
    COORD cWhere;
    HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD dwCharsWritten;
    int opoznienie = 300;
    while(true)
    {
        if (wygrana == true || zgnieciony == true || koniec_czasu == true || escape == true || ukaszony == true)
            break;
        for (int i = 0; i < 22; i++)
        {
            for (int j = 0; j < 40; j++)
            {
                if (MAPA[i][j].zw_typ() == "robak")
                {
                    robak r;
                    r.zmien_wsp(i, j);
                    if (MAPA[i][j].zw_ruch() == true)
                        r.ustaw_ruch(true);
                    ROBAKI.push_back(r);
                }
            }
        }
        for (unsigned i = 0; i < ROBAKI.size(); i++)
        {
            cWhere.X = ROBAKI[i].zw_y();
            cWhere.Y = ROBAKI[i].zw_x();
            outbuf = static_cast<char>(95);
            memset(buferkoloru, (CZARNY << 4) + CZARNY, 1);
            WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
            WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
            ROBAKI[i].ink_wsp_y();
            cWhere.X = ROBAKI[i].zw_y();
            cWhere.Y = ROBAKI[i].zw_x();
            outbuf = static_cast<char>(64);
            memset(buferkoloru, (CIEMNOCZERWONY << 4) + ROZOWY, 1);
            WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
            WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
            MAPA[ROBAKI[i].zw_x()][ROBAKI[i].zw_y()] = ROBAKI[i];
            kurz K;
            MAPA[ROBAKI[i].zw_x()][ROBAKI[i].zw_y() - 1] = K;
            if (MAPA[ROBAKI[i].zw_x() + 1][ROBAKI[i].zw_y()].zw_typ() == "gracz")
            {
                ukaszony = true;
                break;
            }
            if (wygrana == true || zgnieciony == true || koniec_czasu == true || escape == true)
                break;
        }
            Sleep(opoznienie);
        for (unsigned i = 0; i < ROBAKI.size(); i++)
        {
            cWhere.X = ROBAKI[i].zw_y();
            cWhere.Y = ROBAKI[i].zw_x();
            outbuf = static_cast<char>(95);
            memset(buferkoloru, (CZARNY << 4) + CZARNY, 1);
            WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
            WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
            ROBAKI[i].ink_wsp_x();
            cWhere.X = ROBAKI[i].zw_y();
            cWhere.Y = ROBAKI[i].zw_x();
            outbuf = static_cast<char>(64);
            memset(buferkoloru, (CIEMNOCZERWONY << 4) + ROZOWY, 1);
            WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
            WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
            MAPA[ROBAKI[i].zw_x()][ROBAKI[i].zw_y()] = ROBAKI[i];
            kurz K;
            MAPA[ROBAKI[i].zw_x() - 1][ROBAKI[i].zw_y()] = K;
            if (MAPA[ROBAKI[i].zw_x()][ROBAKI[i].zw_y() - 1].zw_typ() == "gracz")
            {
                ukaszony = true;
                break;
            }
            if (wygrana == true || zgnieciony == true || koniec_czasu == true || escape == true)
                break;
        }
            Sleep(opoznienie);
        for (unsigned i = 0; i < ROBAKI.size(); i++)
        {
            cWhere.X = ROBAKI[i].zw_y();
            cWhere.Y = ROBAKI[i].zw_x();
            outbuf = static_cast<char>(95);
            memset(buferkoloru, (CZARNY << 4) + CZARNY, 1);
            WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
            WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
            ROBAKI[i].dek_wsp_y();
            cWhere.X = ROBAKI[i].zw_y();
            cWhere.Y = ROBAKI[i].zw_x();
            outbuf = static_cast<char>(64);
            memset(buferkoloru, (CIEMNOCZERWONY << 4) + ROZOWY, 1);
            WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
            WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
            MAPA[ROBAKI[i].zw_x()][ROBAKI[i].zw_y()] = ROBAKI[i];
            kurz K;
            MAPA[ROBAKI[i].zw_x()][ROBAKI[i].zw_y() + 1] = K;
            if (MAPA[ROBAKI[i].zw_x() - 1][ROBAKI[i].zw_y()].zw_typ() == "gracz")
            {
                ukaszony = true;
                break;
            }
            if (wygrana == true || zgnieciony == true || koniec_czasu == true || escape == true)
                break;
        }
            Sleep(opoznienie);
        for (unsigned i = 0; i < ROBAKI.size(); i++)
        {
            cWhere.X = ROBAKI[i].zw_y();
            cWhere.Y = ROBAKI[i].zw_x();
            outbuf = static_cast<char>(95);
            memset(buferkoloru, (CZARNY << 4) + CZARNY, 1);
            WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
            WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
            ROBAKI[i].dek_wsp_x();
            cWhere.X = ROBAKI[i].zw_y();
            cWhere.Y = ROBAKI[i].zw_x();
            outbuf = static_cast<char>(64);
            memset(buferkoloru, (CIEMNOCZERWONY << 4) + ROZOWY, 1);
            WriteConsoleOutputCharacter(hConsoleOut, outbuf.c_str(), outbuf.length(), cWhere, &dwCharsWritten);
            WriteConsoleOutputAttribute(hConsoleOut, buferkoloru, outbuf.length(), cWhere, &dwCharsWritten);
            MAPA[ROBAKI[i].zw_x()][ROBAKI[i].zw_y()] = ROBAKI[i];
            kurz K;
            MAPA[ROBAKI[i].zw_x() + 1][ROBAKI[i].zw_y()] = K;
            if (MAPA[ROBAKI[i].zw_x()][ROBAKI[i].zw_y() + 1].zw_typ() == "gracz")
            {
                ukaszony = true;
                break;
            }
            if (wygrana == true || zgnieciony == true || koniec_czasu == true || escape == true)
                break;
        }
            Sleep(opoznienie);
    }
    ROBAKI.clear();
}