protected IMove createMoveFromType(MoveType typeOfMove) { Type t = Type.GetType(string.Format("{0}.{1}", Assembly.GetExecutingAssembly().GetName().Name, typeOfMove.ToString())); IMove move = Activator.CreateInstance(t) as IMove; PlayedMoves.Add(move); Console.WriteLine("{0}{1}{2}", Name, Constants.COMPUTER_MOVE, move.TypeOfMove); return(move); }
public override IMove Move() { if (PlayedMoves.Count == 0) { return(generateRandomMove()); } else { IMove lastMove = PlayedMoves.Last(); //If we add lizard, spock etc, then we have to pick a random movetype among defeaters of last move. //We won't have to edit this code, when we add new movetypes in later. MoveType beatLast = lastMove.LoseAgainst[new Random().Next(lastMove.LoseAgainst.Count)]; return(createMoveFromType(beatLast)); } }
public override IMove Move() { string input = string.Empty; while (!Enum.GetNames(typeof(MoveType)).Contains(input)) { Console.Write("{0}, {1}", Name, Constants.ENTER_YOUR_MOVE); input = Console.ReadLine(); } Type t = Type.GetType(string.Format("{0}.{1}", Assembly.GetExecutingAssembly().GetName().Name, input)); IMove move = Activator.CreateInstance(t) as IMove; PlayedMoves.Add(move); return(move); }