Example #1
0
void TMouse::doClip(COORD start_coords, COORD end_coords) {
	// COORD screen_start = {0, 0};
	COORD first_coords, last_coords;
	DWORD Result;

	get_coords(&start_coords, &end_coords, &first_coords, &last_coords);

	// Allocate the minimal size buffer
	int data_size = 3 + ConsoleInfo.dwSize.X *
		(last_coords.Y - first_coords.Y) + (last_coords.X - first_coords.X);
	HGLOBAL clipboard_data = GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE,
		data_size);
	LPVOID mem_ptr = GlobalLock(clipboard_data);

	// Reset data_size so we can count the actual data size
	data_size = 0;

	// Read the console, put carriage returns at the end of each line if
	// reading more than one line (Paul Brannan 9/17/98)
	for(int j = first_coords.Y; j <= last_coords.Y; j++) {

		// Read line at (0,j)
		COORD coords;
		coords.X = 0;
		coords.Y = j;
		int length = ConsoleInfo.dwSize.X;

		if(j == first_coords.Y) {
			coords.X = first_coords.X;
			length = ConsoleInfo.dwSize.X - first_coords.X;
		} else {
			// Add a carriage return to the end of the previous line
			*((char *)mem_ptr + data_size++) = '\r';
			*((char *)mem_ptr + data_size++) = '\n';
		}

		if(j == last_coords.Y) {
			length -= (ConsoleInfo.dwSize.X - last_coords.X);
		}

		// Read the next line
		ReadConsoleOutputCharacter(hStdout, (LPTSTR)((char *)mem_ptr +
			data_size), length, coords, &Result);
		data_size += Result;

		// Strip the spaces at the end of the line
		if((j != last_coords.Y) && (first_coords.Y != last_coords.Y))
			while(*((char *)mem_ptr + data_size - 1) == ' ') data_size--;
	}
	if(first_coords.Y != last_coords.Y) {
		// Add a carriage return to the end of the last line
		*((char *)mem_ptr + data_size++) = '\r';
		*((char *)mem_ptr + data_size++) = '\n';
	}

	*((char *)mem_ptr + data_size) = 0;
	GlobalUnlock(clipboard_data);

	Clipboard.Copy(clipboard_data);
}
Example #2
0
unsigned int __stdcall Rain(void *param)
{
    DWORD		dwRead;
    SMALL_RECT	srcScrollRect;
    char		*bLengthOfRain, *bIsSpace, *buff;
    COORD		coordLine0 = {0, 0}, coordLine2 = {0, 2};
    CHAR_INFO	char_info = {' ', FOREGROUND_GREEN|FOREGROUND_INTENSITY};

    // 设置要移动的范围
//	srcScrollRect.Top		= coord.Y;
    srcScrollRect.Left		= 0;
    srcScrollRect.Right		= sColNum - 1;
    srcScrollRect.Bottom	= sRowNum - 1;

    buff			= (char *)malloc(sColNum);
    bIsSpace		= (char *)malloc(sColNum);
    bLengthOfRain	= (char *)malloc(sColNum);
    memset(bIsSpace, 0, sColNum);
    memset(bLengthOfRain, 0, sColNum);

    do
    {
        Sleep(50);
        /*		if (bStart)	coord.Y = 2;
        		else coord.Y = 0;
        */
        // 上面的if...else...简化如下
        coord.Y = bStart << 1;
        coordDest.Y = coord.Y + 1;
        srcScrollRect.Top = coord.Y;

        // 移动一块字符, 并用 char_info 填充空出来的区域
        ScrollConsoleScreenBuffer(hStdOut, &srcScrollRect, 0, coordDest, &char_info);

        // 输出一行字符
        for (char index = 0; index != sColNum; ++index)
        {
            if (!bLengthOfRain[index]--)
            {
                bIsSpace[index]			= GetRandom(0, 4);		// 25% 概率出字符
                bLengthOfRain[index]	= GetRandom(10, 25);	// 每列最短10, 最长25
            }
            buff[index] = bIsSpace[index] ? ' ' : GetRandom(0x30, 0x7E);
        }
        WriteConsoleOutputCharacter(hStdOut, buff, sColNum, coord, NULL);
        if (bStart)			// 读取第3行的内容并写到第1行
        {
            ReadConsoleOutputCharacter(hStdOut,  buff, sColNum, coordLine2, &dwRead);
            WriteConsoleOutputCharacter(hStdOut, buff, dwRead,  coordLine0, NULL);
        }
    } while (!kbhit());

    bRainExit = true;
    free(bLengthOfRain);
    free(bIsSpace);
    free(buff);
//	MessageBox(NULL, _T("t1 free success"), NULL, 0x40);
    return 0;
}
Example #3
0
//------------------------------  Getchon  ------------------------------------
// 해당 좌표의 값을 char형으로 읽어온다.
//-----------------------------------------------------------------------------
int Getchon(Position pos)
{
	COORD Cur;
	Cur.X= pos.x_;
	Cur.Y= pos.y_;
	TCHAR Char;
	DWORD dwRead;

	ReadConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE),
		&Char,1,Cur,&dwRead);
	return Char;
}
Example #4
0
unsigned int __stdcall Joy(void *param)
{
    DWORD dwRead, dwStrLen;
    const char *szStr;
    char *buff	= (char *)malloc(sColNum);
    char *space = (char *)malloc(sColNum);
    COORD coordLine1 = {0, 0},
          coordLine2 = {0, 1},
          coordMid	 = {sColNum / 3, 1},
             coordStr;

    coordStr.Y = 1;
    memset(space, 0x20, sColNum);

    do
    {
        szStr = szStrings[GetRandom(0, sizeof(szStrings) / 4 - 1)];		// 随机选取一个字符串
        dwStrLen = lstrlenA(szStr);
        coordStr.X = sColNum / 2 - (SHORT)dwStrLen / 2 - 1;					// 计算中间位置
        Sleep(GetRandom(1000, 1000));
        bStart = true;
        Sleep(100);			// 确保另一个线程已完成转换
        if (bRainExit)
            break;

        // 用空格填充第2行
        WriteConsoleOutputCharacter(hStdOut, space, sColNum, coordLine2, NULL);

        for (byte index = 0; index != 15; ++index)
        {
            for (byte ix = 0; ix != coordMid.X; ix += 1)
                buff[ix] = GetRandom('A', 'z');
            WriteConsoleOutputCharacter(hStdOut, buff, coordMid.X, coordMid, NULL);
            Sleep(20);
        }

        WriteConsoleOutputCharacter(hStdOut, space, sColNum, coordLine2, NULL);
        WriteConsoleOutputCharacter(hStdOut, szStr, dwStrLen, coordStr, NULL);
        Sleep(GetRandom(1000, 1000));

        ReadConsoleOutputCharacter(hStdOut,  buff, sColNum, coordLine1, &dwRead);
        WriteConsoleOutputCharacter(hStdOut, buff, dwRead,  coordLine2, NULL);
        bStart = false;
    } while (!kbhit());

    free(space);
    free(buff);
//	MessageBox(NULL, _T("t2 free success"), NULL, 0x40);
    return 0;
}
/* ************************************
* 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");
			}
		}
	}
}
Example #6
0
static VALUE rb_ReadConsoleOutputCharacter( VALUE self, VALUE hConsoleOutput,
					    VALUE charbuf, VALUE len,
					    VALUE x, VALUE y )
{
   HANDLE handle = ULongToPtr( NUM2ULONG( hConsoleOutput ) );
   COORD coords;
   DWORD nofread;
   int l = NUM2INT(len);
   coords.X= NUM2UINT( x );
   coords.Y= NUM2UINT( y );
   if ( (unsigned long)RSTRING_LEN(charbuf) < l*sizeof(TCHAR) )
      rb_raise(rb_eArgError, "String is too small to read that many characters.");
   if (ReadConsoleOutputCharacter(handle,RSTRING_PTR(charbuf),l,
				  coords,&nofread))
      return UINT2NUM( nofread );
   return rb_getWin32Error();
}
Example #7
0
JNIEXPORT jintArray JNICALL Java_com_yifanlu_Josh_Josh_READCONSOLEOUTPUTCHARACTER
  (JNIEnv *env, jclass jcls, jlong pointer, jint x, jint y, jint length)
{
    HANDLE hConsole = pointerToHandle(pointer);
	COORD coordBufCoord = {x , y};
	char *buffer = new char[length];
	DWORD numRead;

	ReadConsoleOutputCharacter(hConsole, (LPTSTR)buffer, 10, coordBufCoord, &numRead);

	int *cInfo = new int[length];

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

	jintArray jInfo = env->NewIntArray(length);
	env->SetIntArrayRegion(jInfo, 0, length, (jint *)cInfo);

	return jInfo;
}
Example #8
0
FBCALL unsigned int fb_ConsoleReadXY( int col, int row, int colorflag )
{
    TCHAR character;
    WORD attribute;
    DWORD res;
    COORD coord;

    fb_hConvertToConsole( &col, &row, NULL, NULL );

    coord.X = (SHORT) col;
    coord.Y = (SHORT) row;

    if( colorflag ) {
        ReadConsoleOutputAttribute( __fb_out_handle, &attribute, 1, coord, &res);
        return ((unsigned int)attribute) & 0xfffful;
    }
    else {
    	ReadConsoleOutputCharacter( __fb_out_handle, &character, 1, coord, &res);
    	return ((unsigned int)character) & (sizeof(TCHAR) == 1? 0xfful : 0xfffful);
    }
}
Example #9
0
BOOL
ReadText(LPTSTR pszText, int iBeginLine, int iEndLine)
{
    COORD coord;
    DWORD dwRead;
    BOOL bRet;

    coord.X = 0;
    coord.Y = iBeginLine;

    bRet = ReadConsoleOutputCharacter(hStdout,
				      pszText,
				      80 * (iEndLine - iBeginLine + 1),
				      coord, &dwRead);

    // Make sure it's null terminated.
    if (bRet)
	pszText[dwRead] = '\0';

    return bRet;
}
Example #10
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;
    }
}
Example #11
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
}
Example #12
0
void demoReadConChar(HANDLE hConOut)
{
  BOOL bSuccess;
  INPUT_RECORD inputBuffer;
  DWORD dwStdInMode;
  HANDLE hStdIn;
  DWORD dwInputEvents;
  COORD coordLine; /* coordinates of where to read characters from */
  CHAR *szLine;  /* buffer to hold the line read from the console */
  DWORD dwCharsRead;
  int i;

  setConTitle(__FILE__);
  myPuts(hConOut, "Click on any line containing characters. I will use\n"
                  "ReadConsoleOutputCharacter to read that line of text into\n"
                  "a buffer, then print that buffer to the console at the\n"
                  "current cursor position. Hit ESC to return.\n\n");
  hStdIn = GetStdHandle(STD_INPUT_HANDLE);
  PERR(hStdIn != INVALID_HANDLE_VALUE, "GetStdHandle");
  /* save the console mode */
  bSuccess = GetConsoleMode(hStdIn, &dwStdInMode);
  PERR(bSuccess, "GetConsoleMode");
  /* enable mouse input */
  bSuccess = SetConsoleMode(hStdIn, dwStdInMode | ENABLE_MOUSE_INPUT);
  PERR(bSuccess, "SetConsoleMode");
  /* allocate space for one line */
  szLine = (char *) malloc(getConX(hConOut));
  PERR(szLine, "malloc");
  for(;;)
    {
    /* get a single input event */
    bSuccess = ReadConsoleInput(hStdIn, &inputBuffer, 1, &dwInputEvents);
    PERR(bSuccess, "ReadConsoleInput");
    switch (inputBuffer.EventType)
      {
      case KEY_EVENT:
        /* is it an ESC key? */
        if (inputBuffer.Event.KeyEvent.bKeyDown &&
            inputBuffer.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
          {
          /* set input mode back to what it was originally and return */
          bSuccess = SetConsoleMode(hStdIn, dwStdInMode);
          PERR(bSuccess, "SetConsoleMode");
          free(szLine); /* free allocated space for a text line */
          return;
          }
        break;
      case MOUSE_EVENT:
        /* was this was a click event? Is any button down or not? */
        if (inputBuffer.Event.MouseEvent.dwEventFlags != MOUSE_MOVED &&
            inputBuffer.Event.MouseEvent.dwButtonState)
          {
          /* read the line where the mouse is, starting at column 0 */
          coordLine.X = 0;
          coordLine.Y = inputBuffer.Event.MouseEvent.dwMousePosition.Y;
          bSuccess = ReadConsoleOutputCharacter(hConOut, szLine,
              getConX(hConOut), coordLine, &dwCharsRead);
          PERR(bSuccess, "ReadConsoleOutputCharacter");
          /* strip trailing spaces */
          i = getConX(hConOut) - 1;
          szLine[i--] = 0; /* null terminate */
          while (szLine[i] == ' ')
            szLine[i--] = 0;
          myPuts(hConOut, szLine);
          }
      } /* switch */
    } /* while */
}
Example #13
0
int main(int argc, char **argv) {
    HANDLE hConsole;
    HANDLE hFile;
    COORD start;
    LPSTR buff;
    CONSOLE_SCREEN_BUFFER_INFO cbi;
    DWORD rchr, ochr, n;
    LONG l;

    if(argc!=2)
        ERRPT("\rUsage: %s <filename>\n", argv[0]);

    hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
    if(hConsole==INVALID_HANDLE_VALUE)
        ERRPT("GetStdHandle" );

    if(GetConsoleScreenBufferInfo(hConsole, &cbi)==0)
        ERRPT("GetConsoleScreenBufferInfo");

    buff=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (cbi.dwSize.X+3)*sizeof(WCHAR));
    if(buff==NULL)
        ERRPT("HeapAlloc");

    hFile=CreateFile(argv[1], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if(hFile==INVALID_HANDLE_VALUE)
        ERRPT("CreateFile %s", argv[1]);

    start.X=0;
    start.Y=0;

    while(start.Y<cbi.dwSize.Y) {

        if(ReadConsoleOutputCharacter(hConsole, buff, cbi.dwSize.X, start, &rchr)==0)
            ERRPT("ReadConsoleOutputCharacter [rchr=%d, y:%d]", rchr, start.Y);

        // trim horizontal
        n=cbi.dwSize.X-1;
        while(n && buff[n]==' ') 
            n--;

        if(n==0)
            n=-1;

        buff[n+1]='\r';
        buff[n+2]='\n';
        buff[n+3]='\0';

        if(WriteFile(hFile, buff, strlen(buff), &ochr, NULL)==0)
            ERRPT("WriteFile");

        // for vertical trim
        if(buff[0]!='\r')
            l=GetFileSize(hFile, NULL);
       
        start.Y++;
    }

    // trim vertical
    SetFilePointer(hFile, l, NULL, FILE_BEGIN);
    SetEndOfFile(hFile);

    CloseHandle(hFile);

    return 0;
}
Example #14
0
int main()
{
	COORD posHead;
	COORD posJopa;
	posJopa.X = 0;
	posJopa.Y = 1;
	posHead.X = 5;
	posHead.Y = 1;
	COORD vert;
	vert.X = 1;
	vert.Y = 0;
	DWORD a = 0;
	char chr = 0;
	char chl = 0;
	char chu = 0;
	char chd = 0;
	char ch = 0;
	char rnd = 0;
	int flag = 1;
	int l = 6;
	char checking; 
	COORD randomPos;
	system("cls");
	srand(time(NULL));
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hConsole, posJopa);
	puts("######");
	while (1){
		for(int i = 0; i < 10; i++){
			Sleep(10);
			if (kbhit() != 0)
				ch = getch();
		}
		checking = 0;
		chl = 0;
		chr = 0;
		chu = 0;
		chd = 0;
		while (flag)
		{
			randomPos.X = rand() % 80;
			randomPos.Y = rand() % 25;
			ReadConsoleOutputCharacter(hConsole, &rnd, 1, randomPos, &a);
			if (rnd != '#'){
				flag = 0;
				SetConsoleCursorPosition(hConsole, randomPos);
				putchar('@');
			}
		}
		switch (ch){
			case 'w': if (vert.Y != 1) {vert.Y = -1; vert.X = 0;} break;
			case 's': if (vert.Y != -1) {vert.Y = 1; vert.X = 0;} break;
			case 'd': if (vert.X != -1) {vert.Y = 0; vert.X = 1;} break;
			case 'a': if (vert.X != 1) {vert.Y = 0; vert.X = -1;} break;
			default: break;
		}
		posHead.X += vert.X;
		if (posHead.X == 80)
			posHead.X = 0;
		else if (posHead.X == -1)
			posHead.X = 79;
		posHead.Y += vert.Y;
		if (posHead.Y == 25)
			posHead.Y = 0;
		else if (posHead.Y == -1)
			posHead.Y = 24;
		ReadConsoleOutputCharacter(hConsole, &rnd, 1, posHead, &a);
		if (rnd == '@'){
			l++;
			flag = 1;
		}
		if (rnd == '#'){
			SetConsoleCursorPosition(hConsole, posHead);
			printf("game over");
			Sleep(1000);
			return 0;
		}
		
		SetConsoleCursorPosition(hConsole, posHead);
		putchar('#');
		if (flag == 0)
		{
			if(posJopa.X == 79)
				posJopa.X = 0;
			else
				posJopa.X++;
			ReadConsoleOutputCharacter(hConsole, &chr, 1, posJopa, &a);
			if (posJopa.X == 0)
				posJopa.X = 78;
			else if (posJopa.X == 1)
					posJopa.X = 79;
				else
					posJopa.X -= 2;
			ReadConsoleOutputCharacter(hConsole, &chl, 1, posJopa, &a);
			if(posJopa.X == 79)
				posJopa.X = 0;
			else
				posJopa.X++;
			if(posJopa.Y == 24)
				posJopa.Y = 0;
			else
				posJopa.Y++;
			ReadConsoleOutputCharacter(hConsole, &chu, 1, posJopa, &a);
			if(posJopa.Y == 0)
				posJopa.Y = 23;
			else if(posJopa.Y == 1)
					posJopa.Y = 24;
				else
					posJopa.Y -= 2;
			ReadConsoleOutputCharacter(hConsole, &chd, 1, posJopa, &a);
			if(posJopa.Y == 24)
				posJopa.Y = 0;
			else
				posJopa.Y++;
			if (chu + chd + chl + chr > '#')
				checking = check(posJopa, l);
			switch (checking){
				case 'l' : chu = 0; chd = 0; chr = 0; break;
				case 'r' : chu = 0; chd = 0; chl = 0; break;
				case 'u' : chl = 0; chd = 0; chr = 0; break;
				case 'd' : chu = 0; chl = 0; chr = 0; break;
				default : break;
			}
			SetConsoleCursorPosition(hConsole, posJopa);
			putchar(' ');
			
			if(chu == '#')
				if(posJopa.Y == 24)
					posJopa.Y = 0;
				else
					posJopa.Y++;
			if(chd == '#')
				if(posJopa.Y == 0)
					posJopa.Y = 24;
				else
					posJopa.Y--;
			if(chl == '#')
				if (posJopa.X == 0)
					posJopa.X = 79;
				else
					posJopa.X--;
			if(chr == '#')
				if(posJopa.X == 79)
					posJopa.X = 0;
				else
					posJopa.X++;
		}
	}
	return 0;

}
Example #15
0
char check(COORD posJopa, int l)
{
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD a = 0;
	char chr = 0;
	char chl = 0;
	char chu = 0;
	char chd = 0;
	char ch = 0;
	if (l == 0)
		return 1;
	SetConsoleCursorPosition(hConsole, posJopa);
	putchar(' ');
			if(posJopa.X == 79)
				posJopa.X = 0;
			else
				posJopa.X++;
			ReadConsoleOutputCharacter(hConsole, &chr, 1, posJopa, &a);
			if (posJopa.X == 0)
				posJopa.X = 78;
			else if (posJopa.X == 1)
					posJopa.X = 79;
				else
					posJopa.X -= 2;
			ReadConsoleOutputCharacter(hConsole, &chl, 1, posJopa, &a);
			if(posJopa.X == 79)
				posJopa.X = 0;
			else
				posJopa.X++;
			if(posJopa.Y == 24)
				posJopa.Y = 0;
			else
				posJopa.Y++;
			ReadConsoleOutputCharacter(hConsole, &chu, 1, posJopa, &a);
			if(posJopa.Y == 0)
				posJopa.Y = 23;
			else if(posJopa.Y == 1)
					posJopa.Y = 24;
				else
					posJopa.Y -= 2;
			ReadConsoleOutputCharacter(hConsole, &chd, 1, posJopa, &a);
			if(posJopa.Y == 24)
				posJopa.Y = 0;
			else
				posJopa.Y++;
			
			if(chu == '#'){
				if(posJopa.Y == 24)
					posJopa.Y = 0;
				else
					posJopa.Y++;
				if (check(posJopa, l - 1))
					ch =  'u';
				if(posJopa.Y == 0)
					posJopa.Y = 24;
				else
					posJopa.Y--;
			}
			if(chd == '#'){
				if(posJopa.Y == 0)
					posJopa.Y = 24;
				else
					posJopa.Y--;
				if (check(posJopa, l - 1))
					ch = 'd';
				if(posJopa.Y == 24)
					posJopa.Y = 0;
				else
					posJopa.Y++;
			}
			if(chl == '#'){
				if (posJopa.X == 0)
					posJopa.X = 79;
				else
					posJopa.X--;
				if (check(posJopa, l - 1))
					ch = 'l';
				if(posJopa.X == 79)
					posJopa.X = 0;
				else
					posJopa.X++;
			}
			if(chr == '#'){
				if(posJopa.X == 79)
					posJopa.X = 0;
				else
					posJopa.X++;
				if (check(posJopa, l - 1))
					ch = 'r';
				if (posJopa.X == 0)
					posJopa.X = 79;
				else
					posJopa.X--;
			}
			SetConsoleCursorPosition(hConsole, posJopa);
				putchar('#');
			return ch;
			
}