void move_player(GameState *game, Direction dir) { Position new_pos = game->player.pos; switch (dir) { case DIRECTION_NW: case DIRECTION_N: case DIRECTION_NE: new_pos.y--; default: break; } switch (dir) { case DIRECTION_NE: case DIRECTION_E: case DIRECTION_SE: new_pos.x++; default: break; } switch (dir) { case DIRECTION_SW: case DIRECTION_S: case DIRECTION_SE: new_pos.y++; default: break; } switch (dir) { case DIRECTION_NW: case DIRECTION_W: case DIRECTION_SW: new_pos.x--; default: break; } Letter *letter = get_letter(game, new_pos); if (letter != NULL) capture_letter(letter); if (game->map[new_pos.y][new_pos.x] == TILE_EMPTY) game->player.pos = new_pos; }
// Play one game void play( char *theWord ) { int numGuess = INCORRECT_GUESSES; char soFar[ MAXWORD ]; int guessesLeft; int result; fill_array( soFar, strlen( theWord ), '*' ); for( ; numGuess > 0; numGuess-- ) { printf( "You have %d guesses left\n\n", numGuess ); result = get_letter( theWord, soFar ); if( result == 1 ) { if( strcmp( soFar, theWord ) == 0 ) { printf( "HOORAY! YOU FIGURED OUT MY WORD!\n" ); printf( "The word you guessed correctly was, in fact, %s.\n", theWord ); printf( "Now send me some Money so my code can be used by everyone!\n\n" ); break; } numGuess++; } else if( result == 0 ) { printf( "Guess again!\n\n" ); printf( "The Word you are trying to figure out so far is:\n\n" ); printf( "%s\n\n", soFar ); } } if( numGuess == 0 ) { printf( "I'm Sorry, but you did not find the word in the amount of guesses!\n\n" ); printf( "The Word you had to figure out was\t%s\n\n", theWord ); printf( "Come play again!\n" ); } }
void wpl_text::parse_value(wpl_namespace *parent_namespace) { ignore_string_match(NEWLINE, NON_NEWLINE_WS); const char *start = get_string_pointer(); const char *end; int par_level = 1; while (par_level > 0 && !at_end()) { end = get_string_pointer(); if (ignore_letter('{')) { if (ignore_string("@LOOP")) { push_chunk (start, end); wpl_text *text = new wpl_text(); wpl_expression *exp = new wpl_expression_par_enclosed(); chunks.emplace_back(new wpl_text_chunks::loop(text, exp)); parse_expression(parent_namespace, exp); ignore_string_match(NEWLINE, NON_NEWLINE_WS); parse_text(parent_namespace, text); start = get_string_pointer(); } else if (ignore_string("@CONDITION")) { push_chunk (start, end); wpl_text *text = new wpl_text(); wpl_expression *exp = new wpl_expression_par_enclosed(); wpl_text *text_else = NULL; wpl_text_chunks::condition *condition = new wpl_text_chunks::condition(text, exp); chunks.emplace_back(condition); parse_expression(parent_namespace, exp); ignore_string_match(NEWLINE, NON_NEWLINE_WS); parse_text(parent_namespace, text); start = get_string_pointer(); } else if (ignore_string("@TEMPLATE")) { push_chunk (start, end); wpl_matcher_position pos = get_position(); char name[WPL_VARNAME_SIZE]; ignore_whitespace(); get_word(name); wpl_template *my_template = parent_namespace->find_template(name); if (!my_template) { load_position(pos); THROW_ELEMENT_EXCEPTION("Unknown template name"); } chunks.emplace_back(new wpl_text_chunks::html_template(my_template)); ignore_whitespace(); if (!ignore_letter ('}')) { THROW_ELEMENT_EXCEPTION("Expected } after TEMPLATE call definition"); } start = get_string_pointer(); } else if (ignore_string("@")) { push_chunk (start, end); wpl_expression *exp = new wpl_expression_loose_end(); chunks.emplace_back(new wpl_text_chunks::expression(exp)); exp->load_position(get_position()); exp->parse_value(parent_namespace); load_position(exp->get_position()); ignore_string_match(WHITESPACE, 0); if (!ignore_letter('}')) { THROW_ELEMENT_EXCEPTION("Expected '}' after expression-in-TEXT"); } start = get_string_pointer(); } else { par_level++; } } else if (ignore_letter('}')) { par_level--; } else { if (!ignore_string_match(NON_CURLY|UTF8, 0)) { cerr << "Unknown character '" << hex << get_letter(ALL) << "'\n"; THROW_ELEMENT_EXCEPTION("Syntax error in text-string"); } } } if (par_level != 0) { THROW_ELEMENT_EXCEPTION("Excepted '}' after TEXT-block"); } end = get_string_pointer() - 2; while (M_NON_NEWLINE_WHITESPACE (*end)) { end--; } end++; if (end > start) { push_chunk (start, end); } }
void wpl_text::parse_value(wpl_namespace *parent_namespace) { ignore_string_match(NEWLINE, NON_NEWLINE_WS); const char *start = get_string_pointer(); const char *end; int par_level = 1; while (par_level > 0 && !at_end()) { end = get_string_pointer(); if (ignore_letter('{')) { if (ignore_string("@LOOP")) { push_chunk (start, end); wpl_text *text = new wpl_text(); wpl_expression *exp = new wpl_expression_par_enclosed(); chunks.emplace_back(new wpl_text_chunks::loop(text, exp)); exp->load_position(get_position()); exp->parse_value(parent_namespace); load_position(exp->get_position()); ignore_string_match(NEWLINE, NON_NEWLINE_WS); text->load_position(get_position()); text->parse_value(parent_namespace); load_position(text->get_position()); start = get_string_pointer(); } else if (ignore_string("@")) { push_chunk (start, end); wpl_expression *exp = new wpl_expression_loose_end(); chunks.emplace_back(new wpl_text_chunks::expression(exp)); exp->load_position(get_position()); exp->parse_value(parent_namespace); load_position(exp->get_position()); ignore_string_match(WHITESPACE, 0); if (!ignore_letter('}')) { THROW_ELEMENT_EXCEPTION("Expected '}' after expression-in-TEXT"); } start = get_string_pointer(); } else { par_level++; } } else if (ignore_letter('}')) { par_level--; } else { if (!ignore_string_match(NON_CURLY|UTF8, 0)) { cerr << "Unknown character '" << hex << get_letter(ALL) << "'\n"; THROW_ELEMENT_EXCEPTION("Syntax error in text-string"); } } } if (par_level != 0) { THROW_ELEMENT_EXCEPTION("Excepted '}' after TEXT-block"); } end = get_string_pointer() - 2; while (M_NON_NEWLINE_WHITESPACE (*end)) { end--; } end++; if (end > start) { push_chunk (start, end); } }
/* play one letters round */ void letters_round(void) { static int turn = 0; int i, j, k; int *player_order; /* stages: pick letters 30 second timer (let dictionary corner think during this time?) reveal word lengths reveal words assign scores dictionary corner words */ printf(" Round %d: Letters round\n", round); printf("It is %s's turn to choose letters.\n", player[turn].name); /* read letter choices and generate letters */ for(i = 0; i < num_letters; i++) get_letter(i); /* let people think */ run_timer(); /* ask each player for their word length */ for(i = 0; i < players; i++) { printf("%s, how long is your word? ", player[(i + turn) % players].name); player[(i + turn) % players].length = atoi(get_line()); } /* get an aray of players sorted by word length */ player_order = malloc(sizeof(int) * players); for(i = 0; i < players; i++) player_order[i] = i; qsort(player_order, players, sizeof(int), length_cmp); /* ask players for their word, shortest first */ for(j = 0; j < players; j++) { i = player_order[j]; if(player[i].length <= 0) { player[i].word = NULL; continue; } printf("%s, what is your %d-letter word? ", player[i].name, player[i].length); player[i].word = strdup(get_line()); if(strlen(player[i].word) != player[i].length || !valid_word(i, letter)) { free(player[i].word); /* try again once if they didn't supply a suitable word */ printf("%s, what is your real %d-letter word? ", player[i].name, player[i].length); player[i].word = strdup(get_line()); if(strlen(player[i].word) != player[i].length || !valid_word(i, letter)) player[i].length = 0; } } /* re-sort to get non-words removed */ qsort(player_order, players, sizeof(int), length_cmp); /* find the best scorers */ for(j = players - 2; j >= 0; j--) { i = player_order[j]; if(player[i].length < player[player_order[players - 1]].length) break; } /* assign points to the scorers */ for(k = players - 1; k > j; k--) { i = player_order[k]; if(player[i].length == num_letters) {/* 9 letters score double */ printf("%d points to %s.\n", num_letters * 2, player[i].name); player[i].score += num_letters * 2; } else { printf("%d points to %s.\n", player[i].length, player[i].name); player[i].score += player[i].length; } } /* TODO: display best word in the blue and white style */ /* ask dictionary corner if they got anything better */ dict_solve(letter); /* TODO: display dictionary corner's word in blue and white */ /* increment the player whose turn it is to choose letters */ round++; turn++; if(turn >= players) turn = 0; /* tidy up */ free(player_order); for(i = 0; i < players; i++) free(player[i].word); }
int draw_vector_char(framebuffer_t fb, vector_font_t *font, uint32_t c, xy_t p, xy_t off, double scale, col_t colour, double line_thick, const int mode, const int bidi) { letter_t *l; double fixoff, wc1, wc2; unicode_data_t ucd; int found = 0; // Algorithmic substitution if (bidi == -2) c = substitute_rtl_punctuation(c); process_one_glyph(font, get_letter_index(font, c)); l = get_letter(font, c); if (l) if (l->obj) { found = 1; fixoff = 0.; if ((mode&12)==MONOSPACE || ((mode&12)==MONODIGITS && c>='0' && c<='9')) fixoff = 0.5 * (4. - l->width); if (bidi == -2) fixoff -= l->br; else fixoff -= l->bl; draw_vobj(fb, l->obj, xy(p.x + off.x + fixoff*scale, p.y + off.y), scale, 0., line_thick, colour); } // Alias if (found==0 && l) if (l->alias) found |= draw_vector_char(fb, font, l->alias, p, off, scale, colour, line_thick, mode, bidi); // Combo if (found==0) { ucd = get_unicode_data(c); if (/*ucd.decomp_type == decomp_canonical &&*/ ucd.combo1) // if we have a valid combo for this character { wc1 = glyph_width(font, off.x, ucd.combo1, scale, mode); found |= draw_vector_char(fb, font, ucd.combo1, p, off, scale, colour, line_thick, mode, bidi); if (ucd.uccat == uccat_Ll) // if character is lowercase { wc2 = ((glyph_width(font, off.x, ucd.combo2, 1., mode) - LETTERSPACING) * LOWERCASESCALE + LETTERSPACING) * scale; scale *= LOWERCASESCALE; } else wc2 = glyph_width(font, off.x, ucd.combo2, scale, mode); if (bidi == -2) off.x -= (wc1 - wc2) * 0.5; else off.x += (wc1 - wc2) * 0.5; found |= draw_vector_char(fb, font, ucd.combo2, p, off, scale, colour, line_thick, mode, bidi); } } // Upper case if (found==0) if (ucd.upper_map) found |= draw_vector_char(fb, font, ucd.upper_map, p, off, scale*LOWERCASESCALE, colour, line_thick, mode, bidi); // Decomposed CJK if (found==0) found |= draw_cjkdec_glyph(fb, font, c, add_xy(p, off), scale, colour, line_thick, mode); return found; }