Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. #include<windows.h>
  2. #include<stdio.h>
  3. #include <conio.h>
  4. using namespace std;
  5.  
  6. void gotoxy(int x, int y)
  7. {
  8. static HANDLE h = NULL;
  9. if(!h)
  10. h = GetStdHandle(STD_OUTPUT_HANDLE);
  11. COORD c = { x, y };
  12. SetConsoleCursorPosition(h,c);
  13. }
  14.  
  15. void printField(char str[20][60])
  16. {
  17. for(int i = 0;i<20;i++)
  18. {
  19. for(int j = 0;j<60;j++)
  20. {
  21. printf("%c",str[i][j]);
  22. }
  23. printf("\n");
  24. }
  25. }
  26.  
  27. bool isSymbol(char c)
  28. {
  29. if(c >= 'a' && c <= 'z') return true;
  30. return false;
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36. int x = 0,
  37. y = 0;
  38. char str[20][60] = {{' '}};
  39. for(int j=0;j<=19;j++)
  40. {
  41. for(int i=0;i<=59;i++)
  42. {
  43. str[j][i]=' ';
  44. }
  45. }
  46. gotoxy(x,y);
  47. char c;
  48. while(1)
  49. {
  50. gotoxy(x,y);
  51. if(kbhit())
  52. {
  53. c = getch();
  54. switch(c)
  55. {
  56. case 72:
  57. if(y > 0)
  58. y--;
  59. break;
  60. case 80:
  61. y++;
  62. break;
  63. case 75:
  64. if(x > 0)
  65. x--;
  66. else if(y > 0)
  67. {
  68. x=59;
  69. y--;
  70. }
  71. break;
  72. case 77:
  73. if(x < 59)
  74. x++;
  75. else
  76. {
  77. x=0;
  78. y++;
  79. }
  80. break;
  81. default:
  82. if(isSymbol(c))
  83. {
  84. if(x==59)
  85. {
  86. for(int j=19;j>=y;j--)
  87. {
  88. if(j!=y)
  89. {
  90. for(int i=58;i>=0;i--)
  91. {
  92. str[j][i+1]=str[j][i];
  93. }
  94. str[j][0]=str[j-1][59];
  95. }
  96. else
  97. {
  98. for(int i=58;i>=x;i--)
  99. {
  100. str[j][i+1]=str[j][i];
  101. }
  102. }
  103. }
  104. str[y][x]=c;
  105. printf("%c",c);
  106. if(y!=19)
  107. {
  108. y++;
  109. x=0;
  110. }
  111. }
  112. else
  113. {
  114. if(isSymbol(str[y][x]) || str[y][x]==' ')
  115. {
  116. for(int j=19;j>=y;j--)
  117. {
  118. if(j!=y)
  119. {
  120. for(int i=58;i>=0;i--)
  121. {
  122. str[j][i+1]=str[j][i];
  123. }
  124. str[j][0]=str[j-1][59];
  125. }
  126. else
  127. {
  128. for(int i=58;i>=x;i--)
  129. {
  130. str[j][i+1]=str[j][i];
  131. }
  132. }
  133. }
  134. }
  135. str[y][x]=c;
  136. system("cls");
  137. printField(str);
  138. x++;
  139. }
  140. }
  141. if(c==' ')
  142. {
  143. for(int j=19;j>=y;j--)
  144. {
  145. if(j!=y)
  146. {
  147. for(int i=58;i>=0;i--)
  148. {
  149. str[j][i+1]=str[j][i];
  150. }
  151. str[j][0]=str[j-1][59];
  152. }
  153. else
  154. {
  155. for(int i=58;i>=x;i--)
  156. {
  157. str[j][i+1]=str[j][i];
  158. }
  159. }
  160. }
  161. str[y][x]=c;
  162. system("cls");
  163. printField(str);
  164. x++;
  165. }
  166. if(c=='\t')
  167. {
  168. for(int j=19;j>=y;j--)
  169. {
  170. if(j!=y)
  171. {
  172. for(int i=51;i>=0;i--)
  173. {
  174. str[j][i+8]=str[j][i];
  175. }
  176. for(int i=8;i>=0;i--)
  177. {
  178. str[j][i]=str[j-1][59-(8-i)];
  179. }
  180. }
  181. else
  182. {
  183. for(int i=51;i>=x;i--)
  184. {
  185. str[y][i+8]=str[y][i];
  186. }
  187. }
  188. }
  189. for(int i=x;i<x+8;i++)
  190. {
  191. str[y][i]=' ';
  192. }
  193. system("cls");
  194. printField(str);
  195. x+=8;
  196. }
  197. if(c=='\b')
  198. {
  199. for(int j=y;j<=19;j++)
  200. {
  201. if(j!=y)
  202. {
  203. for(int i=0;i<=58;i++)
  204. {
  205. str[j][i]=str[j][i+1];
  206. }
  207. str[j][59]=str[j+1][0];
  208. }
  209. else
  210. {
  211. for(int i=x-1;i<=58;i++)
  212. {
  213. str[j][i]=str[j][i+1];
  214. }
  215. str[j][59]=str[j+1][0];
  216. }
  217. }
  218. str[19][59]=' ';
  219. system("cls");
  220. printField(str);
  221. x--;
  222. }
  223. break;
  224.  
  225. }
  226.  
  227. }
  228. }
  229.  
  230. return 0;
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement