1    <HTML>
2    <HEAD><TITLE>Dickinson College - Logo Matching Game</TITLE>
3    <SCRIPT>
4   
5    var gamenotstarted = true;
6   
7    function StartGame() {
8       pics = new Array("red.gif","blue.gif","green.gif","purple.gif","yellow.gif","orange.gif");
9       picused = new Array(0,0,0,0,0,0,2);
10      placement = new Array(12);             // this array tracks the hidden images
11      blankcard = false;
12      gamenotstarted = false;
13      for (var img=0; img < 12; img++) {     // for each image in the Image array
14         index = 6;                          // dummy value for while loop
15         while (picused[index] == 2) {index = Math.floor(Math.random() * pics.length)}
16         picused[index]++;
17         document.images[img].src="blank.jpg";   // display the blank image
18         placement[img] = index;                 // note which image is hidden
19         }
20      //  set all initial values
21      matches = 0;
22      tries = 0;
23      firstcard = true;
24      oldcard = 0;
25      firstimg = 0;
26      document.game.numtry.value = "";
27      document.game.message.value = "";
28      blankup = new Array(12);            // is blank card showing?
29      for (var blnk=0; blnk < 12; blnk++) {blankup[blnk] = true}
30      }   // end function StartGame
31   
32   function ShowCard(imgnum) {
33      document.game.message.value = " ";
34      if (gamenotstarted) {StartGame()}
35      if (blankup[imgnum]) {
36         document.images[imgnum].src = pics[placement[imgnum]];
37         if (firstcard) {                   // first of two clicks?
38            if (blankcard) {                // do we blank previous cards?
39               document.images[tempimg].src = "blank.jpg";
40               document.images[tempfirst].src = "blank.jpg";
41               document.images[imgnum].src = pics[placement[imgnum]];
42               blankcard = false;
43               }
44            oldcard = placement[imgnum];
45            firstimg = imgnum;
46            firstcard = false;
47            tries++;
48            document.game.numtry.value = tries;
49            }
50         else {                             // second of two clicks
51            if (imgnum == firstimg)         // clicked the same card?
52               {document.game.message.value = 'Click a different card.'}
53            else {
54               if (placement[imgnum] == oldcard) {      // is it a match?
55                  matches++;
56                  if (matches < 6) {
57                     MsgText = "Congratulations! You matched!";
58                     blankcard = false;
59                     }
60                  else {
61                     MsgText = "Wow! You won!";
62                     gamenotstarted = true;
63                     }
64                  document.game.message.value = MsgText;
65                  blankup[imgnum] = false;
66                  blankup[firstimg] = false;
67                  }
68               else {                       // not a match
69                  MsgText = "Sorry, no match.";
70                  document.game.message.value = MsgText;
71                  blankcard = true;
72                  tempimg = imgnum;
73                  tempfirst = firstimg;
74                  }
75               firstcard = true;
76               firstimg = 0;
77               }
78            }
79         }
80      else { window.alert("You must select a blank card.", imgnum) }
81      }   // end function ShowCard
82   
83   </SCRIPT>
84   </HEAD>
85   <BODY BGCOLOR="#FFFFCC">
86   <FORM NAME="game"><CENTER>
87   <TABLE BORDER="0" CELLSPACING="4" CELLPADDING="8" BGCOLOR="#FFFFFF">
88   <TR ALIGN="center" VALIGN="middle"><TD COLSPAN="4"><INPUT TYPE="text" NAME="message" VALUE=" SIZE="30"> 
     Tries: <INPUT TYPE="text" NAME="numtry" VALUE=" SIZE="2"> <INPUT TYPE="button" VALUE="New Game" onClick="StartGame()"></TD></TR>
89   <TR ALIGN="center" VALIGN="middle">
90   <TD><A HREF="javascript:ShowCard(0)"><IMG BORDER=0 SRC="blue.gif" WIDTH=100 HEIGHT=100 ALT="></A></TD>
91   <TD><A HREF="javascript:ShowCard(1)"><IMG BORDER=0 SRC="blank.jpg" ALT=" WIDTH=100 HEIGHT=100></A></TD>
92   <TD><A HREF="javascript:ShowCard(2)"><IMG BORDER=0 SRC="red.gif" WIDTH=100 HEIGHT=100 ALT="></A></TD>
93   <TD><A HREF="javascript:ShowCard(3)"><IMG BORDER=0 SRC="blank.jpg" ALT=" WIDTH=100 HEIGHT=100></A></TD>
94   </TR>
95   <TR ALIGN="center" VALIGN="middle">
96   <TD><A HREF="javascript:ShowCard(4)"><IMG BORDER=0 SRC="green.gif" WIDTH=100 HEIGHT=100 ALT="></A></TD>
97   <TD><A HREF="javascript:ShowCard(5)"><IMG BORDER=0 SRC="blank.jpg" ALT=" WIDTH=100 HEIGHT=100></A></TD>
98   <TD><A HREF="javascript:ShowCard(6)"><IMG BORDER=0 SRC="orange.gif" WIDTH=100 HEIGHT=100 ALT="></A></TD>
99   <TD><A HREF="javascript:ShowCard(7)"><IMG BORDER=0 SRC="blank.jpg" ALT=" WIDTH=100 HEIGHT=100></A></TD>
100  </TR>
101  <TR ALIGN="center" VALIGN="middle">
102  <TD><A HREF="javascript:ShowCard(8)"><IMG BORDER=0 SRC="purple.gif" WIDTH=100 HEIGHT=100 ALT="></A></TD>
103  <TD><A HREF="javascript:ShowCard(9)"><IMG BORDER=0 SRC="blank.jpg" ALT=" WIDTH=100 HEIGHT=100></A></TD>
104  <TD><A HREF="javascript:ShowCard(10)"><IMG BORDER=0 SRC="yellow.gif" WIDTH=100 HEIGHT=100 ALT="></A></TD>
105  <TD><A HREF="javascript:ShowCard(11)"><IMG BORDER=0 SRC="blank.jpg" ALT=" WIDTH=100 HEIGHT=100></A></TD>
106  </TR>
107  </TABLE></CENTER>
108  </FORM><P>
109  </BODY>
110  </HTML>