www.webdeveloper.com
Results 1 to 2 of 2

Thread: Memory

Hybrid View

  1. #1
    Join Date
    May 2014
    Posts
    1

    Memory

    Hey guys, i have a really big problem!

    I have to make a javascript Memory for my mommy (Birthday) and i don't know to go on.

    Here's the already written code:

    Code:
    <script type="text/javascript">
    		
    			var maxfeld = 0;
    			
    			var Unsort = new Array();
    			
    			var AufgedeckteKarteId = 0;
    			
    			var AufgedeckteKarte = 0;
    			
    			var BildListe = new Array();
    			BildListe[0] = "1.jpg";
    			BildListe[1] = "2.jpg";
    			BildListe[2] = "3.jpg";
    			BildListe[3] = "4.jpg";
    			BildListe[4] = "5.jpg";
    			BildListe[5] = "6.jpg";
    			BildListe[6] = "7.jpg";
    			BildListe[7] = "8.jpg";					
    			
    			
    					
    			
    			//Erstellt die Tabelle
    			function zeichneFeld(s,r)
    			{
    				x=0;
    				tab = "<table>";
    				for (i=0; i < r; i++)
    				{
    					tab +="<tr>";
    					for (j=0; j < s; j++)
    						{
    							tab += "<td><img id=\"f"+x+"\" src=\"images/0.jpg\" width=\"150\" height=\"150\"  onclick=\"javascript:showCard("+x+")\" /></td>";
    							x++;
    						}
    					tab+="</tr>";		
    				}
    				tab +="</table>";
    				
    				maxfeld = x;
    				
    				document.getElementById("HT").innerHTML=tab;
    			}
    			
    			
    			function newGame()
    			{
    				//Blättchen verdeckt
    				for (i = 0; i < maxfeld; i++)
    					{
    						document.getElementById("f"+i).src = "deck.jpg";
    					}								
    				
    				
    				var SortBildListe = new Array();
    				
    				// 2. Bildliste hinzufügen
    				for (i = 0; i < maxfeld/2; i++)
    					{
    						SortBildListe.push(BildListe[i]);
    						SortBildListe.push(BildListe[i]);
    					}
    				
    				
    				
    				
    				
    				// Bilder "vermischen"		
    				for (i = 0; i < maxfeld; i++)
    					{
    						r = Math.floor((Math.random()*SortBildListe.length));											
    						Unsort.push(SortBildListe[r]);
    						SortBildListe.splice(r,1);
    					}
    					
    					
    				
    				/*	
    				for ( i= 0; i < maxfeld; i++)
    				{
    					document.getElementById("f"+i).src = Unsort[i];
    				}	
    				*/
    
    				
    					
    			}
    			
    			function showCard(id)
    			{
    				document.getElementById("f" + id).src=Unsort[id];
    				
    			}
    			
    					
    		</script>
    I don't know, how write the code for only two open cards, who i compare the two id's of the cards and than the pairs which are not identific should turn back and the others should stay open.

    Maybe somebody can help me.

    Greetings Kate

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    Here is a memory
    Use an object to build your memory. There is no need of an array to find the kth image src, it's k+'.jpg' !
    At the beginning you have only to show back of card and to define a permutation of the two sequences of integers... See the method splice to define randomly this permutation.
    Last edited by 007Julien; 05-18-2014 at 09:57 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles