Fun Stuff · Games · Programming

Two-Way Box released on the Google PlayStore

Two-Way Box IconTwo-Way Box released on the Google PlayStore: 

Pro Edition: https://play.google.com/store/apps/details?id=com.federrot.twowaybox

Free Edition: https://play.google.com/store/apps/details?id=com.federrot.twowayboxfree

 


Two-Way Box is a two-player inverse-space line-clearing black-white box-game that allows two players to play in the same game field on the same device.

Player 1 plays from the bottom to the top with white boxes in a black game field, while at the same time player 2 plays from the top to the bottom with black boxes in a white game field.

Features:
* 2 Player mode: The player with most wins in 4 matches wins. Both players play on the same device.
* 1 Player modes: Play alone as the white or black player.

Source Code:
The source code of the game has been published for learning purposes on github: https://github.com/tivtag/twowaybox

Advertisements
Design Patterns & Best Practices · Programming

Code: Abstract Unit of Work

Today I’ve been tinkering about how to best implement the
Unit of Work/Repository patterns at the client (service)-side.

Warning! This blog post contains experimental source code!

What I want:
1. Simple to use. Usage is easy to explain.
2. Doesn’t leak the underlying data access framework.
3. Supports transactions.
4. Supports multiple parallel units of work when required.
5. Manages the session/context scope for me.
Not quite sure whether I need nested UoWs.

Here is what I have come up so far. I’ll update this post once I figure out something new about all of this.


// Scoped unit of work:
// 1. Quite simple
// 2. Repositories use the currently active UoW
// 3. Doesn't support multiple UoWs to be active
// 4. Using block scopes the current session/object context
// 5. Repositories are injected using the constructor
using( UnitOfWork.Start() )
{
   var user = this.userRepository.GetUserByName( "Paul" );
   var skill = this.skillRepository.GetSkillByName( "Ruby" );
   user.Award( skill );
}

// Scoped UoW, that also starts a new transaction:
// When the UoW is disposed it will be rolled-back
// unless it has been committed.
using( var uow = UnitOfWork.Start( transaction: true ) )
{
   var user = this.userRepository.GetUserByName( "Paul" );
   var skill = this.skillRepository.GetSkillByName( "Ruby" );
   user.Award( skill );
   uow.Commit();
}

Update:
If the current Unit of Work is marked to be unique for each thread (ThreadStaticAttribute) it can safely handle multiple ‘requests’ at the same time. No need for any >special case< handling.

Thanks to @pragmatrix for pointing this out on Twitter. :)