ferencd@0: # ferencd@0: # A class to encapsulate methods for generating a game ferencd@0: # ferencd@0: class Game ferencd@0: ferencd@0: ferencd@0: GAME_STRING_STORY = 'S' ferencd@0: GAME_STRING_ADVENTURE = 'A' ferencd@0: GAME_STRING_TIMERUN = 'T' ferencd@0: ferencd@0: # ferencd@0: # Will generate a URL for the given string ferencd@0: # The first 6 characters are the encryption key of the type ferencd@0: # What comes after is the encrypted game type (SG, AG, TG) ferencd@0: # ferencd@0: def Game.gen_game_url (type) ferencd@0: key = Utils.random_hex_string 6 ferencd@0: encrypted_game_type = type.encrypt(key) ferencd@0: return key + encrypted_game_type ferencd@0: end ferencd@0: ferencd@0: # ferencd@0: # Will create a new sotry game, generate ID and put it in the database ferencd@0: # ferencd@0: def Game.create_new_story_game ferencd@0: # Story game IDs always start with 'S' ferencd@0: game_id = Database.create_valid_game_id(GAME_STRING_STORY) ferencd@0: ferencd@0: # Insert the ID in the DB ferencd@0: Database.insert_game_id_to_db(game_id, 1, 'S') ferencd@0: ferencd@0: handle_maze_with_number(1, game_id) ferencd@0: end ferencd@0: ferencd@0: # ferencd@0: # Will create a new sotry game, generate ID and put it in the database ferencd@0: # ferencd@0: def Game.create_new_adventure_game ferencd@0: # Adventure game IDs always start with 'A' ferencd@0: game_id = Database.create_valid_game_id(GAME_STRING_ADVENTURE) ferencd@0: level_number = rand(1..Integer::MAX) % 2147483647 ferencd@0: ferencd@0: # Insert the ID in the DB and associate it with the given level ferencd@0: Database.insert_game_id_to_db(game_id, level_number, 'A') ferencd@0: Database.update_level_number_for_gid(level_number, game_id) ferencd@0: ferencd@0: handle_maze_with_number(level_number, game_id, MAIN_HTML, GAME_TYPE_ADVENTURE) ferencd@0: end ferencd@0: ferencd@0: # ferencd@0: # Will create a new sotry game, generate ID and put it in the database ferencd@0: # ferencd@0: def Game.create_new_maze_game ferencd@0: # Pure maze game IDs always start with 'T' ferencd@0: game_id = Database.create_valid_game_id(GAME_STRING_TIMERUN) ferencd@0: level_number = rand(1..Integer::MAX) % 2147483647 ferencd@0: ferencd@0: # Insert the ID in the DB and associate it with the given level ferencd@0: Database.insert_game_id_to_db(game_id, level_number, 'T') ferencd@0: Database.update_level_number_for_gid(level_number, game_id) ferencd@0: ferencd@0: handle_maze_with_number(level_number, game_id, MAIN_HTML, GAME_TYPE_MAZE) ferencd@0: end ferencd@0: ferencd@0: # ferencd@0: # Will create a game, with the specified type ferencd@0: # ferencd@0: def Game.create_game(game_type) ferencd@0: ferencd@0: code, retv = create_new_story_game if game_type == 'SG' ferencd@0: code, retv = create_new_adventure_game if game_type == 'AG' ferencd@0: code, retv = create_new_maze_game if game_type == 'TG' ferencd@0: ferencd@0: return code, retv ferencd@0: end ferencd@0: ferencd@0: end