Tuesday, February 27, 2007

Targeting 1.1 with VS 2005

To do this we setup a project in VS 2005 and added only 1.1 references. We created our test assembly with 2.0 components such as rhino mocks. Everything built and all tests were passing.

Now setting up only 1.1 references is one thing, but enforcing 2.0 supported features, such as generics, to cause build errors, will only happen when you build with 1.1. This is not supported by default with 2005. However, a nice group of people have created a tool to do just that!

The tool is called MSBee and you can download it here

MSBee creates a new build target for the 1.1 framework. You need to add this target to your vs project file in an import node:
<Import Project="$(MSBuildBinPath)\MSBee\MSBuildExtras.FX1_1.CSharp.targets" Condition=" '$(BuildingInsideVisualStudio)' == '' AND '$(TargetFX1_1)'=='true'" />

You can easily edit your project files in visual studio from the right click menu -- unload the project, then edit the file.

Tada! You now have a 1.1 build target in VS 2005!

But you want to integrate this with your build server and your NANT script?

Here is a snipet to execute the msbuild target:

<exec program="${msbuildLocation}">
<arg value="${csprojFile}" />
<arg value="/t:Rebuild" />
<arg value="/p:OutputPath=${buildDir}\" />
<arg value="/p:Configuration=${build.solution.config}" />
<arg value="/p:TargetFX1_1=true" />
</exec>

Enjoy!

Sunday, February 25, 2007

First Group Ride Outside

26 Miles of Fun!

I learned something new:
My fancy running sneakers that provide excellent air circulation aren't so good for cold weather biking... my feet were like bricks... I didn't fall off the bike, I fell when I got off the bike because my feet were so numb!

Otherwise, I was a little slow, but I finished and it was fun :)

If you didn't already know, I'm training for 2 century rides as a fundraiser for the leukemia and lymphoma society in the memory of my father, who I lost in 2004 to leukemia -- please help my campaign here

Wednesday, February 21, 2007

XNA Content Builder

Let's you build xna content w/o Game Studio Express!!
You can get it here

Thank you!! And thanks Kris for sending me this link :)

Monday, February 19, 2007

losing to a girl

Tonight I played gears with some women; it was the second time I got to play with women since I signed up for gamerchix.

I'm not so good at multi-player gears (I must say I do rock the single player campaign though!), I don't completely suck, but I like to play, laugh and have fun.

Although most of the guys I play with are cool, a lot can't control themselves and eventually say "you sound cute" or ask "are you hot?" Its flattering, but a reminder that even in this faceless video game, I am different.

Being hot isn't so bad, right?

Tonight was different. I was playing with chicks who were kicking ass. The guys we were playing with got mean, and it was different than anything I'd encountered.

They were mad.

Their egos had been bruised.

They had the ultimate insult, they were beaten by a girl.

After a while, we mixed it up and I was on the team with the most outspoken guy.

When we started playing, he said that one of the other girls was an easy kill. I said "Considering its her first time playing, she's doing awesome."

He wasn't expecting that.

At the end of that round, he said "Hey this is your first time, you're doing really well, are you having fun?"

And she was really quiet and shy and said "ummm... yeah..."

When the game started he asked, "Why did she sound like this was the worst experience?"

My reply was simple, "because you're being so mean."

He was very surprised and asked how. I listed the insults he had been spitting for the past 30 minutes... and he said "I didn't say any of that."

But the conversation ended, the round was over.

Sunday, February 18, 2007

Oksana, where are you??

Oksana, I'm looking at the War Room Crew links over there and its seriously lacking estrogen... Come on now, this is Oxygen, and we need to represent the women developers of the world!!! Where's your blog???

Code Camp Registration is Now Open

Register Here
Thanks for the link Luke!

Getting all the achievements in Madden 06

Yes, I've done it... I've whored myself... stupid rewards... What I've learned is that I really do not enjoy playing a lot of video games and even with rewards, I still don't. But, I managed to pull myself through and figured I'd help some people out with Madden; its really easy.

Just to start -- you will not get game achievements until the game is completed, so don't get discouraged, they'll be there

Really freakin' easy:
Win the superbowl:
1. From main menu go to franchise mode, start a new franchise
2. Select every team
3. Simulate preseason
4. Simulate regular season
5. Simulate wildcard
6. Simulate superbowl
7. tada -- you won the superbowl!

Look at the history book
1. From the main menu, go to franchise mode
2. Select history book
3. Go to any page
4. tada -- you got an uber lame achievement!

In game achievements:
If you do the following, you will get all the game playing achievements, save win a franchise game Note, this will be the most cheesy video game experience of your life.

Notes:

a) At any time in the game, check your current status by pressing start, then clicking down on the right thumbstick, then pressing down on the right thumbstick -- this will give you passed and rushed yards. This gives you the activate RS card achievement.

b) Don't bother doing anything special or control players -- just select plays. The only exception is passing -- if you choose who to pass to, you'll complete passes better.

1. From the main menu, start a new regular game, make the quarters 9 minutes long to make sure you have enough time to get all the achievements. I had 5 minutes left in 4th quarter by the time they were done. Choose rookie difficulty.
2. Choose the Colts for your team -- they rock
3. Choose the Browns for your competitors -- they suck -- make sure the computer is driving or it doesn't count
4. Every time you are on defense, choose based on play type, man blitz -- any one, this will get you Four Sacks in One Game and it may take a while. Just keep at it.
5. In the beginning offense, choose based on play type, shotgun passes when you're far from the goal and then switch to quick pass. You will keep getting touch downs, very exciting. Do this until you reach 350 passing yards for the achievement.
6. After you get the 350 yards, now you need to focus on rushing. The colts aren't quite as good at rushing, but I found starting with Counter to get close to a down and getting the down with an inside hand off. worked most of the time. Since I was so far ahead in points, I never kicked on the forth down and just went for it, this worked most of the time. Do this until you reach 200 rushing yards in your stats and then you can spend the rest of the game loafing
7. Thats it, play until the clock runs out and you'll have 480 more achievements when its all done -- Enjoy.

More difficult:
30 Years of Franchise
This one is time consuming and basically you sit around and wait for simulation. You really only get this one if you have 3 hours to waste and an achievement whoring husband. I take full credit for the theory of getting this to work on simulation, but he gets credit for actually doing it...
1. Start a new franchise -- don't use the one from the superbowl -- it won't work for 30 years!!!
2. Select the worst team with the biggest cap -- he went with the Titans, but didn't look through the list that well. If you choose someone like the colts, after a few years, you'll have to start doing some manual labor cause salaries will get too high and it sucks.
3. put on some good music
4. get a laptop, ds, split screen tv, another xbox....
5. Simulate, repeat
6. Yay, you're done

Win a Franchise Game
1. Start a franchise, select the Colts
2. Simulate the franchise week by week until you play the Browns
3. Use coaches pick for defense and offense, but use passing plays for offense, unless you have less than 3 yards, then you can use a rush.
4. This will be a little more tricky cause franchise is Pro mode only

To completely cheese out, you can adjust the AI during the Pro game. Its under the game play settings when you press "start" during the game. Use the right trigger to select between offense and defense and between you and the computer. Bump your attributes up to 100 and the cpus down to 0. This will make you win the game easily -- doesn't matter what plays you use.

Good luck and don't get too bored!

Saturday, February 17, 2007

Back to training

I went to the gym today for the first time since I had to postpone training and it felt really great! I was suppose to bike 10 miles or for 30 minutes, I think whichever came first. I worked really hard, hoping to finish the 10 miles in 25 minutes; my cadence was about 110 the whole time on level 8 (do the levels even mean anything?)

I felt like I was speeding along, but it took exactly 28 minutes to complete the 10 miles. Not quite as fast as I wanted to go...

The last two minutes I slowed down and cooled off... but the bike was tricky... it seemed that in those 2 minutes, I went .7 miles... sneaky bike, moving just as far even though I was pedaling half as much.

I wonder how far I really went?

Xna, graphics and team edition, oh my

The next step in my quest to only code my xna games in team edition was working with graphics. This proved to be a little more difficult because graphics need to be built inside Xna projects.

So, I needed to break my rules a little...
New rule:
Graphics can live in an Xna library, that is neither living in the main game solution or the GameShell exe assembly.

In Xna, graphics are just content loaded from disk built as "xnb" files, so they only need to be in the TitleLocation of the StorageContainer when your game is running (this is where the ContentManager Loads). If you look at a project containing pipeline content, you'll see an ItemGroup node:

<ItemGroup>
<Content Include="Image.jpg">
<XNAUseContentPipeline>true</XNAUseContentPipeline>
<Importer>TextureImporter</Importer>
<Processor>SpriteTextureProcessor</Processor>
<Name>spriteImage</Name>
</Content>
</ItemGroup>

So, if you wanted to, you could create an Xna library project and then just add content to it manually by copying images into a child directory and adding xml to the project file. Or, you can keep Express edition open for your graphics and build them as you need them.

So, now I have a graphics library with all my assets. Once it builds, I need to put these files in my debug directory if I want to use them, but as one of my stipulations, I didn't want to have any post build steps, so I made the following modifications to my Program.cs class in GameShell:


