From 1f0f954468992cd29ce158e08dde86ca23ce0879 Mon Sep 17 00:00:00 2001 From: Enno Wulff Date: Sat, 14 May 2022 19:24:34 +0000 Subject: [PATCH 01/14] issue #2 fix --- src/zaxage_demo_01.prog.abap | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/zaxage_demo_01.prog.abap b/src/zaxage_demo_01.prog.abap index 8a6fbd5..3266607 100644 --- a/src/zaxage_demo_01.prog.abap +++ b/src/zaxage_demo_01.prog.abap @@ -277,10 +277,13 @@ CLASS main IMPLEMENTATION. result->addtab( finds ). player->things->add( content ). ENDIF. - ELSE. + 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. From 979aed4db33a67a98e0b5815cbf6e2bb13696ca5 Mon Sep 17 00:00:00 2001 From: Enno Wulff Date: Sat, 14 May 2022 20:13:44 +0000 Subject: [PATCH 02/14] interpreter separated from gui --- src/zaxage_demo_01.prog.abap | 286 ++++--------------------------- src/zaxage_game_engine.prog.abap | 282 ++++++++++++++++++++++++++++++ 2 files changed, 311 insertions(+), 257 deletions(-) diff --git a/src/zaxage_demo_01.prog.abap b/src/zaxage_demo_01.prog.abap index 3266607..d484cb1 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,16 @@ CLASS main IMPLEMENTATION. METHOD constructor. - map = NEW #( ). + 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!' ). - map->add_room( entrance ). - map->add_room( developer ). - map->add_room( consulting ). - map->set_floor_plan( VALUE #( + engine->map->add_room( entrance ). + engine->map->add_room( developer ). + engine->map->add_room( consulting ). + engine->map->set_floor_plan( VALUE #( ( `+--------------------+ +--------------------+` ) ( `| | | |` ) ( `| | | |` ) @@ -129,8 +120,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,256 +133,38 @@ 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. - 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. - -* 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->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..2ef982c 100644 --- a/src/zaxage_game_engine.prog.abap +++ b/src/zaxage_game_engine.prog.abap @@ -342,3 +342,285 @@ 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. From 6b4bef365b9dff9f89aab9ed527965489fef9122 Mon Sep 17 00:00:00 2001 From: Enno Wulff Date: Sat, 14 May 2022 21:22:03 +0000 Subject: [PATCH 03/14] unit tests --- src/zaxage_game_engine.prog.abap | 78 +++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/src/zaxage_game_engine.prog.abap b/src/zaxage_game_engine.prog.abap index 2ef982c..76f0bdb 100644 --- a/src/zaxage_game_engine.prog.abap +++ b/src/zaxage_game_engine.prog.abap @@ -358,8 +358,8 @@ CLASS engine DEFINITION. RETURNING VALUE(result) TYPE string. METHODS get_inventory - returning - value(result) type ref to result. + 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. @@ -513,9 +513,9 @@ CLASS engine IMPLEMENTATION. result->addtab( finds ). player->things->add( content ). ENDIF. - ELSEif thing is bound. + ELSEIF thing IS BOUND. result->add( |{ thing->name } cannot be opened!| ). - else. + ELSE. result->add( |You cannot open { cmd2 }| ). ENDIF. ENDIF. @@ -558,9 +558,9 @@ CLASS engine IMPLEMENTATION. METHOD get_inventory. - data inv type abap_bool. + DATA inv TYPE abap_bool. - result = new #( ). + result = NEW #( ). LOOP AT player->things->get_list( ) INTO DATA(thing_inv). IF inv IS INITIAL. result->add( |You are carrying:| ). @@ -624,3 +624,69 @@ CLASS engine IMPLEMENTATION. 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. From 5fc96134133b8c288c12b550bc254c916f54f03b Mon Sep 17 00:00:00 2001 From: Enno <75187288+Ennowulff@users.noreply.github.com> Date: Tue, 31 May 2022 19:42:31 +0200 Subject: [PATCH 04/14] mermaid class diagram draft --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) 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() + + } +``` From cc36cdf081c8afcd08e9f66b2fa6db4d04b1ddf2 Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Mon, 1 May 2023 16:57:28 +0000 Subject: [PATCH 05/14] First Port to all Class based to run in ABAP Cloud --- src/package.devc.xml | 1 + src/zcl_axage_actor.clas.abap | 53 ++++ src/zcl_axage_actor.clas.xml | 16 ++ src/zcl_axage_demo1.clas.abap | 111 ++++++++ src/zcl_axage_demo1.clas.xml | 16 ++ src/zcl_axage_engine.clas.abap | 279 +++++++++++++++++++++ src/zcl_axage_engine.clas.testclasses.abap | 66 +++++ src/zcl_axage_engine.clas.xml | 17 ++ src/zcl_axage_map.clas.abap | 49 ++++ src/zcl_axage_map.clas.xml | 16 ++ src/zcl_axage_openable_thing.clas.abap | 75 ++++++ src/zcl_axage_openable_thing.clas.xml | 16 ++ src/zcl_axage_result.clas.abap | 39 +++ src/zcl_axage_result.clas.xml | 16 ++ src/zcl_axage_room.clas.abap | 57 +++++ src/zcl_axage_room.clas.xml | 16 ++ src/zcl_axage_thing.clas.abap | 26 ++ src/zcl_axage_thing.clas.xml | 16 ++ src/zcl_axage_thing_list.clas.abap | 71 ++++++ src/zcl_axage_thing_list.clas.xml | 16 ++ 20 files changed, 972 insertions(+) create mode 100644 src/zcl_axage_actor.clas.abap create mode 100644 src/zcl_axage_actor.clas.xml create mode 100644 src/zcl_axage_demo1.clas.abap create mode 100644 src/zcl_axage_demo1.clas.xml create mode 100644 src/zcl_axage_engine.clas.abap create mode 100644 src/zcl_axage_engine.clas.testclasses.abap create mode 100644 src/zcl_axage_engine.clas.xml create mode 100644 src/zcl_axage_map.clas.abap create mode 100644 src/zcl_axage_map.clas.xml create mode 100644 src/zcl_axage_openable_thing.clas.abap create mode 100644 src/zcl_axage_openable_thing.clas.xml create mode 100644 src/zcl_axage_result.clas.abap create mode 100644 src/zcl_axage_result.clas.xml create mode 100644 src/zcl_axage_room.clas.abap create mode 100644 src/zcl_axage_room.clas.xml create mode 100644 src/zcl_axage_thing.clas.abap create mode 100644 src/zcl_axage_thing.clas.xml create mode 100644 src/zcl_axage_thing_list.clas.abap create mode 100644 src/zcl_axage_thing_list.clas.xml diff --git a/src/package.devc.xml b/src/package.devc.xml index ff44728..199c648 100644 --- a/src/package.devc.xml +++ b/src/package.devc.xml @@ -4,6 +4,7 @@ ABAP teXt Adventure Game Engine + X 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..97de46b --- /dev/null +++ b/src/zcl_axage_demo1.clas.abap @@ -0,0 +1,111 @@ +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 + out TYPE REF TO if_oo_adt_classrun_out. +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: + interprete( command = 'HELP' out = out ). + interprete( command = 'EAST' out = out ). + interprete( command = 'TAKE KNIFE' out = out ). + + IF 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. + DATA(result) = engine->interprete( command ). + result->add( |You are in the { engine->player->location->name }.| ). + out->write( result->get( ) ). + out->write( 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..68243f4 --- /dev/null +++ b/src/zcl_axage_engine.clas.abap @@ -0,0 +1,279 @@ +CLASS zcl_axage_engine DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + 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 = zcl_axage_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 = zcl_axage_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 = zcl_axage_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 = zcl_axage_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 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 <> zcl_axage_room=>no_exit. + result->add( 'There is a door on the east side' ). + ENDIF. + IF player->location->west <> zcl_axage_room=>no_exit. + result->add( 'There is a door on the west side' ). + ENDIF. + IF player->location->north <> zcl_axage_room=>no_exit. + result->add( 'There is a door on the north side' ). + ENDIF. + IF player->location->south <> zcl_axage_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. 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..bf8ab5c --- /dev/null +++ b/src/zcl_axage_map.clas.abap @@ -0,0 +1,49 @@ +CLASS zcl_axage_map DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + 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..c2e8bb8 --- /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 &&= 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..42cbb81 --- /dev/null +++ b/src/zcl_axage_thing.clas.abap @@ -0,0 +1,26 @@ +CLASS zcl_axage_thing DEFINITION + PUBLIC + CREATE PUBLIC . + + PUBLIC SECTION. + 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..06f4c7e --- /dev/null +++ b/src/zcl_axage_thing_list.clas.abap @@ -0,0 +1,71 @@ +CLASS zcl_axage_thing_list DEFINITION + PUBLIC + CREATE PUBLIC . + + PUBLIC SECTION. + 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 + + + + From 8c067fc024994c475fee024decc9306159aa403f Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Mon, 1 May 2023 19:54:24 +0000 Subject: [PATCH 06/14] Add serializble interface to classes for stateless usage (UI5) --- src/zcl_axage_engine.clas.abap | 1 + src/zcl_axage_map.clas.abap | 1 + src/zcl_axage_thing.clas.abap | 1 + src/zcl_axage_thing_list.clas.abap | 1 + 4 files changed, 4 insertions(+) diff --git a/src/zcl_axage_engine.clas.abap b/src/zcl_axage_engine.clas.abap index 68243f4..d2c813b 100644 --- a/src/zcl_axage_engine.clas.abap +++ b/src/zcl_axage_engine.clas.abap @@ -4,6 +4,7 @@ CLASS zcl_axage_engine DEFINITION CREATE PUBLIC . PUBLIC SECTION. + INTERFACES if_serializable_object. METHODS constructor. METHODS interprete IMPORTING diff --git a/src/zcl_axage_map.clas.abap b/src/zcl_axage_map.clas.abap index bf8ab5c..741fda6 100644 --- a/src/zcl_axage_map.clas.abap +++ b/src/zcl_axage_map.clas.abap @@ -4,6 +4,7 @@ CLASS zcl_axage_map DEFINITION CREATE PUBLIC . PUBLIC SECTION. + INTERFACES if_serializable_object. METHODS add_room IMPORTING room TYPE REF TO zcl_axage_room. diff --git a/src/zcl_axage_thing.clas.abap b/src/zcl_axage_thing.clas.abap index 42cbb81..18b5d1a 100644 --- a/src/zcl_axage_thing.clas.abap +++ b/src/zcl_axage_thing.clas.abap @@ -3,6 +3,7 @@ CLASS zcl_axage_thing DEFINITION CREATE PUBLIC . PUBLIC SECTION. + INTERFACES if_serializable_object. DATA name TYPE string. DATA description TYPE string. diff --git a/src/zcl_axage_thing_list.clas.abap b/src/zcl_axage_thing_list.clas.abap index 06f4c7e..b07b092 100644 --- a/src/zcl_axage_thing_list.clas.abap +++ b/src/zcl_axage_thing_list.clas.abap @@ -3,6 +3,7 @@ CLASS zcl_axage_thing_list DEFINITION 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 From e9029adfd81e3f41f0bdc9cc89dacdbf13be71e7 Mon Sep 17 00:00:00 2001 From: Enno <75187288+Ennowulff@users.noreply.github.com> Date: Tue, 2 May 2023 12:17:06 +0200 Subject: [PATCH 07/14] abaplint.json --- abaplint.json | 292 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 abaplint.json diff --git a/abaplint.json b/abaplint.json new file mode 100644 index 0000000..d03439a --- /dev/null +++ b/abaplint.json @@ -0,0 +1,292 @@ +{ + "global": { + "files": "/src/**/*.*", + "skipGeneratedGatewayClasses": true, + "skipGeneratedPersistentClasses": true, + "skipGeneratedFunctionGroups": true + }, + "syntax": { + "version": "v753", + "errorNamespace": "", + "globalConstants": [], + "globalMacros": [] + }, + "dependencies": [ + { + "url": "https://github.com/abaplint/deps", + "folder": "/deps", + "files": "/src/**/*.*" + } + ], + "rules": { + "7bit_ascii": true, + "avoid_use": { + "define": true, + "endselect": true, + "execSQL": true, + "kernelCall": true, + "communication": true, + "statics": true, + "systemCall": true, + "break": true, + "defaultKey": true + }, + "check_syntax": true, + "class_attribute_names": { + "ignoreExceptions": true, + "statics": "^G._.*$", + "instance": "^M._.*$", + "constants": "^C._.*$", + "ignoreLocal": false, + "ignoreInterfaces": 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": { + "keywords": true, + "startParen": true, + "endParen": true, + "afterColon": true + }, + "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": { + "style": "upper", + "ignoreExceptions": true, + "ignoreLowerClassImplmentationStatement": true, + "ignoreGlobalClassDefinition": false, + "ignoreGlobalInterface": false, + "ignoreFunctionModuleName": false, + "ignoreGlobalClassBoundaries": true, + "ignoreKeywords": [] + }, + "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": { + "ignoreExceptions": true, + "importing": "^I._.*$", + "returning": "^R._.*$", + "changing": "^C._.*$", + "exporting": "^E._.*$", + "ignoreNames": [ + "P_TASK" + ] + }, + "mix_returning": true, + "msag_consistency": true, + "nesting": { + "depth": 5 + }, + "no_public_attributes": { + "allowReadOnly": true + }, + "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": true, + "release_idoc": true, + "prefer_returning_to_exporting": true, + "keep_single_parameter_on_one_line": { + "length": 120 + }, + "allowed_object_naming": true, + "chain_mainly_declarations": true, + "fully_type_constants": true, + "check_abstract": true, + "check_comments": { + "allowEndOfLine": true + }, + "selection_screen_naming": { + "selectOption": "^s_.+$", + "parameter": "^p_.+$", + "patternKind": "required" + }, + "check_text_elements": true, + "check_ddic": true, + "newline_between_methods": { + "logic": "less", + "count": 3 + }, + "check_include": true, + "xml_consistency": true, + "prefix_is_current_class": { + "omitMeInstanceCalls": true + }, + "check_no_handler_pragma": true, + "line_break_multiple_parameters": true, + "forbidden_identifier": { + "check": [], + "exclude": [] + }, + "forbidden_void_type": true, + "prefer_inline": true, + "reduce_string_templates": true, + "sicf_consistency": true, + "sql_escape_host_variables": true, + "try_without_catch": true, + "types_naming": { + "pattern": "^T._.*$" + }, + "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 + } +} From ae7f54d034a568223097c73312f325d99d59d5a6 Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Tue, 2 May 2023 13:20:45 +0200 Subject: [PATCH 08/14] update linter configuration to match code better --- abaplint.json | 80 +++++++++------------------------------------------ 1 file changed, 14 insertions(+), 66 deletions(-) diff --git a/abaplint.json b/abaplint.json index d03439a..de1a09d 100644 --- a/abaplint.json +++ b/abaplint.json @@ -7,9 +7,7 @@ }, "syntax": { "version": "v753", - "errorNamespace": "", - "globalConstants": [], - "globalMacros": [] + "errorNamespace": "^(Z|Y|LCL_|TY_|LIF_)" }, "dependencies": [ { @@ -22,24 +20,13 @@ "7bit_ascii": true, "avoid_use": { "define": true, - "endselect": true, - "execSQL": true, - "kernelCall": true, - "communication": true, + "testSeams": true, "statics": true, - "systemCall": true, "break": true, "defaultKey": true }, "check_syntax": true, - "class_attribute_names": { - "ignoreExceptions": true, - "statics": "^G._.*$", - "instance": "^M._.*$", - "constants": "^C._.*$", - "ignoreLocal": false, - "ignoreInterfaces": false - }, + "class_attribute_names": false, "cloud_types": true, "colon_missing_space": true, "commented_code": true, @@ -47,12 +34,7 @@ "contains_tab": true, "definitions_top": true, "description_empty": true, - "double_space": { - "keywords": true, - "startParen": true, - "endParen": true, - "afterColon": true - }, + "double_space": false, "empty_line_in_statement": { "allowChained": false }, @@ -86,16 +68,7 @@ "ignoreGlobalInterface": false }, "inline_data_old_versions": true, - "keyword_case": { - "style": "upper", - "ignoreExceptions": true, - "ignoreLowerClassImplmentationStatement": true, - "ignoreGlobalClassDefinition": false, - "ignoreGlobalInterface": false, - "ignoreFunctionModuleName": false, - "ignoreGlobalClassBoundaries": true, - "ignoreKeywords": [] - }, + "keyword_case": false, "line_length": { "length": 120 }, @@ -119,24 +92,13 @@ "ignoreTestClasses": false, "errorWhenEmpty": true }, - "method_parameter_names": { - "ignoreExceptions": true, - "importing": "^I._.*$", - "returning": "^R._.*$", - "changing": "^C._.*$", - "exporting": "^E._.*$", - "ignoreNames": [ - "P_TASK" - ] - }, + "method_parameter_names": false, "mix_returning": true, "msag_consistency": true, "nesting": { "depth": 5 }, - "no_public_attributes": { - "allowReadOnly": true - }, + "no_public_attributes": false, "object_naming": { "clas": "^ZC(L|X)\\_AXAGE_", "intf": "^ZIF\\_AXAGE_", @@ -223,12 +185,10 @@ "main_file_contents": true, "type_form_parameters": true, "rfc_error_handling": true, - "abapdoc": true, + "abapdoc": false, "release_idoc": true, "prefer_returning_to_exporting": true, - "keep_single_parameter_on_one_line": { - "length": 120 - }, + "keep_single_parameter_on_one_line": false, "allowed_object_naming": true, "chain_mainly_declarations": true, "fully_type_constants": true, @@ -236,11 +196,7 @@ "check_comments": { "allowEndOfLine": true }, - "selection_screen_naming": { - "selectOption": "^s_.+$", - "parameter": "^p_.+$", - "patternKind": "required" - }, + "selection_screen_naming": false, "check_text_elements": true, "check_ddic": true, "newline_between_methods": { @@ -249,24 +205,16 @@ }, "check_include": true, "xml_consistency": true, - "prefix_is_current_class": { - "omitMeInstanceCalls": true - }, + "prefix_is_current_class": false, "check_no_handler_pragma": true, - "line_break_multiple_parameters": true, - "forbidden_identifier": { - "check": [], - "exclude": [] - }, + "line_break_multiple_parameters": false, "forbidden_void_type": true, - "prefer_inline": true, + "prefer_inline": false, "reduce_string_templates": true, "sicf_consistency": true, "sql_escape_host_variables": true, "try_without_catch": true, - "types_naming": { - "pattern": "^T._.*$" - }, + "types_naming": false, "unknown_types": true, "unused_variables": true, "begin_single_include": true, From c4a8bda12d7da6a266a0f584b0aee1f09e2f03a8 Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Tue, 2 May 2023 14:55:07 +0000 Subject: [PATCH 09/14] Fix issue with if_oo_adt_classrun_out not being available on older releases --- src/zcl_axage_demo1.clas.abap | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/zcl_axage_demo1.clas.abap b/src/zcl_axage_demo1.clas.abap index 97de46b..2356a61 100644 --- a/src/zcl_axage_demo1.clas.abap +++ b/src/zcl_axage_demo1.clas.abap @@ -13,8 +13,9 @@ CLASS zcl_axage_demo1 DEFINITION DATA engine TYPE REF TO zcl_axage_engine. METHODS interprete IMPORTING - command TYPE clike - out TYPE REF TO if_oo_adt_classrun_out. + command TYPE clike + RETURNING + VALUE(result) TYPE REF TO zcl_axage_result. ENDCLASS. @@ -91,9 +92,9 @@ CLASS zcl_axage_demo1 IMPLEMENTATION. METHOD if_oo_adt_classrun~main. "Add Your Commands Here: - interprete( command = 'HELP' out = out ). - interprete( command = 'EAST' out = out ). - interprete( command = 'TAKE KNIFE' out = out ). + out->write( interprete( 'HELP' )->get( ) ). + out->write( interprete( 'EAST' )->get( ) ). + out->write( interprete( 'TAKE KNIFE' )->get( ) ). IF engine->player->location->things->exists( 'RFC' ). engine->mission_completed = abap_true. @@ -102,10 +103,9 @@ CLASS zcl_axage_demo1 IMPLEMENTATION. ENDMETHOD. METHOD interprete. - DATA(result) = engine->interprete( command ). + result = engine->interprete( command ). result->add( |You are in the { engine->player->location->name }.| ). - out->write( result->get( ) ). - out->write( engine->get_inventory( )->get( ) ). + result->add( engine->get_inventory( )->get( ) ). ENDMETHOD. ENDCLASS. From 81b78b48370e974bca810bab9b1b2aa5f6db88bd Mon Sep 17 00:00:00 2001 From: Enno Wulff Date: Thu, 4 May 2023 19:55:38 +0000 Subject: [PATCH 10/14] code compatibality &&= replaced --- src/package.devc.xml | 1 - src/zcl_axage_result.clas.abap | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/package.devc.xml b/src/package.devc.xml index 199c648..ff44728 100644 --- a/src/package.devc.xml +++ b/src/package.devc.xml @@ -4,7 +4,6 @@ ABAP teXt Adventure Game Engine - X diff --git a/src/zcl_axage_result.clas.abap b/src/zcl_axage_result.clas.abap index c2e8bb8..c1c370a 100644 --- a/src/zcl_axage_result.clas.abap +++ b/src/zcl_axage_result.clas.abap @@ -29,7 +29,7 @@ CLASS zcl_axage_result IMPLEMENTATION. METHOD get. LOOP AT text REFERENCE INTO DATA(line). - textstring &&= line->* && cl_abap_char_utilities=>cr_lf. + textstring = textstring && line->* && cl_abap_char_utilities=>cr_lf. ENDLOOP. ENDMETHOD. From 6b18051ff345d88102860938e5f133b9166257b0 Mon Sep 17 00:00:00 2001 From: Thomas Jung Date: Mon, 8 May 2023 20:02:11 +0000 Subject: [PATCH 11/14] Check Room Name to avoid non match after restoring class instances from serialization --- src/zcl_axage_demo1.clas.abap | 1 + src/zcl_axage_engine.clas.abap | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/zcl_axage_demo1.clas.abap b/src/zcl_axage_demo1.clas.abap index 2356a61..b1dca40 100644 --- a/src/zcl_axage_demo1.clas.abap +++ b/src/zcl_axage_demo1.clas.abap @@ -93,6 +93,7 @@ CLASS zcl_axage_demo1 IMPLEMENTATION. "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( ) ). diff --git a/src/zcl_axage_engine.clas.abap b/src/zcl_axage_engine.clas.abap index d2c813b..812e560 100644 --- a/src/zcl_axage_engine.clas.abap +++ b/src/zcl_axage_engine.clas.abap @@ -55,7 +55,7 @@ CLASS zcl_axage_engine IMPLEMENTATION. result->addTab( map->show( ) ). WHEN 'N' OR 'NORTH'. - IF player->location->north = zcl_axage_room=>no_exit. + IF player->location->north->name = zcl_axage_room=>no_exit->name. result->add( 'you cannot go there.' ). ELSE. player->set_location( player->location->north ). @@ -63,7 +63,7 @@ CLASS zcl_axage_engine IMPLEMENTATION. cmd_look( result ). WHEN 'S' OR 'SOUTH'. - IF player->location->south = zcl_axage_room=>no_exit. + IF player->location->south->name = zcl_axage_room=>no_exit->name. result->add( 'you cannot go there.' ). ELSE. player->set_location( player->location->south ). @@ -71,7 +71,7 @@ CLASS zcl_axage_engine IMPLEMENTATION. cmd_look( result ). WHEN 'E' OR 'EAST'. - IF player->location->east = zcl_axage_room=>no_exit. + IF player->location->east->name = zcl_axage_room=>no_exit->name. result->add( 'you cannot go there.' ). ELSE. player->set_location( player->location->east ). @@ -79,7 +79,7 @@ CLASS zcl_axage_engine IMPLEMENTATION. cmd_look( result ). WHEN 'W' OR 'WEST'. - IF player->location->west = zcl_axage_room=>no_exit. + IF player->location->west->name = zcl_axage_room=>no_exit->name. result->add( 'you cannot go there.' ). ELSE. player->set_location( player->location->west ). @@ -253,16 +253,16 @@ CLASS zcl_axage_engine IMPLEMENTATION. result->addtab( player->location->things->show( ) ). ENDIF. - IF player->location->east <> zcl_axage_room=>no_exit. + 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 <> zcl_axage_room=>no_exit. + 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 <> zcl_axage_room=>no_exit. + 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 <> zcl_axage_room=>no_exit. + IF player->location->south->name <> zcl_axage_room=>no_exit->name. result->add( 'There is a door on the south side' ). ENDIF. From 6e158d252697d54bcb7e66cc5ff41688b4671597 Mon Sep 17 00:00:00 2001 From: Enno <75187288+Ennowulff@users.noreply.github.com> Date: Mon, 8 May 2023 23:45:12 +0200 Subject: [PATCH 12/14] line size --- src/zaxage_demo_01.prog.abap | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/zaxage_demo_01.prog.abap b/src/zaxage_demo_01.prog.abap index d484cb1..67a3752 100644 --- a/src/zaxage_demo_01.prog.abap +++ b/src/zaxage_demo_01.prog.abap @@ -72,9 +72,15 @@ CLASS main IMPLEMENTATION. 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!' ). + 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 ). From 966daee0495ce78890085c29eb8704a8e67136f6 Mon Sep 17 00:00:00 2001 From: Kjetil Kilhavn Date: Sun, 4 Jun 2023 05:23:00 +0000 Subject: [PATCH 13/14] Fix conditions for completion of demo game The demo game states that you should deliver the RFC to the developers. Added condition that you have to be in the same room as bill the developer. --- src/zaxage_demo_01.prog.abap | 15 ++++++++------- src/zcl_axage_demo1.clas.abap | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/zaxage_demo_01.prog.abap b/src/zaxage_demo_01.prog.abap index 67a3752..dfb2a10 100644 --- a/src/zaxage_demo_01.prog.abap +++ b/src/zaxage_demo_01.prog.abap @@ -72,14 +72,14 @@ CLASS main IMPLEMENTATION. engine = NEW #( ). - DATA(entrance) = NEW room( - name = 'Entrance' + DATA(entrance) = NEW room( + name = 'Entrance' descr = 'You are in the entrance area. Welcome.' ). - DATA(developer) = NEW room( - name = 'Developers office' + DATA(developer) = NEW room( + name = 'Developers office' descr = 'The developers area. be quiet!' ). - DATA(consulting) = NEW room( - name = 'Consulting Department' + DATA(consulting) = NEW room( + name = 'Consulting Department' descr = 'This is the area where the consultants work. Bring coffee!' ). engine->map->add_room( entrance ). @@ -153,7 +153,8 @@ CLASS main IMPLEMENTATION. result->add( |You are in the { engine->player->location->name }.| ). " { player->location->description }|. text->set_textstream( result->get( ) ). - IF engine->player->location->things->exists( 'RFC' ). + IF engine->player->location = bill_developer->location AND + engine->player->location->things->exists( 'RFC' ). engine->mission_completed = abap_true. ENDIF. diff --git a/src/zcl_axage_demo1.clas.abap b/src/zcl_axage_demo1.clas.abap index b1dca40..22f1291 100644 --- a/src/zcl_axage_demo1.clas.abap +++ b/src/zcl_axage_demo1.clas.abap @@ -97,7 +97,8 @@ CLASS zcl_axage_demo1 IMPLEMENTATION. out->write( interprete( 'EAST' )->get( ) ). out->write( interprete( 'TAKE KNIFE' )->get( ) ). - IF engine->player->location->things->exists( 'RFC' ). + 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. From 103b68cff2363ce2e8e568e1e8beb1443763de7d Mon Sep 17 00:00:00 2001 From: Kjetil Kilhavn Date: Sun, 4 Jun 2023 12:43:09 +0200 Subject: [PATCH 14/14] Add trailing spaces back to statements which weren't changed Trailing spaces added back to statements which weren't changed to reduce the "foot print" of the pull request. --- src/zaxage_demo_01.prog.abap | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/zaxage_demo_01.prog.abap b/src/zaxage_demo_01.prog.abap index dfb2a10..8d33b2e 100644 --- a/src/zaxage_demo_01.prog.abap +++ b/src/zaxage_demo_01.prog.abap @@ -72,14 +72,14 @@ CLASS main IMPLEMENTATION. engine = NEW #( ). - DATA(entrance) = NEW room( - name = 'Entrance' + DATA(entrance) = NEW room( + name = 'Entrance' descr = 'You are in the entrance area. Welcome.' ). - DATA(developer) = NEW room( - name = 'Developers office' + DATA(developer) = NEW room( + name = 'Developers office' descr = 'The developers area. be quiet!' ). - DATA(consulting) = NEW room( - name = 'Consulting Department' + DATA(consulting) = NEW room( + name = 'Consulting Department' descr = 'This is the area where the consultants work. Bring coffee!' ). engine->map->add_room( entrance ).