473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why is code freezing and not turning over images consistently?

tpgames
785 512MB
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 1452
tpgames
785 512MB
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 512MB
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
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:...
3
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...
0
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...
7
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...
8
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...
3
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'); ...
1
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...
4
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.