Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2015, 03:18 AM
Hwona's Avatar
Hwona Hwona is offline
Member
 
Join Date: Mar 2013
Posts: 620
Gender: Female
Credits: 48,801
Hwona is on a distinguished road
Default Using Javascript Games to Give Users Currency

Hi! I've finally learned to create a very simple javascript game. I wanted users to be rewarded money based on the score. However, I can't seem to pass the javascript end variable to a php one. I know this is a lot of code, but would anyone mind helping me?

wordscramblegame.php
PHP Code:
<?php
class wordscramblegameController extends AppController{

    const 
PARAM "eid";
    const 
PARAM2 "confirm";
    private 
$view;
    private 
$subController;
    private 
$explore;

    public function 
__construct(){
        
parent::__construct("member");
        
$mysidia Registry::get("mysidia");
        if(
$this->action != "index"){
            
            
$this->explore = new Explore($mysidia->input->get("eid"));    
            if(
$this->explore->getExploreOwner() != $mysidia->user->username) throw new NoPermissionException("You do not have permission to manage the expeditions of other users.");
        }
    }
    
    public function 
index(){
        
$mysidia Registry::get("mysidia");
        
$document $mysidia->frame->getDocument();
        
$document->setTitle("Game");
        
$stats $_POST['earnedStats'];
        
$user $mysidia->user->username;
        
$document->add(new Comment("{$stats}"));
        
$mysidia->db->update("users",array("money" => '{$stats}'),"username = '{$user}'");
        
$document->add(new Comment('
           <DOCTYPE html>
<html>
<head>
    <script src="https://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <style>
        #playingDisplay {
            display: none;
        }
        
        #gameEndDisplay {
            display: none;
        }
        
        #instructions {
            display: none;
        }
    </style>
</head>

<body>
    <div onload="printMsg()">
        <div id="introScreen">
            <button type="button" id="startButton" onclick="startGame()">Start</button>
            <button onclick="openInstructions()">Instructions</button>
        </div>
        <div id="playingDisplay">
            <div id="infoBox"></div>
            <div id="scrambledWordBox"></div>
            <div id="answerBox">
                Unscramble the word:
                <input type="text" id="myAnswer" value="">
                <button onclick="submitAnswer()">Submit</button>
            </div>
            <div id="sideBox">
                <div id="time">10:00</div>
                <div id="scoreBox"></div>
                <div id="moneyBox"></div>
                <button onclick="quitGame()">Quit</button>
            </div>
        </div>
        <div id="instructions">
            Unscramble as many words as you can and input your answer into the field. You have 10 minutes to correct as many as you can!
            <button onclick="hideInstructions()">Done</button>
        </div>
        <div id="gameEndDisplay">
            <div id="endStats"></div>
            <button onclick="replayGame()" id="replayButton">Replay</button>
        </div>
    </div>
    <script>
        var keepPlaying = true;
        var answersCorrect = true;
        var score = 0;
        var money = 0;

        function startTimer(duration, display) {
            var timer = duration,
                minutes, seconds;
            setInterval(function() {
                minutes = parseInt(timer / 60, 10);
                seconds = parseInt(timer % 60, 10);

                minutes = minutes < 10 ? "0" + minutes : minutes;
                seconds = seconds < 10 ? "0" + seconds : seconds;

                display.textContent = minutes + ":" + seconds;

                if (--timer < 0) {
                    if (answersCorrect != false && keepPlaying != false) {
                        money = score * 10;
                        $("#playingDisplay").hide();
                        $("#endStats").html("Time is up! Your score is " + score + " and you have earned " + money + " fuzzpuffs");
                        $("#gameEndDisplay").show();
                    }
                }
            }, 1000);
        }

        function beginTimer() {
            var tenMinutes = 60 * 10,
                display = document.querySelector("#time");
            startTimer(tenMinutes, display);
        }

        function startGame() {
            beginTimer();
            $("#playingDisplay").show();
            $("#introScreen").hide();
        }

