<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7608507912886264325</id><updated>2011-04-21T14:15:00.908-07:00</updated><category term='c#'/><category term='ruby'/><category term='adventure'/><category term='javascript'/><category term='php'/><category term='html'/><title type='text'>Content-Type: text/plain</title><subtitle type='html'>&amp;lt;!-- Rest assured; everything will be HTTP/1.1 200 OK. --&amp;gt;</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-6215683017267309395</id><published>2007-06-28T07:50:00.000-07:00</published><updated>2007-06-28T08:06:20.711-07:00</updated><title type='text'>sideblog_comments.diff</title><content type='html'>&lt;p&gt;Here's how you add comments to the &lt;a href="http://wordpress.org/extend/plugins/sideblog/"&gt;Sideblog plugin for Wordpress&lt;/a&gt; by &lt;a href="http://katesgasis.com/"&gt;Kates Gasis&lt;/a&gt;. This diff will only work for &lt;b&gt;Version 3.8&lt;/b&gt;.&lt;/p&gt;

&lt;pre name="code" class="diff"&gt;
145c145
&amp;lt;  $sideblog_contents = $wpdb-&gt;get_results("SELECT $wpdb-&gt;posts.ID, $wpdb-&gt;posts.post_title, $wpdb-&gt;posts.post_content, $wpdb-&gt;posts.post_date FROM $wpdb-&gt;posts, $wpdb-&gt;post2cat WHERE $wpdb-&gt;posts.ID = $wpdb-&gt;post2cat.post_id AND $wpdb-&gt;post2cat.category_id = $asidecategory AND $wpdb-&gt;posts.post_status ='publish' AND $wpdb-&gt;posts.post_type = 'post' AND $wpdb-&gt;posts.post_password ='' AND $wpdb-&gt;posts.post_date &lt; '" . $now . "' ORDER BY $wpdb-&gt;posts.post_date DESC LIMIT " . $limit);
---
&amp;gt;  $sideblog_contents = $wpdb-&gt;get_results("SELECT $wpdb-&gt;posts.ID, $wpdb-&gt;posts.post_title, $wpdb-&gt;posts.post_content, $wpdb-&gt;posts.post_date, $wpdb-&gt;posts.comment_count FROM $wpdb-&gt;posts, $wpdb-&gt;post2cat WHERE $wpdb-&gt;posts.ID = $wpdb-&gt;post2cat.post_id AND $wpdb-&gt;post2cat.category_id = $asidecategory AND $wpdb-&gt;posts.post_status ='publish' AND $wpdb-&gt;posts.post_type = 'post' AND $wpdb-&gt;posts.post_password ='' AND $wpdb-&gt;posts.post_date &lt; '" . $now . "' ORDER BY $wpdb-&gt;posts.post_date DESC LIMIT " . $limit);
153a154
&amp;gt;  $patterns[] = "%comments%";
173c174,175
&amp;lt;    $replacements[] = $excerpt2;
---
&amp;gt;    //$replacements[] = $excerpt2;
&amp;gt;    $replacements[] = $sideblog_content-&gt;comment_count . " comment" . ($sideblog_content-&gt;comment_count == 1 ? null : "s");
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-6215683017267309395?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/6215683017267309395/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=6215683017267309395' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/6215683017267309395'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/6215683017267309395'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/06/sideblogcommentsdiff.html' title='sideblog_comments.diff'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-492109991737105381</id><published>2007-06-19T22:41:00.000-07:00</published><updated>2007-06-19T22:58:04.032-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>widont.rb</title><content type='html'>&lt;p&gt;I don't mean to knock Shaun Inman and his wordpress plugin &lt;a href="http://www.shauninman.com/archive/2007/01/03/widont_2_1_wordpress_plugin"&gt;Widon't&lt;/a&gt;.  It's a very useful plugin that eliminates typographical widows by replacing the last space with a non-breaking space. He says the regular expression is &lt;code&gt;'|([^s])s+([^s]+)s*$|'&lt;/code&gt;. This is of course, completely false; something was lost in translation here.&lt;/p&gt;

&lt;p&gt;First, the pipe characters are weird but I think PHP accepts them. I've always used the forward slash to denote a regular expression. Second, the &lt;code&gt;s&lt;/code&gt; is meant to be &lt;code&gt;\s&lt;/code&gt; the notation for whitespace of any sort.&lt;/p&gt;

&lt;p&gt;The actual plugin works fine. I think Shaun's just made a typo on his blog.&lt;/p&gt;

&lt;p&gt;Here's a similar piece of code in Ruby:&lt;/p&gt;

&lt;pre name="code" class="ruby"&gt;
"Lorem Ipsum Dalor Est".gsub(/([^\s])\s+([^\s]+)$/, '\1&amp;amp;nbsp;\2')
# =&gt; "Lorem Ipsum Dalor&amp;amp;nbsp;Est"
&lt;/pre&gt;

&lt;p&gt;I love how Ruby (and Javascript, if I recall correctly) gives regular expressions special status like how most modern languages treat strings. In web development and command line scripting, strings are the only real input/output you work with and regular expressions are akin to the hand of God.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-492109991737105381?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/492109991737105381/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=492109991737105381' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/492109991737105381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/492109991737105381'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/06/widontrb.html' title='widont.rb'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-5168200853288185094</id><published>2007-06-17T08:59:00.000-07:00</published><updated>2007-06-19T15:57:14.182-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><title type='text'>randomhover.js</title><content type='html'>&lt;p&gt;I thought, wouldn't it be a great idea to have the background of a link change to a different color every time you over hover it? That'd look sweet.&lt;/p&gt;

&lt;pre name="code" class="js"&gt;
// NOTE: Load prototype.js first (prototypejs.org)
// NOTE: Load the HTML first, otherwise we don't know what we're dealing with

// function to set random background colors
var sidebarLinks = function(e) {
  var bg = "transparent"; // default background

  if (e.type == "mouseover" || e.type == "focus") {
    var colors = new Array("#ff6", "#6cf", "#f9f"); // list of colors we like
    
    // get random number and use % to make sure i doesn't go out of bounds
    var i = Math.floor(Math.random() * colors.length) % colors.length;
  
    bg = colors[Math.floor(Math.random() * colors.length)];
  }

  // get the link that triggered the event
  var element = Event.element(e);

  // set the background on that link
  element.style["background"] = bg;
}

var sidebars = $$("#sidebar a"); // all the links in the sidebar

for (var i = 0; i &lt; sidebars.length; ++i) {
  // call "sidebarLinks" whenever I mouseover or mouseout a link
  Event.observe(sidebars[i], "mouseover", sidebarLinks);
  Event.observe(sidebars[i], "mouseout", sidebarLinks);

  // these are the keyboard-specific events for accessibility reasons
  Event.observe(sidebars[i], "focus", sidebarLinks);
  Event.observe(sidebars[i], "blur", sidebarLinks);
}
&lt;/pre&gt;

&lt;p&gt;This code can actually be a lot shorter if you inline a few things. But I expanded it out to help the reading process and because my syntax highlighter has a few parsing bugs. Grr.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-5168200853288185094?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/5168200853288185094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=5168200853288185094' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/5168200853288185094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/5168200853288185094'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/06/randomhoverjs.html' title='randomhover.js'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-5752696457027137921</id><published>2007-05-30T12:27:00.000-07:00</published><updated>2007-06-19T15:57:27.560-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>alternator.php</title><content type='html'>&lt;pre name="code" class="php"&gt;
/**
 * Guys, seriously. It is pretty common to want to do something where
 * you do something to every 2nd row, don't use a lengthy if else block.
 *
 * Just have one bool, $foo, and set it to !$foo on every iteration.
 * Simple!
 */
$i = 0;
$alt = true;

echo "&amp;lt;ul&amp;gt;";
while ($i &amp;lt; count($list))
{
    echo "&amp;lt;li";
    echo $alt ? " class=\"alt\"" : null;
    echo "&amp;gt;";

    echo htmlentities($list[$i]);

    echo "&amp;lt;/li&amp;gt;";

    ++$i;

    $alt = !$alt; // aha! sorcery!
    /* if ($alt)
    {
        $alt = false;
    }
    else
    {
        $alt = true;
    } */
}
echo "&amp;lt;/ul&amp;gt;";
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-5752696457027137921?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/5752696457027137921/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=5752696457027137921' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/5752696457027137921'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/5752696457027137921'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/05/alternatorjava.html' title='alternator.php'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-311676784161924084</id><published>2007-05-28T22:30:00.000-07:00</published><updated>2007-06-19T15:57:36.326-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='html'/><title type='text'>An exercise in reading HTML specifications</title><content type='html'>&lt;p&gt;Did you know that web pages are chunked? Imagine the page is like a big piece of paper. When you ask for the piece of paper, the server rips it up into little pieces and hands it out to people. The pieces are passed to random people until you collect all the pieces. Then you have to get some glue and stick it all together before you can read it.&lt;/p&gt;

&lt;p&gt;Internet, that is just idiotic. You are wasting everyone's time with all this ripping up and sticking together. Time that could be spent communicating thoughtful ideas over some massive global network.&lt;/p&gt;

&lt;p&gt;BUT THERE'S A SOLUTION. You make your webpage so small, that it only needs to take up one piece of paper. It's so small that noone will bother to rip it up, so when it reaches your audience, they don't need to glue everything back together. Imagine all the energy we'd save that way.&lt;/p&gt;

&lt;p&gt;So here are some templates for you to build from:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;html4-tiny.html:&lt;/b&gt;&lt;/p&gt;

&lt;pre name="code" class="html"&gt;
&amp;lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;xhtml-tiny.html:&lt;/b&gt;&lt;/p&gt;

&lt;pre name="code" class="xhtml"&gt;
&amp;lt;!DOCTYPE html 
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;b&gt;html5-tiny.html:&lt;/b&gt; (as according to the &lt;a href="http://www.whatwg.org/specs/web-apps/current-work/"&gt;HTML5 specification&lt;/a&gt; on 2007-05-28)&lt;/p&gt;

&lt;pre name="code" class="html"&gt;
&amp;lt;!doctype html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;The truth is, I don't know if these could be smaller or are even valid. First of all, the &lt;a href="http://validator.w3.org"&gt;HTML validator&lt;/a&gt; fails me because it's a pretty generic validator. You see, the W3C provides DTDs for HTML 4.01 and XHTML 1.0 but DTDs alone cannot verify 100% conformance to the spec. This means that things are special-cased and I'm doubtful they've special-cased some idiot wanting to write the smallest possible HTML document.&lt;/p&gt;

&lt;p&gt;The HTML5 spec is easier to read because it is designed with audience in mind. But at the end of the day, it's still a spec. Spec aren't meant to be read by humans. They're meant to be read by pedantic assholes (who yell at people trying to interpret the spec) and angelic humanitarians (who interpret specs and translate for the rest of us).&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-311676784161924084?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/311676784161924084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=311676784161924084' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/311676784161924084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/311676784161924084'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/05/small-html-documents.html' title='An exercise in reading HTML specifications'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-7763411272483583926</id><published>2007-05-28T14:44:00.000-07:00</published><updated>2007-05-28T15:24:47.659-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='adventure'/><title type='text'>toast.exe</title><content type='html'>&lt;pre name="code" class="plain"&gt;

You are in your childhood kitchen but its not your childhood kitchen. You feel
light-headed. There is a piece of toast sitting in the toaster.

&amp;gt; look toast

The toast is burnt just the way you like it.

&amp;gt; get toast

Taken.

&amp;gt; give toast to mr james

You give the toast to Mr. James, your first boss when you took a job over the
holidays in data entry. He greedily eats up the toast and gives you his shirt
that is covered in crumbs.

&amp;gt; look

You are in your childhood kitchen but its not your childhood kitchen. You feel
light-headed. There is toaster. Your old boss, Mr. James is standing topless
in the corner of the room.

&amp;gt; i

You are carrying:
A shirt covered in crumbs.

&amp;gt; save

Ok.

&amp;gt; quit

Your score is 5 (total of 50 points).
This gives you the rank of Beginner.
Do you wish to leave the game? (Y is affirmative):

&gt; y
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-7763411272483583926?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/7763411272483583926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=7763411272483583926' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/7763411272483583926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/7763411272483583926'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/05/toast.html' title='toast.exe'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-8812221204430556876</id><published>2007-05-26T18:23:00.000-07:00</published><updated>2007-05-26T19:20:26.825-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><title type='text'>StateMachine.cs</title><content type='html'>&lt;p&gt;State machines are a very very handy design pattern. I am easily one of the top 3 programmers in the world and I didn't learn state machines until my final year of university. Just goes to show that we all need to keep learning. (Ok I'm kidding about being in the top 3, lighten up and go meet a nice girl instead of drinking so much Haterade.)&lt;/p&gt;

&lt;p&gt;The first class is the &lt;code&gt;Game&lt;/code&gt; class that is the entry point and stores environment variables that are shared between all states (e.g. player name, high score, statistics, etc.). There is very little going in inside &lt;code&gt;Game&lt;/code&gt;.&lt;/p&gt;

&lt;pre name="code" class="c#"&gt;
class Game
{
    /**
     * Entry point for the program. Create a new Game object and start running
     */
    public static void Main()
    {
        Game game = new Game();
        game.Activate();
    }
    
    private bool exitGame;
    private State state; // current state of the game
    public Game()
    {
        exitGame = false;
        state = MainMenu.Instance;
        // do other "new game" stuff here
    }
    public void Activate()
    {
        // keeping running the game until someone tells us to exit
        while (!exitGame)
        {
            state.Activate(this);
        }
    }
    public State GameState
    {
        set
        {
            state = value;
        }
    }
    public bool ExitGame
    {
        set
        {
            exitGame = value;
        }
    }
}
&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;MainMenu&lt;/code&gt; class is quite lively.&lt;/p&gt;

&lt;p&gt;It's got a private constructor to make sure that there's only one copy of the class that is ever instantiated. You don't need to create these states more than once. As a bonus, you could wait until &lt;code&gt;MainMenu#Instance&lt;/code&gt; is called before creating the state. I don't know if the compiler would already optimize for this though, so better run some benchmarks and figure it out before you add more lines to your already unmaintainable codebase.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;MainMenu.Activate(...)&lt;/code&gt; is where all the action is going on. It basically asks for the user's input and then changes the state of the game accordingly. This is the fun of a State pattern. You avoid wasting your time with really verbose &lt;code&gt;switch&lt;/code&gt; and &lt;code&gt;else if&lt;/code&gt; statements and instead abstract it away so you deal with state &lt;em&gt;transitions&lt;/em&gt;. It maps better to the state diagram that you drew (tell me you drew one).&lt;/p&gt;

&lt;pre name="code" class="c#:firstline[43]"&gt;
class MainMenu : State
{
    private static State mainMenu = new MainMenu();
    public static State Instance
    {
        get
        {
            return mainMenu;
        }
    }
    
    private MainMenu() { }
    
    public override void Activate(Game game)
    {
        Console.WriteLine("Welcome to the game!");
        Console.WriteLine("1: Write a novel");
        Console.WriteLine("2: Read a novel");
        Console.WriteLine("3: Plagiarize a novel");
        Console.WriteLine("4: Criticize another novel writer");
        Console.WriteLine("5: Exit to DOS");
        
        // Get keyboard input from the user
        int choice = getChoice(5);
        
        switch (choice)
        {
            case 1:
                ChangeState(game, WriteNovel.Instance);
                break;
            case 2:
                ChangeState(game, ReadNovel.Instance);
                break;
            case 3:
                ChangeState(game, WriteNovel.Instance);
                break;
            case 4:
                ChangeState(game, CriticizeWriter.Instance);
                break;
            case 5:
                ChangeState(game, ExitGame.Instance);
                break;
        }
    }
    
    private int getChoice(int max)
    {
        // Implement this one on your own!
    }
}
&lt;/pre&gt;

&lt;p&gt;Did you notice that &lt;code&gt;MainMenu&lt;/code&gt; inherits from something called &lt;code&gt;State&lt;/code&gt;? Go back and read the code, dummy.&lt;/p&gt;

&lt;p&gt;This is an abstract class that all states inherit from. Every class that inherits from this must have a &lt;code&gt;Activate(Game game)&lt;/code&gt; method and that's about it. You could also add more things here that are common to all the states.&lt;/p&gt;

&lt;p&gt;Umm... I've forgotten what the &lt;code&gt;virtual&lt;/code&gt; keyword does. I think it means the method is late-binding so in the sub-classes, you could re-define this function and it would be polymorphic so you could have a sub-class of &lt;code&gt;State&lt;/code&gt; that does some clean-up before transitioning away.&lt;/p&gt;

&lt;pre name="code" class="c#:firstline[93]"&gt;
abstract class State
{
    /**
     * Activate() gets the state to do whatever it needs to do.
     * When a state has finished running, it calls ChangeState().
     *
     * The Game object is just where important environment data is stored so the
     * different states have can work on this data.
     */
    public abstract void Activate(Game game);
    
    protected virtual void ChangeState(Game game, State state)
    {
        game.GameState = state;
    }   
}
&lt;/pre&gt;

&lt;p&gt;Well that just about covers it! Please please please think about implementing a State before you starting writing a huge &lt;code&gt;switch&lt;/code&gt; statement.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-8812221204430556876?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/8812221204430556876/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=8812221204430556876' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/8812221204430556876'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/8812221204430556876'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/05/statemachinecs.html' title='StateMachine.cs'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-6571748810622962346</id><published>2007-05-26T17:32:00.000-07:00</published><updated>2007-05-26T17:34:40.638-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><title type='text'>HelloWorld.cs</title><content type='html'>&lt;pre name="code" class="c#"&gt;
using System;

class Hello
{
  static void Main() {
    Console.WriteLine("Hello world");
    // System.out.println("Hello world"); // You idiot, this is not Java
  }
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-6571748810622962346?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/6571748810622962346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=6571748810622962346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/6571748810622962346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/6571748810622962346'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/05/helloworldcs.html' title='HelloWorld.cs'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-3551765028139317884</id><published>2007-05-26T08:49:00.000-07:00</published><updated>2007-05-26T17:20:54.981-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>HashToAttributes.rb</title><content type='html'>&lt;pre name="code" class="ruby"&gt;
# When this class is initialized, it takes in a Hash and uses the key/value
# pairs to create instance variables. The problem here is that each key needs to
# be verified to make sure it conforms to the naming rules.
#
# This is like converting a Hash to an object (a Hash.to_o method, if you will).
# Great for when you're hacking up a script to parse some text/XML/YAML as a
# once-off. I wouldn't recommend this be used in a production environment.
# 
class HashToAttributes
  attr_reader :attr1, :attr2, :attr3
  attr_writer :attr3
  
  def initialize(hash)
    # Each key becomes an instance variable
    # TODO: check that key conforms to naming rules
    hash.each do |key, value|
      instance_variable_set(("@" + key).to_sym, value);
    end
  end
end

hsh = { 'attr1' =&gt; "Oh Vey", 'attr2' =&gt; "Virtua Cop 2", 'attr3' =&gt; true }
obj = HashToAttributes.new(hsh)
puts obj.attr1       # =&gt; "Oh Vey"
puts obj.attr2       # =&gt; "Virtua Cop 2"
obj.attr3 = false
puts obj.attr3       # =&gt; false
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-3551765028139317884?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/3551765028139317884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=3551765028139317884' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/3551765028139317884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/3551765028139317884'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/05/hashasattributes.html' title='HashToAttributes.rb'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-6739633298816668518</id><published>2007-05-26T07:55:00.000-07:00</published><updated>2007-05-26T17:19:05.489-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>irb-loop.rb</title><content type='html'>&lt;pre name="code" class="ruby:nogutter"&gt;
irb(main):001:0&amp;gt; # I guess this is as wide as it goes
irb(main):002:0* 80.times do |i|
irb(main):003:1*   print i % 10
irb(main):004:1&amp;gt;   print "\n" if i == 79
irb(main):005:1&amp;gt; end
01234567890123456789012345678901234567890123456789012345678901234567890123456789
=&gt; 80
irb(main):006:0&amp;gt;
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-6739633298816668518?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/6739633298816668518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=6739633298816668518' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/6739633298816668518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/6739633298816668518'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/05/blog-post.html' title='irb-loop.rb'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7608507912886264325.post-7809265513436038734</id><published>2007-05-26T00:26:00.000-07:00</published><updated>2007-05-26T17:18:32.539-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>helloworld.rb</title><content type='html'>&lt;pre name="code" class="ruby"&gt;
# This is as much as you need to know about a programming language.
# The rest will simply fall into place.
puts "Hello World"
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7608507912886264325-7809265513436038734?l=textplain.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://textplain.blogspot.com/feeds/7809265513436038734/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7608507912886264325&amp;postID=7809265513436038734' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/7809265513436038734'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7608507912886264325/posts/default/7809265513436038734'/><link rel='alternate' type='text/html' href='http://textplain.blogspot.com/2007/05/helloworldrb.html' title='helloworld.rb'/><author><name>Jack</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://files.boxofjack.com/looking-around.jpg'/></author><thr:total>1</thr:total></entry></feed>
