Step 4 . Add BalloonActions.cs class file with the following code:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace ShootBalloonForBlog
{
public class BalloonAction
private static string[] nameAction =
"","","","","",
"+2",
"+3",
"+4",
"+5",
"-1",
"-2",
"*2",
"*3",
"*4",
"*5",
"/2",
"*0",
"??", //has to be the last!
};
private static string[] nameActionQuestionMark =
public static string GetRandomAction(Random random)
return nameAction[random.Next(nameAction.Length)];
}
public static int EvaluateAciton(string action, int oriValue)
int retValue = oriValue;
if (action.Length == 0)
return oriValue + 1;
try
switch (action[0])
case '+':
retValue = oriValue + Convert.ToInt32(action.Substring(1));
break;
case '-':
retValue = oriValue - Convert.ToInt32(action.Substring(1));
case '/':
retValue = oriValue / Convert.ToInt32(action.Substring(1));
case '*':
retValue = oriValue * Convert.ToInt32(action.Substring(1));
case '?':
Random random = new Random();
string randomExpression = nameActionQuestionMark[random.Next(nameActionQuestionMark.Length)];
retValue = EvaluateAciton(randomExpression, oriValue);
catch
if (retValue < 0) retValue = 0;
return retValue;