#include "inout.h"//other libraries are there and depend on OS void sysClear() {//clear the console screen #ifdef WINDOWS system("cls"); #else system("clear"); #endif } int runLevel(wchar_t *lines, int chars_max, struct position_s position) { wchar_t c = L'\0'; int mistakes = 0; do { c = readChar(); int color = (c == lines[position.x-1]) ? GREEN : RED; printChar(lines, color, c, position); if (c != lines[position.x-1]) mistakes++; position.x++; } while ( c != EOF && position.x < chars_max); return mistakes; } wchar_t left[] = { L'a', L's', L'd', L'f', L'g', L'\0' }; wchar_t left_t[] = { L'q', L'w', L'e', L'r', L't', L'\0' }; wchar_t left_b[] = { L'<', L'y', L'x', L'c', L'v', L'b', L'\0' }; wchar_t right[] = { L'j', L'k', L'l', L'ö', L'h', L'ä', L'#', L'\0' }; wchar_t right_t[] = { L'u', L'i', L'o', L'p', L'ü', L'z', L'+', L'\0' }; wchar_t right_b[] = { L'm', L',', L'.', L'-', L'n', L'\0' }; int main(){ setlocale(LC_ALL, ""); #ifdef WINDOWS CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); typedef struct windows_winsize{int ws_col,ws_row;}winsize_t; winsize_t window; window.ws_col = csbi.srWindow.Right - csbi.srWindow.Left + 1; window.ws_row = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; #else struct winsize window; ioctl(STDOUT_FILENO, TIOCGWINSZ, &window); // window.ws_col, window.ws_row #endif struct position_s position = {1, 1}; int chars_max = 15; wchar_t lines[chars_max]; int level = 1; int mistakes = 1; wchar_t lvl_arr[100]; while(1) { switch (level) { case 1: wcscpy(lvl_arr, left); break; case 2: wcscpy(lvl_arr, right); break; case 3: wcscpy(lvl_arr, left); wcscat(lvl_arr, right); break; default: perror("Error choosing level!\n"); } sysClear(); position.x = 1, position.y = 1; getLine(lines, lvl_arr, chars_max, window.ws_col); wprintf(L"\033[1;1H%ls", lines);//move cursor and print new line wprintf(L"\033[1;1H");//move cursor to top left mistakes = runLevel(lines, chars_max, position); if (mistakes == 0) level++; } return 0; }