Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.highscore

Class EM_LOCAL_HIGHSCORE


Direct ancestors

XM_CALLBACKS_FILTER_FACTORY, EM_TIME_SINGLETON, EM_SHARED_USER_DIRECTORY, EM_SHARED_APPLICATION_ID

Known direct descendants

EM_HIGHSCORE

Creation

Features

Invariants

indexing

description

Highscore class. Highscore is stored locally. You can add and update entries,
sort and crop the highscore.

date

$Date: 2005/10/26 15:41:47 $

revision

$Revision: 1.14 $

class

EM_LOCAL_HIGHSCORE

inherit

EM_SHARED_APPLICATION_ID

create

make

-- create highscore

require
application_id_set: application_id.item /= void
make_extended (the_other_keys: ARRAY [STRING])

-- create highscore with more keys

require
no_keywords: not has_keywords(the_other_keys)
the_other_keys /= void application_id_set: application_id.item /= void

feature -- Initialization

make

-- create highscore

require
application_id_set: application_id.item /= void
make_extended (the_other_keys: ARRAY [STRING])

-- create highscore with more keys

require
no_keywords: not has_keywords(the_other_keys)
the_other_keys /= void application_id_set: application_id.item /= void

feature -- Access

highscore_file: PLAIN_TEXT_FILE
local_highscore: DS_LINKED_LIST[like highscore_entries]

-- data structure with local highscore in it

num_of_local_entries: INTEGER

-- desired number of entries in local highscore

feature -- Element change

set_local_file (a_directory: STRING; a_filename: STRING)

-- set path for highscore file

require
a_filename /= voida_directory.item (a_directory.count) = '/'
set_num_of_local_entries (a_num_of_local_entries: like num_of_local_entries)

-- Set num_of_local_entries to a_num_of_local_entries.

ensure
num_of_local_entries_assigned: num_of_local_entries = a_num_of_local_entries

feature -- Read/Write

read_local

-- read highscore from a local file

require
file_set: highscore_file /= void
write_local

-- write local highscore to disc

require
highscore_file_set: highscore_file /= void

feature -- Add/Update entries

add_entry (a_name: STRING; a_score: INTEGER)

-- add entry to local highscore

require
name_valid: is_valid_string (a_name)
add_entry_extended (a_name: STRING; a_score: INTEGER; other_values: ARRAY[STRING])

-- add extended entry to local highscore

require
name_valid: is_valid_string (a_name)
right_number_of_values: other_values.count = other_keys.count
add_or_update_entry (a_name: STRING; a_score: INTEGER)

-- add or update entry depending on if it's already present or not

require
name_valid: is_valid_string (a_name)
add_or_update_entry_extended (a_name: STRING; a_score: INTEGER; other_values: ARRAY[STRING])

-- add or update extended entry depending of it's already present or not

require
name_valid: is_valid_string (a_name)
right_number_of_values: other_values.count = other_keys.count
has_entry (a_name: STRING): BOOLEAN

-- check if name is in local highscore

require
name_not_void: a_name /= Void
is_better (a_name: STRING; a_score: INTEGER): BOOLEAN

-- check if 'a_score' of 'a_name' is better than the one already in highscore

require
has_entry (a_name)
is_valid_character (a_char: CHARACTER): BOOLEAN

-- check if character is valid (isn't special character)

is_valid_string (a_string: STRING): BOOLEAN

-- check if string is valid (doesn't contain special characters

update_entry (the_name: STRING; the_score: INTEGER)

-- update entry in local highscore

require
name_valid: is_valid_string (the_name)
update_entry_extended (the_name: STRING; a_score: INTEGER; other_values: ARRAY[STRING])

-- update extended in local highscore

require
name_valid: is_valid_string (the_name)
right_number_of_values: other_values.count = other_keys.count

feature -- Sort and Crop

crop_local (nb_elements: INTEGER)

-- crop local highscore to 'nb_elements'

require
positive: nb_elements > 0
sort_local_by_key (a_key: STRING; sort_reverse: BOOLEAN)

-- sort local highscore by a key (alphabetical sorting)

sort_local_by_name (sort_reverse: BOOLEAN)

-- sort local highscore by name

sort_local_by_score (sort_reverse: BOOLEAN)

-- sort local highscore by score

feature -- Checksum

set_checksum_generator (a_generator: like checksum_generator)

-- set the checksum generator
-- (if you want to use your own checksum generator)

feature -- Keys

has_keywords (the_keys: ARRAY[STRING]): BOOLEAN

-- check if an array has a keyword

require
the_keys /= void
key_valid (the_key: STRING): BOOLEAN

-- check if a key is valid

require
key_not_void: the_key /= void
other_keys: ARRAY[STRING]

feature -- Application ID singleton

application_id: EM_APPLICATION_ID

-- Application ID singleton.

-- (From EM_SHARED_APPLICATION_ID)

invariant


-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

end