Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    4
    Thanked 0 Times in 0 Posts

    PHP+JS Mini game

    Hello. I have a browser-based game and I want to include in it a "Mini games" to train stats.
    these games will be based on PHP, and JS.
    These "mini games" are very simple, but I have no clue how to do this since I never been in this business before.
    My goal, for the first mini game, is to make a mini game that challanges the user to click X Times on a key in the keyboard (such as "K") in a limited time.
    If the player passes, he will gain attack stat (just one query).
    How do I start?

    Thanks in advance..
    Need domain? Buy Cheap Domain at Rapid Host :)

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,456
    Thanks
    0
    Thanked 632 Times in 622 Posts
    What level are your JavaScript and PHP skills at? If you don't have a reasonable knowledge of both languages then acquiring that knowledge would be the place to start.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    What level are your JavaScript and PHP skills at? If you don't have a reasonable knowledge of both languages then acquiring that knowledge would be the place to start.
    I am professional PHP programmer, but not familiar with JS.
    Need domain? Buy Cheap Domain at Rapid Host :)

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by topdown.me View Post
    I am professional PHP programmer, but not familiar with JS.
    So it would make sense to learn Javascript. Here's something for you to bite on.


    Code:
    <html>
    <head>
    </head>
    <body>
    Click the k key as often as you can in 10 seconds:-   <input type = "button" value = "Start"  onclick = "startTimer(0)">
    <br><br>
    <span id="countdown" style="font-weight: bold;"></span>
    
    <script type = "text/javascript">
    
    var count = 0;
    document.onkeydown = function(ev) {	
    var key;
    ev = ev || event;
    key = ev.keyCode;
    
    if (key == 75) {  // k key
    count ++;
    }
    }
    
    var timeInSecs;
    var ticker;
    
    function startTimer(secs) {
    count = 0;
    timeInSecs = parseInt(secs);
    ticker = setInterval("tick()",1000);
    tick();  // start the count right away
    
    }
    
    function tick() {
    var secs = timeInSecs;
    if (secs > 10) {  // stop at 10 seconds
    alert ("Your time is up!  You pressed the k key " + count + " times");
    clearInterval(ticker); // stop counting 
    return false;
    }
    else {
    timeInSecs++;
    }
    
    document.getElementById("countdown").innerHTML = secs;
    }
    
    
    </script>
    
    
    </body>
    </html>
    Last edited by Philip M; 10-04-2013 at 12:12 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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