📄 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; i<numInInv; i++)
{
doDraw(x,y,invItem[i]);
if (currSelected==i)
{
paper.setColor(Color.white);
paper.drawRect(x-2,y-2,22,22);
paper.setColor(Color.black);
}
x+=25;
}
}
// Draw image at x, y, xoff is offset in large image
public void doDraw(int xabs, int yabs, int xoff)
{
int yoff=0;
if (xoff>0)
{
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);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -