www.pudn.com > litwiz.rar > inv.java


import java.awt.*; 
 
class inv 
{ 
	private Graphics paper; 
	private Image gfx; 
	private int[] invItem; 
	private int numInInv; 
	private int currSelected; 
 
	// Items class used to return IDs and names etc of obejcts 
	private items item; 
 
	public inv(Graphics gr, Image im) 
	{ 
		this.paper=gr; 
		this.gfx=im; 
		this.invItem=new int[10]; 
		this.numInInv=0; 
		this.currSelected=0; 
		this.invItem[0]=0; 
		this.invItem[1]=0; 
		this.invItem[2]=0; 
		this.invItem[3]=0; 
		this.invItem[4]=0; 
		this.invItem[5]=0; 
		this.item=new items(); 
	} 
 
	// Return name of currently selected item 
	public String getName() 
	{ 
		return item.getName(invItem[currSelected]); 
	} 
 
	// Return ID of currently selected item 
	public int getID() 
	{ 
		if (numInInv>0) 
		{ 
			return invItem[currSelected]; 
		} 
		return 0; 
	} 
 
	// Returns false if we can't pick up more 
	public boolean addItem(int i) 
	{ 
		if (numInInv<6) 
		{ 
			invItem[numInInv]=i; 
			currSelected=numInInv++; 
			drawInv(); 
			return true; 
		} 
		else 
		{ 
			return false; 
		} 
	} 
 
	// Remove currently Selected 
	public void removeFromInv() 
	{ 
		invItem[currSelected]=invItem[numInInv-1]; 
		numInInv--; 
		currSelected=0; 
		drawInv(); 
	} 
 
	// Change currently selected 
	public void changeItem() 
	{ 
		currSelected++; 
		if (currSelected>=numInInv) 
		{ 
			currSelected=0; 
		} 
		drawInv(); 
	} 
 
	// Draw inventory 
	public void drawInv() 
	{ 
		int x=20; 
		int y=45; 
		paper.setColor(Color.black); 
		paper.fillRect(0,36,200,50); 
		for (int i=0; i0) 
		{ 
			yoff=((int)xoff/10)*20; 
			xoff%=10; 
			xoff*=20; 
			paper.drawImage(gfx, 
				xabs, yabs, xabs+20, yabs+20, 
				xoff, yoff, xoff+20, yoff+20, 
				null); 
		} 
		else 
		{ 
			paper.fillRect(xabs, yabs, 20,20); 
		} 
	} 
 
}