Flex and Flash Developer - Jesse Warden dot Kizz-ohm

A blog on software development, technology, games & movies.

About

This is the blog of Jesse Warden, a Rich Internet Application Architect. He specializes in using Flex and Flash to create Rich Internet Applications.

I read FlashApe’s blog entry a little too quick… I thought it said “InnKeeper” and was like, “Wow! A D&D Flash post NOT by me!!!”

…but it was IntKeeper.

Pissed, I wrote this class to satiate my delusion. You can check an object in and out of rooms if any are available.

class InnKeeper extends Object
{

        static private var rooms_obj:Object = {};

        static var private SUITE:Number = 0;
        static var private NOBLE:Number = 1;
        static var private LUXURY:Number = 2;
        static var private COMMON:Number = 3;

        function InnKeeper()
        {
        }

        static public function getARoom(tennant:Object):Boolean
        {
                if(InnKeeper.isRoomAvailable() == false)
                {
                        return false;
                }
                else
                {
                        var bestRoom:Number = InnKeeper.getBestRoom();
                        if(bestRoom == -1)
                        {
                                // nice try hacker…
                                return false;
                        }
                        InnKeeper.rooms_obj[bestRoom] = tennant;
                        return true;
                }
        }

        static public function checkOut(obj:Object):Boolean
        {
                for(var p in InnKeeper.rooms_obj)
                {
                        if(InnKeeper.rooms_obj[p] == obj)
                        {
                                InnKeeper.rooms_obj[p] == null;
                                return true;
                        }
                }
                return false;
        }

        static public function isRoomAvailable():Boolean
        {
                if(InnKeeper.rooms_obj[InnKeeper.SUITE] != null)
                {
                        if(InnKeeper.rooms_obj[InnKeeper.NOBLE] != null)
                        {
                                if(InnKeeper.rooms_obj[InnKeeper.LUXURY] != null)
                                {
                                        if(InnKeeper.rooms_obj[InnKeeper.COMMON] != null)
                                        {
                                                return false;
                                        }
                                        else
                                        {
                                                return true;
                                        }
                                }
                                else
                                {
                                        return true;
                                }
                        }
                        else
                        {
                                return true;
                        }
                }
                else
                {
                        return true;
                }
        }

        static private function getBestRoom():Number
        {
                if(InnKeeper.rooms_obj[InnKeeper.SUITE] != null)
                {
                        if(InnKeeper.rooms_obj[InnKeeper.NOBLE] != null)
                        {
                                if(InnKeeper.rooms_obj[InnKeeper.LUXURY] != null)
                                {
                                        if(InnKeeper.rooms_obj[InnKeeper.COMMON] != null)
                                        {
                                                return -1;
                                        }
                                        else
                                        {
                                                return InnKeeper.COMMON;
                                        }
                                }
                                else
                                {
                                        return InnKeeper.LUXURY;
                                }
                        }
                        else
                        {
                                return InnKeeper.NOBLE;
                        }
                }
                else
                {
                        return InnKeeper.SUITE;
                }
        }
}


4 Responses to “InnKeeper Class”

  1. Ha. I wrote a Hotel Reseveration system for cows once in Pascal. :) Now that was whack…

    But combining DND and AS2 is dope. ok. I’m a nerd too, sue me. :)

    Scott Janousek

  2. hehehe nice work… too much time on your hands..but nice work.

    You also need to extend it though, like times are tough in the D&D world and if a potential client is an easy mark (ie out of towner) that you of course being an innkeeper may want to notify the thieves guild to come loot that client, so you need a typecast variable for the client, and if that typecast = easy mark, show them the ‘thievesGuildRoom’ ;) hehe

    Scott Barnes

  3. Holy Cow….you can really be a dork sometimes.

    If I only had the time. I’ve been playing WoW.

    Cheers,
    Brent

    Brent

  4. haha…the similarty is not entirely coincidental ;)

    flashape

Leave a Reply