Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. const screen_width = 10;
  2. int current_text_pos = 0;
  3.  
  4. char screen_buffer[screen_width];
  5.  
  6. void clear_screen()
  7. {
  8.   for(int i = 0; i < screen_width; i++) screen_buffer[i] = ' ';
  9. }
  10.  
  11. void fill_screen_buffer(String text)
  12. {  
  13.   int buffer_pos = 0;
  14.  
  15.   if (current_text_pos + screen_width >= text.length)
  16.   {
  17.       for(int i = current_text_pos; i <= text.length; i++)
  18.       {
  19.         screen_buffer[buffer_pos] = text[i];
  20.         buffer_pos++;
  21.       }
  22.  
  23.       buffer_pos++; // space
  24.    
  25.       for(int i = 0; i < (current_text_pos + screen_width + text.length) - text.length - 1; i++)
  26.       {
  27.         screen_buffer[buffer_pos] = text[i];
  28.         buffer_pos++;
  29.       }
  30.   } else {
  31.     for(int i = current_text_pos; i < screen_width + current_text_pos; i++)
  32.     {
  33.       screen_buffer[buffer_pos] = text[i];
  34.       buffer_pos++;
  35.     }
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement