Skip to content

Commit

Permalink
better~
Browse files Browse the repository at this point in the history
  • Loading branch information
whyisverysmart committed Jul 13, 2023
1 parent 3b46e89 commit 86087a9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main() {
Map* map = new Map(game.getGameBoardHeight(), game.getGameBoardWidth());

//指定蛇的初始化位置、length、heart
WordSnake* snake = new WordSnake(map, 10, 10, 2, 1);
WordSnake* snake = new WordSnake(map, game.getGameBoardHeight()/2, game.getGameBoardWidth()/2, 1, 3);

//随机刷新英文字母(此处简单起见,刷新26个不同字母)
setNRandomLetter(map, 26);
Expand Down
2 changes: 1 addition & 1 deletion renders/renders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ void GameBoard::startWord(Map* map, WordSnake* snake) {
//渲染蛇的末尾几位,方便对照
mvwprintw(mWindows[2], 17, 1, "--Snake-->");
wattron(mWindows[2], COLOR_PAIR(5));
mvwprintw(mWindows[2], 18, 1, snake->getString().c_str());
mvwprintw(mWindows[2], 18, 1, snake->getString().substr(0, 15).c_str());
wattroff(mWindows[2], COLOR_PAIR(5));
wrefresh(mWindows[2]);

Expand Down
23 changes: 22 additions & 1 deletion special_modes/word_snake_mode/word_snake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ bool WordSnake::moveForward() {

// 因为 eatFood 中有判定, 所以不担心误判为吃食物
tryEatFood(oldTail_x, oldTail_y, displayStr, new_food_num);
tryEatHeart();
if (tryEatHeart()) setNRandomLetter(ptrMap, 26);

// 检验是否已经拼成了单词
cutWord();

Expand Down Expand Up @@ -249,4 +250,24 @@ bool WordSnake::tryEatFood(int newTail_x, int newTail_y, std::string newTail_s,
ptrHead->get_block()->clear_item();

setNRandomLetter(ptrMap, n);
times++;

//每生成五次食物就生成一个爱心
if (times == 5) {
ptrMap->setRandomItem(ItemType::HEART, "+");
times = 0;
}
}


bool WordSnake::tryEatHeart() {
// 先检测是否有心可吃
BaseItem* item_atHead = ptrHead->get_block()->get_item();

if ( ! item_atHead || item_atHead->type() != ItemType::HEART) {return false;}

ptrHead->get_block()->clear_item();
heart++;

return true;
}
8 changes: 8 additions & 0 deletions special_modes/word_snake_mode/word_snake.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ class WordSnake: public Snake {
// 如果组成了单词, 剪掉, 并返回Entity指针
Entity* cutWord();


int getTimes() {return times;}

private:
const static SnakeType TYPE = SnakeType::WORD_SNAKE;

int new_food_num = 1;

//生成食物次数
int times = 1;

bool tryEatFood(int newTail_x, int newTail_y, std::string newTail_s, int n);

bool tryEatHeart();
};


Expand Down

0 comments on commit 86087a9

Please sign in to comment.