示例#1
0
文件: score.c 项目: EpicMan/angband
/*
 * Predict the players location, and display it.
 */
void predict_score(void)
{
	int j;
	high_score the_score;

	high_score scores[MAX_HISCORES];


	/* Read scores, place current score */
	highscore_read(scores, N_ELEMENTS(scores));
	build_score(&the_score, "nobody (yet!)", NULL);

	if (p_ptr->is_dead)
		j = highscore_where(&the_score, scores, N_ELEMENTS(scores));
	else
		j = highscore_add(&the_score, scores, N_ELEMENTS(scores));

	/* Hack -- Display the top fifteen scores */
	if (j < 10)
	{
		display_scores_aux(scores, 0, 15, j);
	}

	/* Display some "useful" scores */
	else
	{
		display_scores_aux(scores, 0, 5, -1);
		display_scores_aux(scores, j - 2, j + 7, j);
	}
}
void highscore_show(int numb) {
    highscore_add("player name",numb);
     while(!keyboard_check(27 /*vk_escape*/)) {
    draw_highscore(20, 0, room_width-20, room_height);

         screen_refresh();
         io_handle();
     }
}
示例#3
0
int highscore_new(struct highscorelist * list, struct gamedata * gamedata, char * notes)
{
  int level;
  struct playback * playback;
  int position;

  position = -1;
  playback = gamedata->playback;
  
  assert(playback != NULL);
  if(playback != NULL)
    {
      while(playback->next != NULL)
        playback = playback->next;
      level = playback->level;
      
      int playback_id;

      playback_id = 0;
      for(size_t i = 0; i < list->highscores_size; i++)
        if(list->highscores[i] != NULL)
          if(list->highscores[i]->playback_id >= playback_id)
            playback_id = list->highscores[i]->playback_id;
      playback_id += 1;

      struct playback * save_playback;

      save_playback = NULL;
      switch(playback->game_mode)
        {
        case GAME_MODE_CLASSIC:
        case GAME_MODE_ADVENTURE:
          save_playback = gamedata->playback;
          break;
        case GAME_MODE_PYJAMA_PARTY:
          break;
        }

      position = highscore_add(list, time(NULL), gamedata->score, gamedata->diamond_score, gamedata->diamonds, playback->game_mode, playback->cave, level, gamedata->starting_girls, gamedata->traits, true, playback_id, save_playback, notes);
      if(position >= 0)
        {
          list->highscores_dirty = 1;
          if(save_playback == gamedata->playback)
            gamedata->playback = NULL; /* Because the pointer was simply copied in highscore_add() */
        }
    }

  return position;
}
示例#4
0
文件: menu.c 项目: slaeshjag/svgestim
void gameover_handle(DARNIT_KEYS *keys, DARNIT_MOUSE *mouse) {
	if (highscore_is_new(score)) {
		d_render_begin();
		if (d_menu_loop(highscore.name) != -1) {
			if (*highscore.name_buff < 0x20)
				sprintf(highscore.name_buff, "arne.");
			highscore_add(score, highscore.name_buff);
			gamestate(GAMESTATE_HIGHSCORE);
		}
		d_render_end();
	}

	else if(keys->start)
		gamestate(GAMESTATE_MENU);
}
示例#5
0
/**
 * Enters a players name on a hi-score table, if "legal".
 *
 * Assumes "signals_ignore_tstp()" has been called.
 */
void enter_score(time_t *death_time)
{
	int j;

	/* Cheaters are not scored */
	for (j = 0; j < OPT_MAX; ++j) {
		if (option_type(j) != OP_SCORE)
			continue;
		if (!player->opts.opt[j])
			continue;

		msg("Score not registered for cheaters.");
		event_signal(EVENT_MESSAGE_FLUSH);
		return;
	}

	/* Add a new entry, if allowed */
	if (player->noscore & (NOSCORE_WIZARD | NOSCORE_DEBUG)) {
		msg("Score not registered for wizards.");
		event_signal(EVENT_MESSAGE_FLUSH);
	} else if (!player->total_winner &&
			   streq(player->died_from, "Interrupting")) {
		msg("Score not registered due to interruption.");
		event_signal(EVENT_MESSAGE_FLUSH);
	} else if (!player->total_winner && streq(player->died_from, "Quitting")) {
		msg("Score not registered due to quitting.");
		event_signal(EVENT_MESSAGE_FLUSH);
	} else {
		high_score entry;
		high_score scores[MAX_HISCORES];

		build_score(&entry, player->died_from, death_time);

		highscore_read(scores, N_ELEMENTS(scores));
		highscore_add(&entry, scores, N_ELEMENTS(scores));
		highscore_write(scores, N_ELEMENTS(scores));
	}

	/* Success */
	return;
}
void highscore_add_current() {
    highscore_add("Ask for Name!", score);
}
示例#7
0
文件: score.c 项目: EpicMan/angband
/*
 * Enters a players name on a hi-score table, if "legal".
 *
 * Assumes "signals_ignore_tstp()" has been called.
 */
