Arcade Billiards, the Source Code

Although my Mix09 entry didn’t place/win, as promised I’m posting the source code, as-is. It’s not the final completely condensed version that I actually submitted (as that version had carriage returns/line feeds, tabs, etc. all removed).

Download Source

As a consolation prize, I did receive a limited edition T-shirt just for entering (which admittedly, didn’t make the effort worth while – but, I had fun putting it all together nonetheless).

I’ve programmed in many nasty, strict environments over the years, but it felt really dirty to do this in c#:

DateTime _t, _aL, _tS;
B[] _b, _e;
Random _r = new Random();
double TW = 12, TH = 12, SY = 50, MW, MH, SA, G = .03, CSA, SSA;
Point A;
int CW = 20, CH = 40, TB = 21, _s, GM = 0, _c, BR;
Brush _o;
IsolatedStorageSettings _a;
delegate void PAD(Canvas c);

Yeah. Seriously, those were the variable names that I used to keep the file smaller.

I shrunk the standard Application class down to it’s bare minimum and used Lamda expressions everywhere:

public partial class App : Application
{
    public App()
    {
        Startup += ((s, e) => RootVisual = new Page());
        UnhandledException += ((s, e) =>
        {
            if(!System.Diagnostics.Debugger.IsAttached)
            {
                e.Handled = true;
            }
        });
        InitializeComponent();
    }
}

and …

Loaded += ((s, e) =>
{
    _a = IsolatedStorageSettings.ApplicationSettings;
    btnP.Click += ((o, a) =>
    {
        cMs.Visibility = Visibility.Collapsed;
        RG();
        GO();
    });

Last but not least, this was probably the silliest thing I did to stop needing to use the Canvas class everywhere directly (it was still necessary in some places):

class C : Canvas
{
}

You’ve got it. I derived from Canvas so I could just refer to the Canvas class as the letter “C”! Thankfully, it wasn’t sealed.

The code does the necessary math to compute an Isometric view of the game table so that the balls on the table are properly placed.

Fully condensed down, I think I ended up with 240 bytes to spare.

 

(Are you going to Mix09? Sounds like some great stuff will be announced!)