Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ex;
- import java.awt.Point;
- import java.util.Objects;
- import java.util.Random;
- public class StashTab
- {
- public Item[][] items;
- public Point lastChaosPosition = new Point( 0, 0 );
- public String itemNames[] = { "item", "item", "item", "item", "item" };
- public String randomName()
- {
- String r = "";
- Random rd = new Random();
- int randomInRange = rd.nextInt( itemNames.length ) ;
- r = itemNames[ randomInRange ];
- return r;
- }
- public StashTab()
- {
- super();
- items = new Item[ 12 ][ 12 ];
- for( int y = 0; y < 12; y++ )
- {
- for( int x = 0; x < 12; x++ )
- {
- ItemType randomType = ItemType.values()[(int)(Math.random()*ItemType.values().length)];
- String name = "";
- if( Objects.equals( randomType, ItemType.chaos ) )
- name = "chaos";
- else
- name = randomName();
- name = name + " : " + String.valueOf( y ) + ":" + String.valueOf( x );
- items[ y ][ x ] = new Item( name, randomType );
- System.out.println( items[ y ][ x ].name );
- }
- }
- }
- public Point findNextChaos()
- {
- Point pos = new Point( -1, 0 );
- boolean found = false;
- for( int y = lastChaosPosition.y; y < 12; y++ )
- {
- for( int x = lastChaosPosition.x; x < 12; x++ )
- {
- lastChaosPosition.x = 0;
- if( Objects.equals( items[ y ][ x ].type, ItemType.chaos ) )
- {
- found = true;
- pos.x = x;
- pos.y = y;
- lastChaosPosition.y = y;
- if( x < 11 )
- lastChaosPosition.x = x +1;
- else
- {
- lastChaosPosition.x = 0;
- lastChaosPosition.y = y +1;
- }
- System.out.println( String.valueOf( y ) + " : " + String.valueOf( x ) );
- break;
- }
- }
- if( found )
- break;
- }
- return pos;
- }
- public void sortIt()
- {
- for( int y = 0; y < 12; y++ )
- {
- for( int x = 0; x < 12; x++ )
- {
- if( Objects.equals( items[ y ][ x ].type, ItemType.chaos ) == false )
- {
- Point nextChaos = findNextChaos();
- if( nextChaos.x != -1 )
- {
- Item objNotChaos = items[ y ][ x ];
- items[ y ][ x ] = items[ nextChaos.y ][ nextChaos.x ];
- items[ nextChaos.y ][ nextChaos.x ] = objNotChaos;
- }
- }
- }
- }
- }
- public void showTheCurrentTabContainings()
- {
- for( int y = 0; y < 12; y++ )
- {
- for( int x = 0; x < 12; x++ )
- {
- System.out.println( items[ y ][ x ].name );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement