Exemple #1
0
// 動かすのに成功したら1、失敗したら0を返す
int movePlayer(Sugoroku *s, int player_id, enum Direction d, PositionList *plist, SugorokuStatus *ss) {
  if(player_id >= s->player_num || player_id < 0) {
    puts("player番号が頭おかしい");
    return 0;
  }
  Position pos = s->player[player_id].pos;
  Position mpos = pos; // 目的の場所
  switch(d) {
  case UP:
    mpos.y--;
    if(mpos.y < 0 || !canMove(&s->map, mpos)) return 0;
    break;
  case RIGHT:
    mpos.x++;
    if(mpos.x >= s->map.width || !canMove(&s->map, mpos)) return 0;
    break;
  case DOWN:
    mpos.y++;
    if(mpos.y >= s->map.height || !canMove(&s->map, mpos)) return 0;
    break;
  case LEFT:
    mpos.x--;
    if(mpos.x < 0 || !canMove(&s->map, mpos)) return 0;
    break;
  }

  // 既に行ったことがある場所だったら行かない
  // 一個前のとこに戻ることは出来る
  if(isExistPosition(plist, mpos)) {
    if(isPositionEqual(plist->end->pos, mpos)) {
      // 進める数を一つ戻す
      ss->move_num++;
      s->player[player_id].pos = mpos;
      popPosition(plist);
      popPosition(&s->player[player_id].footmark);
    } else {
      return 0;
    }
  } else {
    ss->move_num--;
    s->player[player_id].pos = mpos;
    pushPosition(plist, pos);
    pushPosition(&s->player[player_id].footmark, pos);
  }
  return 1;
}
Exemple #2
0
Parser::Arg Parser::verbatimStuff(string const & end_string, bool const allow_linebreak)
{
	if (!good())
		return Arg(false, string());

	pushPosition();
	ostringstream oss;
	size_t match_index = 0;
	setCatcodes(VERBATIM_CATCODES);
	for (Token t = get_token(); good(); t = get_token()) {
		// FIXME t.asInput() might be longer than we need ?
		if (t.asInput() == end_string.substr(match_index,
						     t.asInput().length())) {
			match_index += t.asInput().length();
			if (match_index >= end_string.length())
				break;
		} else {
			if (!allow_linebreak && t.asInput() == "\n") {
				cerr << "unexpected end of input" << endl;
				popPosition();
				setCatcodes(NORMAL_CATCODES);
				return Arg(false, string());
			}
			if (match_index) {
				oss << end_string.substr(0, match_index)
				    << t.asInput();
				match_index = 0;
			} else
				oss << t.asInput();
		}
	}

	if (!good()) {
		cerr << "unexpected end of input" << endl;
		popPosition();
		setCatcodes(NORMAL_CATCODES);
		return Arg(false, string());
	}
	setCatcodes(NORMAL_CATCODES);
	dropPosition();
	return Arg(true, oss.str());
}