static void ChangeShape(INT16 *x, INT16 *y, INT8 *CurrentShape, INT8 *Status) { if (Possible(*x, *y, *CurrentShape, ((*Status) + 1) % 4)) { hide(*x, *y, *CurrentShape, *Status); *Status = ((*Status) + 1) % 4; } show(*x, *y, *CurrentShape, *Status, BLOCK_ACTIVE); }
static void GoRight(INT16 *x, INT16 *y, INT8 *CurrentShape, INT8 *Status) { if (Possible((*x) + 1, *y, *CurrentShape, *Status)) { hide(*x, *y, *CurrentShape, *Status); (*x)++; } show(*x, *y, *CurrentShape, *Status, BLOCK_ACTIVE); }
int main(int argc, char* argv[]) { // Generate a set of on-hand ingredients AvailableIngredients on_hand; on_hand.insert(AvailableIngredient(5, Large, Potato)); // Generate stuff that's in the pantry AvailableIngredients pantry; pantry.insert(AvailableIngredient(Egg)); pantry.insert(AvailableIngredient(Water)); // Compare against a big list of recipes Recipes recipes; // Create some test recipes Recipe r1; r1.Add(RecipeIngredient(3, 4, Large, Potato)); r1.Add(RecipeIngredient(5, 5, Large, Egg)); r1.Add(RecipeIngredient(1, 1, Tablespoon, Water)); recipes.push_back(r1); Recipe r2; r2.Add(RecipeIngredient(6, 7, Large, Potato)); recipes.push_back(r2); Recipe r3; r3.Add(RecipeIngredient(5, 5, Large, Potato)); recipes.push_back(r3); // Go through all recipes and eliminate anything that's impossible // Also, store the scores of anything possible ScoredRecipes possible; for (auto i = recipes.cbegin(); i != recipes.cend(); ++i) { double s = i->Possible(on_hand, pantry); if (s > 0) { possible.push_back(std::make_pair(*i, s));; } } // Sort the recipes by score std::sort( possible.begin(), possible.end(), [](ScoredRecipe const& r1, ScoredRecipe const& r2) { return r1.second > r2.second; } ); return EXIT_SUCCESS; }
static BOOL GoDown(INT16 *x, INT16 *y, INT8 *CurrentShape, INT8 *Status) { INT8 AllAreOne = 1, removed_lines = 0; INT8 i, j, r, l, rr, ll; UINT8 back_saved; if (Possible(*x, (*y) + 1, *CurrentShape, *Status)) { hide(*x, *y, *CurrentShape, *Status); (*y)++; show(*x, *y, *CurrentShape, *Status, BLOCK_ACTIVE); return TRUE; } normal_speed(); for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { back[i + *y][j + *x] += shape[*CurrentShape][*Status][i][j]; } } for (r = 1; r < MAXY; r++)//20 { for (l = 2; l < 2 + MAXX; l++)//13 { if (back[r][l] == 0) { AllAreOne = 0; } } if (AllAreOne == 1) { for (rr = r; rr > 0; rr--) { for (ll = 2; ll < 2 + MAXX; ll++) { back[rr][ll] = back[rr - 1][ll]; } } for (ll = 2; ll < 2 + MAXX; ll++) { back[0][ll] = 0; }//the upper line will be all zero which represented the line is blank Erasered++; if((!(Erasered % 30)) && (Speed < 10)) { Speed++; osal_timer_set(GAME_CYCLIC_ID, TimeDelay[Speed - 1]); } removed_lines++; } AllAreOne = 1; } show(*x, *y, *CurrentShape, *Status, BLOCK_INACTIVE); //sunk the button CreateNewShape(x, y, CurrentShape, Status); if (!Possible(*x, *y, *CurrentShape, *Status)) { playing = FALSE; osal_timer_activate(GAME_CYCLIC_ID, FALSE); win_compopup_init(WIN_POPUP_TYPE_OK); win_compopup_set_frame(GET_MID_L(250), GET_MID_T(130), 250, 130); win_compopup_set_msg(NULL, NULL, RS_GAME_SORRY_YOU_LOST); win_compopup_open_ext(&back_saved); tetris_init(); update_status(Speed, Erasered, TotalMark); tetris_redraw_main(); tetris_redraw_preview(); OSD_SetAttr((POBJECT_HEAD)&txt_start, C_ATTR_ACTIVE); OSD_ChangeFocus((POBJECT_HEAD)&game_con, 1, \ C_UPDATE_FOCUS | C_DRAW_SIGN_EVN_FLG); } TotalMark += (Speed + 1) * (10 + removed_lines - 1) * removed_lines; update_status(Speed, Erasered, TotalMark); if (removed_lines > 0) { tetris_redraw_main(); } if (playing == TRUE) { show(*x, *y, *CurrentShape, *Status, BLOCK_ACTIVE); } return FALSE; }