示例#1
0
//
// run() - The control layer between the user and the player is here
//
// This method handles major game logic surrounding the player's actions.
// Everything dictated by the user takes place here
//
// Note: The coordinates of the map are still based on curses
// ie, 0,0 is top left.
//
void player::run()
{
	bool done = false;
	while( done == false )
	{
		command input = get_command();
		switch( input )
		{
			case WEST:
			case EAST:
			case NORTH:
			case SOUTH:
			case NW:
			case NE:
			case SW:
			case SE:
				done = move( input );
				break;
			case QUIT:
				done = true;
				gen_map();
				clear_screen();
				break;
			case SAVE:
				done = true;
				save_game();
				break;
		}
	}
}
示例#2
0
文件: get_lc.c 项目: sebastiencs/BSQ
int	get_option(int argc, char **argv)
{
  int	i;
  int	flag_c;

  i = 1;
  flag_c = 0;
  while (i < argc)
  {
    if (argv[i][0] == '-')
    {
      if (argv[i][1] == 'c')
	flag_c = 1;
      else if (argv[i][1] == 'g')
	return (gen_map(argc, argv));
      else
      {
	my_putstr_error("./bsq: invalid option -- '");
	my_putchar_error(argv[i][1]);
	my_putstr_error("\'\n");
	return (-1);
      }
    }
    i = i + 1;
  }
  return (flag_c);
}
示例#3
0
文件: maps.c 项目: PatzHum/rpg
//initialize a map
void load_map(Game* game, TMX_map* map){
    fprintf(fpLog, "Loading map...\n");
    int i, j;

    FILE* fp;
    char dir[128] = "";
    //get size of map
    sprintf(dir, "res/maps/%s/map.map", game->active_map);
    fp = fopen(dir, "r");
    if(game->debug && fp == NULL){
        fprintf(fpLog, "File not opened map.map\n");
    }

    get_dims(fp, &map->w, &map->l);

    //allocate memory for map
    map->tmx = (int**) malloc(map->l * sizeof(int));
    for(i = 0; i < map->l; ++i){
        map->tmx[i] = (int*) malloc(map->w * sizeof(int));
        for(j = 0; j < map->w; ++j){
            //scan in map to locaiton
            fscanf(fp, "%d", &map->tmx[i][j]);
        }
    }
    fclose(fp);

    //get tilemap
    sprintf(dir, "res/maps/%s/tilemap.bmp", game->active_map);
    if ((map->tilemap = load_bitmap(dir, NULL)) == NULL){
        fprintf(fpLog, "Failed to load tilemap\n");
    }

    map->blocker_values = NULL;
    sprintf(dir, "res/maps/%s/settings.map", game->active_map);
    int temp;
    int cR, cG, cB;

    fp = fopen(dir, "r");
    if(game->debug && fp == NULL){
        fprintf(fpLog, "File not opened settings.map\n");
    }

    //get and set default background color
    fscanf(fp, "%d %d %d", &cR, &cG, &cB);
    map->bgCol = makecol(cR, cG, cB);

    i = 0;
    while(fscanf(fp, "%d", &temp) != EOF){
        map->blocker_values = (int*) realloc(map->blocker_values,
                                             (++i) * sizeof(int));
        map->blocker_values[i-1] = temp;
    }
    map->blocker_val_count = i;
    //generate background
    map->map = NULL;
    gen_map(map);
}END_OF_FUNCTION(load_map);
示例#4
0
static void
gen_tf (const struct parse_tf *tf, FILE *out, FILE *f_strs, const array_t *arrs,
        int narrs)
{
    char *buf_deps, *buf_ports;
    size_t sz_deps, sz_ports;
    FILE *f_ports = open_memstream (&buf_ports, &sz_ports);
    FILE *f_deps = open_memstream (&buf_deps, &sz_deps);

    int start = ftell (out);
    struct tf hdr = {ftell (f_strs) + VALID_OFS, tf->nrules};

    if (tf->prefix) fwrite (tf->prefix, 1, strlen (tf->prefix) + 1, f_strs);
    else hdr.prefix = 0;
    fwrite (&hdr, sizeof hdr, 1, out);
    /* TODO: Alignment? */

    struct rule rules[hdr.nrules];
    memset (rules, 0, sizeof rules);

    int i = 0;
    for (struct parse_rule *r = tf->rules.head; r; r = r->next, i++) {
        struct rule *tmp = &rules[i];
        tmp->idx = r->idx;
        tmp->in = gen_ports (ARR (r->in), r->in.n, f_ports);
        tmp->out = gen_ports (ARR (r->out), r->out.n, f_ports);
        tmp->match = arr_find (r->match, arrs, narrs);
        tmp->mask = arr_find (r->mask, arrs, narrs);
        tmp->rewrite = arr_find (r->rewrite, arrs, narrs);
        if (r->deps.head) tmp->deps = gen_deps (&r->deps, f_deps, f_ports, arrs, narrs);
        //tmp->desc = barfoo;
    }
    fclose (f_ports);
    fclose (f_deps);

    qsort (rules, hdr.nrules, sizeof *rules, rule_cmp);
    fwrite (rules, hdr.nrules, sizeof *rules, out);

    hdr.map_ofs = ftell (out) - start;
    gen_map (out, &tf->in_map, rules, ARR_LEN (rules));

    hdr.ports_ofs = ftell (out) - start;
    fwrite (buf_ports, 1, sz_ports, out);
    free (buf_ports);

    hdr.deps_ofs = ftell (out) - start;
    fwrite (buf_deps, 1, sz_deps, out);
    free (buf_deps);

    int end = ftell (out);
    fseek (out, start, SEEK_SET);
    fwrite (&hdr, sizeof hdr, 1, out);
    fseek (out, end, SEEK_SET);
}
示例#5
0
int main(){
  cout<<"Begin---"<<endl;

  Timer gen_timer, main_timer;
  gen_timer.start();
  gen_map();
  gen_timer.stop();


  cout<<"Generating the grid took "<<gen_timer.getTime() << " seconds."<<endl;
  main_timer.start();
  for( int i=0; i<iterations; i++){
    update( map, back); 
    swap( map, back);
  }
  main_timer.stop();

  cout<<"Performed "<<iterations<<" steps of a grid with a side lenth of "<<side_length<<
    " in "<<main_timer.getTime()<<" seconds."<<endl;

  cout<<"END-----"<<endl;
}
示例#6
0
文件: map.c 项目: long5313828/ythtbbs
int load_maps() {
	int shmid;
	key_t shmkey = 12345;
	size_t shmsize = sizeof(McMap) * 3 * 5;

	shmid = shmget(shmkey, shmsize, 0);
	if (shmid < 0) {
		shmid = shmget(shmkey, shmsize, IPC_CREAT | 0644);
		maps = shmat(shmid, NULL, 0);
		if((void*)maps == (void*)-1)
			return -1;
		memset(maps, 0, shmsize);
		maps[0].row = 18;
		maps[0].col = 32;
		maps[0].lvl= 3;
		return gen_map(&maps[0], 0.618);
	} else {
		maps = shmat(shmid, NULL, 0);
	}
	if((void*)maps == (void*)-1)
		return -1;
	return 0;
}
示例#7
0
static void gen_rse( qli_nod* node, qli_req* request)
{
/**************************************
 *
 *	g e n _ r s e
 *
 **************************************
 *
 * Functional description
 *	Generate a record selection expression.
 *
 **************************************/

	qli_rlb* rlb = CHECK_RLB(request->req_blr);

	if ((nod_t) (IPTR) node->nod_arg[e_rse_join_type] == nod_nothing)
		STUFF(blr_rse);
	else
		STUFF(blr_rs_stream);
	STUFF(node->nod_count);

	// Check for aggregate case
	qli_nod* list;
	qli_ctx* context = (qli_ctx*) node->nod_arg[e_rse_count];

	if (context->ctx_sub_rse)
	{
		STUFF(blr_aggregate);
		STUFF(context->ctx_context);
		gen_rse(context->ctx_sub_rse, request);
		STUFF(blr_group_by);
		if (list = node->nod_arg[e_rse_group_by])
		{
			request->req_flags |= REQ_group_by;
			STUFF(list->nod_count);
			qli_nod** ptr = list->nod_arg;
			for (const qli_nod* const* const end = ptr + list->nod_count; ptr < end; ++ptr)
			{
				gen_expression(*ptr, request);
			}
			request->req_flags &= ~REQ_group_by;
		}
		else
			STUFF(0);
		gen_map(context->ctx_map, request);
		if (list = node->nod_arg[e_rse_having])
		{
			STUFF(blr_boolean);
			gen_expression(list, request);
		}
		if (list = node->nod_arg[e_rse_sort])
			gen_sort(list, request, blr_sort);
		STUFF(blr_end);
		return;
	}

	// Make relation clauses for all relations

	qli_nod** ptr = &node->nod_arg[e_rse_count];
	for (const qli_nod* const* const end = ptr + node->nod_count; ptr < end; ++ptr)
	{
		context = (qli_ctx*) *ptr;
		if (context->ctx_stream)
			gen_rse(context->ctx_stream, request);
		else
		{
			const qli_rel* relation = context->ctx_relation;
			STUFF(blr_rid);
			STUFF_WORD(relation->rel_id);
			STUFF(context->ctx_context);
		}
	}

	// Handle various clauses

	if (list = node->nod_arg[e_rse_first])
	{
		STUFF(blr_first);
		gen_expression(list, request);
	}

	if (list = node->nod_arg[e_rse_boolean])
	{
		STUFF(blr_boolean);
		gen_expression(list, request);
	}

	if (list = node->nod_arg[e_rse_sort])
		gen_sort(list, request, blr_sort);

	if (list = node->nod_arg[e_rse_reduced])
		gen_sort(list, request, blr_project);

	const nod_t join_type = (nod_t) (IPTR) node->nod_arg[e_rse_join_type];
	if (join_type != nod_nothing && join_type != nod_join_inner)
	{
		STUFF(blr_join_type);
		switch (join_type)
		{
		case nod_join_left:
			STUFF(blr_left);
			break;
		case nod_join_right:
			STUFF(blr_right);
			break;
		default:
			STUFF(blr_full);
		}
	}

	STUFF(blr_end);
}