for (int i = argIndex; i < args.Length; i++)
{
string graphicsPath =
Path.Combine(args[i], @"bin\x86\Debug");
if (Path.IsPathRooted(graphicsPath) == false)
{
graphicsPath = Path.Combine(projectPath, graphicsPath);
}
foreach (string file in Directory.GetFiles(graphicsPath))
{
File.Copy(file, Path.Combine(debugDirectory,
Path.GetFileName(file)),
true);
}
}

Basically, I added the logic to the GameShell that any additional parameters to the application are graphic resources. If the resources aren't rooted, there are libraries inside the main project directory. So, this just goes through all those folders and copies all the files -- simple.

Still with me? This is a long one... BTW -- I have never even tried to run this on my xbox, I do all my coding on my laptop on my long ass ride home on the train so I take no responsibility for your boxes :P Also, if someone came up with a better solution, please tell me cause I'm without internet on this long ass train ride!

Yay, so now I have all the assets I need :)

Or so I thought...

I couldn't load any of these xnb resources. The content.Load was only working with resources in the bin directory GameShell :(

Reflector to the rescue...

I found this bit of code, used to determine where to find graphics:

public static string TitleLocation
{
get
{
string text1 = string.Empty;
Assembly assembly1 = Assembly.GetEntryAssembly();
if (assembly1 == null)
{
assembly1 = Assembly.GetCallingAssembly();
}
if (assembly1 != null)
{
text1 = Path.GetDirectoryName(
new
Uri(assembly1.EscapedCodeBase).LocalPath);
}
return text1;
}
}

As you can see, its using the entry assembly (or calling assembly) to determine the location of content...

So, back to my original solution with the app domains... oooo I was being clever :P

A few minutes of hacking in some appdomain code and voila, the game will only execute in the main appdomain... d'oh -- wasn't being clever after all, but I think I got that out of my system.

Returning back to my graphics copying code, I decided the simplest approach is copying the assets into the TitleLocation in Program.cs. A slight modification to the file and finally, I'm debugging my Game in Team Edition with Graphics!!!

And there was much rejoicing... yay.

I think I've put off writing some games long enough :P

Thursday, February 15, 2007

They forgot about me...

I'm busy writing today... too many meeting distractions...

I decided to check in with the Leukemia and Lymphoma Society today since I haven't heard about when training for my century ride was starting. And it turns out it started 2 weeks ago! I'm 20 miles behind :(

I'm a little bummed, but am ready to start and really don't want this to keep me from accomplishing my goal of riding a bike 100 miles and raising money for the Leukemia and Lymphoma society.

You can help me reach my goals here.

Wish me luck!!

Code Camp 2007

Looks like I'll be giving 2 presentations at Code Camp 2007 in NYC with a fellow developer from Oxygen, Oksana Udovitska. We're hosting two talks, The Gentle Art of Pair Programming and Testing in C# with RhinoMocks. Hopefully, people will learn something or at least be entertained. I'm thinking a code session taught by two hot chicks will be enough! hahaha

Code camp is in midtown on March 3rd, which is a Saturday (yeah, totally sucks, no?) and its from 9 - 6 or something like that...

Luke Melia -- another excellent developer on our team is also hosting a chat about leveraging the WPF command pattern with dependency injection. It should be good!

base test class

one thing that can make your tests real messy, real fast is duplicated code. however, with mocks, its really hard to get rid of duplication and keep your code readable.

a simple first step to uniform tests is a base test class that you inherit from in all your classes. use this class to setup your mock repository, replay, verify, tear down and do any custom setup your application needs for all your tests.



[TestFixture]
public void BaseTest
{
protected MockRepository _mocks;


[SetUp]
public virtual void Setup()
{
_mocks = new MockRepository();
}

[TearDown]
public virtual void TearDown()
{
}

protected virtual void FinalizeAll()
{
_mocks.ReplayAll();
}

protected void CreateMock<T>()
{
return _mocks.CreateMock<T>();
}

protected T XamlSerializeAndDeserialize<T>(T original)
{
using (MemoryStream stream = new MemoryStream())
{
XamlWriter.Save(original, stream);
stream.Position = 0;
return (T)XamlReader.Load(stream);
}
}
}


We keep the MockRepository protected because there are so many methods on it that inheritors may want to use, but use the base tests methods usages of _mocks when they exist. Also, we call the method that ReplaysAll "FinalizeAll" because methods that override often do more than just replay the mocks, they finalize the state of the other objects in the test. However, this may not be the best name, considering what "finalize" means in the c# world...

If you use an object management framework, logging or other common mocks, the base class can take the responsibility of setting those up.

As you can see, we added a method, "XamlSerializeAndDeserialize," since we test this in many of our classes, you could put this in a separate Assert class too, but it really depends on how often its used and what your team likes.

As your tests evolve, factories to create common mock objects and classes to do custom Asserts are also really helpful. One test class we've found really helpful is a PropertyChangedEventTester that will hook into any class that implements INotifyPropertyChanged and keep track of events.

all about the mocks

i love mocks. i really do. if i could, i would marry mocks, have lots of mock babies, be a grandmock; you get the idea...

the top reasons i love mocks:
1. focus only on what you are testing
2. other classes won't break your tests
3. create new interfaces and use them before they exist
4. use functionality without knowledge
5. i hate math
6. keep the file system, networks and other real resources out of your unit tests

i'll post examples of each of these reasons

a lot of black box testers have valid reasons for disliking mocks, but the benefits surpass any downside i have ever read or encountered. i use rhino mocks, which uses reflection, so some major downsides of mocks, such as difficult refactoring and type casting are completely avoided.

did i mention i love mocks?

thank you rhino mocks!!!

One other must with mocks is dependency injection. In the past I've written my own object management framework to handle injection, but we've been using the castle framework and its totally excellent, i love this too!!! It takes away all the thinking of dependency injection and lets you focus only on your tests and interfaces. An absolute must!!

Tuesday, February 13, 2007

if you don't need the exception...

don't declare a variable...

try
{
some code...
}
catch (ExceptionIWantToCatch)
{
}

No warnings, no cheesy statements to get rid of warnings...

If you don't care about the exception type, just catch{}

Monday, February 12, 2007

i just can't do it...

Code without resharper and visual assist that is...

After 10 minutes of my first Xna tutorial, I decided my first task would be to do all my developing in team edition.

Being my own customer, I made up the following criteria:
1. I can create a new c# library in vs team edition that contains a Game class which can be debugged/run from vs team edition
2. No post build copying of project output
3. No need for maintaining 2 separate solutions for each game
4. No dependencies between my game projects

In order to fulfill these, I created a new Xna solution called GameShell. I deleted the Game class, leaving Program.cs which I filled in with this code:
static void Main(string[] args)
{
string assemblyFilename = args[0];
string path = args[1];

Environment.CurrentDirectory = path;
Assembly assembly = Assembly.LoadFile(Path.Combine(path, assemblyFilename));
string typeName = args[2];
Game game = (Game)assembly.CreateInstance(typeName);
game.Run();
}

I used Assembly.LoadFile, because using Type.GetType(gameTypeName) was returning null... I don't think anything was spelled wrong, but I was feeling lazy, so I used the code above...

Its sad to admit, but before I thought to set Environment.CurrentDirectory, I had created a new appdomain that was rooted in the other directory and had a lovely class, GameStarter : MarshalByRef, that created and ran the game, which I thought was very clever, but completely unnecessary)


Now that I had GameShell to execute my game, I needed a game to run. I created a c# library in Team Edition, added references to Microsoft.Xna.Framework and Microsoft.Xna.Game and then added a game class to the project. Actually its Game1 from the first tutorial from the documentation (very exciting). Now that the project was ready to debug/run, I went into the project properties and changed the Debug settings so that it ran GameShell.exe with the proper command line arguments (AgileSolutions.GameLib.dll, FullPathToDebugDirectory, AgileSolutions.GameLib.Game1)

Viola! The game ran and I can now write any game library with my favorite tools and run it without any headaches... one minor issue though, graphics... you know, not the most important part of the video game, right?

For this first project, I cheated and put my graphics in the GameShell assembly, a big no no, but I'm gonna do some reading and learn more about content pipeline assets and we'll see what happens. Any ideas?

Wednesday, February 7, 2007

XNA

In addition to this very exciting blog, another goal for the year is to experiment with a new technology. Originally I was going to play around with Ruby, but I've decided to try out XNA instead. I was all psyched and ready to embark on the journey to creating my first xbox game when I discovered the following:

1. XNA development is only supported in VS Express addition!!! This is most upsetting because I cannot work without resharper and visual assist. Really, I can't. I keep doing things like ctrl-b, ctrl-alt-F7, ctrl-alt-v, shift F6, the list goes on... And intellisense without the ability to misspell just does not work well for me... I need colored listboxes!!!

2. No xbox live support :( this wasn't as much of a downer as #1, but I was looking forward to making up some clever achievements

3. How am I to test drive without add-ins? This really goes with #1, but this isn't about making development easier, this is about how I develop.

Despite the above, I'm still excited about my game idea and I hope its fun!

Wish me luck