Cześć, mam problem z moim programem. Na moim komputerze działa bez zarzutu(zazwyczaj) ale na innych komputerach podczas wyświetlania znaku na monitorze dostaje zamiast jednego znaku to dwa obok siebie i od tego momentu mój program się zupełnie chrzani wizualnie. Dostaje efekt można powiedzieć podobny do tego z filmu matrix a tego nie chcę. Przeczytałem w sieci że rozwiązaniem problemu może być podwójne getch(); jedno pod drugim albo fflush(stdin); ale to nie rozwiązuje problemu niestety... Także proszę Was o pomoc a jeśli będzie coś jeszcze do poprawy w kodzie to także śmiało możecie pisać.
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <process.h>
#include <time.h>
#include <vector>
#include <algorithm>
using namespace std;
int a = 0;
vector < char > vectorOfChars = { }; vector < int > lifes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 };
bool endOfTurn = false, endOfGame = false;
void endOperations();
void writeLine();
void initConsole();
void textColor( int );
void gotoxy( int, int );
int pointsCount( int );
int getRandomNumber();
template < typename >
int findIndex( vector < char > &, char );
template < typename >
int findIndex( vector < int >, int );
VOID functionKbhit( LPVOID );
VOID myThread( LPVOID );
int main()
{
initConsole();
_beginthread( functionKbhit, 0, NULL ); while( 1 )
{
for( int x = 0; endOfTurn == false; x++ )
{
_beginthread( myThread, x, NULL );
Sleep( 1000 );
}
if( endOfGame ) return 0;
}
}
void endOperations()
{
int z;
pointsCount( 0 ); gotoxy( 14, 12 );
textColor( 15 );
cout << "You Lose! Do you want continue? [Y/N]";
while( endOfTurn )
{
static int i = 13;
z = getch();
if( z != 'n' && z != 'N' && z != 'y' && z != 'Y' )
{
textColor( 15 );
gotoxy( 0, ++i );
cout << "Give correct character!";
}
else if( z == 'y' || z == 'Y' )
{
vectorOfChars.clear(); lifes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 }; i = 13;
a = 0;
endOfTurn = false;
system( "cls" );
writeLine();
}
else if( z == 'N' || z == 'n' ) endOfGame = true;
}
}
void writeLine()
{
textColor( 15 );
gotoxy( 0, 22 );
cout << "________________________________________________________________________________";
}
void initConsole()
{
HANDLE hOut;
CONSOLE_CURSOR_INFO ConCurInf;
hOut = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTitle( "Master of keyboard C++ by Priboi" );
ConCurInf.dwSize = 10; ConCurInf.bVisible = FALSE;
SetConsoleCursorInfo( hOut, & ConCurInf );
system( "cls" );
writeLine();
}
void textColor( int color )
{
HANDLE hConsole;
hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute( hConsole, color ); }
void gotoxy( int x, int y )
{
COORD c;
c.X = x;
c.Y = y;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), c );
}
int pointsCount( int zerowanie )
{
int static points = 0;
if( zerowanie == 0 ) return points = 0;
return ++points;
}
int getRandomNumber()
{
srand( time( NULL ) );
return rand();
}
template < typename T1 > int findIndex( T1 & arr, char item )
{
for( auto i = 0; i < arr.size(); ++i )
{
if( arr[ i ] == item )
return i;
}
return - 1; }
VOID functionKbhit( LPVOID lpVoid )
{
while( 1 )
{
if( endOfTurn == false ) {
if( kbhit() )
{
a = getch(); a = getch();
}
}
}
}
VOID myThread( LPVOID lpVoid )
{
int x, y, h, b;
char character, rakieta = 127;
for( y = 0; y <= 22; y++ )
{
if( endOfTurn == true ) _endthread(); if( y == 0 )
{
x = rand() * getRandomNumber() % lifes.size(); x = lifes[ x ];
b = rand() % 2;
b ? character = rand() % 25 + 65
: character = rand() % 25 + 97; while( find( vectorOfChars.begin(), vectorOfChars.end(), character ) != vectorOfChars.end() ) {
b ? character = rand() % 25 + 65
: character = rand() % 25 + 97; }
vectorOfChars.push_back( character ); }
gotoxy( x, y );
textColor( 15 );
cout << character;
Sleep( 160 );
gotoxy( x, y );
textColor( 0 );
cout << character;
if( a == character && y <= 21 )
{
a = 0; vectorOfChars.erase( vectorOfChars.begin() + findIndex( vectorOfChars, character ) );
textColor( 10 ); gotoxy( x, y );
cout << character;
gotoxy( 0, 24 );
textColor( 15 );
cout << "Your points: " << pointsCount( 1 );
textColor( 0 ); gotoxy( x, y );
cout << character;
y++; for( int h = 21; h >= y; h--, y++ ) {
gotoxy( x, h );
textColor( 10 );
cout << rakieta;
gotoxy( x, y ); cout << character;
Sleep( 160 );
gotoxy( x, h );
textColor( 0 );
cout << rakieta;
gotoxy( x, y );
cout << character;
}
_endthread();
}
if( y == 22 )
{
vectorOfChars.erase( vectorOfChars.begin() + findIndex( vectorOfChars, character ) );
if( findIndex( lifes, x ) != - 1 ) lifes.erase( lifes.begin() + findIndex( lifes, x ) ); if( lifes.size() == 0 )
{
endOfTurn = true;
endOperations();
}
}
}
}