diff --git a/README.md b/README.md index 74961ea..7ef3d34 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,42 @@ OPEN Open something that is in the room ASK Ask a person to talk to you ``` + +# class diagram + +https://mermaid-js.github.io/mermaid/#/classDiagram + + +```mermaid +classDiagram + thing <|-- openable_thing + thing <|-- room + + class thing{ + +name + +description + +constructor() + } + + class openable_thing{ + +needed + +content + +constructor + +get_content() + +open() + +is_open() + } + + class room{ + +north + +east + +south + +west + +things: thing + +constructor() + +class_constructor() + +set_exits() + #set_exit() + + } +``` diff --git a/abaplint.json b/abaplint.json new file mode 100644 index 0000000..de1a09d --- /dev/null +++ b/abaplint.json @@ -0,0 +1,240 @@ +{ + "global": { + "files": "/src/**/*.*", + "skipGeneratedGatewayClasses": true, + "skipGeneratedPersistentClasses": true, + "skipGeneratedFunctionGroups": true + }, + "syntax": { + "version": "v753", + "errorNamespace": "^(Z|Y|LCL_|TY_|LIF_)" + }, + "dependencies": [ + { + "url": "https://github.com/abaplint/deps", + "folder": "/deps", + "files": "/src/**/*.*" + } + ], + "rules": { + "7bit_ascii": true, + "avoid_use": { + "define": true, + "testSeams": true, + "statics": true, + "break": true, + "defaultKey": true + }, + "check_syntax": true, + "class_attribute_names": false, + "cloud_types": true, + "colon_missing_space": true, + "commented_code": true, + "constructor_visibility_public": true, + "contains_tab": true, + "definitions_top": true, + "description_empty": true, + "double_space": false, + "empty_line_in_statement": { + "allowChained": false + }, + "empty_statement": true, + "empty_structure": { + "loop": true, + "if": true, + "while": true, + "case": true, + "select": true, + "do": true, + "at": true, + "try": true + }, + "exit_or_check": true, + "exporting": true, + "functional_writing": { + "ignoreExceptions": true + }, + "global_class": true, + "identical_form_names": true, + "if_in_if": true, + "in_statement_indentation": { + "ignoreExceptions": true + }, + "indentation": { + "ignoreExceptions": true, + "alignTryCatch": false, + "globalClassSkipFirst": false, + "ignoreGlobalClassDefinition": false, + "ignoreGlobalInterface": false + }, + "inline_data_old_versions": true, + "keyword_case": false, + "line_length": { + "length": 120 + }, + "line_only_punc": { + "ignoreExceptions": true + }, + "local_class_naming": { + "local": ".", + "test": ".", + "exception": "." + }, + "local_variable_names": { + "expectedData": ".", + "expectedConstant": "^C_.*$", + "expectedFS": "^<.>$" + }, + "max_one_statement": true, + "message_exists": true, + "method_length": { + "statements": 100, + "ignoreTestClasses": false, + "errorWhenEmpty": true + }, + "method_parameter_names": false, + "mix_returning": true, + "msag_consistency": true, + "nesting": { + "depth": 5 + }, + "no_public_attributes": false, + "object_naming": { + "clas": "^ZC(L|X)\\_AXAGE_", + "intf": "^ZIF\\_AXAGE_", + "prog": "^ZAXAGE_", + "fugr": "^ZAXAGE_", + "tabl": "^ZAXAGE", + "ttyp": "^ZAXAGE", + "dtel": "^ZAXAGE", + "doma": "^ZAXAGE", + "msag": "^ZAXAGE", + "tran": "^ZAXAGE", + "enqu": "^EZ_AXAGE_", + "auth": "^Z", + "pinf": "^Z", + "idoc": "^Z", + "xslt": "^Z", + "shlp": "^ZAXAGE_", + "ssfo": "^Z", + "ssst": "^Z" + }, + "obsolete_statement": { + "refresh": true, + "compute": true, + "add": false, + "subtract": false, + "multiply": false, + "move": true, + "divide": false, + "requested": true, + "occurs": true, + "setExtended": true, + "withHeaderLine": true, + "fieldSymbolStructure": true + }, + "parser_error": true, + "preferred_compare_operator": { + "badOperators": [ + "EQ", + "><", + "NE", + "GE", + "GT", + "LT", + "LE" + ] + }, + "remove_descriptions": { + "ignoreExceptions": false, + "ignoreWorkflow": true + }, + "sequential_blank": { + "lines": 4 + }, + "short_case": { + "length": 1, + "allow": [] + }, + "space_before_colon": true, + "space_before_dot": { + "ignoreGlobalDefinition": true, + "ignoreExceptions": true + }, + "start_at_tab": true, + "superclass_final": true, + "tabl_enhancement_category": true, + "unreachable_code": true, + "use_new": true, + "when_others_last": true, + "whitespace_end": true, + "ambiguous_statement": true, + "allowed_object_types": { + "allowed": [ + "PROG", + "CLAS", + "INTF", + "DEVC" + ] + }, + "begin_end_names": true, + "check_transformation_exists": true, + "form_tables_obsolete": true, + "implement_methods": true, + "local_testclass_location": true, + "main_file_contents": true, + "type_form_parameters": true, + "rfc_error_handling": true, + "abapdoc": false, + "release_idoc": true, + "prefer_returning_to_exporting": true, + "keep_single_parameter_on_one_line": false, + "allowed_object_naming": true, + "chain_mainly_declarations": true, + "fully_type_constants": true, + "check_abstract": true, + "check_comments": { + "allowEndOfLine": true + }, + "selection_screen_naming": false, + "check_text_elements": true, + "check_ddic": true, + "newline_between_methods": { + "logic": "less", + "count": 3 + }, + "check_include": true, + "xml_consistency": true, + "prefix_is_current_class": false, + "check_no_handler_pragma": true, + "line_break_multiple_parameters": false, + "forbidden_void_type": true, + "prefer_inline": false, + "reduce_string_templates": true, + "sicf_consistency": true, + "sql_escape_host_variables": true, + "try_without_catch": true, + "types_naming": false, + "unknown_types": true, + "unused_variables": true, + "begin_single_include": true, + "check_subrc": true, + "cyclomatic_complexity":{ + "max": 6 + }, + "forbidden_pseudo_and_pragma": { + "ignoreGlobalClassDefinition": false, + "ignoreGlobalInterface": false, + "pragmas": ["##NO_TEXT"], + "pseudo": ["#EC NOTEXT"] + }, + "identical_conditions": true, + "line_break_style": true, + "names_no_dash": true, + "parser_missing_space": true, + "prefer_is_not": true, + "unused_types":true, + "use_bool_expression": true, + "use_line_exists": true + } +} diff --git a/src/zaxage_demo_01.prog.abap b/src/zaxage_demo_01.prog.abap index 8a6fbd5..8d33b2e 100644 --- a/src/zaxage_demo_01.prog.abap +++ b/src/zaxage_demo_01.prog.abap @@ -15,45 +15,36 @@ REPORT zaxage_demo_01 NO STANDARD PAGE HEADING. INCLUDE zaxage_game_engine. - - CLASS main DEFINITION. PUBLIC SECTION. METHODS constructor. - METHODS interprete - IMPORTING - command TYPE clike - RETURNING - VALUE(result) TYPE REF TO result. METHODS init_view IMPORTING container TYPE REF TO cl_gui_container. METHODS init_inventory IMPORTING container TYPE REF TO cl_gui_container. - METHODS is_completed + METHODS interprete + IMPORTING + command TYPE clike RETURNING - VALUE(result) TYPE abap_bool. + VALUE(result) TYPE REF TO result. + METHODS show_inventory. METHODS get_location RETURNING VALUE(result) TYPE string. + METHODS is_completed + RETURNING + VALUE(result) TYPE abap_bool. PRIVATE SECTION. - DATA player TYPE REF TO actor. DATA bill_developer TYPE REF TO actor. DATA mark_consultant TYPE REF TO actor. - DATA map TYPE REF TO map. - DATA actors TYPE REF TO thinglist. DATA container TYPE REF TO cl_gui_container. DATA inventory_container TYPE REF TO cl_gui_container. DATA text TYPE REF TO cl_gui_textedit. DATA inventory TYPE REF TO cl_gui_textedit. - DATA mission_completed TYPE abap_bool. - METHODS show_inventory. - METHODS cmd_look - IMPORTING - result TYPE REF TO result - cmd2 TYPE string OPTIONAL. + DATA engine TYPE REF TO engine. ENDCLASS. @@ -79,16 +70,22 @@ CLASS main IMPLEMENTATION. METHOD constructor. - map = NEW #( ). - - DATA(entrance) = NEW room( name = 'Entrance' descr = 'You are in the entrance area. Welcome.' ). - DATA(developer) = NEW room( name = 'Developers office' descr = 'The developers area. be quiet!' ). - DATA(consulting) = NEW room( name = 'Consulting Department' descr = 'This is the area where the consultants work. Bring coffee!' ). - - map->add_room( entrance ). - map->add_room( developer ). - map->add_room( consulting ). - map->set_floor_plan( VALUE #( + engine = NEW #( ). + + DATA(entrance) = NEW room( + name = 'Entrance' + descr = 'You are in the entrance area. Welcome.' ). + DATA(developer) = NEW room( + name = 'Developers office' + descr = 'The developers area. be quiet!' ). + DATA(consulting) = NEW room( + name = 'Consulting Department' + descr = 'This is the area where the consultants work. Bring coffee!' ). + + engine->map->add_room( entrance ). + engine->map->add_room( developer ). + engine->map->add_room( consulting ). + engine->map->set_floor_plan( VALUE #( ( `+--------------------+ +--------------------+` ) ( `| | | |` ) ( `| | | |` ) @@ -129,8 +126,7 @@ CLASS main IMPLEMENTATION. needed = needed_to_open_box ). consulting->things->add( card_box ). - player = NEW #( name = 'PLAYER' descr = 'player name' ). - player->set_location( entrance ). + engine->player->set_location( entrance ). bill_developer = NEW #( name = 'Bill' descr = 'An ABAP developer' ). bill_developer->set_location( developer ). @@ -143,253 +139,39 @@ CLASS main IMPLEMENTATION. mark_consultant->add_sentences( VALUE #( ( |Hello, My name is Mark and I am an SAP consultant| ) ( |You can ask me anything about SAP processes.| ) ) ). - actors = NEW #( ). - actors->add( bill_developer ). - actors->add( mark_consultant ). + + engine->actors->add( bill_developer ). + engine->actors->add( mark_consultant ). ENDMETHOD. + + METHOD interprete. - DATA cmd TYPE c LENGTH 100. - - result = NEW #( ). - - cmd = to_upper( command ). - - SPLIT cmd AT space INTO DATA(cmd1) DATA(cmd2). - - CASE cmd1. - WHEN 'MAP'. - result->addtab( map->show( ) ). - - WHEN 'N' OR 'NORTH'. - IF player->location->north = room=>no_exit. - result->add( 'you cannot go there.' ). - ELSE. - player->set_location( player->location->north ). - ENDIF. - cmd_look( result ). - - WHEN 'S' OR 'SOUTH'. - IF player->location->south = room=>no_exit. - result->add( 'you cannot go there.' ). - ELSE. - player->set_location( player->location->south ). - ENDIF. - cmd_look( result ). - - WHEN 'E' OR 'EAST'. - IF player->location->east = room=>no_exit. - result->add( 'you cannot go there.' ). - ELSE. - player->set_location( player->location->east ). - ENDIF. - cmd_look( result ). - - WHEN 'W' OR 'WEST'. - IF player->location->west = room=>no_exit. - result->add( 'you cannot go there.' ). - ELSE. - player->set_location( player->location->west ). - ENDIF. - cmd_look( result ). - - WHEN 'HELP'. - - result->add( |N or NORTH Go to the room on the north side| ). - result->add( |E or EAST Go to the room on the east side| ). - result->add( |S or SOUTH Go to the room on the south side| ). - result->add( |W or WEST Go to the room on the west side| ). - result->add( |MAP Show map/ floor plan/ world| ). - result->add( || ). - result->add( |INV or INVENTARY Show everything you carry| ). - result->add( |LOOK Look what''s in the room| ). - result->add( |LOOK Have a closer look at the object in the room or in your inventory| ). - result->add( |TAKE Take object in the room| ). - result->add( |DROP Drop an object that you carry| ). - result->add( |OPEN Open something that is in the room| ). - result->add( || ). - result->add( |ASK Ask a person to tell you something| ). - - - WHEN 'LOOK'. - cmd_look( - result = result - cmd2 = cmd2 ). - - WHEN 'TAKE'. - IF player->location->things->get_list( ) IS INITIAL. - result->add( 'There is nothing you can take' ). - ELSE. - IF player->location->things->exists( cmd2 ). - result->add( |You take the { cmd2 }| ). - player->things->add( player->location->things->get( cmd2 ) ). - player->location->things->delete( cmd2 ). - ELSE. - result->add( |You cannot take the { cmd2 }| ). - ENDIF. - ENDIF. - - WHEN 'DROP'. - IF player->things->get_list( ) IS INITIAL. - result->add( 'There is nothing you can drop' ). - ELSE. - IF player->things->exists( cmd2 ). - result->add( |You drop the { cmd2 }| ). - player->location->things->add( player->things->get( cmd2 ) ). - player->things->delete( cmd2 ). - ELSE. - result->add( |You cannot drop the { cmd2 }| ). - ENDIF. - ENDIF. - - WHEN 'INV' OR 'INVENTORY'. - IF player->things->get_list( ) IS INITIAL. - result->add( 'You don''t carry anything' ). - ELSE. - result->add( 'You carry' ). - result->addtab( player->things->show( ) ). - ENDIF. - - WHEN 'OPEN'. - IF cmd2 IS INITIAL. - result->add( 'Open what?' ). - ELSEIF player->things->get_list( ) IS INITIAL - AND player->location->things->get_list( ) IS INITIAL. - result->add( 'There is nothing you can open...' ). - ELSE. - IF player->things->exists( cmd2 ). - DATA(thing) = player->things->get( cmd2 ). - ELSEIF player->location->things->exists( cmd2 ). - thing = player->location->things->get( cmd2 ). - ENDIF. - - IF thing IS INSTANCE OF openable_thing. - DATA(thing_to_open) = CAST openable_thing( thing ). - DATA finds TYPE string_table. - result->add( thing_to_open->open( player->things )->get( ) ). - IF thing_to_open->is_open( ). - - LOOP AT thing_to_open->get_content( )->get_list( ) INTO DATA(content). - APPEND |a { content->name }| TO finds. - ENDLOOP. - result->add( |The { thing->name } contains:| ). - result->addtab( finds ). - player->things->add( content ). - ENDIF. - ELSE. - result->add( |{ thing->name } cannot be opened!| ). - ENDIF. - ENDIF. - WHEN 'ASK'. - DATA actors_in_the_room TYPE STANDARD TABLE OF REF TO actor. - DATA actor TYPE REF TO actor. - LOOP AT actors->get_list( ) INTO thing. - actor ?= thing. - IF actor->get_location( ) = player->location. - APPEND actor TO actors_in_the_room. - ENDIF. - ENDLOOP. - - IF actors_in_the_room IS INITIAL. - result->add( 'There is no one here to ask...' ). - ELSE. - IF cmd2 IS INITIAL. - result->add( 'Whom do you want to ask?' ). - ELSE. - LOOP AT actors_in_the_room INTO actor. - IF to_upper( actor->name ) = cmd2. - result->addtab( actor->speak( ) ). - ELSE. - result->add( |You cannot ask { cmd2 }| ). - ENDIF. - ENDLOOP. - ENDIF. - ENDIF. - - WHEN OTHERS. - result->add( 'You cannot do that' ). - ENDCASE. - -* result->add( |You are in the { player->location->name }.| ). " { player->location->description }|. + result = engine->interprete( command ). + + result->add( |You are in the { engine->player->location->name }.| ). " { player->location->description }|. text->set_textstream( result->get( ) ). - IF player->location->things->exists( 'RFC' ). - mission_completed = abap_true. + IF engine->player->location = bill_developer->location AND + engine->player->location->things->exists( 'RFC' ). + engine->mission_completed = abap_true. ENDIF. show_inventory( ). ENDMETHOD. - METHOD is_completed. - result = mission_completed. - ENDMETHOD. - - METHOD show_inventory. - - DATA inv TYPE string. - LOOP AT player->things->get_list( ) INTO DATA(thing_inv). - IF inv IS INITIAL. - inv = |You are carrying:{ cl_abap_char_utilities=>cr_lf }|. - ENDIF. - inv = |{ inv }{ thing_inv->name } - { thing_inv->description }{ cl_abap_char_utilities=>cr_lf }|. - ENDLOOP. - IF inv IS INITIAL. - inv = |Your inventory is empty...|. - ENDIF. - inventory->set_textstream( inv ). - + inventory->set_textstream( engine->get_inventory( )->get( ) ). ENDMETHOD. - METHOD get_location. - result = player->location->name. + result = engine->get_location( ). ENDMETHOD. - - METHOD cmd_look. - - IF cmd2 IS INITIAL. - DATA actor TYPE REF TO actor. - LOOP AT actors->get_list( ) INTO DATA(thing). - actor ?= thing. - IF actor->get_location( ) = player->location. - result->add( |There is { actor->name }, { actor->description }| ). - ENDIF. - ENDLOOP. - - IF player->location->things->get_list( ) IS INITIAL. - result->add( 'There is nothing interesting to see...' ). - ELSE. - result->add( |You see| ). - result->addtab( player->location->things->show( ) ). - ENDIF. - - IF player->location->east <> room=>no_exit. - result->add( 'There is a door on the east side' ). - ENDIF. - IF player->location->west <> room=>no_exit. - result->add( 'There is a door on the west side' ). - ENDIF. - IF player->location->north <> room=>no_exit. - result->add( 'There is a door on the north side' ). - ENDIF. - IF player->location->south <> room=>no_exit. - result->add( 'There is a door on the south side' ). - ENDIF. - - ELSE. - IF player->location->things->exists( cmd2 ). - result->add( |It's { player->location->things->get( cmd2 )->description }| ). - ELSEIF player->things->exists( cmd2 ). - result->add( |It's { player->things->get( cmd2 )->description }| ). - ELSE. - result->add( |You cannot look at the { cmd2 }| ). - ENDIF. - ENDIF. - + METHOD is_completed. + result = engine->is_completed( ). ENDMETHOD. ENDCLASS. diff --git a/src/zaxage_game_engine.prog.abap b/src/zaxage_game_engine.prog.abap index 3f5c2bc..76f0bdb 100644 --- a/src/zaxage_game_engine.prog.abap +++ b/src/zaxage_game_engine.prog.abap @@ -342,3 +342,351 @@ CLASS actor IMPLEMENTATION. my_sentences = sentences. ENDMETHOD. ENDCLASS. + +CLASS engine DEFINITION. + PUBLIC SECTION. + METHODS constructor. + METHODS interprete + IMPORTING + command TYPE clike + RETURNING + VALUE(result) TYPE REF TO result. + METHODS is_completed + RETURNING + VALUE(result) TYPE abap_bool. + METHODS get_location + RETURNING + VALUE(result) TYPE string. + METHODS get_inventory + RETURNING + VALUE(result) TYPE REF TO result. + DATA player TYPE REF TO actor. + DATA map TYPE REF TO map. + DATA actors TYPE REF TO thinglist. + DATA mission_completed TYPE abap_bool. + + PRIVATE SECTION. + DATA inventory_container TYPE REF TO cl_gui_container. + + METHODS cmd_look + IMPORTING + result TYPE REF TO result + cmd2 TYPE string OPTIONAL. + +ENDCLASS. + +CLASS engine IMPLEMENTATION. + + METHOD constructor. + + map = NEW #( ). + player = NEW #( name = 'PLAYER' descr = 'player name' ). + actors = NEW #( ). + + ENDMETHOD. + + METHOD interprete. + DATA cmd TYPE c LENGTH 100. + + result = NEW #( ). + + cmd = to_upper( command ). + + SPLIT cmd AT space INTO DATA(cmd1) DATA(cmd2). + + CASE cmd1. + WHEN 'MAP'. + result->addtab( map->show( ) ). + + WHEN 'N' OR 'NORTH'. + IF player->location->north = room=>no_exit. + result->add( 'you cannot go there.' ). + ELSE. + player->set_location( player->location->north ). + ENDIF. + cmd_look( result ). + + WHEN 'S' OR 'SOUTH'. + IF player->location->south = room=>no_exit. + result->add( 'you cannot go there.' ). + ELSE. + player->set_location( player->location->south ). + ENDIF. + cmd_look( result ). + + WHEN 'E' OR 'EAST'. + IF player->location->east = room=>no_exit. + result->add( 'you cannot go there.' ). + ELSE. + player->set_location( player->location->east ). + ENDIF. + cmd_look( result ). + + WHEN 'W' OR 'WEST'. + IF player->location->west = room=>no_exit. + result->add( 'you cannot go there.' ). + ELSE. + player->set_location( player->location->west ). + ENDIF. + cmd_look( result ). + + WHEN 'HELP'. + + result->add( |N or NORTH Go to the room on the north side| ). + result->add( |E or EAST Go to the room on the east side| ). + result->add( |S or SOUTH Go to the room on the south side| ). + result->add( |W or WEST Go to the room on the west side| ). + result->add( |MAP Show map/ floor plan/ world| ). + result->add( || ). + result->add( |INV or INVENTARY Show everything you carry| ). + result->add( |LOOK Look what''s in the room| ). + result->add( |LOOK Have a closer look at the object in the room or in your inventory| ). + result->add( |TAKE Take object in the room| ). + result->add( |DROP Drop an object that you carry| ). + result->add( |OPEN Open something that is in the room| ). + result->add( || ). + result->add( |ASK Ask a person to tell you something| ). + + + WHEN 'LOOK'. + cmd_look( + result = result + cmd2 = cmd2 ). + + WHEN 'TAKE'. + IF player->location->things->get_list( ) IS INITIAL. + result->add( 'There is nothing you can take' ). + ELSE. + IF player->location->things->exists( cmd2 ). + result->add( |You take the { cmd2 }| ). + player->things->add( player->location->things->get( cmd2 ) ). + player->location->things->delete( cmd2 ). + ELSE. + result->add( |You cannot take the { cmd2 }| ). + ENDIF. + ENDIF. + + WHEN 'DROP'. + IF player->things->get_list( ) IS INITIAL. + result->add( 'There is nothing you can drop' ). + ELSE. + IF player->things->exists( cmd2 ). + result->add( |You drop the { cmd2 }| ). + player->location->things->add( player->things->get( cmd2 ) ). + player->things->delete( cmd2 ). + ELSE. + result->add( |You cannot drop the { cmd2 }| ). + ENDIF. + ENDIF. + + WHEN 'INV' OR 'INVENTORY'. + IF player->things->get_list( ) IS INITIAL. + result->add( 'You don''t carry anything' ). + ELSE. + result->add( 'You carry' ). + result->addtab( player->things->show( ) ). + ENDIF. + + WHEN 'OPEN'. + IF cmd2 IS INITIAL. + result->add( 'Open what?' ). + ELSEIF player->things->get_list( ) IS INITIAL + AND player->location->things->get_list( ) IS INITIAL. + result->add( 'There is nothing you can open...' ). + ELSE. + IF player->things->exists( cmd2 ). + DATA(thing) = player->things->get( cmd2 ). + ELSEIF player->location->things->exists( cmd2 ). + thing = player->location->things->get( cmd2 ). + ENDIF. + + IF thing IS INSTANCE OF openable_thing. + DATA(thing_to_open) = CAST openable_thing( thing ). + DATA finds TYPE string_table. + result->add( thing_to_open->open( player->things )->get( ) ). + IF thing_to_open->is_open( ). + + LOOP AT thing_to_open->get_content( )->get_list( ) INTO DATA(content). + APPEND |a { content->name }| TO finds. + ENDLOOP. + result->add( |The { thing->name } contains:| ). + result->addtab( finds ). + player->things->add( content ). + ENDIF. + ELSEIF thing IS BOUND. + result->add( |{ thing->name } cannot be opened!| ). + ELSE. + result->add( |You cannot open { cmd2 }| ). + ENDIF. + ENDIF. + + WHEN 'ASK'. + DATA actors_in_the_room TYPE STANDARD TABLE OF REF TO actor. + DATA actor TYPE REF TO actor. + LOOP AT actors->get_list( ) INTO thing. + actor ?= thing. + IF actor->get_location( ) = player->location. + APPEND actor TO actors_in_the_room. + ENDIF. + ENDLOOP. + + IF actors_in_the_room IS INITIAL. + result->add( 'There is no one here to ask...' ). + ELSE. + IF cmd2 IS INITIAL. + result->add( 'Whom do you want to ask?' ). + ELSE. + LOOP AT actors_in_the_room INTO actor. + IF to_upper( actor->name ) = cmd2. + result->addtab( actor->speak( ) ). + ELSE. + result->add( |You cannot ask { cmd2 }| ). + ENDIF. + ENDLOOP. + ENDIF. + ENDIF. + + WHEN OTHERS. + result->add( 'You cannot do that' ). + ENDCASE. + + ENDMETHOD. + + METHOD is_completed. + result = mission_completed. + ENDMETHOD. + + METHOD get_inventory. + + DATA inv TYPE abap_bool. + + result = NEW #( ). + LOOP AT player->things->get_list( ) INTO DATA(thing_inv). + IF inv IS INITIAL. + result->add( |You are carrying:| ). + ENDIF. + result->add( |{ thing_inv->name } - { thing_inv->description }| ). + ENDLOOP. + + IF sy-subrc > 0. + result->add( |Your inventory is empty...| ). + ENDIF. + + ENDMETHOD. + + + METHOD get_location. + result = player->location->name. + ENDMETHOD. + + + METHOD cmd_look. + + IF cmd2 IS INITIAL. + DATA actor TYPE REF TO actor. + LOOP AT actors->get_list( ) INTO DATA(thing). + actor ?= thing. + IF actor->get_location( ) = player->location. + result->add( |There is { actor->name }, { actor->description }| ). + ENDIF. + ENDLOOP. + + IF player->location->things->get_list( ) IS INITIAL. + result->add( 'There is nothing interesting to see...' ). + ELSE. + result->add( |You see| ). + result->addtab( player->location->things->show( ) ). + ENDIF. + + IF player->location->east <> room=>no_exit. + result->add( 'There is a door on the east side' ). + ENDIF. + IF player->location->west <> room=>no_exit. + result->add( 'There is a door on the west side' ). + ENDIF. + IF player->location->north <> room=>no_exit. + result->add( 'There is a door on the north side' ). + ENDIF. + IF player->location->south <> room=>no_exit. + result->add( 'There is a door on the south side' ). + ENDIF. + + ELSE. + IF player->location->things->exists( cmd2 ). + result->add( |It's { player->location->things->get( cmd2 )->description }| ). + ELSEIF player->things->exists( cmd2 ). + result->add( |It's { player->things->get( cmd2 )->description }| ). + ELSE. + result->add( |You cannot look at the { cmd2 }| ). + ENDIF. + ENDIF. + + ENDMETHOD. + +ENDCLASS. + +CLASS ltcl_engine DEFINITION FINAL FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. + + PRIVATE SECTION. + DATA cut TYPE REF TO engine. + METHODS: + setup, + map_simple FOR TESTING RAISING cx_static_check, + take_and_drop FOR TESTING RAISING cx_static_check. +ENDCLASS. + + +CLASS ltcl_engine IMPLEMENTATION. + + METHOD map_simple. + + "floor plan configuration + DATA(room_left) = NEW room( name = 'LEFT' descr = 'Left room' ). + DATA(room_right) = NEW room( name = 'RIGHT' descr = 'Right room' ). + room_left->set_exits( e = room_right ). + room_right->set_exits( w = room_left ). + cut->map->add_room( room_left ). + cut->map->add_room( room_right ). + cut->player->set_location( room_left ). + + "GO WEST -> not possible -> current position still ROOM_LEFT + cut->interprete( 'W' ). + cl_abap_unit_assert=>assert_equals( + act = cut->player->get_location( ) + exp = room_left ). + "GO EAST -> leads to room_right + cut->interprete( 'e' ). + cl_abap_unit_assert=>assert_equals( + act = cut->player->get_location( ) + exp = room_right ). + ENDMETHOD. + + METHOD setup. + cut = NEW #( ). + ENDMETHOD. + + METHOD take_and_drop. + "floor plan configuration + DATA(room_left) = NEW room( name = 'LEFT' descr = 'Left room' ). + DATA(room_right) = NEW room( name = 'RIGHT' descr = 'Right room' ). + room_left->set_exits( e = room_right ). + DATA(bottle) = NEW thing( name = 'BOTTLE' descr = 'an empty bottle' ). + room_left->things->add( bottle ). + room_right->set_exits( w = room_left ). + cut->map->add_room( room_left ). + cut->map->add_room( room_right ). + + cut->player->set_location( room_left ). + + cut->interprete( 'TAKE BOTTLE' ). + cut->interprete( 'e' ). + cut->interprete( 'DROP BOTTLE' ). + cl_abap_unit_assert=>assert_equals( + act = room_right->things->get_list( ) + exp = VALUE thinglist=>_things( ( bottle ) ) ). + + ENDMETHOD. + +ENDCLASS. diff --git a/src/zcl_axage_actor.clas.abap b/src/zcl_axage_actor.clas.abap new file mode 100644 index 0000000..9927512 --- /dev/null +++ b/src/zcl_axage_actor.clas.abap @@ -0,0 +1,53 @@ +CLASS zcl_axage_actor DEFINITION INHERITING FROM zcl_axage_thing + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + DATA location TYPE REF TO zcl_axage_room. + DATA things TYPE REF TO zcl_axage_thing_list. + METHODS constructor + IMPORTING + name TYPE clike + descr TYPE clike. + METHODS set_location + IMPORTING + room TYPE REF TO zcl_axage_room. + METHODS get_location + RETURNING + VALUE(room) TYPE REF TO zcl_axage_room. + METHODS speak + RETURNING + VALUE(sentences) TYPE string_table. + METHODS add_sentences + IMPORTING + sentences TYPE string_table. + PROTECTED SECTION. + PRIVATE SECTION. + DATA my_sentences TYPE string_table. +ENDCLASS. + + + +CLASS zcl_axage_actor IMPLEMENTATION. + METHOD constructor. + super->constructor( name = name descr = descr ). + things = NEW #( ). + ENDMETHOD. + + METHOD set_location. + location = room. + ENDMETHOD. + + METHOD get_location. + room = location. + ENDMETHOD. + + METHOD speak. + sentences = my_sentences. + ENDMETHOD. + + METHOD add_sentences. + my_sentences = sentences. + ENDMETHOD. +ENDCLASS. diff --git a/src/zcl_axage_actor.clas.xml b/src/zcl_axage_actor.clas.xml new file mode 100644 index 0000000..5eae67a --- /dev/null +++ b/src/zcl_axage_actor.clas.xml @@ -0,0 +1,16 @@ + + + + + + ZCL_AXAGE_ACTOR + E + ABAP Game Engine Actor + 1 + X + X + X + + + + diff --git a/src/zcl_axage_demo1.clas.abap b/src/zcl_axage_demo1.clas.abap new file mode 100644 index 0000000..22f1291 --- /dev/null +++ b/src/zcl_axage_demo1.clas.abap @@ -0,0 +1,113 @@ +CLASS zcl_axage_demo1 DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + INTERFACES if_oo_adt_classrun. + METHODS constructor. + PROTECTED SECTION. + PRIVATE SECTION. + DATA bill_developer TYPE REF TO zcl_axage_actor. + DATA mark_consultant TYPE REF TO zcl_axage_actor. + DATA engine TYPE REF TO zcl_axage_engine. + METHODS interprete + IMPORTING + command TYPE clike + RETURNING + VALUE(result) TYPE REF TO zcl_axage_result. +ENDCLASS. + + + +CLASS zcl_axage_demo1 IMPLEMENTATION. + METHOD constructor. + engine = NEW #( ). + DATA(entrance) = NEW zcl_axage_room( name = 'Entrance' descr = 'You are in the entrance area. Welcome.' ). + DATA(developer) = NEW zcl_axage_room( name = 'Developers office' descr = 'The developers area. be quiet!' ). + DATA(consulting) = NEW zcl_axage_room( name = 'Consulting Department' descr = 'This is the area where the consultants work. Bring coffee!' ). + + engine->map->add_room( entrance ). + engine->map->add_room( developer ). + engine->map->add_room( consulting ). + engine->map->set_floor_plan( VALUE #( + ( `+--------------------+ +--------------------+` ) + ( `| | | |` ) + ( `| | | |` ) + ( `| +-+ |` ) + ( `| ENTRANCE DEVELOPERS |` ) + ( `| +-+ |` ) + ( `| | | |` ) + ( `| | | |` ) + ( `+--------+ +--------+ +--------------------+` ) + ( ` | |` ) + ( `+--------+ +--------+` ) + ( `| |` ) + ( `| |` ) + ( `| |` ) + ( `| CONSULTANTS |` ) + ( `| |` ) + ( `| |` ) + ( `| |` ) + ( `+--------------------+` ) ) ). + + entrance->set_exits( + e = developer + s = consulting ). + developer->set_exits( + w = entrance ). + consulting->set_exits( + n = entrance ). + DATA(cutter_knife) = NEW zcl_axage_thing( name = 'KNIFE' descr = 'a very sharp cutter knife' ). + developer->things->add( cutter_knife ). + DATA(needed_to_open_box) = NEW zcl_axage_thing_list( ). + needed_to_open_box->add( cutter_knife ). + DATA(content_of_box) = NEW zcl_axage_thing_list( ). + content_of_box->add( NEW zcl_axage_thing( name = 'RFC' descr = 'The request for change.' ) ). + DATA(card_box) = NEW zcl_axage_openable_thing( + name = 'BOX' + descr = 'a little card box' + content = content_of_box + needed = needed_to_open_box ). + consulting->things->add( card_box ). + + engine->player->set_location( entrance ). + + bill_developer = NEW #( name = 'Bill' descr = 'An ABAP developer' ). + bill_developer->set_location( developer ). + bill_developer->add_sentences( VALUE #( + ( |Hey, I am Bill, an experienced ABAP developer.| ) + ( |If you have programming tasks for me, you can pass the requirement to me| ) ) ). + + mark_consultant = NEW #( name = 'Mark' descr = 'An SAP consultant' ). + mark_consultant->set_location( consulting ). + mark_consultant->add_sentences( VALUE #( + ( |Hello, My name is Mark and I am an SAP consultant| ) + ( |You can ask me anything about SAP processes.| ) ) ). + + engine->actors->add( bill_developer ). + engine->actors->add( mark_consultant ). + ENDMETHOD. + + METHOD if_oo_adt_classrun~main. + + "Add Your Commands Here: + out->write( interprete( 'HELP' )->get( ) ). + out->write( interprete( 'NORTH' )->get( ) ). + out->write( interprete( 'EAST' )->get( ) ). + out->write( interprete( 'TAKE KNIFE' )->get( ) ). + + IF engine->player->location = bill_developer->location AND + engine->player->location->things->exists( 'RFC' ). + engine->mission_completed = abap_true. + out->write( 'Congratulations! You delivered the RFC to the developers!' ). + ENDIF. + ENDMETHOD. + + METHOD interprete. + result = engine->interprete( command ). + result->add( |You are in the { engine->player->location->name }.| ). + result->add( engine->get_inventory( )->get( ) ). + ENDMETHOD. + +ENDCLASS. diff --git a/src/zcl_axage_demo1.clas.xml b/src/zcl_axage_demo1.clas.xml new file mode 100644 index 0000000..c0e1bc4 --- /dev/null +++ b/src/zcl_axage_demo1.clas.xml @@ -0,0 +1,16 @@ + + + + + + ZCL_AXAGE_DEMO1 + E + ABAP Game Engine Demo #1 + 1 + X + X + X + + + + diff --git a/src/zcl_axage_engine.clas.abap b/src/zcl_axage_engine.clas.abap new file mode 100644 index 0000000..812e560 --- /dev/null +++ b/src/zcl_axage_engine.clas.abap @@ -0,0 +1,280 @@ +CLASS zcl_axage_engine DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + INTERFACES if_serializable_object. + METHODS constructor. + METHODS interprete + IMPORTING + command TYPE clike + RETURNING + VALUE(result) TYPE REF TO zcl_axage_result. + METHODS is_completed + RETURNING + VALUE(result) TYPE abap_bool. + METHODS get_location + RETURNING + VALUE(result) TYPE string. + METHODS get_inventory + RETURNING + VALUE(result) TYPE REF TO zcl_axage_result. + DATA player TYPE REF TO zcl_axage_actor. + DATA map TYPE REF TO zcl_axage_map. + DATA actors TYPE REF TO zcl_axage_thing_list. + DATA mission_completed TYPE abap_bool. + PROTECTED SECTION. + PRIVATE SECTION. + METHODS cmd_look + IMPORTING + result TYPE REF TO zcl_axage_result + cmd2 TYPE string OPTIONAL. +ENDCLASS. + +CLASS zcl_axage_engine IMPLEMENTATION. + METHOD constructor. + + map = NEW #( ). + player = NEW #( name = 'PLAYER' descr = 'player name' ). + actors = NEW #( ). + + ENDMETHOD. + + METHOD interprete. + DATA cmd TYPE string. "c LENGTH 100. + + result = NEW #( ). + + cmd = to_upper( command ). + + SPLIT cmd AT space INTO DATA(cmd1) DATA(cmd2). + + CASE cmd1. + WHEN 'MAP'. + result->addTab( map->show( ) ). + + WHEN 'N' OR 'NORTH'. + IF player->location->north->name = zcl_axage_room=>no_exit->name. + result->add( 'you cannot go there.' ). + ELSE. + player->set_location( player->location->north ). + ENDIF. + cmd_look( result ). + + WHEN 'S' OR 'SOUTH'. + IF player->location->south->name = zcl_axage_room=>no_exit->name. + result->add( 'you cannot go there.' ). + ELSE. + player->set_location( player->location->south ). + ENDIF. + cmd_look( result ). + + WHEN 'E' OR 'EAST'. + IF player->location->east->name = zcl_axage_room=>no_exit->name. + result->add( 'you cannot go there.' ). + ELSE. + player->set_location( player->location->east ). + ENDIF. + cmd_look( result ). + + WHEN 'W' OR 'WEST'. + IF player->location->west->name = zcl_axage_room=>no_exit->name. + result->add( 'you cannot go there.' ). + ELSE. + player->set_location( player->location->west ). + ENDIF. + cmd_look( result ). + + WHEN 'HELP'. + + result->add( |N or NORTH Go to the room on the north side| ). + result->add( |E or EAST Go to the room on the east side| ). + result->add( |S or SOUTH Go to the room on the south side| ). + result->add( |W or WEST Go to the room on the west side| ). + result->add( |MAP Show map/ floor plan/ world| ). + result->add( || ). + result->add( |INV or INVENTARY Show everything you carry| ). + result->add( |LOOK Look what''s in the room| ). + result->add( |LOOK Have a closer look at the object in the room or in your inventory| ). + result->add( |TAKE Take object in the room| ). + result->add( |DROP Drop an object that you carry| ). + result->add( |OPEN Open something that is in the room| ). + result->add( || ). + result->add( |ASK Ask a person to tell you something| ). + + + WHEN 'LOOK'. + cmd_look( + result = result + cmd2 = cmd2 ). + + WHEN 'TAKE'. + IF player->location->things->get_list( ) IS INITIAL. + result->add( 'There is nothing you can take' ). + ELSE. + IF player->location->things->exists( cmd2 ). + result->add( |You take the { cmd2 }| ). + player->things->add( player->location->things->get( cmd2 ) ). + player->location->things->delete( cmd2 ). + ELSE. + result->add( |You cannot take the { cmd2 }| ). + ENDIF. + ENDIF. + + WHEN 'DROP'. + IF player->things->get_list( ) IS INITIAL. + result->add( 'There is nothing you can drop' ). + ELSE. + IF player->things->exists( cmd2 ). + result->add( |You drop the { cmd2 }| ). + player->location->things->add( player->things->get( cmd2 ) ). + player->things->delete( cmd2 ). + ELSE. + result->add( |You cannot drop the { cmd2 }| ). + ENDIF. + ENDIF. + + WHEN 'INV' OR 'INVENTORY'. + IF player->things->get_list( ) IS INITIAL. + result->add( 'You don''t carry anything' ). + ELSE. + result->add( 'You carry' ). + result->addtab( player->things->show( ) ). + ENDIF. + + WHEN 'OPEN'. + IF cmd2 IS INITIAL. + result->add( 'Open what?' ). + ELSEIF player->things->get_list( ) IS INITIAL + AND player->location->things->get_list( ) IS INITIAL. + result->add( 'There is nothing you can open...' ). + ELSE. + IF player->things->exists( cmd2 ). + DATA(thing) = player->things->get( cmd2 ). + ELSEIF player->location->things->exists( cmd2 ). + thing = player->location->things->get( cmd2 ). + ENDIF. + + IF thing IS INSTANCE OF zcl_axage_openable_thing. + DATA(thing_to_open) = CAST zcl_axage_openable_thing( thing ). + DATA finds TYPE string_table. + result->add( thing_to_open->open( player->things )->get( ) ). + IF thing_to_open->is_open( ). + LOOP AT thing_to_open->get_content( )->get_list( ) INTO DATA(content). + APPEND |a { content->name }| TO finds. + ENDLOOP. + result->add( |The { thing->name } contains:| ). + result->addtab( finds ). + player->things->add( content ). + ENDIF. + ELSEIF thing IS BOUND. + result->add( |{ thing->name } cannot be opened!| ). + ELSE. + result->add( |You cannot open { cmd2 }| ). + ENDIF. + ENDIF. + + WHEN 'ASK'. + DATA actors_in_the_room TYPE STANDARD TABLE OF REF TO zcl_axage_actor. + DATA actor TYPE REF TO zcl_axage_actor. + LOOP AT actors->get_list( ) INTO thing. + actor ?= thing. + IF actor->get_location( ) = player->location. + APPEND actor TO actors_in_the_room. + ENDIF. + ENDLOOP. + + IF actors_in_the_room IS INITIAL. + result->add( 'There is no one here to ask...' ). + ELSE. + IF cmd2 IS INITIAL. + result->add( 'Whom do you want to ask?' ). + ELSE. + LOOP AT actors_in_the_room INTO actor. + IF to_upper( actor->name ) = cmd2. + result->addtab( actor->speak( ) ). + ELSE. + result->add( |You cannot ask { cmd2 }| ). + ENDIF. + ENDLOOP. + ENDIF. + ENDIF. + + WHEN OTHERS. + result->add( 'You cannot do that' ). + ENDCASE. + + ENDMETHOD. + + METHOD is_completed. + result = mission_completed. + ENDMETHOD. + + METHOD get_inventory. + + DATA inv TYPE abap_bool. + + result = NEW #( ). + LOOP AT player->things->get_list( ) INTO DATA(thing_inv). + IF inv IS INITIAL. + result->add( |You are carrying:| ). + ENDIF. + result->add( |{ thing_inv->name } - { thing_inv->description }| ). + ENDLOOP. + + IF sy-subrc > 0. + result->add( |Your inventory is empty...| ). + ENDIF. + + ENDMETHOD. + + + METHOD get_location. + result = player->location->name. + ENDMETHOD. + + + METHOD cmd_look. + + IF cmd2 IS INITIAL. + DATA actor TYPE REF TO zcl_axage_actor. + LOOP AT actors->get_list( ) INTO DATA(thing). + actor ?= thing. + IF actor->get_location( ) = player->location. + result->add( |There is { actor->name }, { actor->description }| ). + ENDIF. + ENDLOOP. + + IF player->location->things->get_list( ) IS INITIAL. + result->add( 'There is nothing interesting to see...' ). + ELSE. + result->add( |You see| ). + result->addtab( player->location->things->show( ) ). + ENDIF. + + IF player->location->east->name <> zcl_axage_room=>no_exit->name. + result->add( 'There is a door on the east side' ). + ENDIF. + IF player->location->west->name <> zcl_axage_room=>no_exit->name. + result->add( 'There is a door on the west side' ). + ENDIF. + IF player->location->north->name <> zcl_axage_room=>no_exit->name. + result->add( 'There is a door on the north side' ). + ENDIF. + IF player->location->south->name <> zcl_axage_room=>no_exit->name. + result->add( 'There is a door on the south side' ). + ENDIF. + + ELSE. + IF player->location->things->exists( cmd2 ). + result->add( |It's { player->location->things->get( cmd2 )->description }| ). + ELSEIF player->things->exists( cmd2 ). + result->add( |It's { player->things->get( cmd2 )->description }| ). + ELSE. + result->add( |You cannot look at the { cmd2 }| ). + ENDIF. + ENDIF. + + ENDMETHOD. +ENDCLASS. diff --git a/src/zcl_axage_engine.clas.testclasses.abap b/src/zcl_axage_engine.clas.testclasses.abap new file mode 100644 index 0000000..4c66a4b --- /dev/null +++ b/src/zcl_axage_engine.clas.testclasses.abap @@ -0,0 +1,66 @@ +*"* use this source file for your ABAP unit test classes +CLASS ltcl_engine DEFINITION FINAL FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. + + PRIVATE SECTION. + DATA cut TYPE REF TO zcl_axage_engine. + METHODS: + setup, + map_simple FOR TESTING RAISING cx_static_check, + take_and_drop FOR TESTING RAISING cx_static_check. +ENDCLASS. + + +CLASS ltcl_engine IMPLEMENTATION. + + METHOD map_simple. + + "floor plan configuration + DATA(room_left) = NEW zcl_axage_room( name = 'LEFT' descr = 'Left room' ). + DATA(room_right) = NEW zcl_axage_room( name = 'RIGHT' descr = 'Right room' ). + room_left->set_exits( e = room_right ). + room_right->set_exits( w = room_left ). + cut->map->add_room( room_left ). + cut->map->add_room( room_right ). + cut->player->set_location( room_left ). + + "GO WEST -> not possible -> current position still ROOM_LEFT + cut->interprete( 'W' ). + cl_abap_unit_assert=>assert_equals( + act = cut->player->get_location( ) + exp = room_left ). + "GO EAST -> leads to room_right + cut->interprete( 'e' ). + cl_abap_unit_assert=>assert_equals( + act = cut->player->get_location( ) + exp = room_right ). + ENDMETHOD. + + METHOD setup. + cut = NEW #( ). + ENDMETHOD. + + METHOD take_and_drop. + "floor plan configuration + DATA(room_left) = NEW zcl_axage_room( name = 'LEFT' descr = 'Left room' ). + DATA(room_right) = NEW zcl_axage_room( name = 'RIGHT' descr = 'Right room' ). + room_left->set_exits( e = room_right ). + DATA(bottle) = NEW zcl_axage_thing( name = 'BOTTLE' descr = 'an empty bottle' ). + room_left->things->add( bottle ). + room_right->set_exits( w = room_left ). + cut->map->add_room( room_left ). + cut->map->add_room( room_right ). + + cut->player->set_location( room_left ). + + cut->interprete( 'TAKE BOTTLE' ). + cut->interprete( 'e' ). + cut->interprete( 'DROP BOTTLE' ). + cl_abap_unit_assert=>assert_equals( + act = room_right->things->get_list( ) + exp = VALUE zcl_axage_thing_list=>_things( ( bottle ) ) ). + + ENDMETHOD. + +ENDCLASS. diff --git a/src/zcl_axage_engine.clas.xml b/src/zcl_axage_engine.clas.xml new file mode 100644 index 0000000..30e5739 --- /dev/null +++ b/src/zcl_axage_engine.clas.xml @@ -0,0 +1,17 @@ + + + + + + ZCL_AXAGE_ENGINE + E + ABAP Game Engine + 1 + X + X + X + X + + + + diff --git a/src/zcl_axage_map.clas.abap b/src/zcl_axage_map.clas.abap new file mode 100644 index 0000000..741fda6 --- /dev/null +++ b/src/zcl_axage_map.clas.abap @@ -0,0 +1,50 @@ +CLASS zcl_axage_map DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + INTERFACES if_serializable_object. + METHODS add_room + IMPORTING + room TYPE REF TO zcl_axage_room. + METHODS get_room + IMPORTING + name TYPE clike + RETURNING + VALUE(room) TYPE REF TO zcl_axage_room. + METHODS set_floor_plan + IMPORTING + input TYPE string_table. + METHODS show + RETURNING + VALUE(result) TYPE string_table. + PROTECTED SECTION. + TYPES _map TYPE STANDARD TABLE OF REF TO zcl_axage_room. + DATA map TYPE _map. + DATA floor_plan TYPE string_table. + PRIVATE SECTION. +ENDCLASS. + + + +CLASS zcl_axage_map IMPLEMENTATION. + METHOD add_room. + APPEND room TO map. + ENDMETHOD. + + METHOD get_room. + READ TABLE map WITH KEY table_line->name = name INTO room. + IF room IS INITIAL. + room = zcl_axage_room=>no_exit. + ENDIF. + ENDMETHOD. + + METHOD set_floor_plan. + me->floor_plan = input. + ENDMETHOD. + + METHOD show. + result = floor_plan. + ENDMETHOD. +ENDCLASS. diff --git a/src/zcl_axage_map.clas.xml b/src/zcl_axage_map.clas.xml new file mode 100644 index 0000000..1c8c928 --- /dev/null +++ b/src/zcl_axage_map.clas.xml @@ -0,0 +1,16 @@ + + + + + + ZCL_AXAGE_MAP + E + ABAP Game Engine Map + 1 + X + X + X + + + + diff --git a/src/zcl_axage_openable_thing.clas.abap b/src/zcl_axage_openable_thing.clas.abap new file mode 100644 index 0000000..8045e4c --- /dev/null +++ b/src/zcl_axage_openable_thing.clas.abap @@ -0,0 +1,75 @@ +CLASS zcl_axage_openable_thing DEFINITION + INHERITING FROM zcl_axage_thing + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + METHODS constructor + IMPORTING + name TYPE clike + descr TYPE clike + needed TYPE REF TO zcl_axage_thing_list + content TYPE REF TO zcl_axage_thing_list. + METHODS get_content + RETURNING + VALUE(content) TYPE REF TO zcl_axage_thing_list. + METHODS open + IMPORTING + things TYPE REF TO zcl_axage_thing_list + RETURNING + VALUE(result) TYPE REF TO zcl_axage_result. + METHODS is_open + RETURNING + VALUE(result) TYPE abap_bool. + + DATA needed TYPE REF TO zcl_axage_thing_list. + PROTECTED SECTION. + DATA opened TYPE abap_bool. + DATA content TYPE REF TO zcl_axage_thing_list. + PRIVATE SECTION. +ENDCLASS. + + + +CLASS zcl_axage_openable_thing IMPLEMENTATION. + + METHOD constructor. + super->constructor( + name = name + descr = descr ). + me->needed = needed. + me->content = content. + ENDMETHOD. + + METHOD get_content. + IF opened = abap_true. + content = me->content. + ENDIF. + ENDMETHOD. + + METHOD is_open. + result = opened. + ENDMETHOD. + + METHOD open. + result = NEW #( ). + data allowed type abap_Bool. + + LOOP AT needed->get_list( ) INTO DATA(open_with). + IF things->exists( open_with->name ). + allowed = abap_true. + result->add( |The { name } is now open| ). + me->opened = abap_true. + EXIT. "from loop + ENDIF. + ENDLOOP. + + IF allowed = abap_false. + result->add( |You have nothing the { name } can be opened with!| ). + ENDIF. + + opened = me->opened. + ENDMETHOD. + +ENDCLASS. diff --git a/src/zcl_axage_openable_thing.clas.xml b/src/zcl_axage_openable_thing.clas.xml new file mode 100644 index 0000000..eb340f2 --- /dev/null +++ b/src/zcl_axage_openable_thing.clas.xml @@ -0,0 +1,16 @@ + + + + + + ZCL_AXAGE_OPENABLE_THING + E + ABAP Game Engine Openable Thing + 1 + X + X + X + + + + diff --git a/src/zcl_axage_result.clas.abap b/src/zcl_axage_result.clas.abap new file mode 100644 index 0000000..c1c370a --- /dev/null +++ b/src/zcl_axage_result.clas.abap @@ -0,0 +1,39 @@ +CLASS zcl_axage_result DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + METHODS add + IMPORTING + text TYPE clike. + + METHODS addTab + IMPORTING + textTab TYPE string_table. + + METHODS get + RETURNING + VALUE(textString) TYPE string. + PROTECTED SECTION. + DATA text TYPE string_table. + PRIVATE SECTION. +ENDCLASS. + + + +CLASS zcl_axage_result IMPLEMENTATION. + METHOD add. + APPEND text TO me->text. + ENDMETHOD. + + METHOD get. + LOOP AT text REFERENCE INTO DATA(line). + textstring = textstring && line->* && cl_abap_char_utilities=>cr_lf. + ENDLOOP. + ENDMETHOD. + + METHOD addTab. + APPEND LINES OF textTab TO text. + ENDMETHOD. +ENDCLASS. diff --git a/src/zcl_axage_result.clas.xml b/src/zcl_axage_result.clas.xml new file mode 100644 index 0000000..468ce95 --- /dev/null +++ b/src/zcl_axage_result.clas.xml @@ -0,0 +1,16 @@ + + + + + + ZCL_AXAGE_RESULT + E + ABAP Game Engine Results + 1 + X + X + X + + + + diff --git a/src/zcl_axage_room.clas.abap b/src/zcl_axage_room.clas.abap new file mode 100644 index 0000000..c3bed7b --- /dev/null +++ b/src/zcl_axage_room.clas.abap @@ -0,0 +1,57 @@ +CLASS zcl_axage_room DEFINITION INHERITING FROM zcl_axage_thing + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + DATA north TYPE REF TO zcl_axage_room. + DATA east TYPE REF TO zcl_axage_room. + DATA south TYPE REF TO zcl_axage_room. + DATA west TYPE REF TO zcl_axage_room. + DATA things TYPE REF TO zcl_axage_thing_list. + CLASS-DATA no_exit TYPE REF TO zcl_axage_room. + CLASS-METHODS class_constructor. + METHODS constructor + IMPORTING + name TYPE clike + descr TYPE clike. + METHODS set_exits + IMPORTING + n TYPE REF TO zcl_axage_room OPTIONAL + e TYPE REF TO zcl_axage_room OPTIONAL + s TYPE REF TO zcl_axage_room OPTIONAL + w TYPE REF TO zcl_axage_room OPTIONAL. + PROTECTED SECTION. + METHODS set_exit + IMPORTING + room TYPE REF TO zcl_axage_room + RETURNING + VALUE(exit) TYPE REF TO zcl_axage_room. + PRIVATE SECTION. +ENDCLASS. + + + +CLASS zcl_axage_room IMPLEMENTATION. + METHOD constructor. + super->constructor( name = name descr = descr ). + things = NEW #( ). + ENDMETHOD. + METHOD class_constructor. + no_exit = NEW zcl_axage_room( name = 'No Exit' descr = 'There is no exit in this direction...' ). + ENDMETHOD. + + METHOD set_exits. + north = set_exit( n ). + east = set_exit( e ). + south = set_exit( s ). + west = set_exit( w ). + ENDMETHOD. + METHOD set_exit. + IF room IS BOUND. + exit = room. + ELSE. + exit = no_exit. + ENDIF. + ENDMETHOD. +ENDCLASS. diff --git a/src/zcl_axage_room.clas.xml b/src/zcl_axage_room.clas.xml new file mode 100644 index 0000000..e7bf606 --- /dev/null +++ b/src/zcl_axage_room.clas.xml @@ -0,0 +1,16 @@ + + + + + + ZCL_AXAGE_ROOM + E + ABAP Game Engine Room + 1 + X + X + X + + + + diff --git a/src/zcl_axage_thing.clas.abap b/src/zcl_axage_thing.clas.abap new file mode 100644 index 0000000..18b5d1a --- /dev/null +++ b/src/zcl_axage_thing.clas.abap @@ -0,0 +1,27 @@ +CLASS zcl_axage_thing DEFINITION + PUBLIC + CREATE PUBLIC . + + PUBLIC SECTION. + INTERFACES if_serializable_object. + DATA name TYPE string. + DATA description TYPE string. + + METHODS constructor + IMPORTING + name TYPE clike + descr TYPE clike. + + PROTECTED SECTION. + + PRIVATE SECTION. +ENDCLASS. + + + +CLASS zcl_axage_thing IMPLEMENTATION. + METHOD constructor. + me->name = name. + me->description = descr. + ENDMETHOD. +ENDCLASS. diff --git a/src/zcl_axage_thing.clas.xml b/src/zcl_axage_thing.clas.xml new file mode 100644 index 0000000..dd04a25 --- /dev/null +++ b/src/zcl_axage_thing.clas.xml @@ -0,0 +1,16 @@ + + + + + + ZCL_AXAGE_THING + E + ABAP Game Engine Thing + 1 + X + X + X + + + + diff --git a/src/zcl_axage_thing_list.clas.abap b/src/zcl_axage_thing_list.clas.abap new file mode 100644 index 0000000..b07b092 --- /dev/null +++ b/src/zcl_axage_thing_list.clas.abap @@ -0,0 +1,72 @@ +CLASS zcl_axage_thing_list DEFINITION + PUBLIC + CREATE PUBLIC . + + PUBLIC SECTION. + INTERFACES if_serializable_object. + TYPES _things TYPE STANDARD TABLE OF REF TO zcl_axage_thing WITH EMPTY KEY. + METHODS constructor + IMPORTING + things TYPE _things OPTIONAL. + METHODS get_list + RETURNING VALUE(things) TYPE _things. + METHODS get + IMPORTING + name TYPE clike + RETURNING + VALUE(thing) TYPE REF TO zcl_axage_thing. + METHODS show + RETURNING + VALUE(result) TYPE string_table. + METHODS add + IMPORTING + thing TYPE REF TO zcl_axage_thing + RETURNING + VALUE(result) TYPE REF TO zcl_axage_result. + METHODS delete + IMPORTING + name TYPE clike. + METHODS exists + IMPORTING + name TYPE clike + RETURNING + VALUE(exists) TYPE abap_bool. + PROTECTED SECTION. + DATA things TYPE _things. + PRIVATE SECTION. +ENDCLASS. + + + +CLASS zcl_axage_thing_list IMPLEMENTATION. + METHOD constructor. + me->things = things. + ENDMETHOD. + + METHOD get_list. + things = me->things. + ENDMETHOD. + + METHOD get. + READ TABLE me->things INTO thing WITH KEY table_line->name = name. + ENDMETHOD. + + METHOD exists. + exists = xsdbool( line_exists( me->things[ table_line->name = name ] ) ). + ENDMETHOD. + + METHOD show. + LOOP AT things into DATA(currentThing). + APPEND |a { currentThing->name } - { currentThing->description }| TO result. + ENDLOOP. + ENDMETHOD. + + METHOD add. + APPEND thing TO things. + ENDMETHOD. + + METHOD delete. + DELETE things WHERE table_line->name = name. + ENDMETHOD. + +ENDCLASS. diff --git a/src/zcl_axage_thing_list.clas.xml b/src/zcl_axage_thing_list.clas.xml new file mode 100644 index 0000000..b4e1031 --- /dev/null +++ b/src/zcl_axage_thing_list.clas.xml @@ -0,0 +1,16 @@ + + + + + + ZCL_AXAGE_THING_LIST + E + ABAP Game Engine Thing List + 1 + X + X + X + + + +