-
Notifications
You must be signed in to change notification settings - Fork 9
/
zaxage_demo_01.prog.abap
211 lines (172 loc) · 6.39 KB
/
zaxage_demo_01.prog.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
REPORT zaxage_demo_01 NO STANDARD PAGE HEADING.
" next: add actors
" command like
" - OPEN BOX WITH KNIFE
" - GIVE DOCUMENT TO BILL
" new class INTERPRETER/ GAME LOGIC
" - Main class must only have general objects (map, actors, ?)
" - method INTERPRETE must be a general class
" - give complete game instance to interpretere or only necessary objects (map, actors)?
" separate GUI from GAME class
" - Main game class should only have the definitions of map, actors
"
INCLUDE zaxage_game_engine.
CLASS main DEFINITION.
PUBLIC SECTION.
METHODS constructor.
METHODS init_view
IMPORTING
container TYPE REF TO cl_gui_container.
METHODS init_inventory
IMPORTING
container TYPE REF TO cl_gui_container.
METHODS interprete
IMPORTING
command TYPE clike
RETURNING
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 bill_developer TYPE REF TO actor.
DATA mark_consultant TYPE REF TO actor.
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 engine TYPE REF TO engine.
ENDCLASS.
CLASS main IMPLEMENTATION.
METHOD init_view.
me->container = container.
me->text = NEW #( parent = container ).
me->text->set_readonly_mode( 1 ).
me->text->set_toolbar_mode( 0 ).
me->text->set_statusbar_mode( 0 ).
me->text->set_font_fixed( 1 ).
ENDMETHOD.
METHOD init_inventory.
me->inventory_container = container.
me->inventory = NEW #( parent = inventory_container ).
me->inventory->set_readonly_mode( 1 ).
me->inventory->set_toolbar_mode( 0 ).
me->inventory->set_statusbar_mode( 0 ).
me->inventory->set_font_fixed( 1 ).
ENDMETHOD.
METHOD constructor.
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 #(
( `+--------------------+ +--------------------+` )
( `| | | |` )
( `| | | |` )
( `| +-+ |` )
( `| ENTRANCE DEVELOPERS |` )
( `| +-+ |` )
( `| | | |` )
( `| | | |` )
( `+--------+ +--------+ +--------------------+` )
( ` | |` )
( `+--------+ +--------+` )
( `| |` )
( `| |` )
( `| |` )
( `| CONSULTANTS |` )
( `| |` )
( `| |` )
( `| |` )
( `+--------------------+` ) ) ).
entrance->set_exits(
e = developer
s = consulting ).
developer->set_exits(
w = entrance ).
consulting->set_exits(
n = entrance ).
DATA(cutter_knife) = NEW thing( name = 'KNIFE' descr = 'a very sharp cutter knife' ).
developer->things->add( cutter_knife ).
DATA(needed_to_open_box) = NEW thinglist( ).
needed_to_open_box->add( cutter_knife ).
DATA(content_of_box) = NEW thinglist( ).
content_of_box->add( NEW thing( name = 'RFC' descr = 'The request for change.' ) ).
DATA(card_box) = NEW 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 interprete.
result = engine->interprete( command ).
result->add( |You are in the { engine->player->location->name }.| ). " { player->location->description }|.
text->set_textstream( result->get( ) ).
IF engine->player->location = bill_developer->location AND
engine->player->location->things->exists( 'RFC' ).
engine->mission_completed = abap_true.
ENDIF.
show_inventory( ).
ENDMETHOD.
METHOD show_inventory.
inventory->set_textstream( engine->get_inventory( )->get( ) ).
ENDMETHOD.
METHOD get_location.
result = engine->get_location( ).
ENDMETHOD.
METHOD is_completed.
result = engine->is_completed( ).
ENDMETHOD.
ENDCLASS.
SELECTION-SCREEN COMMENT /1(70) TEXT-in1.
SELECTION-SCREEN COMMENT /1(70) TEXT-in2.
PARAMETERS input TYPE c LENGTH 70.
PARAMETERS location TYPE c LENGTH 70 MODIF ID dsp.
INITIALIZATION.
DATA(app) = NEW main( ).
DATA(docker) = NEW cl_gui_docking_container( ratio = 80 side = cl_gui_docking_container=>dock_at_bottom ).
DATA(inventory) = NEW cl_gui_docking_container( ratio = 40 side = cl_gui_docking_container=>dock_at_right ).
app->init_view( docker ).
app->init_inventory( inventory ).
START-OF-SELECTION.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'DSP'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
AT SELECTION-SCREEN.
app->interprete( input ).
CLEAR input.
location = app->get_location( ).
IF app->is_completed( ).
MESSAGE 'Congratulations! You delivered the RFC to the developers!' TYPE 'I'.
ENDIF.