/** * Dessine l'entité passée en paramètre sur le plateau de jeu. * @param board Le plateau sur lequel l'entité est ajoutée * @param entity L'entité à ajouter */ void drawEntity(char board[ROWS][COLS], const Entity* entity) { board[entity->pos->x][entity->pos->y] = entity->symbol; goToXY(entity->pos->y, entity->pos->x); setColor(entity->symbolColor); putchar(convertCase(entity->symbol)); resetColor(); }
/** * Nettoie la case de l'ancienne position de l'entité. * @param board Le plateau de jeu sur lequel l'entité est retirée * @param entity L'entité à nettoyer */ void clearEntity(char board[ROWS][COLS], const Entity* entity) { goToXY(entity->pos->y, entity->pos->x); if (entity->caseBelow == THICK_CHAR) { setColor(THIN_CHAR_COLOR); board[entity->pos->x][entity->pos->y] = THIN_CHAR; putchar(convertCase(THIN_CHAR)); } else if (entity->caseBelow == SLIP_CHAR) { setColor(SLIP_CHAR_COLOR); board[entity->pos->x][entity->pos->y] = SLIP_CHAR; putchar(convertCase(SLIP_CHAR)); } else { setColor(entity->nextSymbolColor); board[entity->pos->x][entity->pos->y] = entity->nextSymbol; putchar(convertCase(entity->nextSymbol)); } resetColor(); }
void Scrollpad::flush() { auto &w = static_cast<Window &>(*this); const auto &s = m_buffer.str(); const auto &ps = m_buffer.properties(); auto p = ps.begin(); size_t i = 0; auto load_properties = [&]() { for (; p != ps.end() && p->position() == i; ++p) w << *p; }; auto write_whitespace = [&]() { for (; i < s.length() && iswspace(s[i]); ++i) { load_properties(); w << s[i]; } }; auto write_word = [&](bool load_properties_) { for (; i < s.length() && !iswspace(s[i]); ++i) { if (load_properties_) load_properties(); w << s[i]; } }; auto write_buffer = [&](bool generate_height_only) -> size_t { int new_y; size_t height = 1; size_t old_i; auto old_p = p; int x, y; i = 0; p = ps.begin(); y = getY(); while (i < s.length()) { // write all whitespaces. write_whitespace(); // if we are generating height, check difference // between previous Y coord and current one and // update height accordingly. if (generate_height_only) { new_y = getY(); height += new_y - y; y = new_y; } if (i == s.length()) break; // save current string position state and get current // coordinates as we are before the beginning of a word. old_i = i; old_p = p; x = getX(); y = getY(); // write word to test if it overflows, but do not load properties // yet since if it overflows, we do not want to load them twice. write_word(false); // restore previous indexes state i = old_i; p = old_p; // get new Y coord to see if word overflew into next line. new_y = getY(); if (new_y != y) { if (generate_height_only) { // if it did, let's update height... ++height; } else { // ...or go to old coordinates, erase // part of the string from previous line... goToXY(x, y); wclrtoeol(m_window); } // ...start at the beginning of next line... ++y; goToXY(0, y); // ...write word again, this time with properties... write_word(true); if (generate_height_only) { // ... and check for potential // difference in Y coordinates again. new_y = getY(); height += new_y - y; } } else { // word didn't overflow, rewrite it with properties. goToXY(x, y); write_word(true); } if (generate_height_only) { // move to the first line, since when we do // generation, m_real_height = m_height and we // don't have many lines to use. goToXY(getX(), 0); y = 0; } } // load remaining properties if there are any for (; p != ps.end(); ++p) w << *p; return height; }; m_real_height = std::max(write_buffer(true), m_height); if (m_real_height > m_height) recreate(m_width, m_real_height); else werase(m_window); write_buffer(false); }
/** * Affiche la légende du jeu. */ static void drawPanel() { setColor(GRAY_COLOR); goToXY(INFOPANEL_X, 4); setColor(getCaseColor(HERO_CHAR)); printf("%c", convertCase(HERO_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Personnage"); goToXY(INFOPANEL_X, 5); setColor(getCaseColor(WALL_CHAR)); printf("%c", convertCase(WALL_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Mur"); goToXY(INFOPANEL_X, 6); setColor(getCaseColor(DOOR_CHAR)); printf("%c", convertCase(DOOR_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Porte de sortie"); goToXY(INFOPANEL_X, 7); setColor(getCaseColor(THIN_CHAR)); printf("%c", convertCase(THIN_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Glace fine"); goToXY(INFOPANEL_X, 8); setColor(getCaseColor(THICK_CHAR)); printf("%c", convertCase(THICK_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Glace epaisse"); goToXY(INFOPANEL_X, 9); setColor(getCaseColor(SLIP_CHAR)); printf("%c", convertCase(SLIP_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Glace glissante"); goToXY(INFOPANEL_X, 10); setColor(getCaseColor(MELT_CHAR)); printf("%c", convertCase(MELT_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Eau"); goToXY(INFOPANEL_X, 11); setColor(getCaseColor(LIGHTNESS_POTION_CHAR)); printf("%c", convertCase(LIGHTNESS_POTION_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Potion de legerete"); goToXY(INFOPANEL_X, 12); setColor(getCaseColor(SCORE_BONUS_CHAR)); printf("%c", convertCase(SCORE_BONUS_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Bonus de score"); goToXY(INFOPANEL_X, 13); setColor(getCaseColor(TUNNEL_CHAR)); printf("%c", convertCase(TUNNEL_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Tunnel"); goToXY(INFOPANEL_X, 14); setColor(getCaseColor(MOWER_CHAR)); printf("%c", convertCase(MOWER_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Tondeuse"); goToXY(INFOPANEL_X, 15); setColor(getCaseColor(HOLE_CHAR)); printf("%c", convertCase(HOLE_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Trou"); goToXY(INFOPANEL_X, 16); setColor(getCaseColor(ENEMY_CHAR)); printf("%c", convertCase(ENEMY_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Ennemi"); goToXY(INFOPANEL_X, 18); printf("%s %4s\n", "(p)", "Pause"); goToXY(INFOPANEL_X, 19); printf("%s %4s\n", "(r)", "Recommencer le niveau"); goToXY(INFOPANEL_X, 20); printf("%s %2s\n", "(q)", "Quitter"); resetColor(); }
/** * Affiche le temps de jeu. * @param game L'état du jeu */ void drawTime(GameState* game) { goToXY(INFOPANEL_X, 2); printf("Temps %3.0f\n", game->timePlayed + game->timeTmp); }
/** * Affiche les informations du jeu. * @param game L'état actuel du jeu */ void drawToolbar(const GameState* game) { goToXY(INFOPANEL_X, 0); printf("Niveau %2u\n", game->level); goToXY(INFOPANEL_X, 1); printf("Score %3u\n", game->score + game->levelScore); }