Here jars, there jars, everywhere jars jars

Yesterday I implemented jars for the snail game. A user can have multiple jars and move snails between those jars (well, they can’t move snails yet, but they can put a wild-caught snail inside their personal jar). Some jars are “breeding jars” (all other jars are considered breeding suppressed, snails can’t mate in them. Otherwise there’d be snail babies everywhere!)

Anyway, a jar is created by default when the user logs into the game for the first time after verifying their email (I don’t want to create new jars for people who create accounts that they never use).

To handle all the jar stuff I created a jar manager class. So now I have a user manager, snail manager, and jar manager.

Jars can have various sizes/capacities - the smallest, “Tiny”, jar can hold up to 5 snails.

		<?PHP $jarmanager->GenerateJar("tiny", $fgmembersite) ?>


    function GenerateJar($type, $fgmembersite) {
        $jar['ownerID'] = $fgmembersite->UserID();
        switch ($type) {
            case "tiny":
                $jar['capacity'] = 5;


I haven’t really decided the best way to update a user’s jar list yet. For now I save all jars to a session variable and refer to it as required, and plan to update the jar list whenever jars are added/removed/modified. At first glance to me this seems more efficient than querying the DB every time the user wants to list all of their jars. Of course, I guess I’ll have to query the db anyway if the user wants to see other users’ jars, which will happen.

    function FindAllUserJars($fgmembersite) {
        $userID = $fgmembersite->UserID();
        $qry = "Select name, jarID, isBreedingJar, capacity from $this->tablename where ownerID='$userID'";
        $result = mysql_query($qry,$fgmembersite->connection);
        if(!$result || mysql_num_rows($result) <= 0)
            return false;
        $rowID = 0;
        while( $row = mysql_fetch_assoc( $result)){
            $allJars[ $rowID ] = $row;
        $_SESSION['all_user_jars'] = $allJars;


So when the player finds a snail from the wild (which I covered in my previous post) that he/she wants to keep, they can choose which of their jars they want to snail to be placed into.

	<label for='jarID' >Jar*:</label><br/>
   	<select name='jarID' id='jarID'>
   	<?PHP foreach ($jarmanager->AllUserJars() as $jar) { ?>
		<option value="<?= $jar['jarID'] ?>"><?= $jar['name'] ?> - <?= $jar['jarID'] ?></option>
    <?PHP } ?>


Up next I’ll be working on a snail profile page.

comments powered by Disqus