Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.3.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=42)
-   -   Mys v1.3.4 Higher Or Lower Game (http://www.mysidiaadoptables.com/forum/showthread.php?t=4964)

Kyttias 12-30-2015 06:40 PM

Higher Or Lower Game
 
Higher Or Lower Guessing Game
http://orig04.deviantart.net/3fcf/f/...as-d9m3eb7.gif
Try it out here (this is also a good place to modify the css to your liking):
http://jsbin.com/cubeze/edit?html,css,js,output

Download Link: http://sta.sh/01mfv39n0h0d

Upload the following files:
games/.htaccess
games/hilo/sendscore.php
games/hilo/hilo.php
games/hilo/hilo.css
games/hilo/hilo.js
hilo.php
view/hiloview.php
Open phpMyAdmin, login if necessary, open up your database, press SQL, and paste in the following:
Code:

CREATE TABLE IF NOT EXISTS `adopts_games` (
  `gid` int(11) NOT NULL AUTO_INCREMENT,
  `game` varchar(30) NOT NULL,
  `username` varchar(30) NOT NULL,
  `plays` int(11) NOT NULL,
  `timestamp` int(11) NOT NULL,
  PRIMARY KEY (`gid`),
  UNIQUE KEY `key` (`gid`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;

If done properly, it will probably say "MySQL returned an empty result set (i.e. zero rows)" with a green checkmark. This is not an error!
Note - This all assumes you did not change the prefix for your database from "adopts_" to something else when you first installed the Mysidia framework. If you did, modify the SQL provided above. In addition, inside games/hilo/sendscore.php you will need to change all instances of "adopts_" to reflect your custom prefix.

You should then be able to visit this game at yoursite.com/hilo.


Feel free to modify games/hilo/hilo.css to your heart's content!

Modifying Game Code
There are TWO versions of the .js files. One is human readable (games/hilo/hilo_non.js) but is NOT being used by the game. It exists only for your reference. The other (games/hilo/hilo.js) is obfuscated, making the javascript code nearly impossible to read and therefore harder for users to cheat the system. If you'd like to use the non-obfuscated version while testing, modify the link to the script found at the end of games/hilo/hilo.php. If you'd like to re-obfuscate any changes you've made, you can do so here.
Defaults:
★ Cards are numbered 1 through 16. To modify the number of cards, edit lines 7 and 13 in games/hilo/hilo_non.js.
★ Users can only play 20 times a day. To modify this limit, edit line 5 in games/hilo/hilo_non.js, and on line 4 in games/hilo/sendscore.php.
★ For each correct guess, 25 money is rewarded. To change, modify lines 18, 27 and 49 in games/hilo/hilo_non.js.
(Reminder to re-obfuscate and update games/hilo/hilo.js after making changes! See Modifying Game Code above!!!)
Note - The user's currency is updated with EACH correct guess, but you won't be able to see that until you visit another page. If you'd like to see the user's cash go up LIVE, you'll need to add a class of "money" to a span or div surrounding where the user's currency is displayed on the page. You can do this in classes/class_sidebar.php in the setMoneyBar() function. Surround just {$mysidia->user->money} in a <div class='money'></div>.
★ ★ ★ Let me know of any problems!★ ★ ★



edit @ Feb 4, 1:30PM EST - MAJOR BUG FIX (fixed bug in post #11).
If you have installed before this date, redownload the latest copy, REPLACE sendscore.php, and DELETE all entries in the 'adopts_games' table to prevent corrupt data.

Abronsyth 12-30-2015 06:44 PM

Ah, man, this is so exciting, thank you so much for sharing! I will have to test it out tomorrow!

Hwona 12-30-2015 08:09 PM

Re
 
This looks amazing! Do you know if it's compatible with v1.3.3?

Bexasaurus 12-30-2015 08:16 PM

This is really cool, thanks for sharing this and contributing.

Kyttias 12-30-2015 08:40 PM

Quote:

Originally Posted by Wallie987 (Post 33359)
This looks amazing! Do you know if it's compatible with v1.3.3?

It should be! This is how it works for v1.3.4 in view/hiloview.php:

PHP Code:

$mysidia Registry::get("mysidia");
$document $this->document;    
$document->setTitle('Higher or Lower');
$document->add(new Comment('<p>Guess if the second number will be higher or lower. The highest possible number is 16.</p>
<iframe id="game" style="width: 100%; min-height: 500px;" src="../../games/hilo/hilo.php?username='
.$mysidia->user->username.'" frameborder="0" scrolling="yes"></iframe>')); 

To make it work with v1.3.3, the most important thing is to make sure that an iframe is made that links to hilo.php with the username as a parameter. Can you see how that works above? I'm not familiar with how pages are constructed in v1.3.3 but if you are, just add in an iframe and it should take care of itself.

Hwona 12-30-2015 08:49 PM

Quote:

Originally Posted by Kyttias (Post 33361)
It should be! This is how it works for v1.3.4 in view/hiloview.php:

PHP Code:

$mysidia Registry::get("mysidia");
$document $this->document;    
$document->setTitle('Higher or Lower');
$document->add(new Comment('<p>Guess if the second number will be higher or lower. The highest possible number is 16.</p>
<iframe id="game" style="width: 100%; min-height: 500px;" src="../../games/hilo/hilo.php?username='
.$mysidia->user->username.'" frameborder="0" scrolling="yes"></iframe>')); 

To make it work with v1.3.3, the most important thing is to make sure that an iframe is made that links to hilo.php with the username as a parameter. Can you see how that works above? I'm not familiar with how pages are constructed in v1.3.3 but if you are, just add in an iframe and it should take care of itself.

Awesome! I made a JS wordscramble game that failed because I couldn't figure out how to use ajax... user cash wasn't updated. If I can get this to work, I can share the scramble script too.

Kyttias 12-31-2015 12:38 AM

Let me know if I can help with your game, Wallie. :meow:

I'm hoping to buy a game off CodeCanyon and integrate it with Mysidia, I just need to convince my significant other than its worth the money.

Abronsyth 12-31-2015 06:45 AM

O-oohkay not sure what is going on. I haven't touched any of the script files at all, so everything is original from the download you provided. I am running into 2 issues;
1) The score is not updating at all for me, it remains on 0 regardless of how many times I am getting it correct. It is adding the currency to my account, though.
2) Once I do guess correctly the question-mark card disappears, and if I guess correctly again after that then both cards disappear, though the buttons are still clickable.

GIF of glitches HERE, and HERE is a link to the game on my site itself.

Sorry for being a pain :cfrown:

Kyttias 12-31-2015 11:11 AM

Quote:

Originally Posted by Abronsyth (Post 33368)
O-oohkay not sure what is going on. I haven't touched any of the script files at all, so everything is original from the download you provided. I am running into 2 issues;
1) The score is not updating at all for me, it remains on 0 regardless of how many times I am getting it correct. It is adding the currency to my account, though.
2) Once I do guess correctly the question-mark card disappears, and if I guess correctly again after that then both cards disappear, though the buttons are still clickable.

GIF of glitches HERE, and HERE is a link to the game on my site itself.

Sorry for being a pain :cfrown:

That's... extremely weird?? What browser are you using?

(As a PSA, you can also access the game directly without being logged in - it doesn't reward any money to anyone and you can refresh and play forever - http://catisserie.mysidiahost.com/games/hilo/hilo.php )

I can't seem to replicate that behavior at all on my end. D;

Please try using an updated version of the files so I can rule out any problems? I uploaded a newer copy this morning because I left a reference to my css file in and no one has that (it's not important, just additionally styling on my end, no harm to anyone to have left it there, but, yknow, better that it's gone).

I notice that you don't seem to be utilizing jQuery as part of your theme. I don't think that should be a problem, because I include my own link to jQuery for the file inside the iframe, as that's really the only place I'm using it in this. Let's rule out some other stuff first, because if I have to have you include jQuery in your header then I'm also going to have to help you fix your profile tabs. x'D What a mess.

Abronsyth 12-31-2015 02:29 PM

I'm using Google Chrome, and I tested it on Firefox but have the same issue. I updated the files, but still to no avail.

Oh my goodness! I thought that I had jQuery in the header since I'm using the tooltips for items, but it turns out I totally forgot to do that, which would explain why tooltips didn't look right XD So I just added it in and everything is working now (as are profile tabs, no worries there)!

I'm so sorry to have bothered you with this! I should have known about that ages ago, ahaha.

Thank you, Kyttias!

Abronsyth 01-10-2016 03:15 PM

Sorry to further pester you...but I seem to be having an issue. I just did a fresh download and reset it all up, but the day following the first a user plays they can simply refresh the page and continue playing endlessly, but are not rewarded with any currency. So they can wait a day, and then play again but not earn any of the currency. It works right the very first day, but not any of the days after that.

I don't know if that makes any sense, sorry ;^;

Kyttias 01-10-2016 06:53 PM

After a while, I finally managed to recreate this problem on one of my accounts. It's actually a major problem but I should be able to fix it. :exexex: It should be updating on a duplicate entry but it's not, thus causing some weird issues. When the fix is up I'm probably also going to have to have you guys clean out the table (by deleting it and readding it), so everyone will have their plays reset properly.

Sooooo I'll get back to you on that!!

Abronsyth 01-11-2016 09:48 PM

Alrighty! If there's any way I might be able to help, please let me know!

I've been looking at the files you created to see if I can figure out how to apply this to some different javascript games, as well!

bisexuowl 01-19-2016 08:47 PM

https://gyazo.com/10be6dad33a390269df542d3cdfd3a22 this happened upon installing :C

Abronsyth 01-19-2016 09:18 PM

Simply sounds like you didn't do something right, likely a file was not put into the proper place in your site directory. I would double check the front thread thoroughly and check the listed directories to make sure the right files are in there;
games/.htaccess
games/hilo/sendscore.php
games/hilo/hilo.php
games/hilo/hilo.css
games/hilo/hilo.js
hilo.php
view/hiloview.php

So the first 5 should be in a folder called "games" (exactly, including all lower case), hilo.php should be in your base directory, and then hiloview.php should be in your view folder.

Hwona 01-27-2016 05:08 AM

Hi Kyttias! Mind if I confirm something with you? I noticed that the iframe displays the hilo game page with the username in the url. Since this is editable via inspect element, wouldn't users be able to play as others? Thanks! :3

Kyttias 01-27-2016 09:38 AM

In short... yes? If you have a better solution, feel free to suggest one? If they play as another user, that other user will get the gold, not them (no matter what may display for the current user pretending). It will also count down the the other user's plays.

Hwona 01-27-2016 05:16 PM

Re
 
Quote:

Originally Posted by Kyttias (Post 33593)
In short... yes? If you have a better solution, feel free to suggest one? If they play as another user, that other user will get the gold, not them (no matter what may display for the current user pretending). It will also count down the the other user's plays.

Okay, I see. I was just concerned as some users might mischeviously try to use up all others' plays and guess the number wrong? O.o

Kyttias 01-27-2016 05:53 PM

It should be possible to do it by the user's id number instead... since that information is less readily available?

Hwona 01-27-2016 06:11 PM

Re
 
Quote:

Originally Posted by Kyttias (Post 33598)
It should be possible to do it by the user's id number instead... since that information is less readily available?

Wait, I found a solution! We can just use cookies on the sendscore.php page. Umm, I'll try creating a new cookie when a user logs in... this will be username. If the cookie doesn't match the inputed username, the script can be stopped.

Kyttias 01-27-2016 06:28 PM

Hmm that might actually help a lot! :3

Hwona 01-27-2016 06:53 PM

This should work?
Overwrite your games/hilo/sendscore.php file with this
Edit: Sorry, 1.3.4 has a different cookie file than my version (I posted my file). Replace your classes/class_cookies.php file with:
class_cookies

Kyttias 02-04-2016 12:41 PM

MAJOR BUG WAS FIXED @ Feb 4, 1:30PM EST
If you have installed before this date, please redownload the latest copy, REPLACE sendscore.php, and DELETE all entries in the 'adopts_games' table to prevent corrupt data.

Thanks Abronsyth for reporting the bug, I apologize for the wait in getting it fixed. Let me know if for some reason the bug hasn't been fixed??????

For Wallie - the sendscore.php file has been entirely revised, but for the better (you'll see what I mean). All you have to do is change some variables near the top for the name of the game and number of plays, and this will make it easier for other game developers. I think this version is what you should use if you want to continue to cross check with cookies to prevent users from playing as other people (but I haven't been able to test it):
  Spoiler: cookie version of sendscore.php 
PHP Code:

<?php
/* What game is it, how many daily plays are there? */
$game_name "HiLo";
$number_of_plays 20;

/* This function will help sanitize input to prevent errors. */
function sanitizeInput($data) {
    
$data trim($data);
    
$data stripslashes($data);
    
$data htmlspecialchars($data);
    return 
$data;
}

/* Find when and who! */
$day date('z');
$username sanitizeInput($_POST['username']);

/* If the username matches the cookie from login, proceed, if not, throw an error: */
$cookie_name 'mysusername';
$cookievalue $_COOKIE[$cookie_name];
if (
$cookievalue != $username) {
    
$warning "Please do not exploit the system!";
    return 
$warning;
} else {
    
/* This sets up the database connection. */
    
include("../../inc/config.php");  
    
$db = new mysqli(DBHOSTDBUSERDBPASSDBNAME);
    if (
$db->connect_error) { die("Database connection failed!"); }

    
/* Grab this user's info on this game from the database. */
    
$game_data "SELECT * FROM adopts_games WHERE `username` = '{$username}' AND `game` = '{$game_name}'";
    
$result mysqli_query($db$game_data);
    
$game mysqli_fetch_array($result);

    
/* If no data is found with the user having ever played before... create some! */
    
if (!$game) {
        
$sql "INSERT INTO `adopts_games`(`plays`, `username`, `game`, `timestamp`) VALUES ('{$number_of_plays}', '{$username}', '{$game_name}', '{$day}')";
        if (
$db->query($sql) === FALSE) { echo "Error creating new game data: " $db->error; }
    }

    
/* If a score is being sent through post data, do this. */
    
if (isset($_POST['amt'])) {
        
$score sanitizeInput($_POST['amt']);
        
// If there are still plays left for today's game...
        
if ($game['plays'] > 0){
            
// Add score to user's money.
            
$sql "UPDATE adopts_users SET `money` = money + $score WHERE `username` = '{$username}'";    
            if (
$db->query($sql) === TRUE) { echo "Score updated successfully!"; } else { echo "Error updating score: " $db->error; }

            
// Reduce the number of plays left available for this game by one & updates the timestamp to reflect current day of the year.
            
$plays_left $game['plays'] - 1;
            
$sql "UPDATE adopts_games SET `plays` = '{$plays_left}', `timestamp` = '{$day}' WHERE `username` = '{$username}' AND `game` = '{$game_name}'";
            if (
$db->query($sql) === TRUE) { echo "Game data updated successfully!"; } else { echo "Error updating game data: " $db->error; }
        }
    }

    if (isset(
$_POST['plays'])) {
        
// Check if today matches the timestamp in the database.
        
if (date('z') != $game['timestamp']){
            
// If the timestamp is different, reset plays to max and update the timestamp to today.
            
$sql "UPDATE adopts_games SET `plays` = '{$number_of_plays}', `timestamp` = '{$day}' WHERE `username` = '{$username}' AND `game` = '{$game_name}'";
            if (
$db->query($sql) === TRUE) { echo "{$number_of_plays}"; } else { echo "Error updating time stamp: " $db->error; }
        } else {
            
// If the timestamp is the same, send back the state of the game.
            
if ($game['plays'] <= 0){ echo "GameOver"; } else { echo $game['plays']; } 
        }
    }

    
$db->close();

}
?>


Abronsyth 02-04-2016 02:15 PM

I'm glad you were able to get it fixed! Thank you for sharing :)

gunpowdercat 02-16-2016 07:07 AM

I did all of what it said to do before I could follow the link to get to the game-- issue is, it just redirects me to my homepage. How do I fix this? I uploaded the files, it successfully worked- but mysite.com/hilo just redirects me.

Kyttias 02-16-2016 09:42 AM

Can you confirm for me that /hilo.php, ../view/hiloview.php, and ../games/.htaccess exist for me in their proper directories? If any of these files are missing or out of place it would cause a redirect. :desudesudesu:

gunpowdercat 02-16-2016 09:51 AM

Quote:

Originally Posted by Kyttias (Post 33804)
Can you confirm for me that /hilo.php, ../view/hiloview.php, and ../games/.htaccess exist for me in their proper directories? If any of these files are missing or out of place it would cause a redirect. :desudesudesu:


I ended up figuring it out--- Everything works, except, after 1 play, the cards/numbers completely disappear. Everything is in the correct spot. :cfrown:
http://prntscr.com/a41iu5

Kyttias 02-16-2016 10:03 AM

Well... you've modified the base files by changing the number of plays. Did you at least confirm it was working before you started tinkering with it?

gunpowdercat 02-16-2016 10:56 AM

Quote:

Originally Posted by Kyttias (Post 33807)
Well... you've modified the base files by changing the number of plays. Did you at least confirm it was working before you started tinkering with it?

Yes; I also changed it back to make sure that wasnt the issue.

NobodysHero 02-16-2016 11:37 AM

Same issue: No Longer Displays Cards After 1st Turn.
 
I have that same issue. The only file I changed was the hilo_non.js to update the amount of money offered. Also, doesn't appear that my score is updating? Having the same issue with the Word Scramble game, which used your coding as a foundation.

Below is my hilo_non.js file and some screenshots for reference and piece of mind. Didn't included view and index file screenshots, but both are placed appropriately.

Code:

PHP Code:

$(function() {
    
checkPlays();
});

var 
plays 20;
var 
score 0;
var 
first Math.floor(Math.random()*16);

$(
'.first').html(first);

$(
'.guess').click(function(){
  if (
plays >= 0){
    var 
second Math.floor(Math.random()*16);
    $(
'.second').html(second);
    if ($(
this).hasClass('higher')){
      if (
first <= second){
        
resultIs('correct'second);
        
sendScore(150);
      } else {
        
resultIs('incorrect'second);
        
sendScore(0);
      }
    }
    if ($(
this).hasClass('lower')){
      if (
first >= second){
        
resultIs('correct'second);
        
sendScore(150);
      } else {
        
resultIs('incorrect'second);
        
sendScore(0);
      }
    }
  }
});

function 
resultIs(resultsecond){
  $(
'.result').html(result);
  $(
'.result').fadeIn(1000, function(){
    $(
'.first').fadeOut(500);
      $(
'.second').fadeOut(500, function(){    
      $(
'.first').html(second);
      
first second;
      
plays plays 1;
      $(
'.first').fadeIn(500);
      $(
'.second').html('?');
      $(
'.second').fadeIn(500);      
      $(
'.plays').html(plays);
      if (
result == 'correct'){
        
score score 150;
        
current parseFloat(window.parent.$('.money').text());
        
window.parent.$('.money').fadeTo(1000.1);
        
window.parent.$('.money').text((current score));
        
window.parent.$('.money').fadeTo(1001);
      }
      $(
'.score').html(score);
      if (
plays <= 0){
        
disableGame();
      }
    });
  }); 
  $(
'.result').fadeOut(500);
}

function 
sendScore(amt) {
  var 
values = {
    
'username': $("#username").text(),
    
'amt'amt
  
};
  $.
ajax({
    
url"sendscore.php",
    
type"POST",
    
datavalues,
  }).
done(function(status){
    if (
status == "GameOver"){
      
disableGame();
    } else {
      $(
'.plays').html(status);
      
plays status;
    }
  });
}

function 
disableGame(){
  $(
'.plays').html("0");
  $(
'.guess').off('click');
  $(
'.guess').css'cursor''not-allowed' );
  $(
'.arrow-box').fadeTo('slow'0.3);
  $(
'.first').html('game');
  $(
'.second').html('over');
  $(
'.finalscore').html("<b>Plays Left Today:</b> 0 of 20<h2>See You Tomorrow!</h2>");
}

function 
checkPlays(){
  var 
values = {
    
'username': $("#username").text(),
    
'plays''check'
  
};
  $.
ajax({
    
url"sendscore.php",
    
type"POST",
    
datavalues,
  }).
done(function(status){
    if (
status == "GameOver"){
      
disableGame();
    } else {
      $(
'.plays').html(status);
      
plays status;
    }
  });


Screenshots:
http://i.imgur.com/K7hBs7N.png

http://i.imgur.com/IIUQCJL.png

http://i.imgur.com/hiyUmmz.png

gunpowdercat 02-16-2016 12:19 PM

Went ahead and deleted and re-installed it-- working now, thank you!

Kyttias 02-16-2016 12:22 PM

I'm a bit concerned I uploaded a bugged version of the non-obfuscated javascript (meaning the default install will work but the file I welcomed you to edit that's human-readable is somehow flawed). I'll try to look into it soon.

I plan on buying an open source game from Code Canyon to integrate soon, so this definitely needs fixed for that to work.

Kasandra 02-16-2016 07:49 PM

If it awards 25 credits for correct guesses, could you make it remove credits for incorrect guesses?

Since it updates the persons credits automagically, if they then keep losing and have no credits, will the game stop/not allow them to play again?

Kyttias 02-16-2016 08:08 PM

