Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

<1kb RL Challenge

73 views
Skip to first unread message

Numeron

unread,
Aug 7, 2008, 11:57:42 PM8/7/08
to
After a lot more work, my <1kb Roguelike has evolved somewhat since I
first posted it, but this is the final version. This challenge was a
lot of fun.

Now a zombie apocalypse game, the game features a zombie which chases
you around. Collecting all the '$' on a level will make the stairs
appear, and on the third level an '&' which is the big $100 gold coin
you came looking for in these zombie infested wherevers. Collecting it
wins you the game. Being slow gets you eaten. The game also supports
the diagonals, and 5 for wait, and is impossible to crash by falling
off the edge of the map.

The code is 948 bytes and written in Java with 2 secondary classes I
wrote in about 5 minutes for better input... only one method called
g() is used by my code and it essentially replicates getch(). I dont
count these in my source size since everyone else seems to be using
libraries and stuff for io as well. Here is the code:


class M{static int k,X=2,Y=X,x,y,g,a=6,b=a,z,l,G;public static void
main(String[] S)throws Exception{for(;;){char m[][]=new char[9][9];l+
+;g=9;for(x=0;x<9;x++)for(y=0;y<9;y++){if(m[x][y]!=36){m[x]
[y]=46;if(Math.random()<.1&&g>0){m[x]
[y]=36;g--;}}if(x>7&&y>7&&g>0)x=y=0;}m[X][Y]=64;m[a][b]=90;boolean
t=true;for(;;z=0){for(x=0;x<99;x++)System.out.println();for(y=0;y<9;y+
+){for(x=0;x<9;x++){System.out.print(m[x][y]);if(m[x][y]==36)z+
+;}System.out.println();}String q="$:"+G+" L:"+l;if(z<1)m[4]
[4]=l>2?'&':'>';if(X==4&&Y==4&&l>2){q+=" WIN!";l=0;G+=100;}else
if(X==a&&Y==b){q+="
LOST!";l=0;}System.out.println(q);k=F.i();if(l<1)System.exit(0);m[X]
[Y]=46;m[a][b]=46;if(k>48&&k<52&&Y<8)Y++;if((k==52||k==55||
k==49)&&X>0)X--;if((k==54||k==57||k==51)&&X<8)X+
+;if(k<58&&k>54&&Y>0)Y--;if(k>48&&k<58){t=!t;if(t)
{if(X<a&&a>0)a--;else if(X!=a&&a<8)a++;if(Y<b&&b>0)b--;else if(Y!
=b&&b<8)b++;}}if(m[X][Y]==36)G++;if(m[X][Y]==62)break;m[X][Y]=64;m[a]
[b]=90;}}}}


The easy to read, not compressed onto one line version follows:


class M{
static int k,X=2,Y=X,x,y,g,a=6,b=a,z,l,G;
public static void main(String[] S)throws Exception{
for(;;){
char m[][]=new char[9][9];
l++;
g=9;
for(x=0;x<9;x++)
for(y=0;y<9;y++){
if(m[x][y]!=36){
m[x][y]=46;
if(Math.random()<.1&&g>0){
m[x][y]=36;
g--;
}
}
if(x>7&&y>7&&g>0)x=y=0;
}
m[X][Y]=64;
m[a][b]=90;
boolean t=true;
for(;;z=0){
for(x=0;x<99;x++)System.out.println();
for(y=0;y<9;y++){
for(x=0;x<9;x++){
System.out.print(m[x][y]);
if(m[x][y]==36)z++;
}
System.out.println();
}
String q="$:"+G+" L:"+l;
if(z<1)m[4][4]=l>2?'&':'>';
if(X==4&&Y==4&&l>2){q+=" WIN!";l=0;G+=100;}
else if(X==a&&Y==b){q+=" LOST!";l=0;}
System.out.println(q);
k=F.i();
if(l<1)System.exit(0);
m[X][Y]=46;
m[a][b]=46;
if(k>48&&k<52&&Y<8)Y++;
if((k==52||k==55||k==49)&&X>0)X--;
if((k==54||k==57||k==51)&&X<8)X++;
if(k<58&&k>54&&Y>0)Y--;
if(k>48&&k<58){
t=!t;
if(t){
if(X<a&&a>0)a--;else if(X!=a&&a<8)a++;
if(Y<b&&b>0)b--;else if(Y!=b&&b<8)b++;
}
}
if(m[X][Y]==36)G++;
if(m[X][Y]==62)break;
m[X][Y]=64;
m[a][b]=90;
}
}
}
}


The input stuff I wrote which it works with follows:


import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class F{
public static JFrame frame;
public static Keyboard vKeyboard;
public static int i(){
if(frame == null){
frame = new JFrame();
frame.setSize(305, 50);
frame.add(new JLabel("This Window is used for input as long as
it has focus"));
vKeyboard = new Keyboard();
frame.addKeyListener(vKeyboard);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
int key = -1;
while(key == -1){
frame.requestFocus();
try{ Thread.sleep(50); }
catch(Exception e){ System.out.println(e); }
key = vKeyboard.key;
vKeyboard.key = -1;
}
return key;
}
}

class Keyboard implements KeyListener{
public int key;
public Keyboard(){}
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e){}
public void keyPressed(KeyEvent e){ key = e.getKeyChar(); }
}


-Numeron

Numeron

unread,
Aug 8, 2008, 12:11:39 AM8/8/08
to
Quick bugfix:

if(X==4&&Y==4&&l>2){q+=" WIN!";l=0;G+=100;}

Should be

if(X==4&&Y==4&&l>2&&z<1){q+=" WIN!";l=0;G+=100;}

This pushes the game up to 953 bytes :)

-Numeron

Slash

unread,
Aug 8, 2008, 12:18:50 PM8/8/08
to
On Aug 7, 11:11 pm, Numeron <irunsofastineedafinonmyh...@hotmail.com>
wrote:

You could try libjcsi, it makes console support less cumbersome :)
>
> -Numeron


--
Slashie

Slash

unread,
Sep 2, 2008, 1:06:32 PM9/2/08
to
On Aug 7, 10:57 pm, Numeron <irunsofastineedafinonmyh...@hotmail.com>
wrote:

SNIP

Ok here it goes with some small adjustements to use libjcsi, so it is
now flickerless and wont need a separate window for input! It runs
over 882 bytes now (no IO included, didnt want to mess too much with
the original source so it is kept as a separate class as the original.
With some adjustments all would fit <1024 bytes)

class N{static int k,X=2,Y=X,x,y,g,a=6,b=a,z,l,G;public static
void main(String[] S)throws Exception{F.c();for(;;){char m[][]


=new char[9][9];l++;g=9;for(x=0;x<9;x++)for(y=0;y<9;y++){if(

m[x][y]!=36){m[x][y]=46;if(Math.random()<.1&&g>0){m[x][y]=36;
g--;}}if(x>7&&y>7&&g>0)x=y=0;}m[X][Y]=64;m[a][b]=90;boolean t

=true;for(;;z=0){for(y=0;y<9;y++){for(x=0;x<9;x++){F.p(x,y,
m[x][y]);if(m[x][y]==36)z++;}}String q="$:"+G+" L:"+l;if(z<1)
m[4][4]=l>2?'&':'>';if(X==4&&Y==4&&l>2&&z<1){q+=" WIN!";l=0;
G+=100;}elseif(X==a&&Y==b){q+="LOST!";l=0;}F.p(0, 15, q);k=


F.i();if(l<1)System.exit(0);m[X][Y]=46;m[a][b]=46;if(k>48&&
k<52&&Y<8)Y++;if((k==52||k==55||k==49)&&X>0)X--;if((k==54||k==

57||k==51)&&X<8)X++;if(k<58&&k>54&&Y>0)Y--;if(k>48&&k<58){t=!t


;if(t){if(X<a&&a>0)a--;else if(X!=a&&a<8)a++;if(Y<b&&b>0)b--;
else if(Y!=b&&b<8)b++;}}if(m[X][Y]==36)G++;if(m[X][Y]==62)

break;m[X][Y]=64;m[a][b]=90;}}}}

... and the IO

import net.slashie.libjcsi.jcurses.JCursesConsoleInterface;
class F {
static JCursesConsoleInterface c = new JCursesConsoleInterface();
static int i(){return c.inkey().code - 69;}
static void p(int x, int y, String ch){c.print(x,y,ch,7);}
static void p(int x, int y, char ch){p(x,y,ch+"");}
static void c(){c.cls();}
}

It can be downloaded here: http://www.roguetemple.com/1kbrls/energonAbsorber2.zip

Run energonAbsorber.bat for the (almost) original version and
energonAbsorber2.bat for an enhanced version

Hope you like it ;)

>
> -Numeron

--
Slashie

0 new messages