Robots: Difference between revisions

m
syntax highlighting fixup automation
m (J: add a tiny bit of documentation)
m (syntax highlighting fixup automation)
 
(2 intermediate revisions by one other user not shown)
Line 21:
=={{header|J}}==
 
This approximately emulates the bsd robots game. There's a few differences (the game board is larger and has an explicitly displayed junk border, to quit early you close the window, ...), but the fundamental mechanics and display should be pretty close.
 
We use two callbacks here: 'game_handler' to capture keyboard events, and 'sys_timer_z_' to capture timer events when the user uses the 'wait for game over' option.
<lang J>require'~addons/ide/qt/gl2.ijs'
 
<langsyntaxhighlight Jlang="j">require'~addons/ide/qt/gl2.ijs'
coinsert'jgl2'
 
Line 136 ⟶ 138:
 
wd'pc game closeok; setp wh 1280 720; cc chase isidraw flush;pshow'
start''</langsyntaxhighlight>
 
=={{header|Java}}==
Line 157 ⟶ 159:
(formerly Perl 6)
The bots single-mindedly chase you, taking the shortest path, ignoring obstacles. Use arrow keys to navigate your character(╂) around the board. Avoid bots(☗) and hazards(☢). "Kill" bots by causing them to crash into hazards or other bots. A dead bot creates another hazard. If you eliminate all of the bots on the board, another wave will spawn in random positions. If you touch a hazard or are touched by a bot, you die(†).
<syntaxhighlight lang="raku" perl6line>use Term::termios;
 
constant $saved = Term::termios.new(fd => 1).getattr;
Line 314 ⟶ 316:
print "\nSurvived " , $info , ' bots, but succumbed in the end.';
exit
}</langsyntaxhighlight>
{{out|Sample game}}
<pre>████████████████████████████████████████████████████████████████████████████████████████████████████
10,327

edits