📄 milionercanvas.java
字号:
nOldStatus = nStatus;
nStatus = 1;
}
break;
case 1: //uputstvo
case 5: // prijatelj
case 6: // publika
nStatus = nOldStatus;
break;
case 8: // rezultati
if (keyCode == KEY_STAR ) {
// posalji rezultate
boolean lHas14 = false;
for (int i = 0; i < 5; i++) {
if (MilScore.anRez[i] > 14000) lHas14 = true;
}
if (lHas14) {
MilScore.saveHighScore();
connect();
}
} else {
// Nazad
nStatus = nOldStatus;
}
break;
case 7: // odustani - potvrda
if (keyCode == KEY_STAR || keyCode == KEY_SOFTKEY1 ) {
// Da
// nPitanje = 0;
lDaNe = false;
lOdustani = false;
cPitanje = "";
lUpNOVA = false;
nStatus = 2;
checkRez();
// Efekti.playDaNe();
} else if (keyCode == KEY_POUND || keyCode == KEY_SOFTKEY2 ) {
// Ne
lDaNe = false;
lOdustani = true;
lcOdustani = false;
nStatus = 3;
}
break;
}
repaint();
}
}
//-------------------------------------------------------
// graphics methods
/**
* paint the game graphics on the screen.
*/
public void paint(Graphics g) {
switch (nStatus) {
case 0: // Splash
if (!lLoadStarted) {
// Efekti.playMil1();
g.setClip( 0, 0, 128, 128);
g.setColor( 1, 2, 72 );
g.fillRect( 0, 0, 128, 128 );
try { g.drawImage( Image.createImage("/logo.jpg"), 0, 0, 0 );
} catch (Exception ex) {};
g.setFont(Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_BOLD, Font.SIZE_SMALL));
g.setColor( 0, 0, 0 );
g.drawString(VERZIJA+" Milika 2004", 127, 127, g.BOTTOM|g.RIGHT);
g.setColor( 255, 255, 255 );
g.drawString(VERZIJA+" Milika 2004", 126, 126, g.BOTTOM|g.RIGHT);
nPomocTimer = 0;
timerPomoc.schedule(new TimerPomoc(), 0, 1);
lLoadStarted = true;
}
g.setColor( 10+nLoad*35, 12+nLoad*35, 212 );
g.fillRect( 3, 122, nLoad*7, 2 );
/* try {
goreImage = Image.createImage("/gore.png");
doleImage = Image.createImage("/dole.png");
dugmeImage = Image.createImage("/dugme.png");
dugmeCImage = Image.createImage("/dugmec.png");
dugmeZImage = Image.createImage("/dugmez.png");
p50Image = Image.createImage("/50.png");
p50xImage = Image.createImage("/50x.png");
prijateljImage = Image.createImage("/prijatelj.png");
prijateljxImage = Image.createImage("/prijateljx.png");
// scprijateljImage = Image.createImage("/scprijatelj.jpg");
pubImage = Image.createImage("/pub.png");
pubxImage = Image.createImage("/pubx.png");
// scpubImage = Image.createImage("/scpub.png");
} catch (Exception ex) {};*/
break;
case 1: // Uputstvo
g.setColor( 1, 2, 72 );
g.fillRect( 0, 0, 128, 128 );
g.drawImage( dugmeImage, 0, 2, 0 );
g.drawImage( dugmeImage, 0, 112, 0 );
g.setColor( 0, 0, 0 );
g.fillRect( 0, 9, 128, 111 );
g.setFont(Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_BOLD, Font.SIZE_MEDIUM));
g.setColor( 255, 255, 255 );
g.drawString("UPUTSTVO", 64, 10, g.TOP|g.HCENTER);
g.setFont(Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_PLAIN, Font.SIZE_SMALL));
for( int i=0; i < UPUTSTVO_STRING.length; i++ ) {
g.drawString(UPUTSTVO_STRING[i], 64, 35+i*11, g.TOP|g.HCENTER);
}
break;
case 2:
if (!lUpNOVA) {
lUpNOVA = true;
cPitanje += " Nova igra?";
}
cDA = "Da";
cNE = "Ne";
/* for (int i = 0; i < 4; i++) {
cOdgovori[i] = "";
lPitanjaC[i] = false;
lPitanjaZ[i] = false;
lPitanjaFlicker[i] = false;
}*/
l50 = false;
lPrijatelj = false;
lPub = false;
lDaNe = true;
lOdustani = false;
iscrtaj( g );
break;
case 3: //Pitanje
case 4: //Pitanje
case 7: //odustani
iscrtaj( g );
break;
case 5: //Prijatelj
// postavi font
g.setClip( 14, 21, 102, 73);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,
Font.STYLE_PLAIN, Font.SIZE_SMALL));
g.setColor( 1, 2, 72 );
g.fillRect( 14, 21, 102, 73 );
g.setColor( 155, 155, 255 );
g.drawRect( 14, 21, 101, 72 );
// g.drawImage( scprijateljImage, 14, 21, 0 );
g.setColor( 255, 255, 255 );
for (int i = 0; i < 3; i++) {
g.drawString( acPrijatelj[i], 18, 28+i*18, g.TOP|g.LEFT);
}
break;
case 6: //Publika
// postavi font
g.setClip( 14, 3, 98, 120);
g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,
Font.STYLE_PLAIN, Font.SIZE_SMALL));
// g.drawImage( scpubImage, 14, 3, 0 );
// rucno crtanje pozadine
g.setColor( 0, 0, 0 );
g.fillRect( 14, 3, 98, 120 );
g.setColor( 204, 204, 204 );
g.drawRect( 14, 3, 97, 119 );
for (int i = 0; i < 4; i++) {
g.drawRect( 14+4+22*i, 3+7, 11, 96 );
}
for (int i = 0; i < 6; i++) {
g.drawRect( 14+4, 3+7+16*i, 88, 8 );
}
g.setColor( 255, 100, 0 );
g.fillRect( 14+4, 3+7, 88, 16 );
g.setColor( 204, 204, 204 );
g.drawRect( 14+4, 3+7, 88, 16 );
for (int i = 0; i < 4; i++) {
g.drawRect( 14+4+22*i, 3+7, 22, 96 );
g.drawString( Odg2Str(i), 14+4+22*i+12, 110, g.TOP|g.HCENTER);
}
int nSafeTimer = nPomocTimer;
if (nSafeTimer > 10) { nSafeTimer = 10; }
for (int i = 0; i < 4; i++) {
g.setColor( 255, 255, 255 );
g.drawString( ""+anPub[i]*nSafeTimer/10, 29+i*22, 14, g.TOP|g.HCENTER);
g.setColor( 190, 190, 190 );
// g.fillRect( 20+i*22, 23, 18, 88 ); (100-anPub[i]*nPomocTimer/10)*(88/100)
// g.fillRect( 20+i*22, 23+88-(anPub[i]*nPomocTimer/10)*88/100,
// 18, (anPub[i]*nPomocTimer/10)*88/100 );
milFilRect( g, 20+i*22, 28+78-(anPub[i]*nSafeTimer/10)*78/100,
18, (anPub[i]*nSafeTimer/10)*78/100 );
g.setClip( 14, 3, 98, 120);
}
break;
case 8: // Rezultati
g.setColor( 1, 2, 72 );
g.fillRect( 0, 0, 128, 128 );
g.drawImage( dugmeImage, 0, 2, 0 );
g.drawImage( dugmeImage, 0, 112, 0 );
g.setColor( 0, 0, 0 );
g.fillRect( 0, 9, 128, 111 );
g.setFont(Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_BOLD, Font.SIZE_MEDIUM));
g.setColor( 255, 255, 255 );
g.drawString("REZULTATI", 64, 10, g.TOP|g.HCENTER);
g.setFont(Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_PLAIN, Font.SIZE_SMALL));
for( int i=0; i < 5; i++ ) {
g.drawString( MilScore.acRez[i], 5, 38+i*12, g.TOP|g.LEFT);
g.drawString( ""+MilScore.anRez[i], 123, 38+i*12, g.TOP|g.RIGHT);
}
g.drawString( "http://tagtag.com/milika",
123, 38+5*12, g.TOP|g.RIGHT);
boolean lHas14 = false;
for (int i = 0; i < 5; i++) {
if (MilScore.anRez[i] > 14000) lHas14 = true;
}
if (!lHas14) g.setColor( 128, 128, 128 );
g.drawString( "*=po"+YU_SLOVA.charAt(3)+"alji rezultate",
123, 38+6*12, g.TOP|g.RIGHT);
break;
}
/*
g.setClip( 0, 0, 128, 128);
g.setColor( 255, 255, 255 );
g.drawString("*"+nStatus, 0, 0, g.TOP|g.LEFT);
*/
}
void PostaviPitanje( int nTPitanje ) {
switch (nTPitanje) {
case 1:
case 2:
case 3:
case 4:
case 5:
String2Pitanje( GetPitanje( 11 ) );
break;
case 6:
case 7:
case 8:
case 9:
case 10:
String2Pitanje( GetPitanje( 6 ) );
break;
case 11:
case 12:
case 13:
String2Pitanje( GetPitanje( 3 ) );
break;
case 14:
case 15:
String2Pitanje( GetPitanje( 1 ) );
break;
}
repaint();
}
void String2Pitanje( String cT ) {
int nT, nTa;
char cTt;
String cTs;
int nMesto;
/*
cPitanje = '?';
cOdgovori[0] = '?';
cOdgovori[1] = '?';
cOdgovori[2] = '?';
cOdgovori[3] = '?';
*/
String cTacan = "";
String[] cNetacan;
cNetacan = new String[6];
for (int i = 0; i < 6; i++) { cNetacan[i] = ""; }
nMesto = 0;
nT = 0;
cTs = "";
while (nT < cT.length()) {
cTt = cT.charAt(nT);
if ( (cTt == '~') || ( nT == cT.length()-1 ) ) {
switch (nMesto) {
case 0 : cPitanje = cTs;
break;
case 1 : cTacan = cTs;
break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7: cNetacan[nMesto-2] = cTs;
break;
}
cTs = "";
nMesto++;
} else { cTs = cTs + cTt; }
nT++;
}
nTacan = Math.abs(random.nextInt() % 4);
cOdgovori[nTacan] = cTacan;
// broje se netacni
int nNetacnih = 0;
for (int nTi = 0; nTi < 6; nTi++) {
if ( cNetacan[nTi] != "" && cNetacan[nTi] != "?" ) { nNetacnih++; } }
// { traze se pozicije netacnih i random bira }
int[] aNetacni;
aNetacni = new int[6];
for (int a = 0; a < 6; a++) { aNetacni[a] = 0; }
boolean lT = false;
for (int nTi = 0; nTi < 3; nTi++) {
lT = false;
while (!lT) {
aNetacni[nTi] = Math.abs(random.nextInt() % nNetacnih);
lT = true;
for (int nTo = 0; nTo < nTi ; nTo++) {
if ( aNetacni[nTo] == aNetacni[nTi]) { lT = false; }
}
}
}
for (int nTi = 0; nTi < 3; nTi++) {
nT = 0; //{ Kobajagi pozicija }
nTa = 0; //{ Prava pozicija }
while (nT != aNetacni[nTi]) {
nTa++;
if ( cNetacan[nTi] != "" || cNetacan[nTi] != "?" ) { nT++; }
}
aNetacni[nTi] = nTa;
}
// raposredi netacne u cOdgovori
nT = 0;
for (int nTi = 0; nTi < 4; nTi++) {
if (nTi != nTacan) {
cOdgovori[nTi] = cNetacan[aNetacni[nT]];
nT++;
}
}
cOdgovori[0] = "A: "+cOdgovori[0];
cOdgovori[1] = "B: "+cOdgovori[1];
cOdgovori[2] = "C: "+cOdgovori[2];
cOdgovori[3] = "D: "+cOdgovori[3];
}
int GetBodovi() {
int nG = nPitanje;
if (!lcOdustani) { nG = (nPitanje/5)*5+1; };
int nT = 0;
for (int i = 1; i < nG; i++) {
nT += i*100;
if ( i%5 == 0 ) { nT += i*100; }
}
if (!lPub) { nT -= 500; }
if (!lPrijatelj) { nT -= 500; }
if (!l50) { nT -= 500; }
return nT-nBodoviTimer;
}
// string to more lines compared to width
String[] Str2Lines( String cOrig, int nWidth ) {
String[] cRet;
String cBuff = "";
String cLineBuff = "";
Font font = Font.getFont(Font.FACE_PROPORTIONAL,
Font.STYLE_PLAIN, Font.SIZE_SMALL);
int nIndex = 0;
int naRet = 0;
cRet = new String[5];
for (int i = 0; i < 5; i++) { cRet[i] = ""; }
cBuff = GetNextWord( cOrig, nIndex );
nIndex = nIndex + cBuff.length() + 1;
while ( cBuff != "" && naRet < 5) {
if (font.stringWidth(cLineBuff+" "+cBuff) > nWidth) {
cRet[naRet] = cLineBuff ;
naRet++;
cLineBuff = cBuff;
/* if ( nIndex >= cOrig.trim().length() ) {
cRet[naRet] = cLineBuff+" "+cBuff;
naRet=5;
}
} else if ( nIndex >= cOrig.trim().length() ) {
cRet[naRet] = cLineBuff+" "+cBuff;
naRet=5; */
} else {
cLineBuff = cLineBuff+" "+cBuff;
}
cBuff = GetNextWord( cOrig, nIndex );
nIndex = nIndex + cBuff.length() + 1;
}
if ( naRet < 5 ) { cRet[naRet] = cLineBuff+" "+cBuff; }
return cRet;
}
String GetNextWord( String cOrig, int nIndex ) {
String cT;
if (nIndex < cOrig.length()) {
cT = cOrig.substring( nIndex ).trim()+" ";
return cT.substring( 0, cT.indexOf( " " ) ).trim();
} else {
return "";
}
}
void iscrtaj( Graphics g ) {
String[] cTPitanje;
int nPPrazno = 0;
int nPOffset = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -