MtG Player Assistant


Tic Tac Toe

I wrote Tic Tac Toe as a first attempt at coding a game. I chose Tic Tac Toe because of the film War Games.

Here is an example of the AI code used when the AI must play a blocking move to prevent the player playing a winning piece.

public static void BlockingMove(ObservableCollection gameBoard, string playerPiece, string aiPiece, int firstSquare, int secondSquare, int thirdSquare, out bool blockSuccess)
blockSuccess = false;
bool firstPiece = gameBoard[firstSquare].pieceContent == playerPiece ? true : false;
bool secondPiece = gameBoard[secondSquare].pieceContent == playerPiece ? true : false;
bool thirdPiece = gameBoard[thirdSquare].pieceContent == playerPiece ? true : false;

if (firstPiece == true && secondPiece == true)
if (gameBoard[thirdSquare].pieceContent == " ")
gameBoard[thirdSquare].pieceContent = aiPiece;
blockSuccess = true;

if (firstPiece == true && thirdPiece == true)
if (gameBoard[secondSquare].pieceContent == " ")
gameBoard[secondSquare].pieceContent = aiPiece;
blockSuccess = true;

if (secondPiece == true && thirdPiece == true)
if (gameBoard[firstSquare].pieceContent == " ")
gameBoard[firstSquare].pieceContent = aiPiece;
blockSuccess = true;


This app was designed as a tool for analysing personal finance and determining methods to increase disposable income.

The main view of the app displays an annual summary of income, expense and disposable for each month. There is then an income section and expense section which display data broken down by category (user defined). The expense grouping can be switched between category or date and there are chart or list display options.

2017-03-21 (1)
Chart view of income

I made improvements to the UX by creating a simple ‘guide’ for the user. When the app launches the user is prompted toward creating an account and then adding categories.

private void AddAccount_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
	AddAccount acc = (AddAccount)sender;
	UserData newAccount = new UserData("account", acc.newAccountName, acc.newAccountType);

//if the user has set up first account prompt toward adding categories
	if (dataManager.userAccounts.Count == 1)
//find the add category button to display its flyout
		object button = FindName("AddCategory");
		FlyoutBase.ShowAttachedFlyout(button as Button);
		dataManager.accountName = dataManager.userAccounts[0].dataContent;
		dataManager.accountType = dataManager.userAccounts[0].dataTypeOrColour;

	if (dataManager.userAccounts.Count > 0)
		appLock = false;

As the app grew I wanted to ensure it worked across the range of Windows devices. It was then that I included the visual state manger.

<DataTemplate x:Key="MonthTemplate">
							<AdaptiveTrigger MinWindowWidth="720"/>
							<Setter Target="Amount.(RelativePanel.RightOf)" Value="Reference"/>
							<Setter Target="Reference.Width" Value="240"/>
							<AdaptiveTrigger MinWindowWidth="0"/>
							<Setter Target="Amount.(RelativePanel.RightOf)" Value="Reference"/>
							<Setter Target="Reference.Width" Value="175"/>

<Style TargetType="TextBlock">
					<Setter Property="Margin" Value="4"/>
					<Setter Property="Width" Value="90"/>


			<TextBlock x:Name="Amount" 				Text="{Binding itemValue}" 				Foreground="{Binding itemColour}" 				TextAlignment="Right"/>
			<TextBlock x:Name="Reference" 				FontStyle="Italic" 				Text="{Binding itemReference}" 				Foreground="{Binding itemColour}"/>


During initial testing I realised the data input could be improved through appropriate use of auto suggest boxes.

Here is the code for the auto suggest box

private void Category_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
	string inputText = Category.Text;
	int inputLength = Category.Text.Length;

	if (inputLength > 0)
		if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
			List<string> filteredList = categories.FindAll(w => w.ToLower().StartsWith(inputText.ToLower())).ToList();
			filteredList.Add(inputText + " (New)");
			Category.ItemsSource = filteredList;
		//a simple workaround for the "(new)" keyword in the drop down
		if (inputText.EndsWith(" (New)") == true)
			sender.Text = inputText.Remove(inputLength - 6);
	//keep add button disabled until basic data has been provided
	IsPrimaryButtonEnabled = Referenece.Text.Length > 0 && Category.Text.Length > 0 ? true : false;

Excel pop Up Calender

Some time ago I wanted to add a pop up calendar to an Excel workbook I was developing. After looking through the Add-On’s and then spending a reasonable amount of time searching the internet, I decided it would just be easier to create my own.

I styled the pop up using the desktop calendar as it seemed a familiar layout that people would understand.

My toolbox was limited to vba and userforms so ultimately the UI would feel basic in comparison to the modern Windows 10 styles. None the less I’m quite proud of my little pop up which can easily be imported into any workbook.

The above images show the main view and the year view or month selection. The month view displays the current or selected month dates with the previous and next months dates greyed out/disabled and today shown in red. The spin buttons allow for a quick scroll through the months.

Clicking on the month and year ‘header’ will switch the display to the year view where a different month can be selected. The year can be changed using the spin button and after selecting a month the view will switch back.

An example of the vba code used,

Public Sub UpdateCalander(selectedMonth As Integer, selectedYear As Integer)
Dim thisDay As Integer
thisDay = CInt(Format(Date, "dd"))
Dim thisMonth As Integer
thisMonth = Month(Now())
Dim thisYear As Integer
thisYear = Year(Now())
Dim currentMonthStart As Date
currentMonthStart = CDate("01/" & selectedMonth & "/" & selectedYear)
Dim dayMonthStarted As Integer
dayMonthStarted = weekday(currentMonthStart, vbMonday)
Dim firstMondayFirstWeek As String
firstMondayFirstWeek = Format(currentMonthStart - (dayMonthStarted - 1), "dd")
Dim nextMonthStart As String
nextMonthStart = DateAdd("m", 1, currentMonthStart)
Dim currentMonthEnd As String
currentMonthEnd = DateAdd("d", -1, nextMonthStart)
Dim currentMonthMaxDay As String
currentMonthMaxDay = Format(currentMonthEnd, "dd")
Dim previousMonthEnd As String
previousMonthEnd = DateAdd("d", -1, currentMonthStart)
Dim DayButton(42) As CommandButton
'create array of buttons
For i = 1 To 42
Set DayButton(i) = Controls("CommandButton" & i)
Next i
'the month buttons can be styled using the following loops
'you can access the buttons as follows "DayButton(i).ForeColor"
'apply styling to all buttons
For i = 1 To 42
DayButton(i).Enabled = True
DayButton(i).ForeColor = RGB(9, 75, 122)
Next i
'apply styling to buttons before current month starts
For i = 1 To dayMonthStarted - 1
DayButton(i).Caption = CInt(firstMondayFirstWeek) + (i - 1)
DayButton(i).Enabled = False
Next i
'apply styling to current month buttons
For i = dayMonthStarted To CInt(currentMonthMaxDay + dayMonthStarted) - 1
DayButton(i).Caption = i - (dayMonthStarted - 1)
If i = thisDay + (dayMonthStarted - 1) And selectedMonth = thisMonth And selectedYear = thisYear Then DayButton(i).ForeColor = RGB(256, 0, 0)
Next i
'apply styling to buttons of next month
For i = currentMonthMaxDay + dayMonthStarted To 42
DayButton(i).Caption = i - (currentMonthMaxDay + dayMonthStarted) + 1
DayButton(i).Enabled = False
Next i
'update the header text
Select Case selectedMonth
Case 1
HeaderText.Caption = "January" &amp; " " &amp; yearClicked
Case 2
HeaderText.Caption = "February" &amp; " " &amp; yearClicked
Case 3
HeaderText.Caption = "March" &amp; " " &amp; yearClicked
Case 4
HeaderText.Caption = "April" &amp; " " &amp; yearClicked
Case 5
HeaderText.Caption = "May" &amp; " " &amp; yearClicked
Case 6
HeaderText.Caption = "June" &amp; " " &amp; yearClicked
Case 7
HeaderText.Caption = "July" &amp; " " &amp; yearClicked
Case 8
HeaderText.Caption = "August" &amp; " " &amp; yearClicked
Case 9
HeaderText.Caption = "September" &amp; " " &amp; yearClicked
Case 10
HeaderText.Caption = "October" &amp; " " &amp; yearClicked
Case 11
HeaderText.Caption = "November" &amp; " " &amp; yearClicked
Case 12
HeaderText.Caption = "December" &amp; " " &amp; yearClicked
End Select
End Sub

Here is a workbook showing the calendar icon and the result of selecting a date:

To get the pop up calendar, download a copy of the workbook. After downloading the workbook you’ll have access to the vba files which can be exported and saved.

Alternatively feel free to contact me if you want to know more or require