Mys 1.3.4 Higher Or Lower Game

Forum
Last Post
Threads / Messages
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:
<?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(DBHOST, DBUSER, DBPASS, DBNAME);
	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();

}
?>
 
Last edited:
I'm glad you were able to get it fixed! Thank you for sharing :)
 
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.
 
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:
 
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
 
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?
 
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.
 
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:
$(function() {
    checkPlays();
});

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

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

$('.guess').click(function(){
  if (plays >= 0){
    var second = 1 + 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(result, second){
  $('.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(100, 0.1);
        window.parent.$('.money').text((current + score));
        window.parent.$('.money').fadeTo(100, 1);
      }
      $('.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",
    data: values,
  }).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",
    data: values,
  }).done(function(status){
    if (status == "GameOver"){
      disableGame();
    } else {
      $('.plays').html(status);
      plays = status;
    }
  });
}

Screenshots:
K7hBs7N.png


IIUQCJL.png


hiyUmmz.png
 
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.
 
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?
 
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.
 
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".
 
Last edited:
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
 
Last edited:
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:
 
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
 
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!
 
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
arcade_machine_1_by_xluc_1-dbgw3x0.png

Edit: i think i'll make these as f2u for any project.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top