public override void HandleOut(string command, List <string> args, string line) { switch (command) { case "opponentIsReady": { Console.WriteLine("Opponent is ready!"); Program.connection.SendCommand(setup.ToCommand()); } return; case "opponentLayout": { int cnt; Int32.TryParse(args[0], out cnt); string name; int x, y, rotated; int argOffset = 1; for (int i = 0; i < cnt; i++) { name = args[argOffset]; Int32.TryParse(args[argOffset + 1], out x); Int32.TryParse(args[argOffset + 2], out y); Int32.TryParse(args[argOffset + 3], out rotated); opponentSetup.TryPlace(name, x, y, rotated == 1 ? true : false); argOffset += 4; } } if (setup.UnitsArePlaced() && opponentSetup.UnitsArePlaced()) { Program.SwitchState(new GameplayState(setup, opponentSetup, yourTurn)); } return; } base.HandleOut(command, args, line); }
public override void HandleLocal(string command, List <string> args, string line) { switch (command) { case "print": { if (args.Count == 0) { break; } if (args[0] == "map") { setup.PrintMap(); return; } if (args.Count == 1) { break; } if (args[0] == "unplaced" && args[1] == "units") { for (int i = 0; i < setup.unplacedEntities.Count; i++) { Console.WriteLine(setup.unplacedEntities[i].name + " of size " + setup.unplacedEntities[i].layoutStr); } } if (args[0] == "placed" && args[1] == "units") { for (int i = 0; i < setup.placedEntities.Count; i++) { Console.WriteLine(setup.placedEntities[i].layout.name + " " + setup.placedEntities[i].x + " " + setup.placedEntities[i].y); } } } return; case "place": { if (args.Count != 4) { break; } string unitName = args[0]; int x, y, rotationInt; bool rotated; Int32.TryParse(args[1], out x); Int32.TryParse(args[2], out y); Int32.TryParse(args[3], out rotationInt); rotated = rotationInt == 0 ? false : true; Memento nMemento = setup.CreateMemento(); if (setup.TryPlace(unitName, x, y, rotated)) { if (setup.UnitsArePlaced()) { Console.WriteLine("All units are placed!"); Program.connection.SendCommand("opponentIsReady"); ReadyToPlayState state = new ReadyToPlayState(setup); Program.SwitchState(state); state.Init(opponentIsReady); } else { memento = nMemento; Console.WriteLine("Unit placed!"); } } } return; case "undo": { if (memento != null) { setup.Restore(memento); memento = null; Console.WriteLine("Unit restored"); } else { Console.WriteLine("Cant undo"); } } return; } base.HandleLocal(command, args, line); }