void enter_score(time_t *death_time)
{
	int j;

	/* Cheaters are not scored */
	for (j = OPT_SCORE; j < OPT_MAX; ++j)
	{
		if (!op_ptr->opt[j]) continue;

		msg_print("Score not registered for cheaters.");
		message_flush();
		return;
	}

	/* Wizard-mode pre-empts scoring */
	if (p_ptr->noscore & (NOSCORE_WIZARD | NOSCORE_DEBUG))
	{
		msg_print("Score not registered for wizards.");
		message_flush();
	}

#ifndef SCORE_BORGS

	/* Borg-mode pre-empts scoring */
	else if (p_ptr->noscore & NOSCORE_BORG)
	{
		msg_print("Score not registered for borgs.");
		message_flush();
	}

#endif /* SCORE_BORGS */

	/* Hack -- Interupted */
	else if (!p_ptr->total_winner && streq(p_ptr->died_from, "Interrupting"))
	{
		msg_print("Score not registered due to interruption.");
		message_flush();
	}

	/* Hack -- Quitter */
	else if (!p_ptr->total_winner && streq(p_ptr->died_from, "Quitting"))
	{
		msg_print("Score not registered due to quitting.");
		message_flush();
	}

	/* Add a new entry to the score list, see where it went */
	else
	{
		high_score entry;
		high_score scores[MAX_HISCORES];

		build_score(&entry, p_ptr->died_from, death_time);

		highscore_read(scores, N_ELEMENTS(scores));
		highscore_add(&entry, scores, N_ELEMENTS(scores));
		highscore_write(scores, N_ELEMENTS(scores));
	}

	/* Success */
	return;
}
示例#8
0
void menu_func_play_game(){
	while(JOY_direction(JOY_x_pos(), JOY_y_pos()) == NEUTRAL){
		//Waits for the player to start the game
	}
	
	can_message_t start_game_message;
	start_game_message.id = 1;
	start_game_message.length = 1;
	start_game_message.data[0] = device;
	CAN_message_send(&start_game_message);
	
	while( ((PIND & (1<< PD2)) == (1<<PD2)) ){
		//Waiting for response from node 2
	}

	can_message_t can_receive = CAN_data_receive();

	
	if (can_receive.id == 5)
	{				

		menu_func_OLED_game_print(can_receive.data[0],(uint16_t)(can_receive.data[2]<<8)+can_receive.data[1] , "Playing Game");

		while( can_receive.id != 2 ){ // Waits until Node 2 sends a game over message
		

			can_message_t joy_status;
			joy_status.id = 4;
			joy_status.length = 3;
			if (device == 1)								//Joystick
			{
				joy_status.data[0] = JOY_button(0);
				joy_status.data[1] = JOY_y_pos_raw();
				joy_status.data[2] = JOY_x_pos_raw();
				
			}
			if (device == 2)								//Slider
			{
				joy_status.data[0] = JOY_button(0);
				joy_status.data[1] = JOY_y_pos_raw();
				joy_status.data[2] = JOY_slider(1);
				
			}
			
			if (device == 3)								//Ultrasonic
			{
				joy_status.length = 2;
				joy_status.data[0] = JOY_button(0);
				joy_status.data[1] = JOY_y_pos_raw();		
			}
			
			
			CAN_message_send(&joy_status);
			
			if( !((PIND & (1<< PD2)) == (1<<PD2)) ){	//If can_msg from node 2
				can_receive = CAN_data_receive();
				if(can_receive.id == 3){
					
					menu_func_OLED_game_print(can_receive.data[0],((can_receive.data[2] << 8) + can_receive.data[1]) , "Playing Game");

				}			
			}
		}
	}
	
	menu_func_OLED_game_print(can_receive.data[0],((can_receive.data[2] << 8) + can_receive.data[1]) , "GAME OVER!");
	
	printf("GAME OVER! \n");

	uint8_t position = 0;
	position = highscore_add((can_receive.data[2] << 8) + can_receive.data[1]);
	if(position == 1){
		OLED_pos(4,0x20);
		OLED_print_string("NEW HIGHSCORE!");
	}
	
}
示例#9
0
/*
 * Enters a players name on a hi-score table, if "legal", and in any
 * case, displays some relevant portion of the high score list.
 *
 * Assumes "signals_ignore_tstp()" has been called.
 */
errr top_twenty(void)
{
    int          j;

    high_score   the_score;

    time_t ct = time((time_t*)0);

    errr err;

    /* Clear the record */
    (void)WIPE(&the_score, high_score);

    /* Save the version */
    sprintf(the_score.what, "%u.%u.%u",
        VER_MAJOR, VER_MINOR, VER_PATCH);

    /* Calculate and save the points */
    sprintf(the_score.pts, "%9ld", (long)total_points());
    the_score.pts[9] = '\0';

    /* Save the current gold */
    sprintf(the_score.gold, "%9d", p_ptr->au);
    the_score.gold[9] = '\0';

    /* Save the current turn */
    sprintf(the_score.turns, "%9d", turn_real(turn));
    the_score.turns[9] = '\0';

#ifdef HIGHSCORE_DATE_HACK
    /* Save the date in a hacked up form (9 chars) */
    (void)sprintf(the_score.day, "%-.6s %-.2s", ctime(&ct) + 4, ctime(&ct) + 22);
#else
    /* Save the date in standard form (8 chars) */
/*    (void)strftime(the_score.day, 9, "%m/%d/%y", localtime(&ct)); */
    /* Save the date in standard encoded form (9 chars) */
    strftime(the_score.day, 10, "@%Y%m%d", localtime(&ct));
#endif

    /* Save the player name (15 chars) */
    sprintf(the_score.who, "%-.15s", player_name);

    /* Save the player info XXX XXX XXX */
    sprintf(the_score.uid, "%7u", player_uid);
    sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f'));
    sprintf(the_score.p_r, "%2d", p_ptr->prace);
    sprintf(the_score.p_c, "%2d", p_ptr->pclass);
    sprintf(the_score.p_a, "%2d", p_ptr->personality);

    /* Save the level and such */
    sprintf(the_score.cur_lev, "%3d", p_ptr->lev);
    sprintf(the_score.cur_dun, "%3d", dun_level);
    sprintf(the_score.max_lev, "%3d", p_ptr->max_plv);
    sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]);

    /* Save the cause of death (31 chars) */
    if (strlen(p_ptr->died_from) >= sizeof(the_score.how))
    {
        my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 3);
        strcat(the_score.how, "...");
    }
    else
    {
        strcpy(the_score.how, p_ptr->died_from);
    }

    /* Grab permissions */
    safe_setuid_grab();

    /* Lock (for writing) the highscore file, or fail */
    err = fd_lock(highscore_fd, F_WRLCK);

    /* Drop permissions */
    safe_setuid_drop();

    if (err) return (1);

    /* Add a new entry to the score list, see where it went */
    j = highscore_add(&the_score);

    /* Grab permissions */
    safe_setuid_grab();

    /* Unlock the highscore file, or fail */
    err = fd_lock(highscore_fd, F_UNLCK);

    /* Drop permissions */
    safe_setuid_drop();

    if (err) return (1);


    /* Hack -- Display the top fifteen scores */
    if (j < 10)
    {
        display_scores_aux(0, 15, j, NULL);
    }

    /* Display the scores surrounding the player */
    else
    {
        display_scores_aux(0, 5, j, NULL);
        display_scores_aux(j - 2, j + 7, j, NULL);
    }


    /* Success */
    return (0);
}
示例#10
0
void highscores_load(struct highscorelist * list, enum GAME_MODE game_mode, const char * cave)
{
#ifdef PROFILING

  if(list || cave || game_mode)
    {
    }
#else

  FILE * fp;
  
  { /* Free the old entries. Save other variables. */
    char * tmp;

    tmp = list->filename;
    list->filename = NULL;
    highscores_free(list);
    list->filename = tmp;
  }

  list->highscores_dirty = 0;

  if(list->filename == NULL)
    list->filename = highscore_filename(game_mode, cave);
  assert(list->filename != NULL);

  fp = fopen(get_save_filename(list->filename), "rb");
  if(fp != NULL)
    {
      int done;
      int i;
      char header[4];
      int version;
      int ok;

      version = 1; /* Version 1 did not have any header. */
      if(fread(header, 4, 1, fp) == 1) /* Header will always be 4 characters. */
        {
          if(memcmp(header, FILE_HEADER_V2, 4) == 0)
            version = 2;
          else if(memcmp(header, FILE_HEADER_V3, 4) == 0)
            version = 3;
          else if(memcmp(header, FILE_HEADER_V4, 4) == 0)
            version = 4;
          else if(memcmp(header, FILE_HEADER_V5, 4) == 0)
            version = 5;
        }

      if(version == 1)
        rewind(fp);

      ok = 1;
      if(version >= 3)
        {
          if(ok)
            ok = fread(&list->total.caves_entered,      sizeof list->total.caves_entered,      1, fp);
          if(ok)
            ok = fread(&list->total.levels_completed,   sizeof list->total.levels_completed,   1, fp);
          if(ok)
            ok = fread(&list->total.diamonds_collected, sizeof list->total.diamonds_collected, 1, fp);
          if(ok)
            ok = fread(&list->total.girls_died,         sizeof list->total.girls_died,         1, fp);
        }

      done = 0;
      i = 0;
      while(ok && !done)
	{
	  struct highscore_entry tmp;
          char tmp_cave[0xff];

          if(ok)
            ok = fread(&tmp.timestamp, sizeof tmp.timestamp, 1, fp);
	  if(ok)
	    ok = fread(&tmp.score, sizeof tmp.score, 1, fp);
          
          tmp.diamonds_collected = 0;
          if(version >= 3)
            if(ok)
              ok = fread(&tmp.diamonds_collected, sizeof tmp.diamonds_collected, 1, fp);

	  if(ok)
	    ok = fread(&tmp.level, sizeof tmp.level, 1, fp);

          tmp.playback_id = 0;
          if(version >= 2)
            if(ok)
              ok = fread(&tmp.playback_id, sizeof tmp.playback_id, 1, fp);

          if(cave != NULL)
            strcpy(tmp_cave, cave);
          else
            strcpy(tmp_cave, "");
          
          strcpy(tmp.notes, "");

          if(version >= 3)
            {
              if(ok)
                { /* Cave name. */
                  uint8_t len;
              
                  ok = fread(&len, sizeof len, 1, fp);
                  if(ok)
                    {
                      assert(len < sizeof tmp_cave);
                      assert(len > 0);
                      ok = fread(tmp_cave, len, 1, fp);
                      tmp_cave[len] = '\0';
                    }
                }
              if(ok)
                { /* Notes */
                  uint8_t len;
              
                  ok = fread(&len, sizeof len, 1, fp);
                  if(ok)
                    {
                      assert(len < sizeof tmp.notes);
                      if(len > 0)
                        ok = fread(tmp.notes, len, 1, fp);
                      tmp.notes[len] = '\0';
                    }
                }
            }

          if(version >= 4)
            {
              if(ok)
                ok = fread(&tmp.diamond_score, sizeof tmp.diamond_score, 1, fp);
              if(ok)
                ok = fread(&tmp.starting_girls, sizeof tmp.starting_girls, 1, fp);

              if(ok)
                {
                  if(version == 4)
                    {
                      uint16_t t;

                      ok = fread(&t, sizeof t, 1, fp);
                      tmp.traits = t;
                    }
                  else /* if(version >= 5) */
                    {
                      ok = fread(&tmp.traits, sizeof tmp.traits, 1, fp);
                    }
                }
            }
          else
            {
              tmp.diamond_score  = 0;
              tmp.starting_girls = 3;
              tmp.traits         = 0;
            }

	  if(ok)
	    {
	      highscore_add(list, tmp.timestamp, tmp.score, tmp.diamond_score, tmp.diamonds_collected, game_mode, tmp_cave, tmp.level, tmp.starting_girls, tmp.traits, false, tmp.playback_id, NULL, tmp.notes);
              i++;
	    }
	  else
	    {
	      if(!feof(fp))
		fprintf(stderr, "Failed to read highscores from %s: %s\n", get_save_filename(list->filename), strerror(errno));
	      done = 1;
	    }
	}
      fclose(fp);
    }

#endif
}