Foros del Web » Programando para Internet » Javascript »

Laberinto

Estas en el tema de Laberinto en el foro de Javascript en Foros del Web. Hola Aqui tengo un laberinto facilitado por w w w . h t m l p o i n t . c o m Mi ...
  #1 (permalink)  
Antiguo 17/04/2006, 02:01
 
Fecha de Ingreso: junio-2001
Mensajes: 277
Antigüedad: 22 años, 10 meses
Puntos: 1
Laberinto

Hola

Aqui tengo un laberinto facilitado por w w w . h t m l p o i n t . c o m
Mi pregunta es si se puede hacer que en vez de signos # haya en el campo a sortear imagenes gif o jpg

O sea, me gustaria que el usuario se desplace entre imagenes, en vez de signos #

Muchas gracias

Este es el laberinto


<HEAD>
<TITLE>Maze</TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF" onLoad="fillBoard(document.board);update(document. board);">



<!-- begin Script here -->
<!-- -->
<!-- Copyright 1996 by Steven Weinberger of Transaction Information Systems.-->
<!-- Free permission is given to re-use this code, if and only if -->
<!-- this copyright notice is kept in. -->
<script>
var line = "";
var x = 0;
var y = 0;
var fill="*";
var blank = ".";
var full = "*";

// Functions to create the board

function makeboard() {
for (var i=1; i<= 10; i++)
this[i] = new makeRow();
return this;
}

function makeRow() {
for (var i=1; i<= 10; i++)
this[i]=blank;
return this;
}

// Functions to fill & clear the board.

function clearBoard (form) {
x = 0;
y = 0;
form.xval.value = 1;
form.yval.value = 1;
for (var i=1; i<= 10; i++)
for (var j=1; j<= 10; j++)
theBoard[i][j]=blank;
plot_maze();
fillBoard(form);
return;
}

function fillBoard (form) {
line = "";
form.grid.value = "";
for (var i=1; i<= 10; i++)
for (var j=1; j<= 10; j++)
line += theBoard[i][j];
form.grid.value=line;
}

function update(form) {
var horiz = eval(form.xval.value);
var vert = eval(form.yval.value);
theBoard[vert][horiz] = fill;
fillBoard(form);
return;
}

// Functions to handle the cross-hairs
function decx(form) {
fill = blank;
update(form);
checkx = eval(form.xval.value - 1);
checky = form.yval.value;
if (form.xval.value > 1) {
if (theBoard[checky][checkx] != "#") {
form.xval.value=eval(form.xval.value - 1);
}
else {
alert("THUD!\nYou hit a wall.");
//linebreak
}

if (theBoard[checky][checkx] == "$") {
alert("YOU WIN!");

}
}
fill = full;
update(form);
}

function incx(form) {
fill = blank;
update(form);
checkx = eval(1 * form.xval.value + 1);
checky = form.yval.value;
if (form.xval.value < 10) {
if (theBoard[checky][checkx] != "#") {
form.xval.value=eval(1 * form.xval.value + 1);
}
else {
alert("THUD!\nYou hit a wall.");
}
if (theBoard[checky][checkx] == "$") {
alert("YOU WIN!");
}
}
fill = full;
update(form);
}

function decy(form) {
fill = blank;
update(form);
checkx = form.xval.value;
checky = eval(form.yval.value - 1);
if (form.yval.value > 1) {
if (theBoard[checky][checkx] != "#") {
form.yval.value=eval(form.yval.value - 1);
}
else {
alert("THUD!\nYou hit a wall.");
}
if (theBoard[checky][checkx] == "$") {
alert("YOU WIN!");
}
}
fill = full;
update(form);
}

function incy(form) {
fill = blank;
update(form);
checkx = form.xval.value;
checky = eval(1 * form.yval.value + 1);
if (form.yval.value <= 9) {
if (theBoard[checky][checkx] != "#") {
form.yval.value=eval(1 * form.yval.value + 1);
}
else {
alert("THUD!\nYou hit a wall.");
}
if (theBoard[checky][checkx] == "$") {
alert("YOU WIN!");
}
}
fill = full;
update(form);
}

// Various Functions

function no (form) {
alert("You can't change this value manually.\nPlease use the buttons.");
clearBoard(form);
update(form);
}

function plot_maze() {
theBoard[10][10] = "$";
theBoard[1][2] = "#";
theBoard[2][2] = "#";
theBoard[4][1] = "#";
theBoard[4][2] = "#";
theBoard[4][3] = "#";
theBoard[2][3] = "#";
theBoard[5][2] = "#";
theBoard[6][2] = "#";
theBoard[2][5] = "#";
theBoard[4][5] = "#";
theBoard[5][5] = "#";
theBoard[2][6] = "#";
theBoard[2][7] = "#";
theBoard[9][10] = "#";
theBoard[9][9] = "#";
theBoard[8][9] = "#";
theBoard[7][9] = "#";
theBoard[10][7] = "#";
theBoard[9][7] = "#";
theBoard[8][7] = "#";
theBoard[6][7] = "#";
theBoard[9][2] = "#";
theBoard[9][3] = "#";
theBoard[9][4] = "#";
theBoard[8][2] = "#";
theBoard[7][4] = "#";
theBoard[7][5] = "#";
theBoard[6][5] = "#";
theBoard[5][7] = "#";
theBoard[5][8] = "#";
theBoard[5][9] = "#";
theBoard[4][9] = "#";
}

// End of functions
theBoard = new makeboard();
plot_maze();
document.writeln('<center><font size=+2>JavaScript Maze</font>');
document.writeln('<p>\n<dd>Your player is represented by the "*" in the upper-left corner.');
document.writeln(' Use the buttons to move it around the maze. The boxes will show your coordinates. Be careful not to hit any walls.');
document.writeln(' Reach the "$" in the lower-right to win. Press "Reset" to start over.<br><b>Good luck!</b><hr>\n<p>');
document.writeln('<form method="post" name="board">');
document.writeln('textarea name="grid" rows="9" cols="10" wrap=virtual>');
document.writeln('/textarea>');
document.writeln('<br>');

document.writeln("<input type='button' value='UP' onClick='decy(this.form)'><br>");
document.writeln("<input type='button' value='LEFT' onClick='decx(this.form)'><input type='button' value='RIGHT' onClick='incx(this.form)'><br>");
document.writeln("<input type='button' value='DOWN' onClick='incy(this.form)'><br>");
document.writeln("<input type='text' value='1' size=5 name='xval' onChange='no(this.form);'><input type='text' value='1' size=5 name='yval' onChange='no(this.form);'>");


//document.writeln("<br><input type='button' value='FIRE!' onClick='update(this.form);'>");


document.writeln("<br><input type='button' value='Reset' onClick='clearBoard(this.form);update(document.boa rd);'>");
document.writeln('</form></center>');
document.writeln('</body>');
</script>
  #2 (permalink)  
Antiguo 04/05/2006, 10:37
Avatar de ludovico2000  
Fecha de Ingreso: noviembre-2003
Ubicación: Bizkaia
Mensajes: 1.315
Antigüedad: 20 años, 6 meses
Puntos: 2
No, porque el laberinto se crea dentro de un input text que sólo admite texto.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:52.