Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <tetris.h>
- extern g_args process;
- int setup_loop(t_window *window)
- {
- while (1)
- {
- wbkgd(window->game_box, COLOR_PAIR(1));
- box(window->game_box, 0, 0);
- wrefresh(window->game_box);
- }
- }
- t_ascii init_ascii()
- {
- t_ascii ascii;
- int fd;
- if ((ascii.ascii_hold = malloc(sizeof(char) * 500)) == NULL)
- exit(0);
- fd = open("./hold", O_RDWR);
- read(fd, ascii.ascii_hold, 400);
- return (ascii);
- }
- int print_each_char(WINDOW *box, char *str, int color)
- {
- int line;
- int cols;
- int i;
- i = 0;
- line = 1;
- cols = 3;
- wattron(box, COLOR_PAIR(color));
- while (str[i] != '\0')
- {
- if (str[i] == '\n')
- {
- line++;
- cols = 3;
- }
- mvwaddch(box, line, cols, str[i]);
- cols++;
- i++;
- }
- wattroff(box, COLOR_PAIR(color));
- wrefresh(box);
- }
- int print_decor(t_ascii ascii, t_window *window)
- {
- int i;
- wbkgd(window->next, COLOR_PAIR(1));
- wbkgd(window->hold, COLOR_PAIR(1));
- wbkgd(window->level, COLOR_PAIR(1));
- wbkgd(window->title, COLOR_PAIR(2));
- box(window->hold, 0, 0);
- box(window->next, 0, 0);
- box(window->level, 0, 0);
- wattron(window->next, A_BOLD);
- wattron(window->hold, A_BOLD);
- wattron(window->level, A_BOLD);
- mvwprintw(window->next, 2 , 15 / 2 - 2 , "NEXT");
- mvwprintw(window->hold, 2, 15 / 2 - 2, "HOLD");
- mvwprintw(window->level, 3, 14 / 2 - 2 , "LEVEL");
- mvwprintw(window->level, 5 , 14 / 2 , "1");
- wrefresh(window->hold);
- wrefresh(window->next);
- wrefresh(window->level);
- wrefresh(window->title);
- wattroff(window->next, A_BOLD);
- wattroff(window->level, A_BOLD);
- wattroff(window->hold, A_BOLD);
- }
- void init_screen(t_window *window, t_ascii ascii)
- {
- curs_set(0);
- start_color();
- init_color(0, 0, 0, 0);
- noecho();
- init_color(COLOR_BLUE, 60, 100, 255);
- init_pair(3, COLOR_CYAN, COLOR_BLACK);
- init_pair(1, COLOR_CYAN, 0);
- init_pair(2, 0, COLOR_BLUE);
- init_pair(4, COLOR_CYAN, COLOR_BLUE);
- wbkgd(stdscr, COLOR_PAIR(2));
- refresh();
- window->game_box = newwin(35, 30, LINES / 2 - 12 , COLS / 2 - 16);
- window->hold = newwin(5, 14, 2, 4);
- window->next = newwin(5, 14, 2, COLS - 20);
- window->preview_next = newwin(5, 14, 8, COLS - 20);
- window->level = newwin(10, 14, LINES - 12 - 2, 4);
- window->title = newwin(16, 54, 2, 18);
- window->preview_hold = newwin(5, 14, 8, 4);
- wrefresh(window->preview_next);
- wrefresh(window->preview_hold);
- }
- int start_game()
- {
- t_window *window;
- t_ascii ascii;
- ascii = init_ascii();
- if ((window = malloc(sizeof(t_window))) == NULL)
- return (84);
- initscr();
- init_screen(window, ascii);
- print_each_char(window->title, ascii.ascii_hold, 4);
- wrefresh(window->title);
- print_decor(ascii, window);
- setup_loop(window);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement