Twitter: raymondcamden


Address: Lafayette, LA, USA

Latest Nook App - TBS Horoscope

08-28-2011 4,476 views Mobile, Flex 4 Comments

A week or so ago I shared my thoughts on developing for the NookColor. Today I'm happy to say my second Nook app is available on the market. The turn around time for this app was much quicker than before. I had the idea for it last Sunday. By Monday night it was almost done. Tuesday I submitted my metadata and it was approved in a couple hours. I then submitted the application and it was approved by Friday. I checked Friday and it wasn't in the store yet, but as of this morning it's there. I'm pretty sure it was out Saturday as I'm seeing a few sales already.

NOOK App : TBS Horoscope

TBS Horoscope is mainly a joke horoscope generator. Unlike serious horoscope programs (ahem), this one creates horoscopes entirely randomly. Here's the initial screen.

The icons there are scrollable. You can also see the background image I blogged about before. Once you select the sign you get a horoscope:

Yeah - that's crazy - again - unlike real, scientific horoscopes out there. (Ahem again.) One thing that's kind of interesting is the persistence. I generate a random horoscope per sign per day. If you click on Aries twice it will be the same until the next day. Here's the snippet that handles that:

view plain print about
1protected function getHoroscope(date:Date):String {
2        //A repeat of the above, but in theory, you could run the app for a while
3        var today:Date = new Date();
4        var dateString:String = (today.month+1) + "/" + today.date + "/" + today.fullYear;
5
6        //See if we have one in the db
7        var stmt:SQLStatement = new SQLStatement();
8        stmt.sqlConnection = sqlConnection;
9        
10        stmt.text = "select horoscope from horoscopes where sign = :sign and date = :datestr";
11        stmt.parameters[":sign"] = data.sign.name;
12        stmt.parameters[":datestr"] = dateString;
13        stmt.execute();
14        var res:SQLResult = stmt.getResult();
15
16        if(!res.data) {
17            var newHoroscope:String = horoscopeGenerator.generateHoroscope();
18
19            var insStmt:SQLStatement = new SQLStatement();
20            insStmt.sqlConnection = sqlConnection;
21            insStmt.text = "insert into horoscopes(sign,horoscope,date) " +
22                         "values(:sign,:horoscope,:datestr)";
23            insStmt.parameters[":sign"] = data.sign.name;
24            insStmt.parameters[":horoscope"] = newHoroscope;
25            insStmt.parameters[":datestr"] = dateString;
26            
27            insStmt.execute();
28
29            return newHoroscope;
30        } else {
31            return res.data[0].horoscope;
32        }
33    }

I'm using AIR's SQLite support to handle checking for an existing horoscope (I could probably cache that but it executes so fast I don't think it would be worth it) in the database. If it doesn't exist, I generate the random one and store it. In case you're curious, here's the entire ActionScript class for the horoscope generator. It's not terribly intelligent, but was fun as heck to write.

view plain print about
1package model {
2
3    public class HoroscopeGenerator {
4
5        private var adjectives:Array = ["forgetful","scary","red","blue","green","yellow","orange","brown","smelly","left handed","right handed","smart","dumb",
6                                    "blue haired","red haired","tall","short","fat","thin","remote","close","skinny","wide","high","low"];
7        private var nouns:Array = ["mouse","wig","radio","computer","cat","dog","duck","desk","piece of paper","bird","werewolf","vampire","ghost",
8                                    "dart board","chair","television","egg","table","book","phone","pillow","cactus","rose","hat","airplane"];
9        
10        public function HoroscopeGenerator() {
11        }
12
13        private function getAdjective():String {
14            return adjectives[randRange(0,adjectives.length-1)];
15        }
16
17        private function getFinancialString():String {
18            var options:Array = [
19                "Today is a good day to invest. Stock prices will change. ",
20                "Today is a bad day to invest. Stock prices will change. ",
21                "Investments are a good idea today. Spend wisely before the " + getAdjective() + " " + getNoun() + " turns your luck! ",
22                "Save your pennies! Your " + getNoun() + " is not a safe investment today. ",
23                "You can buy a lottery ticket or a " + getNoun() + ". Either is a good investment. "
24            ];
25            return options[randRange(1,options.length-1)];
26        }
27        
28
29        private function getNoun():String {
30            return nouns[randRange(0,nouns.length-1)];
31        }
32
33        private function getRomanticString():String {
34            var options:Array = [
35                "Follow your heart like you would follow a "+getAdjective() + " " + getNoun() + ". It won't lead you astray. ",
36                "Romance is not in your future today. Avoid it like a " + getAdjective() + " " + getNoun() + ". ",
37                "Romance is blossoming like a " + getAdjective() + " " + getNoun() + "! ",
38                "Avoid romantic engagements today. Wait for a sign - it will resemble a " +getAdjective() + " " + getNoun() + ". ",
39                "Love is in the air. Unfortunately not the air you will be breathing. "
40            ];
41            return options[randRange(1,options.length-1)];
42        }
43
44        private function getRandomString():String {
45            var options:Array = [
46                "Today you need to practice your patience. And your piano. ",
47                "Meet new people today. Show them your " + getNoun() + ". ",
48                "Your spirits are high today - but watch our for a " + getAdjective() + " " + getNoun() + ". ",
49                "Your sign is in the third phase today. This is important. ",
50                "Your sign is in the second phase today. This is critical. ",
51                "Something big is going to happen today. Or tomorrow. ",
52                "A " + getAdjective() + " " + getNoun() + " will give you important advice today. ",
53                "A " + getAdjective() + " " + getNoun() + " has it out for you today. ",
54                "Last Tuesday was a good day. Today - not so much. ",
55                "A dark stranger will enter your life. They will have a " + getAdjective() + " " + getNoun() + ". "
56            ];
57            return options[randRange(1,options.length-1)];
58        }
59        
60        public function generateHoroscope():String {
61            var horoscope:String = "";
62            horoscope += getRandomString();
63            horoscope += getFinancialString();
64            horoscope += getRomanticString();
65            horoscope += "\n\n";
66            horoscope += "Your lucky numbers are " + randRange(1,10) + ", " + randRange(1,10) + ", and " + getNoun() + ".";
67            return horoscope;
68        }
69    
70        //credit: http://snipplr.com/view/7326/
71        private function randRange(minNum:Number, maxNum:Number):Number {
72            return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
73        }
74        
75    }
76}

So folks - if you have a Nook and 99 cents to spare, check it out. (Direct Link) I'd especially love it if you would rate it up a bit against some anonymous person who gave it one star. It's easily a two star app, right???

4 Comments

  • Commented on 08-28-2011 at 7:32 PM
    Quick question for you about deploying to the Nook. Just went and checked out the developer section and it states that the Nook uses Android 2.2. Just wondering if this means that if I write something using Flex 4.5, that I can just "export release build for Android" and it'll just work or does it have to be HTML or Java?
  • Commented on 08-28-2011 at 7:34 PM
    Argh! Eejit...Didn't even notice in your screenshots that you're using the AIR runtime to demo :) I guess I can write a mobile app in Flex and deploy to the Nook.
  • Commented on 08-28-2011 at 8:28 PM
    Yep, AIR can now get you on an iPhone, an iPad, a Nook, a Playbook, and all the Android devices in the world.
  • Commented on 08-29-2011 at 9:19 AM
    What? You mean horoscopes aren't real?

    ;)

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty