Advertisement
StormWingDelta

MainandObjectListSystem

Apr 22nd, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.38 KB | None | 0 0
  1. //These are the 3 main classes needed to get this thing up and running
  2.  
  3. //Main class
  4. import java.util.*;
  5. import java.awt.*;
  6.  
  7. /**
  8.  * Write a description of class Main here.
  9.  *
  10.  * @author (your name)
  11.  * @version (a version number or a date)
  12.  */
  13. public class Main
  14. {
  15.     //
  16.     public static void main(String args[])
  17.     {
  18.         MainList M = new MainList();
  19.         //char t;
  20.         //t = (char)145;
  21.         //System.out.println(t);
  22.        
  23.         M.getList().add(new Sprite1());//1
  24.         M.getList().add(new Sprite1());//1
  25.         M.getList().add(new Sprite1());//1
  26.         for(int F1 = 0; F1 < 2; F1++)
  27.         {
  28.             Sprite1 G = new Sprite1();//1
  29.             for(int F = 0; F < 10; F++){
  30.                 G.getList().add(new Sprite1());//2
  31.                
  32.             }
  33.             M.getList().add(G);
  34.             for(int F3 = 0; F3 < 10; F3++)
  35.             {
  36.                 Sprite1 V = (Sprite1)G.getList().get(F3);
  37.                 V.getList().add(new Sprite1());//3
  38.             }
  39.         }
  40.        
  41.         for(int F = 0; F < 6; F++)
  42.         {
  43.             System.out.println("\t\t\t\t\t" + "Cycle: ".toUpperCase() + F);
  44.             M.allListUpdate();
  45.             if(F == 1)
  46.             {
  47.                 System.out.println("\t\t\t\t\t" + "Searching Lists ".toUpperCase());
  48.                
  49.                 searchSubLists(M.getList(), "0");
  50.                    
  51.             }
  52.             if(F == 2)
  53.             {
  54.                 System.out.println("\t\t\t\t\t" + "Adding To Lists ".toUpperCase());
  55.                 //addToSubLists(M.getList(), "5");
  56.                 addToSubLists(M.getList(), "2");
  57.             }
  58.             if(F == 3)
  59.             {
  60.                 System.out.println("Main List Cleared!!!!!!!!!".toUpperCase());
  61.                 M.getList().clear();
  62.             }
  63.         }
  64.        
  65.     }
  66.    
  67.     public static void searchSubLists(LinkedList Sub, String Name)
  68.     {
  69.         //
  70.         for(int fall = 0; fall < Sub.size(); fall++)
  71.         {
  72.            
  73.             Sprite1 S1 = (Sprite1)Sub.get(fall);
  74.             //System.out.print("List Depth: " + depths + "   ");
  75.             //System.out.print("Sprite : " + fall + "\t");
  76.            
  77.             if(S1.getName().contains(Name))
  78.             {
  79.                 Sub.remove(fall);
  80.                 System.out.println("\t\tSprite ".toUpperCase() + fall + " Name : ".toUpperCase() + S1.getName().toUpperCase() + " Cleared!!!!!!!!! O".toUpperCase());
  81.             }
  82.             if(S1.HSL())
  83.             {
  84.                 System.out.println("\t\tSprite1 : " + fall + "\n\t\t\tHas Sub List!" + "\n\t\t\t\tSearching List of " + S1.getName().toUpperCase() + " Now!");
  85.                
  86.                 searchSubLists(S1.getList(), Name);
  87.             }
  88.         }
  89.     }
  90.    
  91.     public static void addToSubLists(LinkedList Sub, String Name)
  92.     {
  93.         //
  94.         for(int fall = 0; fall < Sub.size(); fall++)
  95.         {
  96.            
  97.             Sprite1 S1 = (Sprite1)Sub.get(fall);
  98.             //System.out.print("List Depth: " + depths + "   ");
  99.             //System.out.print("Sprite : " + fall + "\t");
  100.            
  101.             if(S1.getName().contains(Name))
  102.             {
  103.                 System.out.println("\\ \\ \\ \\ \\ " + S1.getName().toUpperCase() + " New Sprite(s)!!!!!!!!!".toUpperCase());
  104.                 for(int G = 0; G < 2; G++)
  105.                 {
  106.                     Sub.add(new Sprite1());
  107.                 }
  108.                 System.out.println("\t\tSprite ".toUpperCase() + fall + " Name : ".toUpperCase() + S1.getName().toUpperCase() + " New Sprite(s)!!!!!!!!!".toUpperCase());
  109.             }
  110.             if(S1.HSL())
  111.             {
  112.                 System.out.println("\t\tSprite1 : " + fall + "\n\t\t\tHas Sub List!" + "\n\t\t\t\tSearching List of " + S1.getName().toUpperCase() + " Now!");
  113.                
  114.                 addToSubLists(S1.getList(), Name);
  115.             }
  116.         }
  117.     }
  118. }
  119. //Main Class
  120.  
  121.  
  122. //Main List Manager
  123. import java.util.*;
  124. import java.awt.*;
  125. /**
  126.  * Write a description of class MainList here.
  127.  *
  128.  * @author (your name)
  129.  * @version (a version number or a date)
  130.  */
  131. public class MainList
  132. {
  133.     //
  134.     private LinkedList MAIN;
  135.     private int depths;
  136.     public LinkedList getList() {return MAIN;}
  137.     /**
  138.      * Constructor for objects of class MainList
  139.      */
  140.     public MainList()
  141.     {
  142.         //
  143.         MAIN = new LinkedList<Sprite1>();
  144.     }
  145.  
  146.     public void updateItem(Sprite1 S1)
  147.     {
  148.         S1.updateStats();
  149.         S1.displayStats();
  150.     }
  151.    
  152.     public void allListUpdate()
  153.     {
  154.         depths = 0;
  155.         System.out.println();
  156.         for(int fall = 0; fall < MAIN.size(); fall++)
  157.         {
  158.             depths = 1;
  159.             System.out.print("List Depth: " + depths + "   ");
  160.             Sprite1 S1 = (Sprite1)MAIN.get(fall);
  161.             System.out.print("Sprite : " + fall + "\t");
  162.             updateItem(S1);
  163.             if(S1.HSL())
  164.             {
  165.                 System.out.println("Sprite1 : " + fall + "\n\tHas Sub List!" + "\n\t\tUpdating List of " + S1.getName().toUpperCase() + " Now!");
  166.                
  167.                 updateSubLists(S1.getList());
  168.             }
  169.         }
  170.        
  171.     }
  172.    
  173.     private void updateSubLists(LinkedList SUB)
  174.     {
  175.         depths++;
  176.         for(int fall = 0; fall < SUB.size(); fall++)
  177.         {
  178.            
  179.             Sprite1 S1 = (Sprite1)SUB.get(fall);
  180.             System.out.print("List Depth: " + depths + "   ");
  181.             System.out.print("Sprite : " + fall + "\t");
  182.             updateItem(S1);
  183.             if(S1.HSL())
  184.             {
  185.                 System.out.println("Sprite1 : " + fall + "\n\tHas Sub List!" + "\n\t\tUpdating List of " + S1.getName().toUpperCase() + " Now!");
  186.                
  187.                 updateSubLists(S1.getList());
  188.             }
  189.         }
  190.     }
  191.    
  192. //These two methods are still being worked on as will as a few others I'm going to put in.
  193.     public Sprite1 getSprite(Sprite1 S1)
  194.     {
  195.         return S1;
  196.     }
  197.     public Sprite1 getSprite(int S1)
  198.     {
  199.         Sprite1 S2 = (Sprite1)MAIN.get(S1);
  200.         return S2;
  201.     }
  202.    
  203. }
  204.  
  205.  
  206. //Main List Manager
  207.  
  208. //Starter Object, aka a test object
  209.  
  210. import java.util.*;
  211. import java.awt.*;
  212. /**
  213.  * Write a description of class Sprite1 here.
  214.  *
  215.  * @author (your name)
  216.  * @version (a version number or a date)
  217.  */
  218. public class Sprite1
  219. {
  220.     //
  221.     protected Random mix;
  222.     protected String Name;
  223.     protected int x, y, z, f;
  224.     private static long NN;
  225.     protected boolean hasSubList;
  226.     protected LinkedList sub;
  227.     public LinkedList getList() {return sub;}
  228.     //private LinkedList AltLists;
  229.    
  230.     /**
  231.      * Constructor for objects of class Sprite1
  232.      */
  233.     public Sprite1()
  234.     {
  235.         // initialise instance variables
  236.         mix = new Random();
  237.        
  238.        
  239.         Name = "Sprite " + NN;
  240.         NN++;
  241.        
  242.         x = 0;
  243.         y = 0;
  244.         z = 0;
  245.         f = 0;
  246.        
  247.         sub = new LinkedList<Sprite1>();
  248.        
  249.     }
  250.    
  251.     public void updateStats()
  252.     {
  253.         x += 1;
  254.         y += 1;
  255.         z += 1;
  256.         f += 1;
  257.         SubListOn();
  258.     }
  259.    
  260.     public void displayStats()
  261.     {
  262.         System.out.println("Name: " + Name + " X = " + x + " Y = " + y + " Z = " + z + " F = " + f + " Has Sub List = " + HSL() + " List Size = " + sub.size());
  263.     }
  264.    
  265.     private void SubListOn()
  266.     {
  267.         if(sub.size() > 0 && sub != null)
  268.         {
  269.             hasSubList = true;
  270.         }
  271.         else
  272.         {
  273.             hasSubList = false;
  274.         }
  275.     }
  276.     public boolean HSL(){return hasSubList;}
  277.    
  278.     public String getName(){return Name;}
  279.     public void setName(String N){Name = N;}
  280.    
  281. //not sure If I'm going to need these or not as of yet. ?_?
  282.     /*
  283.     public void addSub(Sprite1 S1)
  284.     {
  285.        
  286.         sub.add(S1);
  287.     }
  288.    
  289.     public Sprite1 removeSub(Sprite1 S1)
  290.     {
  291.         if(S1 == null)
  292.         {
  293.             return null;
  294.         }
  295.         else
  296.         {
  297.             for(int n = 0; n < sub.size(); n++)
  298.             {
  299.                 Sprite1 spr = (Sprite1) sub.get(n);
  300.                 if(spr.equals(S1) && (S1 != null && spr != null) )
  301.                 {
  302.                    
  303.                     sub.remove(n);
  304.                 }
  305.             }
  306.             return S1;
  307.         }
  308.     }
  309.    
  310.     public Sprite1 removeSub(int index)
  311.     {
  312.         Sprite1 spr = (Sprite1) sub.get(n);
  313.        
  314.         sub.remove(n);
  315.     }
  316.    
  317.     public Sprite1 getSLS(Sprite1 me)
  318.     {
  319.         Sprite1 spr1 = me;
  320.         if(me == null)
  321.         {
  322.             return null;
  323.         }
  324.         else
  325.         {
  326.             for(int n = 0; n < sub.size(); n++)
  327.             {
  328.                 Sprite1 spr2 = (Sprite1) sub.get(n);
  329.                 if(spr2.equals(spr1) && (spr1 != null && spr2 != null) )
  330.                 {
  331.                     spr1 = spr2;
  332.                 }
  333.             }
  334.             return spr1;
  335.         }
  336.     }
  337.    
  338.     public Sprite1 getSLS(int index)
  339.     {
  340.         Sprite1 spr1 = (Sprite1)sub.get(index);
  341.         if(spr1 == null)
  342.         {
  343.             return null;
  344.         }
  345.         else if(spr1 != null)
  346.         {
  347.             return spr1;
  348.         }
  349.         else
  350.         {
  351.             System.err.println("An error has occurred in getSLS!");
  352.             return null;
  353.         }
  354.     }
  355.     */
  356. }
  357.  
  358. //Starter Object, aka a test object
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement