A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: new music game

  1. #1
    Member
    Join Date
    Feb 2002
    Posts
    71
    Hi, everyone. I've recently put up a new game I've been working on for quite a while off and on. It is a 2-note interval matching game using a keyboard. The only thing I would still like to add to it is a way of keeping track of players'scores, with a top ten high score list. Anyone have experience coding something like that?

    Here's the link: www.pedaplus.com/2_intervals.html. I'd be glad to hear any feedback. (made entirely with 3dfa)

    Jon

  2. #2
    Senior Member kusco's Avatar
    Join Date
    Nov 2001
    Posts
    681

    Excellent

    Hello Jon,

    I've been playing the game for about 10 minutes and love it.

    However, I think that I've found a little bug in it. When the two notes are played for you to hear, you can press the key of the second note without an error. eg. if notes c and d are played then I can press d first without it being a problem but the second note will always catch me out.

    It may not be a biggy and it's possible that it's intended this way.

    Aside from that, it's great for learning the notes by ear and put a key to the note.

    Welldone!!

  3. #3
    Member
    Join Date
    Feb 2002
    Posts
    71
    I think you mean that the error is not indicated until the second note is played back by the user? I thought about adding the "first-note" error, and just didn't bother adding the code. The way I coded it, the first two note values heard are stored in an array, and the two note values played back by the user are stored in another array, and the two are compared after the second note is played by the user. I guess it would be pretty simple to compare the first notes in each array after the first note is played back by the user. I'll work at adding that. Thanks for the suggestion!

    Jon

  4. #4
    Member
    Join Date
    Feb 2002
    Posts
    71
    OK. Now the first wrong note played will register as wrong, and send you to the next test interval.

    http://www.pedaplus.com/flash/2_intervals.swf

  5. #5
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    high scores

    Originally posted by JDE
    OK. Now the first wrong note played will register as wrong, and send you to the next test interval.

    http://www.pedaplus.com/flash/2_intervals.swf
    JDE If your server has MySql and PHP I will consider doing the server side for you.

  6. #6
    Member
    Join Date
    Feb 2002
    Posts
    71

    it has them

    Yes, the webhost provides perl, MySqL, PHP, and several other things that I know very little about. I am interested in learning more about PHP and MySQL as I get time. As mentioned before, I've got a book on Perl/CGI, and I'm working through the basics on that - though I haven't had the time or nerve to write any perl scripts (even very simple ones) yet. Maybe this would be a good project to learn some things - and if you're willing to help, thanks!

  7. #7
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    Re: it has them

    Originally posted by JDE
    Yes, the webhost provides perl, MySqL, PHP, and several other things that I know very little about. I am interested in learning more about PHP and MySQL as I get time. As mentioned before, I've got a book on Perl/CGI, and I'm working through the basics on that - though I haven't had the time or nerve to write any perl scripts (even very simple ones) yet. Maybe this would be a good project to learn some things - and if you're willing to help, thanks!
    Ok lets see first you need a database. If you don't already have one get it set up by you host.

    They will give you some way to interact with this database commonly it's through MySqlAdmin wich makes building the table we'll need very easy

    You can just paste the following into the database as a query to creat a table called MusicGame

    SQL-query :
    CREATE TABLE MusicGame (Mid INT not null AUTO_INCREMENT, date VARCHAR (10) not null , name TINYTEXT not null , score BIGINT not null , PRIMARY KEY (Mid)) comment = 'Keep score for music game'



    This will make a table like this
    Field Type Attributes Null Default Extra Action
    Code:
    Mid  date  name  score 
    
    ^ Mid is the Record Id
         ^ date is obvious
               ^name of the person 
                     ^the score.
    
    I think that's all we'll need.
    
    I think we should populate it with default data to start. Like
    1 00.00.2002 Nobody 0000
    2 00.00.2002 Nobody 0000
    till we have 10 (assume we want only top 10)
    
    etc.
    Now we have a database table of high scores by nobody with scores of 0

    Next we tackle the PHP code to get this data out and to add new high scores. We'll leave the code for deciding if there is a high score to the game code. So we need a php script that simply gets the data and formats it so that we can use it in 3dfa and also will update a slot with new data.


  8. #8
    Senior Member
    Join Date
    Jul 2001
    Posts
    173
    Hi there - thanks for the post. Love the game. Are you using it exclusively for teaching ? We'd love to display this as a demonstration of 3DFA's capabilities in different areas - do you have any objection to us linking to your site, or even better - would you consider allowing us to use the .movie file ? We understand if you cannot do the latter.

    Great work - best of luck with the program. In regard your question on high scores, etc. - the previous post are the best suggestions we could offer as well. The 'insanelander' demo contains code that uses a shared 'highscores' server. You may want to examine how that works, but the real 'guts' of the technique is in the database and ASP/PHP on the server-side. Let us know if we can be of any more assistance.

    Regards


  9. #9
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    PHP so far

    Been working on this and so far I have the PHP nearly ready:
    You can test this right now by the following:
    http://deadyeti.com/blanius/musicgame.php?action=get will dispay the data the way it will appear to 3dfa. (I'll explain later)

    You can also get an HTML response with
    http://deadyeti.com/blanius/musicgame.php?action=html

    I added this in case you want to be able to display the high scores in a web page.

    The update seems to be ready as well, but I'm still testing iit. (I do this by hand entering the variables that 3dfa will need to send)

    Here is the partial code:
    Code:
    <?php
    // This is not a secure way to do this we should really take all the connection code and put it in
    // another file and use Include filename to add it
    $host="myhost.com";//This is your server name
    $dbname="mydatabase";//The name of the database on your server
    $username="myusername";		// The username for accessing the database
    $password="mypassword"; // The password for accessing the database
    $dbtable="MusicGame";		// The name of the table we are using
    $notify="youremail";	// The email address you want notices sent to. (optional)
    
    
    
    mysql_connect($host,$username,$password) OR die("Can't connect to database");
    mysql_select_db("$dbname") or die("Unable to select database");
    if ($action=="html")
    		{
    		echo ("<table border=\"1\">");
    		$result = mysql_db_query ("$dbname", "SELECT * FROM $dbtable ORDER by Mid");
    
     		while ($row = mysql_fetch_array ($result))
    		{
     			$name =$row["name"];
       			$date =$row[date];
       			$score =$row[score];
    
    
    			echo"<tr><td>$date</td> <td>$name</td><td>$score</td></tr>";
    		}
    	echo "</table>";
    
    	}
    
    if ($action=="get")
    		{
    
    		$result = mysql_db_query ("$dbname", "SELECT * FROM $dbtable");
    
     		while ($row = mysql_fetch_array ($result))
    		{
     			$name =$name.$row["name"]."|";
       			$date =$date.$row["date"]."|";
       			$Mid =$Mid.$row["Mid"]."|";
    			$score =$score.$row["score"]."|";
    
    		}
    
    		echo ("&Mid=".$Mid."&dates=".$date."&names=".$name."&score=".$score);
    
    	}
    
    
    if ($action=="add")
    	{
    		$day = date("d");
    		$month = date("m");
    		$year = date("Y");
    
    		$date = "$day"."."."$month"."."."$year";
    
    		$sql = "UPDATE $dbtable SET name='".$name."',date='".$date."',score='".$score."' WHERE Mid='".$Mid."'";
    		echo $sql;
      		$result = mysql_query($sql);
    
      		/*if ($notify){
    			mail($notify,"new high score added ",$name."\n".$score,"");
    		}*/ //commented out while testing.
    
    	}
    
    ?>

    Next the hard part. The javascript side within your game.
    You will have to call the php script at the start of the game and the variables loaded into an array. Then if the user playing gets higher than the lowest score, add them and shift all the scores.

    Perhaps Kusco would like to dive in at this point.

  10. #10
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    comments

    Oh by the way I will try to comment this code a bit more. Bear with me I'm just learning this myself.

  11. #11
    Member
    Join Date
    Feb 2002
    Posts
    71

    man!

    Whew! I'll try to catch up with what you're doing. I think I'll study your code along with some of those PHP tutorials you suggested earlier. Thanks for doing all that work.
    BTW, I've added a 3-note version of the game: http://www.pedaplus.com/games.html
    DKerr, as for the link, movie, etc. I'm flattered. No problem.
    http://www.pedaplus.com/flash/interval_2notes.movie and http://www.pedaplus.com/flash/interval_3notes_bk.movie
    [Edited by JDE on 07-01-2002 at 02:03 AM]

  12. #12
    Member
    Join Date
    Feb 2002
    Posts
    71

    sounds and javascript advice

    If anyone's interested, here are the sounds (piano notes) used in this game:
    http://www.pedaplus.com/flash/sounds.zip

    Also, I'd be interested in advice about how to tighten the code (Ed?). Part of my problem with this game was trying to get the code for controlling the test/response sequence into one script. As it is now, the game depends heavily on each individual keyboard button for control, which makes maintaining or changing the javascript a little bit of a pain. I tried getting the note-test/response comparisons into one list of actions without much success. I also suspect I'm using more variables, etc. than necessary.

    thanks

    Jon E

  13. #13
    Member
    Join Date
    Feb 2002
    Posts
    71

    ready

    OK, Bret. Thanks for the help with the PHP/MySQL so far. I was able to figure out how to get the database set up on my server, and also used your script, putting the connect info into a separate file and using the include() function. It works!! http://www.pedaplus.com/musicgame.php?action=html

    Also, I've been tweaking things a little. The 2-note interval game has a "choose level" feature now, and I've added a 3-note version.

    http://www.pedaplus.com/flash/2_intervals.html
    http://www.pedaplus.com/flash/3_intervals.html

    [Edited by JDE on 07-04-2002 at 01:06 AM]

  14. #14
    Member
    Join Date
    Nov 2002
    Posts
    67

    Re: PHP so far

    Originally posted by blanius
    Been working on this and so far I have the PHP nearly ready:
    You can test this right now by the following:
    http://deadyeti.com/blanius/musicgame.php?action=get will dispay the data the way it will appear to 3dfa. (I'll explain later)

    You can also get an HTML response with
    http://deadyeti.com/blanius/musicgame.php?action=html

    I added this in case you want to be able to display the high scores in a web page.

    The update seems to be ready as well, but I'm still testing iit. (I do this by hand entering the variables that 3dfa will need to send)

    Here is the partial code:
    [code]
    <?php
    // This is not a secure way to do this we should really take all the connection code and put it in
    // another file and use Include filename to add it
    $host="myhost.com";//This is your server name
    $dbname="mydatabase";//The name of the database on your server
    $username="myusername"; // The username for accessing the database
    $password="mypassword"; // The password for accessing the database
    $dbtable="MusicGame"; // The name of the table we are using
    $notify="youremail"; // The email address you want notices sent to. (optional)



    mysql_connect($host,$username,$password) OR die("Can't connect to database");
    mysql_select_db("$dbname") or die("Unable to select database");
    if ($action=="html")
    Hi Bret,

    I copied all your code here and tried to run it and get the message below:

    Parse error: parse error in /home/carbonst/public_html/yahtzee.php on line 5

    Line 5 on my script is

    if ($action=="html")

    Any ideas why I get this message? It is driving me nuts, all looks fine with the code.

    If I can get it to run, I have an idea how to adapt it to what I want the code to do for me and will post the change if I can get it to work. I only started with PHP but have gotten some ideas from doing some reading and asking questions.

    Thanks
    Phil

  15. #15
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    Re: Re: PHP so far

    Originally posted by phillong
    Hi Bret,

    I copied all your code here and tried to run it and get the message below:

    Parse error: parse error in /home/carbonst/public_html/yahtzee.php on line 5

    Line 5 on my script is

    if ($action=="html")

    Any ideas why I get this message? It is driving me nuts, all looks fine with the code.

    If I can get it to run, I have an idea how to adapt it to what I want the code to do for me and will post the change if I can get it to work. I only started with PHP but have gotten some ideas from doing some reading and asking questions.

    Thanks
    Phil
    Hard to tell from that one line, I've found it's usually a ; or " or a { that is missing. Check for those. You can send me the file And I'll look at it

  16. #16
    Member
    Join Date
    Nov 2002
    Posts
    67

    Re: Re: Re: PHP so far

    Originally posted by blanius
    Hard to tell from that one line, I've found it's usually a ; or " or a { that is missing. Check for those. You can send me the file And I'll look at it
    Hi Bret,

    I copied and pasted again and this time it worked.

    I have been racking my brain for over a week and playing with code and asking questions on other forums and I finally got the code to what I was looking for.

    I was looking for setting the variables for the data right in the php file. This meant all I had to do in 3dfa was to link the edit boxes to the right variable. I then did not need any code in 3dfa to handle the data. I also read somewhere that some browsers/plugins have trouble with reading in the first element of a url-encoded string. So I wanted dummy data first, so I placed "script_done=no" first, and then my data. Then I wanted a way to check in 3dfa if data was sent and finished. So I put "script_done=yes" at the end of the string. Now I can check if script_done=yes then do something.

    The data that is output can be checked here if interested:
    http://www.carbonst.com/yahtzee.php?action=get

    The code that does this, if anybody can use it, is:
    Code:
    if ($action=="get")
    	{
    
    		print 'script_done=no&'; 
    
    		$scores_to_return = 10; 
    		$result = mysql_select_db("$dbname"); 
    		$result = mysql_query ("SELECT * FROM $dbTable"); 
    
    		$output = ""; 
    		$i = 0; 
    		while(($row = mysql_fetch_array ($result)) && $i < $scores_to_return) { 
    		$name =$row["names"]; 
    		$Mid =$row["Mid"]; 
    		$score =$row["scores"]; 
    		if($output != "") { 
    		$output .= "&"; 
    		} 
    		$output .= "name_" .++$i. "=" .rawurlencode($name); 
    		$output .= "&score_" .$i. "=" .rawurlencode($score); 
    		} 
    
    		print $output;
    		print '&script_done=yes'; 
    
    	}
    I did have help with the code and the ideas so it is not all mine so a Thanks to all that did help.

    Phil

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center