Java ME中一個(gè)通用的游戲信息框架類
發(fā)表時(shí)間:2024-01-01 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]本類實(shí)現(xiàn)游戲菜單,游戲關(guān)于和游戲幫助的信息,能夠自適應(yīng)不同的手機(jī)/*游戲中的一些常用的框架*/import javax.microedition.lcdui.*;import java.util.Vector;class showContent int w,h;//屏幕的長和寬 int cw;//...
本類實(shí)現(xiàn)游戲菜單,游戲關(guān)于和游戲幫助的信息,能夠自適應(yīng)不同的手機(jī)
/*游戲中的一些常用的框架*/
import javax.microedition.lcdui.*;
import java.util.Vector;
class showContent
{
int w,h;//屏幕的長和寬
int cw;//字體的寬
int page,maxPage;//幫助信息中的頁碼/最大頁碼
int rn;//每行最大字?jǐn)?shù)
int maxR;//每屏最多顯示的行數(shù)
int cr;//字體行距
Vector about;
Vector help;
public showContent(int wid,int hei,int charw,int charR,String[] aboutText,String[] helpText)
{
about=new Vector(0,1);
help=new Vector(0,1);
w=wid;h=hei;cw=charw;cr=charR;
rn=w/cw;
maxR=(h-20)/cr;
page=0;
for(int m=0;m<aboutText.length;m++)
{
int i=1+(aboutText[m].length()-1)/rn;
for(int p=0;p<i;p++)
{
if(p<i-1)
about.addElement((String)(aboutText[m].substring(p*rn,(p+1)*rn)));
else
about.addElement((String)(aboutText[m].substring(p*rn)));
}
}
for(int m=0;m<helpText.length;m++)
{
int i=1+(helpText[m].length()-1)/rn;
for(int p=0;p<i;p++)
{
if(p<i-1)
help.addElement((String)(helpText[m].substring(p*rn,(p+1)*rn)));
else
help.addElement((String)(helpText[m].substring(p*rn)));
}
}
maxPage=(help.size()-1)/maxR;
}
public void showAbout(Graphics g1,int x,int y)//顯示關(guān)于
{
g1.setColor(0);
g1.fillRect(0,0,w,h);
g1.setColor(0xffffff);
for(int i=0;i<about.size();i++)
{
g1.drawString((String)(about.elementAt(i)),x,y+i*cr,0);
}
}
/*顯示暫停*/
public void drawPause(Graphics g1)
{
g1.setColor(0);
g1.fillRect(w/2-30,h/2-6,60,30);
g1.setColor(0xffffff);
g1.drawRect(w/2-30,h/2-6,60,30);
g1.drawString("暫停中",w/2-20,h/2,0);
}
public void showHelp(Graphics g1,int x,int y)//顯示幫助
{
g1.setColor(0);
g1.fillRect(0,0,w,h);
g1.setColor(0xffffff);
for(int i=0;i<maxR;i++)
{
if(page*maxR+i<help.size())
g1.drawString((String)(help.elementAt(page*maxR+i)),x,y+i*cr,0);
}
g1.setColor(0xffff00);
g1.drawString("按上下方向鍵翻頁",20,h-20,0);
}
public void drawMenu(Graphics g1,int x,int y,int row,int w,String[] arrayStr,int no)//顯示菜單
{
g1.setColor(0xffff00);
g1.fillRect(x,y,w,arrayStr.length*row);
g1.setColor(0xffffff);
g1.drawRect(x,y,w,arrayStr.length*row);
for(int m=0;m<arrayStr.length;m++)
{
if(no==m)
g1.setColor(0x0000ff);
else
g1.setColor(0);
g1.drawString(arrayStr[m],x+5,y+5+m*row,0);
}
}
}