rabidlemming
Technical User
hi,
I have included the java script below. I am trying to make an array 100 blocks big. (See in the code where it say’s "this is where I need help"
. I need to put the values of 0 to 99 into the array blocks. I then need to check that when a user clicks an image it checks the image index number again the values in the array. If the number is in the array it will do an image swap. Then it will remove the number that matched the image index number from the array. This is so that once an image has been click once it can not be click again. I need an alert message to say something like "this has already been clicked on". I then need it so when the array is empty or when all the images have been click on, if the value life is still = or > 1 then alert you win. Then reload the page. It’s for a java game version of mind sweeper. There are a total of 100 images that swap over in a table. Can you please help me?
My javascript is:
<script language="JavaScript" type="text/JavaScript">
var life = 3;
var b = 0;
var a = 9;
var v = 1;
var rNum;
var SwapImg = new Image;
SwapImg.src="BOXCORRECT.gif";
var bang = new Image;
bang.src="BANG.gif";
var numArray = new Array(a);
function makebomb() {
if (v == 1){
name = "normal";
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
;
v = v + 1;
}
for(i=0;i<=a;i++) {
rNum = Math.round(Math.random()*99);
for(k=0;k<=a;k++) {
if(rNum==numArray[k]) {
rNum = Math.round(Math.random()*99);
i=0;
}
}
}
numArray=rNum;
}
function add(userschoice) {
// THIS IS WHERE I AM STUCK
THIS IS WHERE I AM STUCK
{
function easy() {
name = "easy"
life = 3;
a = 4;
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
;
for(j=0;j<=99;j++) {
b = b + 1;
document.images[j].src="BOX.gif";
}
makebomb();
}
function normal() {
name = "normal"
life = 3;
a = 9;
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
;
for(l=0;l<=99;l++) {
document.images[l].src="BOX.gif";
}
makebomb();
}
function hard() {
name = "hard"
life = 3;
a = 19;
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
;
for(m=0;m<=99;m++) {
document.images[m].src="BOX.gif";
}
makebomb();
}
function message1() {
alert ("You have " + life + " life(s) left"
;
}
function message() {
if (v == 1);
name = "notmal";
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
;
v == v + 1;
}
function swap(userschoice) {
var found = 0;
for(i=0;i<=a;i++){
if (numArray==userschoice)
found++;
}
if(found >0){
life = life - 1;
document.images[userschoice].src=bang.src;
end();
}
else
{
document.images[userschoice].src=SwapImg.src;
alert ("Thew! That was close."
;
}
function end() {
if (life == 0){
alert ("Sorry you died Game Over"
;
window.location.reload();
}
else
{
message1();
}
}}}}</script>
</head>
<body onLoad="makebomb();">
<div align="center"></div>
<table width="38%" align="center" height="339" border="1" cellpadding="1" cellspacing="1" bordercolor="#000000" bgcolor="#000000">
<tr>
<td><a href="JavaScript:add(0)" onMouseDown="add(0)"src="BOXCORRECT.gif" width="70" height="70"><img src="BOX.gif" width="70" height="70"></a></td>
<td><a href="JavaScript:add(1)" onMouseDown="add(1)" src="BOXCORRECT.gif" width="70" height="70"><img src="BOX.gif" width="70" height="70"></a></td>
<td>" DITTO DITTO"</a></td>
<td>"DITTO DITTO"</a></td>
</tr>
<tr>
cheers
I have included the java script below. I am trying to make an array 100 blocks big. (See in the code where it say’s "this is where I need help"
My javascript is:
<script language="JavaScript" type="text/JavaScript">
var life = 3;
var b = 0;
var a = 9;
var v = 1;
var rNum;
var SwapImg = new Image;
SwapImg.src="BOXCORRECT.gif";
var bang = new Image;
bang.src="BANG.gif";
var numArray = new Array(a);
function makebomb() {
if (v == 1){
name = "normal";
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
v = v + 1;
}
for(i=0;i<=a;i++) {
rNum = Math.round(Math.random()*99);
for(k=0;k<=a;k++) {
if(rNum==numArray[k]) {
rNum = Math.round(Math.random()*99);
i=0;
}
}
}
numArray=rNum;
}
function add(userschoice) {
// THIS IS WHERE I AM STUCK
THIS IS WHERE I AM STUCK
{
function easy() {
name = "easy"
life = 3;
a = 4;
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
for(j=0;j<=99;j++) {
b = b + 1;
document.images[j].src="BOX.gif";
}
makebomb();
}
function normal() {
name = "normal"
life = 3;
a = 9;
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
for(l=0;l<=99;l++) {
document.images[l].src="BOX.gif";
}
makebomb();
}
function hard() {
name = "hard"
life = 3;
a = 19;
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
for(m=0;m<=99;m++) {
document.images[m].src="BOX.gif";
}
makebomb();
}
function message1() {
alert ("You have " + life + " life(s) left"
}
function message() {
if (v == 1);
name = "notmal";
alert ("You have " + life + " lives. You must find " + (a + 1) + " Mines. This is set to " + name + " difficulty. To change the difficulty setting click on the difficulty settings below."
v == v + 1;
}
function swap(userschoice) {
var found = 0;
for(i=0;i<=a;i++){
if (numArray==userschoice)
found++;
}
if(found >0){
life = life - 1;
document.images[userschoice].src=bang.src;
end();
}
else
{
document.images[userschoice].src=SwapImg.src;
alert ("Thew! That was close."
}
function end() {
if (life == 0){
alert ("Sorry you died Game Over"
window.location.reload();
}
else
{
message1();
}
}}}}</script>
</head>
<body onLoad="makebomb();">
<div align="center"></div>
<table width="38%" align="center" height="339" border="1" cellpadding="1" cellspacing="1" bordercolor="#000000" bgcolor="#000000">
<tr>
<td><a href="JavaScript:add(0)" onMouseDown="add(0)"src="BOXCORRECT.gif" width="70" height="70"><img src="BOX.gif" width="70" height="70"></a></td>
<td><a href="JavaScript:add(1)" onMouseDown="add(1)" src="BOXCORRECT.gif" width="70" height="70"><img src="BOX.gif" width="70" height="70"></a></td>
<td>" DITTO DITTO"</a></td>
<td>"DITTO DITTO"</a></td>
</tr>
<tr>
cheers