Seems kind of cruel. And I won't be making modifications of the base game, sorry. Is it possible? Definitely.

But I'd have to create a new variable to be sent from Javascript to PHP to inform the other language it's dealing with a negative number and then write a whole new function in PHP, or heavily modify the existing one, to deal with subtracting rather than adding. And then I'd have to write a check to make sure the user isn't below on cash and then send an error message if they are. And then I'd have go back through and make sure it's cheatproof.

This wasn't a feature I had planned on, and it would add a half times more to the amount of code the game is already using. I hope you understand... I just don't have time to fulfill requests like that.

gunpowdercat 02-17-2016 11:28 AM

It began glitching again. Uploaded it. Made no changes to any code WHATSOEVER. it is still glitching. after about 2 plays, the cards disappear. It doesn't register correct guesses, either. It stays at "0".

Chaos77777 01-29-2017 05:33 PM

It glitches for me too, lol I also found out that if you get a number you don't like, such as 10, you can keep refreshing til you get 1 or 16

-Edit-
Needed jQuery in my template. It works just fine now :D
People can still refresh for a more optimal number lol, but I'm not worried about that

Kyttias 01-30-2017 04:44 PM

I'm glad you figured out what was wrong on your end.

It's too difficult, at this point, to assist anyone with modifying this code. It remains here for intermediate to advanced coders to ponder over and observe the connection points needed to send a game score in exchange for currency -- but it's also up to them to make a far more functional game.

I hope to eventually improve upon all of this, but I'm still getting way more hours than I asked for at my job and I'll be moving cross country early this summer. :catfish:

Chaos77777 01-30-2017 05:33 PM

I'm going to try to set it up to where the player gets money based on points earned, rather than correct guesses. I've noticed that if I do refresh, the points restart back at 0. It would be incentive to keep going for more points, rather than simply correct answers. I'll post what I come up with if I can figure it out. I'm not all that great at coding, so me "coding" is a couple hours of trial and error lol

Abronsyth 01-30-2017 08:13 PM

I plan on taking a look more deeply into this and seeing if I can get some other javascript games to work, such as tic-tac-toe, etc.

I hope all goes well for you with the job and move, Kyttias!

LUC1G07CH1 07-19-2017 09:55 AM

It actually works as i wanted!
It has just 1 problem...after some rounds both numbers dissapear. But okay, i just refresh the page.

I also did this for my site, it's a small arcade machine with a mini pixel of this game haha
http://orig07.deviantart.net/1b00/f/..._1-dbgw3x0.png
Edit: i think i'll make these as f2u for any project.


All times are GMT -5. The time now is 04:43 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.