        if (answersCorrect != false && keepPlaying != false) {
            var words = ["caterpillar", "butterfly", "flower"];
            var word = words[Math.floor(Math.random() * words.length)];

            String.prototype.shuffle = function() {
                var a = this.split(""),
                    n = a.length;
                for (var i = n - 1; i > 0; i--) {
                    var j = Math.floor(Math.random() * (i + 1));
                    var tmp = a[i];
                    a[i] = a[j];
                    a[j] = tmp;
                }
                return a.join("");
            }
            var scrambledWord = word.shuffle();

            (function printMsg() {
                var scrambledWordBox = document.getElementById("scrambledWordBox");
                scrambledWordBox.innerHTML = "<p>" + scrambledWord + "</p>";
                var scoreBox = document.getElementById("scoreBox");
                scoreBox.innerHTML = "<p>Score: " + score + "</p>";
                var moneyBox = document.getElementById("moneyBox");
                moneyBox.innerHTML = "<p>Money Earned: " + money + "</p>";
            })();

            function submitAnswer() {
                var userAnswer = document.getElementById("myAnswer").value;
                if (userAnswer == word) {
                    words = ["caterpillar", "butterfly", "flower"];
                    word = words[Math.floor(Math.random() * words.length)];
                    scrambledWord = word.shuffle();
                    score++;
                    money = score * 10;
                    $("#infoBox").html("Correct!");
                    $("#scrambledWordBox").html("<p>" + scrambledWord + "</p>");
                    $("#scoreBox").html("<p>Score: " + score + "</p>");
                    $("#moneyBox").html("<p>Money Earned: " + money + "</p>");
                } else {
                    $("#playingDisplay").hide();
                    $("#endStats").html("Your answer was incorrect. Your score is " + score + " and you have earned " + money + " fuzzpuffs");
                    $("#gameEndDisplay").show();
                    answersCorrect = false;
                }
            }
        }

        function quitGame() {
        var moneyEarned = money + score;
            $("#playingDisplay").hide();
            $("#endStats").html("Your score is " + score + " and you have earned " + money + " fuzzpuffs");
            $.ajax({
        type: "POST",
        url: "wordscramblegame.php",
        data: { earnedStats : moneyEarned }, 
        success: function(data){
            alert(data);
        }
    });
            $("#gameEndDisplay").show();
            keepPlaying = false;
        }

        function replayGame() {
            location.reload();
        }

        function openInstructions() {
            $("#instructions").show();
            $("#introScreen").hide();
        }

        function hideInstructions() {
            $("#instructions").hide();
            $("#introScreen").show();
        }
    </script>
    <body>
</html>
        '
));
    }
}    
?>
__________________
Reply With Quote
  #2  
Old 12-13-2015, 05:00 AM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 334,361
Hall of Famer is on a distinguished road
Default

Well are you using Mys v1.3.3? If so, this may become a bit more tricky, as the codebase of Mys v1.3.3 is quite different from Mys v1.3.4, the former does not have separation of concerns of application and presentation logic.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #3  
Old 12-13-2015, 05:01 AM
Hwona's Avatar
Hwona Hwona is offline
Member
 
Join Date: Mar 2013
Posts: 620
Gender: Female
Credits: 48,801
Hwona is on a distinguished road
Default

Quote:
Originally Posted by Hall of Famer View Post
Well are you using Mys v1.3.3? If so, this may become a bit more tricky, as the codebase of Mys v1.3.3 is quite different from Mys v1.3.4, the former does not have separation of concerns of application and presentation logic.
Unfortunately, because my script is so heavily modified, I'm stuck with v1.3.3... at least for now. ;^;
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Second Currency and Currency icon Rovick Suggestions and Feature Requests 14 11-11-2014 05:29 PM
How to give users more way to earn money? Skaiya Questions and Supports 30 04-23-2014 04:38 AM
Give promocode when buy item? dulop Questions and Supports 5 02-02-2013 05:42 AM
ok im new and i give up i am asking for help chinchillapals Questions and Supports 12 04-18-2012 04:22 PM
Let's give this another shot Killgore Questions and Supports 7 02-07-2009 12:03 AM


All times are GMT -5. The time now is 02:13 PM.

Currently Active Users: 9838 (0 members and 9838 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636