Posts tagged Programming

Welcome to www.plinky.it

0

Dear reader,

I’m proud to present you the new Plinky Blog, yesterday we moved to a no-free domain and also upgraded to Worpress 4.7 and Librio 1.0.

Many news are coming, stay tuned!!!

See you very soon again on WWW.PLINKY.IT.

Ivan

Galaxy wars with ABAP

0

It is a simple shooting game; you are a cannon at the screen bottom and you have to hit the ship moving on the top.

Use the buttons left and right for moving your cannon and press launch button when ready. Game can be improved but it’s not the scope of this experiment.

Galaxy wars

Create a report named ZMOVING and copy & paste the code below:

*************************************************************

*===============================================*
*
* Galaxy wars
* This report was initially created at http://www.plinky.it/
* Please, read terms and conditions on the site.
*
*===============================================*
*
* Created on 2008-02-15
*
*===============================================*

REPORT ZMOVING LINE-SIZE 132 no standard page heading.

INCLUDE <ICON>.

DATA:
ship TYPE string,
ship_pos TYPE INT4 value 1,
rocket_pos TYPE INT4 value 10,
rocket_tower TYPE INT4 value 10,
reverse type c value ‘ ‘,
launched type c value ‘ ‘,
point type i value 0,
launch type i value 0,
ratio type ETDTAXPERCNT value 0,
screen_size type i value 20.

ship = ‘Y’.

GET TIME.
PERFORM PRINT_PANEL.
PERFORM PRINT_SHIP CHANGING reverse ship_pos.

CALL FUNCTION ‘Z_SCREEN_REFRESH’
STARTING NEW TASK ‘IF’
PERFORMING START_REFRESH ON END OF TASK.

AT LINE-SELECTION.
DATA: FIELD(30),VALUE(50).
GET CURSOR FIELD FIELD VALUE VALUE.
IF FIELD = ‘ICON_ACTIVATE’ OR VALUE = ‘ LAUNCH! ‘.
if launched = ‘ ‘.
launched = ‘X’.
launch = launch + 1.
endif.
ELSEIF FIELD = ‘ICON_COLUMN_LEFT’.
if rocket_tower > 1 AND launched = ‘ ‘.
rocket_tower = rocket_tower – 1.
endif.
ELSEIF FIELD = ‘ICON_COLUMN_RIGHT’.
if rocket_tower < screen_size AND launched = ‘ ‘.
rocket_tower = rocket_tower + 1.
endif.
ELSEIF FIELD = ‘ICON_BREAKPOINT’ OR VALUE = ‘ EXIT ‘.
LEAVE PROGRAM.
ENDIF.

AT USER-COMMAND.
IF SY-UCOMM = ‘REFR’.
SY-LSIND = SY-LSIND – 1.
GET TIME.
PERFORM PRINT_PANEL.
PERFORM PRINT_SHIP CHANGING reverse ship_pos.
PERFORM PRINT_ROCKET CHANGING rocket_pos ship_pos point.

CALL FUNCTION ‘Z_SCREEN_REFRESH’
STARTING NEW TASK ‘IF’
PERFORMING START_REFRESH ON END OF TASK.

ENDIF.

*—————————————————————-
* Program Subroutines
*—————————————————————-
FORM START_REFRESH USING TASKNAME.

SET USER-COMMAND ‘REFR’.
ENDFORM.

FORM PRINT_SHIP CHANGING
reverse TYPE c
cur_pos TYPE i.

if cur_pos >= screen_size.
reverse = ‘X’.
elseif cur_pos <= 1.
reverse = ‘ ‘.
endif.
if reverse = ‘X’.
cur_pos = cur_pos – 1.
else.
cur_pos = cur_pos + 1.
endif.
SKIP TO LINE 1.
POSITION cur_pos.
WRITE: ship.
ENDFORM.

FORM PRINT_ROCKET CHANGING
cur_pos TYPE i
ship_pos TYPE i
point TYPE i.

if cur_pos > 1 AND launched = ‘X’.
cur_pos = cur_pos – 1.
else.
launched = ‘ ‘.
cur_pos = 10.
ratio = ( point * 10 ) / launch.
endif.

if launched = ‘X’.

SKIP TO LINE cur_pos.

POSITION rocket_tower.
if cur_pos = 1 AND ship_pos = rocket_tower.
WRITE: ‘X’.
ship_pos = 1.
point = point + 10.
else.
WRITE: ‘^’.
endif.
endif.

ENDFORM.

FORM print_panel.
data:
row type i value 0,
last_col type i.
last_col = screen_size + 1.

DO 10 TIMES.
row = row + 1.
SKIP TO LINE row.
POSITION last_col.
WRITE: ‘|’.
ENDDO.

last_col = last_col + 1.
SKIP TO LINE 3.
POSITION last_col.
FORMAT COLOR COL_NEGATIVE.
WRITE: ‘Point: ‘, point, ‘ ‘.
SKIP TO LINE 4.
POSITION last_col.
FORMAT COLOR COL_POSITIVE.
WRITE: ‘Launch: ‘, launch, ‘ ‘.
SKIP TO LINE 5.
POSITION last_col.
FORMAT COLOR COL_TOTAL.
WRITE: ‘Ratio:’, ratio, ‘%’.
FORMAT RESET.
POSITION 0.
SKIP TO LINE row.
ULINE: AT /(SY-SCOLS).
POSITION rocket_tower.
WRITE: ‘U’.
write /.
ULINE: AT /(5), AT 7(5).
FORMAT COLOR COL_KEY.
WRITE:/ ‘|’,ICON_COLUMN_LEFT AS ICON NO-GAP,
‘|’ NO-GAP ,SPACE NO-GAP COLOR COL_BACKGROUND,
‘|’,ICON_COLUMN_RIGHT AS ICON NO-GAP,’|’.
FORMAT RESET.
ULINE: AT /(5), AT 7(5).
write /.
ULINE: AT /(15), AT 17(12).
FORMAT COLOR COL_KEY.
WRITE:/ ‘|’,ICON_ACTIVATE AS ICON NO-GAP, ‘ LAUNCH! ‘ HOTSPOT,
‘|’ NO-GAP ,SPACE NO-GAP COLOR COL_BACKGROUND,
‘|’,ICON_BREAKPOINT AS ICON NO-GAP,’ EXIT ‘ HOTSPOT,’|’.
FORMAT RESET.
ULINE: AT /(15), AT 17(12).
ENDFORM.

*************************************************************

Create a RFC function named Z_SCREEN_REFRESH and copy & paste code below:

*************************************************************

*”———————————————————————-
*”*”Local Interface:
*”———————————————————————-

DATA: ZTIME LIKE SY-UZEIT.

GET TIME.

ZTIME = SY-UZEIT + 1.

DO.
GET TIME.
IF SY-UZEIT >= ZTIME.
EXIT.
ENDIF.
ENDDO.

ENDFUNCTION.

*************************************************************

Go to Top