473,785 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is code freezing and not turning over images consistently?

tpgames
785 Contributor
Me memory game freezes after I click some cards. I seems to be random as to the number of clicks needed before it freezes.
I posted the entire code, as I am not sure what is needed for help. I am new to Java Script, and trying to learn it as a hobby. I'm stuck! It matters not if cards match or not.

The link to the game is here:
http://www.tpgames.net/gaming/2/memo...yzmemwork.html

Thanks in advance!

Expand|Select|Wrap|Line Numbers
  1. <!--
  2.  
  3. var variable = window.name;
  4. if (variable=='')
  5. {
  6.     var num_rows = 4;
  7.     var num_columns = 4;
  8. }
  9. else
  10. {
  11.     var temp1=variable.lastIndexOf("c");
  12.     var num_rows=variable.slice(1,temp1);
  13.     var num_columns=variable.slice(temp1+1,variable.length);
  14. }
  15.  
  16. var num_fields=num_rows * num_columns;
  17. var num_pics=num_rows * num_columns/2;
  18. var opened_pics=0;
  19. var firstclick=0;
  20. var pic1;
  21. var pic2;
  22. var start_time;
  23. var end_time;
  24. var firstimage=0;
  25. var first_clicked_image=0;
  26. var image_number;
  27. var attempts=0;
  28. var allow_click=1;
  29.  
  30. var last_image=25;
  31.  
  32. var covered=new Image;covered.src="/gaming/2/memory/MemoryWORK/q/covered.jpg";
  33. var bild=new Array();
  34.  
  35. bild[0]=new Array(2);
  36. bild[0]["nick"]=new Image;bild[0]["nick"].src="/gaming/2/memory/MemoryWORK/q/101.gif";
  37. bild[0]["avatar"]=new Image;bild[0]["avatar"].src="/gaming/2/memory/MemoryWORK/q/201.gif";
  38. bild[1]=new Array(2);
  39. bild[1]["nick"]=new Image;bild[1]["nick"].src="/gaming/2/memory/MemoryWORK/q/102.gif";
  40. bild[1]["avatar"]=new Image;bild[1]["avatar"].src="/gaming/2/memory/MemoryWORK/q/202.gif";
  41. bild[2]=new Array(2);
  42. bild[2]["nick"]=new Image;bild[2]["nick"].src="/gaming/2/memory/MemoryWORK/q/103.gif";
  43. bild[2]["avatar"]=new Image;bild[2]["avatar"].src="/gaming/2/memory/MemoryWORK/q/203.gif";
  44. bild[3]=new Array(2);
  45. bild[3]["nick"]=new Image;bild[3]["nick"].src="/gaming/2/memory/MemoryWORK/q/104.gif";
  46. bild[3]["avatar"]=new Image;bild[3]["avatar"].src="/gaming/2/memory/MemoryWORK/q/204.gif";
  47. bild[4]=new Array(2);
  48. bild[4]["nick"]=new Image;bild[4]["nick"].src="/gaming/2/memory/MemoryWORK/q/105.gif";
  49. bild[4]["avatar"]=new Image;bild[4]["avatar"].src="/gaming/2/memory/MemoryWORK/q/205.gif";
  50. bild[5]=new Array(2);
  51. bild[5]["nick"]=new Image;bild[5]["nick"].src="/gaming/2/memory/MemoryWORK/q/106.gif";
  52. bild[5]["avatar"]=new Image;bild[5]["avatar"].src="/gaming/2/memory/MemoryWORK/q/206.gif";
  53.  
  54. //EDITED CODE HERE
  55.  
  56. bild[23]["nick"]=new Image;bild[23]["nick"].src="/gaming/2/memory/MemoryWORK/q/124.gif";
  57. bild[23]["avatar"]=new Image;bild[23]["avatar"].src="/gaming/2/memory/MemoryWORK/q/224.gif";
  58. bild[24]=new Array(2);
  59. bild[24]["nick"]=new Image;bild[24]["nick"].src="/gaming/2/memory/MemoryWORK/q/125.gif";
  60. bild[24]["avatar"]=new Image;bild[24]["avatar"].src="/gaming/2/memory/MemoryWORK/q/225.gif";
  61. bild[25]=new Array(2);
  62. bild[25]["nick"]=new Image;bild[25]["nick"].src="/gaming/2/memory/MemoryWORK/q/126.gif";
  63. bild[25]["avatar"]=new Image;bild[25]["avatar"].src="/gaming/2/memory/MemoryWORK/q/226.gif";
  64.  
  65.  
  66.  
  67.  
  68.  
  69. var image_numbers = new Array();
  70. for (var t=0;t < num_fields; t++)
  71. {
  72.     image_numbers[('M'+t)]=new Array();
  73.     image_numbers[('M'+t)]["zahl"]=t;
  74.     image_numbers[('M'+t)]["status"]=0;
  75. }
  76.  
  77. var temp_numbers= new Array();
  78. function init()
  79. {
  80.     for (var t=0;t < num_fields; t++)
  81.     {
  82.         temp_numbers[('M'+t)]=t;
  83.     }
  84.  
  85.     for (var t=0;t < num_fields; t++)
  86.     {   
  87.         do    
  88.         {    
  89.             random_number = Math.round(Math.random() * (num_fields));    
  90.         } while (random_number > (num_fields-1))
  91.         //random_number = (Math.random() * 1000) % num_fields; 
  92.  
  93.         var temp=temp_numbers[('M'+t)];
  94.  
  95.         temp_numbers[('M'+t)]=temp_numbers[('M'+random_number)];
  96.         temp_numbers[('M'+random_number)]=temp;
  97.     }
  98.     for (t=0; t < num_fields; t++) image_numbers[('M'+t)]["zahl"]=temp_numbers[('M'+t)];
  99. }
  100.  
  101. function close(pic1,pic2)
  102. {
  103.     window.document.images[pic1].src=covered.src;
  104.     image_numbers[pic1]["status"]=0;
  105.     window.document.images[pic2].src=covered.src;
  106.     image_numbers[pic2]["status"]=0;
  107.     allow_click=1;
  108. }
  109.  
  110. var game;
  111. var temp;
  112.  
  113. function look(x,y)
  114. {
  115.     if (firstclick==0)
  116.     {
  117.         start_time=new Date();
  118.         firstclick=1;
  119.     }
  120.  
  121.     image_number='M'+(x*num_columns+y);
  122.     if ((firstimage==0) && (image_numbers[image_number]["status"]<3))
  123.     {
  124.         allow_click=0;
  125.         firstimage=1;
  126.  
  127.         pic1=Math.floor(image_numbers[image_number]["zahl"]/2);
  128.  
  129.         if ((image_numbers[image_number]["zahl"] % 2)==0)
  130.             window.document.images[image_number].src=bild[pic1]["avatar"].src
  131.         else
  132.             window.document.images[image_number].src=bild[pic1]["nick"].src;
  133.         image_numbers[image_number]["status"]=10;
  134.         first_clicked_image=image_number;
  135.         allow_click=1;
  136.     }
  137.     else if ((firstimage==1) && (image_numbers[image_number]["status"]<3))
  138.     {
  139.         allow_click=0;
  140.         firstimage=0;
  141.         attempts++;
  142.         pic2=Math.floor(image_numbers[image_number]["zahl"]/2);
  143.         if ((image_numbers[image_number]["zahl"] % 2)==0)
  144.             window.document.images[image_number].src=bild[pic2]["avatar"].src
  145.         else
  146.             window.document.images[image_number].src=bild[pic2]["nick"].src;
  147.         image_numbers[image_number]["status"]=10;
  148.         if (pic1!=pic2)
  149.             window.setTimeout("close(first_clicked_image,image_number)",600);
  150.         else
  151.         {
  152.             opened_pics++;
  153.             allow_click=1;
  154.         }
  155.         if (opened_pics==num_pics) end_time=new Date();
  156.     }
  157.  
  158.     if (opened_pics==num_pics)
  159.     {
  160.         var seconds=Math.floor(eval(((end_time.getTime() - start_time.getTime())) / 1200));
  161.  
  162.         alert("Congratulations, you solved game in "+attempts+" turns and "+seconds+" seconds!")
  163.         if (num_columns == 6)
  164.         {
  165.             if (num_rows == 5)
  166.                 document.spiel.Level.value="1";
  167.             else
  168.                 document.spiel.Level.value="0";
  169.         }
  170.         else
  171.             document.spiel.Level.value="nix";
  172.         if (document.spiel.Level.value == "0" || document.spiel.Level.value == "1")
  173.             window.document.getElementById('highscore').style.visibility = 'visible';
  174.         document.spiel.Versuche.value=attempts;
  175.         document.spiel.Zeit.value=seconds;
  176.     }
  177. }
  178.  
  179. function loadmemory()
  180. {
  181.     var start=0;
  182.  
  183.     if (document.spiel.settings[0].checked == true) { game="r4c4";start=1; }
  184.     if (document.spiel.settings[1].checked == true) { game="r6c5";start=1; }
  185.     if (document.spiel.settings[2].checked == true) { game="r11c5";start=1; }
  186.  
  187.     window.name=game;
  188.     location.reload();
  189. }
  190. //-->
  191.  
Expand|Select|Wrap|Line Numbers
  1. <!--
  2.  
  3. init();
  4.  
  5.  
  6. for (var i=0;i < num_rows; i++)
  7. {
  8.     for (var j=0;j < num_columns; j++)
  9.     {
  10.         document.write('<img src="'+covered.src+'" onClick="if (allow_click==1) look('+i+','+j+')" name="M'+(i*num_columns+j)+'">');
  11.     }
  12.     document.write('<br>');
  13. }
  14. //-->
  15. </script>
  16.  
  17. <table width=100%>
  18. <br>
  19. <tr><td valign="top">Choose your Skill:</td></tr>
  20. <tr><td valign="top">
  21.  
  22. <input type="radio" name="settings" id="s1" value="rookie"> <label for="s1">Rookie</label><br>
  23.  
  24. <input type="radio" name="settings" id="s2" value="advanced"> <label for="s2">Advanced</label><br>
  25. <input type="radio" name="settings" id="s3" value="professional"> <label for="s3">Professional</label>
  26.  
  27. <br><br><br>
  28.  
  29. <input type="button" value="New Game" onClick="loadmemory()">
  30.  
  31. <input type="hidden" name="Level" value="">
  32. <input type="hidden" name="Versuche" value="">
  33. <input type="hidden" name="Zeit" value="0">
  34.  
  35. <input type="submit" id="highscore" style="visibility:hidden" value="Submit Score">
  36.  
Jan 18 '07 #1
2 1484
tpgames
785 Contributor
I forgot to add, that I am testing it in professional mode. As, that contains the amount of cards I want to test. It only freezes in professional mode.
Jan 18 '07 #2
tpgames
785 Contributor
Solved in that I found that the code requires one to have the exact number of images that row x column =. Thus, my 26 images x 2 did not = the 55 images I needed. I only had 52 images.

However, how does one rewrite the code so that it can take any number of images? If this means a complete rewrite of the code, then just say so. I don't want to cause anyone a boat load of work. Thanks!
Jan 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
5862
by: Greg Raven | last post by:
I styled my links just the way I want them using CSS, but now my linked images have picked up these same styles. I've tried turning the styles off for the images with: a img { text-decoration: none; outline: none; margin: 0px; padding: 0px;
3
3483
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or less would display, but those close to 300 pixels/inch or greater would not (MS Access cannot recognize the file format xxx.jpg). The larger, original images were scanned and saved as .bmp (at 300 dpi producing a 15MB file). Then the images were...
0
930
by: dylpkls91 | last post by:
Hi all, I am working on a little program for home automation under the X10 protocol. I have given up using a Palm device for input, so I have resorted to using voice recognition, which I knew nothing about. However, I found a nice little script on the internet that does exactly what I need, and it recognizes phrases with pretty much 100% accuracy. The script can be found here: ...
7
2042
by: bearophileHUGS | last post by:
Most of my ideas seem usless or stupid, but I think expressing them here doesn't harm much. This is an idea for Py 3.0, because it's not backward compatible. Dicts and sets require immutable keys, like tuples or frozensets, but to me they look like a duplication. So the idea is to remove tuples and frozensets (and replace the few other uses of tuples with lists, like the % interpolation), and to add a freeze operation, to freeze lists,...
8
3632
by: Mark A. Sam | last post by:
Hello I am working locally with Visual Web Developer 2005 Express. Before I even installed it, the information from Microsoft was that you could FTP it to a remote site and it should work. The site I FTP'd to has .Net Framework 2.0 installed. I got this error when I tried to open the site: Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details...
3
1619
by: Motion Musso aka: Sathia | last post by:
function up(bpid) { image = document.getElementById('up_'+bpid); image.setAttribute('SRC','/templates/images/yespulse.gif') up_down('/up_down.php?bpid=' + bpid + '&action=up'); image.setAttribute('SRC','/templates/images/rated_up.gif')
1
1374
by: joehehir | last post by:
Hi, I have netscape 8.1, and just today it started acting weird. About every 60 secons, the browser stops responding and about 60% of my CPU Usage spikes. It then unfreezes and the browser works normally again for about 60 more seconds. I have tried turning off all the controls and security settings, but I am at a loss as to why this just startedt o happen to a program i have been using easily for months. I have run a virus scan and adaware...
4
2845
kestrel
by: kestrel | last post by:
I have a Sony Vaio FS920. My OS is Windows XP Home Edition Version 2002 Service Pack 2 Recently (starting 2 months ago), my computer has been freezing up and turning one solid color. The first time it was white, second black, third white and fourth Pink. The first time it froze what when i was just surfing the internet. The second i had left it to go to the bathroom. the third i had left it downloading files while i ate. And this last time,...
2
2074
by: everly | last post by:
Hi, I'm helping my friends band and making their MySpace. I messed something up and I can't figure out what it is. Everything is all out of whack on the bottom half of the page. The comments shouldn't be on the left hand side. Help please! Thanks. ____________________________________________________- <style type="text/css"> { Background Properties } table, tr, td { background-color:transparent; border:none; border-width:0;} body {...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.