BgLOG.net 30.06.2005 Stratovarius 373 прочитания

За мравките ...

Измислих всичко и е почти готово ама вече след като остана само да го напиша не ми се занимава вече ;):

Ето сорса на готовите неща, някой ако види нещо което може да е по добре да коментира ще съм благодарен:

..................................................................................................................................


public class Punkt {

    private int x;

    private int y;

    private String punkt_wert;

    private boolean isHinderniss;

    private static int index;

    private int a = index;

    private boolean isStartPunkt = false;

    private boolean isEndPunkt = false;

    private static int pnamezahl = 0;

    private String pname = "Punkt_" + pnamezahl;

    private static int ant_step = 0;

    public static void setant_step(Punkt p) {
        ant_step++;
    }

    public void setName() {
        pnamezahl++;
    }

    public int getIndex() {
        int at = a;
        return at;
    }

    public int getNamezahl() {
        return pnamezahl;
    }

    public String getName() {
        return pname;
    }

    public String getPunktWert() {
        return punkt_wert;
    }

    public boolean isHinderniss() {
        return isHinderniss;
    }

    public void setIndex(int a) {
        index = a;
    }

    public void setIsStartPunkt(boolean t) {
        t = this.isStartPunkt;
    }

    public void setisEndPunkt(boolean t) {
        t = this.isEndPunkt;
    }

    public int getXPos() {
        return x;
    }

    public int getYPos() {
        return y;
    }

    // public void getLinksN(Punkt p1) {
    // newPunkt.getXPos()-1, newPunkt.getYPos()
    // }
    public Punkt(int x, int y, int hind) {
        this.x = x;
        this.y = y;

        if (hind == -1) {
            this.isHinderniss = true;
        } else if (hind == 0) {
            this.isHinderniss = false;
        } else
            this.isHinderniss = false;
        String t = pname + "\\n X: " + x + "\\n Y: " + y + "\\n isHinderniss: "
                + isHinderniss + "\\n Index: " + index + "\\n Ant Step: " +ant_step;
        this.punkt_wert = t;
    }
}
..............................................................................................................................

import static java.lang.System.out;

public class Nachbar_Punkte {
   
    private static Punkt top;

    private static Punkt bot;

    private static Punkt rechts;

    private static Punkt links;

    private static Punkt oben_links;

    private static Punkt oben_rechts;

    private static Punkt unten_links;

    private static Punkt unten_rechts;

    static int b = Board.getBoardlaenge();
   
    public static void getNachbar(Punkt newPunkt) {
        out.println("Uebergebene Punkt: ");
        out.println(newPunkt.getPunktWert());
        out.println("\\n");
        getBot(newPunkt);
        getTop(newPunkt);
        getLinks(newPunkt);
        getRechts(newPunkt);
        getUnten_links(newPunkt);
        getUnten_rechts(newPunkt);
        getOben_links(newPunkt);
        getOben_rechts(newPunkt);
    }
   
    public static Punkt getBot(Punkt pp_n) {
        int ind = pp_n.getIndex(/*pp_n*/);
        try {
            bot = (Punkt)Board.getVector().elementAt(ind + 1);
            out.println("Bottom Nachbar: ");
            out.println(bot.getPunktWert());
            out.println("\\n");
        } catch (IndexOutOfBoundsException e) {
            out
                    .println("Dieses Punkt Existiert nicht. Sie Haben gerade ins Lehre zugegrifen");
        }
        return bot;
    }

    public static Punkt getTop(Punkt pp_n) {
        int ind = pp_n.getIndex(/*pp_n*/);
        try {
            top = (Punkt) Board.getVector().elementAt(ind - 1);
            out.println("Top Nachbar: ");
            out.println(top.getPunktWert());
            out.println("\\n");
        } catch (IndexOutOfBoundsException e) {
            out
                    .println("Dieses Punkt Existiert nicht. Sie Haben gerade ins Lehre zugegrifen");
        }
        return top;
    }

    public static Punkt getLinks(Punkt pp_n) {
        int ind = pp_n.getIndex(/*pp_n*/);
        try {
            links = (Punkt) Board.getVector().elementAt(ind - b);
            out.println("Linken Nachbar: ");
            out.println(links.getPunktWert());
            out.println("\\n");
        } catch (IndexOutOfBoundsException e) {
            out
                    .println("Dieses Punkt Existiert nicht. Sie Haben gerade ins Lehre zugegrifen");
        }
        return links;
    }

    public static Punkt getRechts(Punkt pp_n) {
        try {
            int ind = pp_n.getIndex(/*pp_n*/);
            rechts = (Punkt) Board.getVector().elementAt(ind + b);
            out.println("Rechten Nachbar: ");
            out.println(rechts.getPunktWert());
            out.println("\\n");
        } catch (IndexOutOfBoundsException e) {
            out
                    .println("Dieses Punkt Existiert nicht. Sie Haben gerade ins Lehre zugegrifen");
        }
        return rechts;
    }

    public static Punkt getOben_links(Punkt pp_n) {
        int ind = pp_n.getIndex(/*pp_n*/);
        try {
            oben_links = (Punkt) Board.getVector().elementAt(ind - b - 1);
            out.println("Oberen Linken Nachbar: ");
            out.println(oben_links.getPunktWert());
            out.println("\\n");
        } catch (IndexOutOfBoundsException e) {
            out
                    .println("Dieses Punkt Existiert nicht. Sie Haben gerade ins Lehre zugegrifen");
        }
        return oben_links;
    }

    public static Punkt getOben_rechts(Punkt pp_n) {
        int ind = pp_n.getIndex(/*pp_n*/);
        try {
            oben_rechts = (Punkt) Board.getVector().elementAt(ind + b - 1);
            out.println("Oberen Rechten Nachbar: ");
            out.println(oben_rechts.getPunktWert());
            out.println("\\n");
        } catch (IndexOutOfBoundsException e) {
            out
                    .println("Dieses Punkt Existiert nicht. Sie Haben gerade ins Lehre zugegrifen");
        }
        return oben_rechts;
    }

    public static Punkt getUnten_links(Punkt pp_n) {
        int ind = pp_n.getIndex(/*pp_n*/);
        try {
            unten_links = (Punkt) Board.getVector().elementAt(ind - b + 1);
            out.println("Unteren Linken Nachbar: ");
            out.println(unten_links.getPunktWert());
            out.println("\\n");
        } catch (IndexOutOfBoundsException e) {
            out
                    .println("Dieses Punkt Existiert nicht. Sie Haben gerade ins Lehre zugegrifen");
        }
        return unten_links;
    }

    public static Punkt getUnten_rechts(Punkt pp_n) {
        int ind = pp_n.getIndex(/*pp_n*/);
        try {
            unten_rechts = (Punkt) Board.getVector().elementAt(ind + b + 1);
            out.println("Unteren Rechten: ");
            out.println(unten_rechts.getPunktWert());
            out.println("\\n");
        } catch (IndexOutOfBoundsException e) {
            out
                    .println("Dieses Punkt Existiert nicht. Sie Haben gerade ins Lehre zugegrifen");
        }
        return unten_rechts;
    }

}
...............................................................................................................................

import java.util.*;

public class Board {
   
    static int cnt = 1;
   
    private static Vector<Punkt> feld = new Vector<Punkt>();

    private Punkt newPunkt;

    private static int[][] board = {
            { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
            { -1,  0,  0, -1, -1,  0,  0, -1, -1,  0,  0, -1 },
            { -1,  0,  0, -1,  0,  0,  0, -1, -1,  0,  0, -1 },
            { -1,  0,  0,  0, -1,  0,  0,  0, -1,  0,  0, -1 },
            { -1,  0,  0,  0, -1,  0,  0,  0,  0,  0,  0, -1 },
            { -1,  0,  0,  0,  0,  0, -1,  0,  0,  0,  0, -1 },
            { -1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1 },
            { -1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, -1 },
            { -1,  0,  0,  0, -1,  0,  0, -1, -1,  0,  0, -1 },
            { -1,  0,  0, -1,  0,  0,  0, -1,  0,  0,  0, -1 },
            { -1,  0,  0, -1, -1,  0,  0, -1,  0,  0,  0, -1 },
            { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } };

    public Board() {
       
        for (int i = 0; board.length > i; i++) {
            for (int j = 0; board.length > j; j++) {
                if (board[i][j] == -1) {
                    newPunkt = new Punkt(i, j, -1);
                    newPunkt.setName();
                    newPunkt.setIndex(cnt);
                } else {
                    newPunkt = new Punkt(i, j, 0);
                    newPunkt.setName();
                    newPunkt.setIndex(newPunkt.getNamezahl());
                }
               
                cnt++;
                feld.add(newPunkt);
            }
        }
    }

    public static Vector getVector() {
        return feld;
    }

    public static int getBoardlaenge() {
        return board.length;
    }
}
................................................................................................................................

import java.util.*;

public class Ant {
   
    private String name;
    private int namezahl;
   
    public Ant(Punkt ps,Punkt pe) {
        ps.setIsStartPunkt(true);
        pe.setisEndPunkt(true);
        namezahl++;
        name = "Ameise" + namezahl;
        view(ps);
    }
   
    private void view(Punkt p) {
         p = Nachbar_Punkte.getRechts(p);
         Punkt.setant_step(p);
         p.getPunktWert();
    }

}
............................... Не е готово но е ясно какво трябва се напише .........

/**
 * ****************************************
 *
 * @author Ivaylo Mateev (imateev@uos.de)*
 *         ****************************************
 */
public class HauptProgramm {

    /**
     * @param args
     */

    public static void main(String[] args) {
        for (int i = 0; Board.getVector().size() > i; i++) {
            Punkt p = (Punkt) Board.getVector().elementAt(i);
        }
        // TODO Auto-generated method stub
        Board spielfeld = new Board();
        Board.getVector();
        Punkt stp = new Punkt(1, 2, 0);
        Punkt endp = new Punkt(10, 10, 0);
        Ant ammeise = new Ant(stp, endp);
    }

}
.............................  тук просато се пускат готовите класове ......... ...........

след като е готова мравката и графичната среда ако изобщо ги напиша и като го допалня от тук сте се пуска програмата. Но за олеснение на Потребителя всичко се архивира в архив.jar и се пише един Manifest фаил в който се казва каде се намира main(). С Eclipse само се казва extract Project to JAR  и то си знае работата. - Вече казах колко обичам Eclipse, нали.
 

Коментари