Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

i made an applet! two classes

Name: faggot mcwhorenut 2007-07-09 10:24 ID:7VWjQAC1


import java.awt.*;
import java.applet.*;

public class grid extends Applet
{
    private interpreter test;
   
    public void init()
    {
        test = new interpreter(12,448,32);
    //    test = new interpreter(10,224,16);
    //    test = new interpreter();
    }

    public void paint(Graphics g)
    {
        int X = 0;
        int Y = 0;
       
        int[] map2 = new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,9,9,9,9,9,9,0,6,6,0,0,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,1,1,1,9,9,9,9,0,6,0,0,0,0,6,0,0,1,1,1,0,0,0,0,0,0,0,0,0,9,9,9,9,1,1,1,1,9,9,9,0,0,0,2,3,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,9,9,9,1,1,1,1,1,1,9,9,0,0,0,4,5,0,0,0,0,2,2,2,0,0,0,0,0,0,0,0,9,9,9,1,1,1,1,1,1,1,9,9,0,6,0,0,0,0,6,0,0,2,2,2,0,0,0,0,0,0,9,9,9,9,9,1,1,1,1,1,1,1,1,9,0,6,6,0,0,6,6,0,0,0,0,0,0,0,0,0,0,9,9,9,9,9,1,1,1,1,1,1,1,1,1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,9,1,1,1,1,1,1,1,1,1,1,9,0,0,9,9,9,0,0,0,0,0,0,0,0,0,0,0,9,9,9,9,9,1,1,1,1,1,1,1,1,1,1,9,0,9,9,9,9,9,0,0,3,3,0,0,0,0,0,0,9,9,9,9,9,1,1,1,1,1,1,1,1,1,9,9,0,9,9,9,9,9,9,0,3,3,0,0,0,0,0,9,9,9,9,9,9,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,3,3,9,9,9,9,9,9,9,9,9,9,9,9,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,3,3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
        int[] map = new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,6,0,0,6,6,0,0,1,1,1,1,0,0,0,0,6,0,0,0,0,6,0,1,1,1,1,1,1,0,0,0,0,0,2,3,0,0,0,0,2,2,2,2,0,0,0,0,0,0,4,5,0,0,0,0,2,2,2,2,0,0,0,0,6,0,0,0,0,6,0,0,2,2,2,2,0,0,0,0,6,6,0,0,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,9,9,0,0,3,3,0,0,0,0,0,0,0,9,9,9,9,9,9,0,3,3,0,0,0,0,0,9,0,0,9,9,9,9,9,9,3,3,9,9,9,9,9,9,0,0,9,9,9,9,9,9,3,3,9,9,9,9,9,9,0,9,9,9,9,9,9,9,3,3,9,9,9,9,9,9};
        int[] field = new int[] {0,0,0,0,0,0,0,0,0,6,6,0,0,6,6,0,0,6,0,0,0,0,6,0,0,0,0,2,3,0,0,0,0,0,0,4,5,0,0,0,0,6,0,0,0,0,6,0,0,6,6,0,0,6,6,0,0,0,0,0,0,0,0,0};
       
        test.interpret(map2,g);
    }
   
}

//
//
//
// below this is another class
//
//
//

import java.awt.*;
import java.lang.String;

public class interpreter
{
   
    private int distance;
    private int tilesize;
    private int mapsize;
    private int TOP;
    private int MID;
    private Color tiletype;

    public interpreter ()
    {
        distance = 8;
        tilesize = 20;
        mapsize = 64;
        TOP = 40;
        MID = 60;
    }
   
    public interpreter (int tile, int map, int horizontal)
    {
        distance = horizontal;
        tilesize = tile;
        mapsize = map;
        TOP = tile * 2;
        MID = tile * 3;
    }

    public void interpret(int[] work, Graphics page)
    {
        int MIDreset = MID;
        int a = 0;
        int tcount = 0;
        while(a != mapsize)
        {
            if (work[a] == 0)
            {
                page.setColor (Color.green);
                page.fillRect (MID, TOP, tilesize,tilesize);
            }
            else
            if (work[a] == 1)
            {
                page.setColor (Color.lightGray);
                page.fillRect (MID, TOP, tilesize,tilesize);
            }
            else
            if (work[a] == 2)
            {
                page.setColor (Color.orange);
                page.fillRect (MID, TOP, tilesize,tilesize);
            }
            else
            if (work[a] == 3)
            {
                page.setColor (Color.red);
                page.fillRect (MID, TOP, tilesize,tilesize);
            }
            else
            if (work[a] == 4)
            {
                page.setColor (Color.pink);
                page.fillRect (MID, TOP, tilesize,tilesize);
            }
            else
            if (work[a] == 5)
            {
                page.setColor (Color.magenta);
                page.fillRect (MID, TOP, tilesize,tilesize);
            }
            else
            if (work[a] == 6)
            {
                page.setColor (Color.darkGray);
                page.fillRect (MID, TOP, tilesize,tilesize);
            }
            else
            page.setColor (Color.blue);
            page.fillRect (MID, TOP, tilesize,tilesize);
           
            a = a + 1;
            tcount = tcount + 1;
            MID = MID + tilesize;
           
            if (tcount == distance)
            {
                tcount = 0;
                TOP = TOP + tilesize;
                MID = MIDreset;
            }
        }   
    }           
}

Name: Anonymous 2007-07-09 10:26 ID:7VWjQAC1

i'm looking for any sort of advice on how to tidy this up, and also if anyone knows, would this be useful at all towards a vidyagame? you can see from the maps i made i was originally thinking a zelda clone, but i think i will start simple and make tetris first.

the interpret command is ugly, but i don't know how to make it any tidier. i need to make it work with 2D arrays, but i have no fucking clue how (then again, before i did this, i had know idea how to do this, so i think i can figure it out).

Name: Anonymous 2007-07-09 10:32 ID:Heaven

That's some serious ENTERPRISE QUALITY code there

Name: Anonymous 2007-07-09 10:37 ID:Heaven

resources go in external files

Name: Anonymous 2007-07-09 10:37 ID:7VWjQAC1

oh wait, i forgot, this is a 4chan textboard

Name: Anonymous 2007-07-09 10:38 ID:7VWjQAC1

>>4
yea, i had thought about that, i know ther is a way, but forgot how. i think that'll be the next thing i add, in order to make it less HUEG

Name: Anonymous 2011-02-03 2:38

Don't change these.
Name: Email:
Entire Thread Thread List