02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 21: High score tables<br />

19 function getScore (playerID, gameID, conn)<br />

20 {<br />

21 var rs=Server.CreateObject("ADODB.recordset");<br />

22 var score = 0;<br />

23<br />

24 rs.Open ("SELECT score FROM Scores WHERE playerID=\’" + playerID +<br />

25 "\’ AND gameID=\’" + gameID + "\’", conn);<br />

26<br />

27 if (!rs.EOF) score = rs.Fields.Item(0).value;<br />

28 rs.Close();<br />

29 return score;<br />

30 }<br />

31<br />

32 var gameID = Request("gameID");<br />

33 var playerID = Session("playerID");<br />

34 var scoreCount = 0;<br />

35<br />

36 //Connect <strong>to</strong> the database<br />

37 var conn = Server.CreateObject("ADODB.Connection");<br />

38 connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=" +<br />

39 Server.Mappath("register.mdb") + ";" + "Password=;";<br />

40 conn.Open(connStr);<br />

41<br />

42 scoreCount = getScoreCount(gameID, conn);<br />

43<br />

44 // We may have <strong>to</strong> return less than they ask.<br />

45 if (scoreCount > 10) scoreCount = 10;<br />

46<br />

47 var rs = Server.CreateObject("ADODB.recordset");<br />

48 rs.Open ("SELECT TOP " + scoreCount +<br />

49 " playerID, score FROM Scores WHERE gameID=\’" + gameID +<br />

50 "\’ ORDER BY score DESC", conn);<br />

51<br />

52 var count = 1, str;<br />

53<br />

54 while (!rs.EOF) {<br />

55 str = "hs" + String(count++) + "=" + rs.Fields.Item(0).value + " " +<br />

56 rs.Fields.Item(1).value + "&";<br />

57 Response.Write(str);<br />

58 rs.moveNext();<br />

59 }<br />

60 rs.Close();<br />

61<br />

62 score = getScore(playerID, gameID, conn);<br />

63 str = "message=Your best score for " + gameID + " is " +<br />

64 String(score) + "&viewscores=true";<br />

345

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!