Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<windows.h>
- #include<stdio.h>
- #include <conio.h>
- using namespace std;
- void gotoxy(int x, int y)
- {
- static HANDLE h = NULL;
- if(!h)
- h = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD c = { x, y };
- SetConsoleCursorPosition(h,c);
- }
- void printField(char str[20][60])
- {
- for(int i = 0;i<20;i++)
- {
- for(int j = 0;j<60;j++)
- {
- printf("%c",str[i][j]);
- }
- printf("\n");
- }
- }
- bool isSymbol(char c)
- {
- if(c >= 'a' && c <= 'z') return true;
- return false;
- }
- int main()
- {
- int x = 0,
- y = 0;
- char str[20][60] = {{' '}};
- for(int j=0;j<=19;j++)
- {
- for(int i=0;i<=59;i++)
- {
- str[j][i]=' ';
- }
- }
- gotoxy(x,y);
- char c;
- while(1)
- {
- gotoxy(x,y);
- if(kbhit())
- {
- c = getch();
- switch(c)
- {
- case 72:
- if(y > 0)
- y--;
- break;
- case 80:
- y++;
- break;
- case 75:
- if(x > 0)
- x--;
- else if(y > 0)
- {
- x=59;
- y--;
- }
- break;
- case 77:
- if(x < 59)
- x++;
- else
- {
- x=0;
- y++;
- }
- break;
- default:
- if(isSymbol(c))
- {
- if(x==59)
- {
- for(int j=19;j>=y;j--)
- {
- if(j!=y)
- {
- for(int i=58;i>=0;i--)
- {
- str[j][i+1]=str[j][i];
- }
- str[j][0]=str[j-1][59];
- }
- else
- {
- for(int i=58;i>=x;i--)
- {
- str[j][i+1]=str[j][i];
- }
- }
- }
- str[y][x]=c;
- printf("%c",c);
- if(y!=19)
- {
- y++;
- x=0;
- }
- }
- else
- {
- if(isSymbol(str[y][x]) || str[y][x]==' ')
- {
- for(int j=19;j>=y;j--)
- {
- if(j!=y)
- {
- for(int i=58;i>=0;i--)
- {
- str[j][i+1]=str[j][i];
- }
- str[j][0]=str[j-1][59];
- }
- else
- {
- for(int i=58;i>=x;i--)
- {
- str[j][i+1]=str[j][i];
- }
- }
- }
- }
- str[y][x]=c;
- system("cls");
- printField(str);
- x++;
- }
- }
- if(c==' ')
- {
- for(int j=19;j>=y;j--)
- {
- if(j!=y)
- {
- for(int i=58;i>=0;i--)
- {
- str[j][i+1]=str[j][i];
- }
- str[j][0]=str[j-1][59];
- }
- else
- {
- for(int i=58;i>=x;i--)
- {
- str[j][i+1]=str[j][i];
- }
- }
- }
- str[y][x]=c;
- system("cls");
- printField(str);
- x++;
- }
- if(c=='\t')
- {
- for(int j=19;j>=y;j--)
- {
- if(j!=y)
- {
- for(int i=51;i>=0;i--)
- {
- str[j][i+8]=str[j][i];
- }
- for(int i=8;i>=0;i--)
- {
- str[j][i]=str[j-1][59-(8-i)];
- }
- }
- else
- {
- for(int i=51;i>=x;i--)
- {
- str[y][i+8]=str[y][i];
- }
- }
- }
- for(int i=x;i<x+8;i++)
- {
- str[y][i]=' ';
- }
- system("cls");
- printField(str);
- x+=8;
- }
- if(c=='\b')
- {
- for(int j=y;j<=19;j++)
- {
- if(j!=y)
- {
- for(int i=0;i<=58;i++)
- {
- str[j][i]=str[j][i+1];
- }
- str[j][59]=str[j+1][0];
- }
- else
- {
- for(int i=x-1;i<=58;i++)
- {
- str[j][i]=str[j][i+1];
- }
- str[j][59]=str[j+1][0];
- }
- }
- str[19][59]=' ';
- system("cls");
- printField(str);
- x--;
- }
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement