Page 289 - The Definitive Guide to Building Java Robots
P. 289

Preston_5564C07.fm  Page 270  Monday, September 26, 2005  5:38 AM



                 270    CHAPTER 7  ■  NAVIGATION



                        Example 7-17. Room.java
                        package com.scottpreston.javarobot.chapter7;

                        import java.util.ArrayList;

                        public class Room extends Vertex {

                            private ArrayList regions = new ArrayList();
                            private ArrayList edges = new ArrayList();

                            public Room(String name) {
                                super(name);
                            }

                            public void addRegion(Region r) {
                                regions.add(r);
                            }

                            public void addEdge(Region r1, Region r2, DistanceVector vect) {
                                vect.v1 = r1;
                                vect.v2 = r2;
                                edges.add(vect);
                            }

                            public static Room getBasement() {
                                // 1st create regions
                                Region a = new Region("home",36);
                                a.setCharacteristic(new int[]{0,0,1,1});
                                // add specific location of the trash can
                                Region b = new Region("trash",36);
                                b.setCharacteristic(new int[]{1,0,0,1});
                                b.addWayPoint("can",80,20);
                                Region c = new Region("desk",24);
                                c.setCharacteristic(new int[]{1,1,0,0});
                                Region d = new Region("exit",24);
                                d.setCharacteristic(new int[]{0,1,0,1});
                                Region e = new Region("treadmill",48);
                                c.setCharacteristic(new int[]{0,1,1,0});
                                Region f = new Region("fridge",36);
                                c.setCharacteristic(new int[]{1,0,0,0});
                                Region g = new Region("sofa",24);
                                c.setCharacteristic(new int[]{0,0,0,1});
   284   285   286   287   288   289   290   291   292   293   294