» »

novi java problemi

novi java problemi

StratOS ::

preglej


in povej kako ti je šlo ??
"Multitasking - ability to f##k up several things at once."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."

Gandalfar ::

dej stratOS daj poskusi to malo drugace narediti. Imas tam temo eno ze k je programerski problem. Najprej tistega resite potem pa novega postavi. Ne za vsakega nove teme odpirat oz. lahko novo temo odpres toda najprej pocakaj da boste tistega resili in da bo vmes minil _vsaj_ kaksn teden.

Drugace bo prevec problemov in bo zmanjkalo interesa. To moras pocasi v obvladljivih kolicinah..

Zgodovina sprememb…

StratOS ::

oki, naj maj malce dela med weekendi ...
"Multitasking - ability to f##k up several things at once."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."

krho ::

codename = SpaceMan

kar pa se tice drugega dela geslo je "undefined"

Ce te zanima pot do resitve.
Prvi del:
var codenm = new String(document.codename.name.value);
var i = 0;
var len = codenm.length;
var xor = 1;
var sol = new Array(82, 113, 98, 100, 102, 78, 98, 111);
var good = "Good to see you friend. Let's get on with this mission...";
var bad = "I'm sorry, i dont recognise you. Goodbye.";
var res = 1;

if (len != 8) res = 0;

for(i = 0; i < len; i++) {
//sprehodimo se cez string, ki ga je uporabnik vpisal
if (res) {
/*od znaka, ki ga je uporabnik vpisal odstejemmo xor
,in ga primerjamo z i-tim znakom v sol Arrayu
ker je xor 1 pomeni, da ima prvi znak vrednost 83 to
pa je crka S V naslednji vrstici pa se xor spremeni v -1, to pa pomeni, da so vsi naslednji znaki v tabeli vecji za 1 torej je naslednja crka p,a,c,....
*/
if (sol[i] != (codenm.charCodeAt(i) - xor)) res = 0;

if (xor)
xor = -1;
else
xor = 1;
}
}



Drugi del:
v var sol8 = new Array(82, 106, 98, 100, 118, 78, 98, 111, 113, 98, 100, 102, 96);
na tretje mesto vpises 1337 in dobis, da je geslo undefined

StratOS ::

U did it :)
Hurayyy
"Multitasking - ability to f##k up several things at once."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."

StratOS ::

Kdor zna delati z C-jem bi ga potrboval da mi napiše eno rutinico za igro Sokoban v javi !
Za kaj gre !

Kako bi v javi naredil npr. da bi recimo pri eni igri sokobana, za katero potrebuješ recimo min X potez, če ti le uspe vse postaviti na mesto v javi hrefn-u na nov page.

Če koga zanima mam source za Sokoban.

/**********************************************************
Sokoban.java - My First Java Game
**********************************************************/

import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.util.*;

/******** TEST ********/

public class Sokoban extends Applet
{
static int MAX_X=17, MAX_Y=13, MAX_LVL=0, MAX_IMG=8, MAX_HIST=100;
static int X_0 = 5, Y_0 = 5;
static int Max_Potez=100;

private Sokoban main;

private Image mainImg;
private Graphics g;
private TextField txt1;
private Image[] xImg = new Image[MAX_IMG+1];
private int xPos, yPos, gLevel, mvPos;
private byte[][] currCanvas = new byte[MAX_Y+1][MAX_X+1];
private byte[] xMove = new byte[MAX_HIST];
private byte firstTime;

private Button btn1 = new Button("X");
private Button btnN2 = new Button(">>");
private Button btnN = new Button(">");
private Button btnP = new Button("<");
private Button btnP2 = new Button("<<");
private Button btnU = new Button("U");

private static String mCode = " 01234567, :o#@XHB";
private static int xCoord[][] =
{{ 0, 0,20,20}, { 20, 0,20,20}, { 40, 0,20,20},
{ 0,20,20,20}, { 20,20,20,20}, { 40,20,20,20},
{ 0,40,20,20}, { 20,40,20,20}, { 40,40,20,20}};

private static String biDat[] = {
"##### ####,#ooo# #::####,#ooo###::H::#,#oooo##:H::H###,##oooo##:::H::#,###ooo:##:H:H:#,#:##::::#::H::#,#::##:#:###:####,#:H:#:#H::H::::#,#::H:@:H::::H::#,#:::#:H:HH:H:###,#::######::###,#:## ####,###",
};

public void init()
{
String param;
int i;

if (g==null) g = getGraphics();

URL url = getCodeBase();

String str = "";
int b = 0;

MediaTracker tracker = new MediaTracker(this);
mainImg = getImage(url, "images.gif");
tracker.addImage(mainImg,0);

for (i=0; i<=MAX_IMG; i++)
{
xImg[i] = extractImage(xCoord[i]);
tracker.addImage(xImg[i], i+1);
}

try { tracker.waitForAll(); }
catch (InterruptedException e) {}

setLayout(new BorderLayout());

txt1 = new TextField(25);
txt1.setForeground(new Color(255,255,204));
txt1.setBackground(new Color(102,51,51));
txt1.setEditable(false);

Panel p = new Panel();

p.add(txt1);
p.add(btn1);
p.add(btnU);

add("South", p);

gLevel = 0;
dat2Canvas(0);
firstTime = 1;
}

public boolean dat2Canvas(int dlvl)
{
int i,x,y;
byte z = 0;
String param;

try
{
gLevel += dlvl; if (gLevel<0) gLevel = 0;
param = getParameter("data"+gLevel);
if (param==null) param = biDat[gLevel];
}
catch (ArrayIndexOutOfBoundsException exc)
{
gLevel -= dlvl;
return false;
}

for (y=0; y<=MAX_Y; y++)
{ for (x=0; x<=MAX_X; x++)
{ currCanvas[y][x] = 0; }
}

x = y = 0;
for (i=0; i {
z = (byte)(mCode.indexOf(param.charAt(i)) % 10);
if (z>MAX_IMG || x>MAX_X)
{
x = 0; y++;
if (y>MAX_Y) break;
}
else
{
if (z<0) z = 0;
currCanvas[y][x] = z;
x++;
}
}
for (i=0; i mvPos = 0;
txt1.setText(" Restarting game level "+gLevel+".");
if (firstTime==1) firstTime = 0;
return true;
}

public boolean action(Event e, Object arg)
{
int h = -1;

if (e.target==btn1) h = 18;
else if (e.target==btnU) h = 8;

if (h>0) keyDown(e, h);

return true;
}

public boolean keyDown(Event e, int c)
{
int dx = 0;
int dy = 0;
int ch = 0;
int h = 0;
byte z0,z1,z2;
String st0 = "";

switch (c)
{
case e.UP: dy = -1; h = 1; break;
case e.DOWN: dy = 1; h = 3; break;
case e.LEFT: dx = -1; h = 5; break;
case e.RIGHT: dx = 1; h = 7; break;
case 8:

h = xMove[--mvPos];
if (h<=0) return true;
if (h>8) { ch = 5; h = h % 8; st0 = "(Pushed)"; }
if (h<4) { dy = h-2; if (dy>0) st0 = "Down "+st0; else st0 = "Up "+st0; }
else { dx = h-6; if (dx>0) st0 = "Right "+st0; else st0 = "Left "+st0; }

if (ch>0)
{
int xTmp = xPos+dx;
int yTmp = yPos+dy;
z0 = (byte)(currCanvas[yTmp][xTmp] -= 5);
g.drawImage(xImg[z0],X_0+20*xTmp,Y_0+20*yTmp,this);
}

z0 = (byte)(currCanvas[yPos][xPos] += ch-3);
g.drawImage(xImg[z0],X_0+20*xPos,Y_0+20*yPos,this);

xPos -= dx; yPos -= dy;
z0 = (byte)(currCanvas[yPos][xPos] += 3);
g.drawImage(xImg[z0],X_0+20*xPos,Y_0+20*yPos,this);


txt1.setText(" History #"+mvPos+" : "+st0);
return true;

case 18:
if (mvPos==0) { firstTime = (byte)(1-firstTime); paint(null); return true; }
h = -100; break;
case 44: h = -101; break;
case 46: h = -99; break;
case 14: h = -90; break;
case 16: h = -110; break;

default:
txt1.setText(" Use ^P,<,>,^N,^R, or BS key.");
break;
}

if (dx==0 && dy==0)
{
if (h<0) { if (dat2Canvas(h+100)) paint(null); }
return true;
}

int xTmp = xPos+dx;
int yTmp = yPos+dy;

z0 = currCanvas[yPos][xPos];
z1 = currCanvas[yTmp][xTmp];
z2 = 0;

if (z1==1 || z1==2)
{
z0 -= 3; z1 += 3;
ch = 1;
}
else
if ((z1==6 || z1==7) &&
((z2=currCanvas[yTmp+dy][xTmp+dx])==1 || z2==2))
{
z0 -= 3; z1 -= 2; z2 += 5;
ch = 2; h += 8;
}

if (ch>0)
{
currCanvas[yPos][xPos] = z0;
currCanvas[yTmp][xTmp] = z1;
g.drawImage(xImg[z0],X_0+20*xPos,Y_0+20*yPos,this);
g.drawImage(xImg[z1],X_0+20*xTmp,Y_0+20*yTmp,this);
yPos = yTmp; xPos = xTmp;
if (ch==2)
{
yTmp += dy; xTmp += dx;
currCanvas[yTmp][xTmp] = z2;
g.drawImage(xImg[z2],X_0+20*xTmp,Y_0+20*yTmp,this);
}

xMove[(mvPos++) % MAX_HIST] = (byte)h;

z0 = 0;
for (dy=0; dy<=MAX_Y; dy++)
{ for (dx=0; dx<=MAX_X; dx++)
{ if (currCanvas[dy][dx]==6) z0++; }
}

if (z0==0) { txt1.setText(" Completed after "+mvPos+" steps."); }
else { txt1.setText(" Step: "+mvPos+", Load: "+z0); }
if(mvPos>Max_Potez) {txt1.setText(" Too much moves !("+mvPos+"!");}
}


return true;
}

private Image extractImage(int[] xyCoord)
{
Image newImage;
ImageFilter filter;
ImageProducer producer;

filter = new CropImageFilter(xyCoord[0],xyCoord[1],xyCoord[2],xyCoord[3]);
producer = new FilteredImageSource(mainImg.getSource(), filter);
newImage = createImage(producer);
return newImage;
}

public void paint(Graphics g)
{
if (g==null) g = getGraphics();
int y2 = Y_0;
for (int y=0; y<=MAX_Y; y++)
{
int x2 = X_0;
for (int x=0; x<=MAX_X; x++)
{
byte z = currCanvas[y][x];
if (z==4 || z==5) { xPos = x; yPos = y; }
if (firstTime==1 || z>MAX_IMG) z = 0;
g.drawImage(xImg[z],x2,y2,this);
x2 += 20;
}
y2 += 20;
}
if (firstTime==1)
{
int y = 30, x = 15;
g.setColor(new Color(255,255,204));
String str = "*SOKOBAN* by StratOS";
g.drawString(str,15,y);
txt1.setText(str);
y += 25; g.drawString("Objective of this game is to put every object into the marked place.",x,y);
y += 15; g.drawString("We can not pull the object, and we can only push one of it every time.",x,y);
y += 35; g.drawString("Use arrow keys to move the worker.",x,y);
y += 15; g.drawString("Press [Ctrl]-R (or click X button) to restart the game.",x,y);
y += 15; g.drawString("Press Backspace (or U button) to undo until 100 last movement.",x,y);
y += 25; g.drawString("SOKOBAN is trademark by somebody else whose wrote this game for",x,y);
y += 15; g.drawString("the first time. I just convert it into Java Applet and hope you enjoy it.",x,y);
y += 15; g.drawString("When u finish it in deserved moves, u'll get password 4 nex level.",x,y);
}
}

}

Rutino z rdečo bi trebalo spremeniti, kako ?
ma kdo kakšen primer, če ma ga naj proba asemblirati na http://www.innovation.ch/java/java_comp....
Pozdrav
"Multitasking - ability to f##k up several things at once."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."

Zgodovina sprememb…

  • spremenila: StratOS ()


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Davčne blagajne (strani: 1 2 3 424 25 26 27 )

Oddelek: Programiranje
1344331478 (71481) Macketina
»

[Java] Ne zažene appleta

Oddelek: Programiranje
51204 (1137) iggy
»

[JAVA] branje iz datoteke

Oddelek: Programiranje
242399 (2034) Bela01
»

[Java] Zmešnjava

Oddelek: Programiranje
462057 (1562) ]Fusion[
»

Kako pošiljanje datotek v JAVI.

Oddelek: Programiranje
141829 (1700) kopernik

Več podobnih tem