public CreateTemplateCode CreateBoardInterfaceForAllBoards(string name, string description, string meta, Guid intefaceType) { var retValue = CreateTemplateCode.Updated; foreach (var board in Db.BoardTypes) { var boardInterface = Db.BoardInterfaces.SingleOrDefault(a => a.This2InterfaceType == intefaceType); if (boardInterface == null) { boardInterface = new BoardInterface(); boardInterface.ObjId = Guid.NewGuid(); boardInterface.This2BoardType = board.Type; retValue = CreateTemplateCode.Created; } boardInterface.Name = name; boardInterface.Description = description; boardInterface.This2InterfaceType = intefaceType; boardInterface.Meta = meta; if (retValue == CreateTemplateCode.Created) { Db.BoardInterfaces.Add(boardInterface); } else { Db.BoardInterfaces.Update(boardInterface); } } return(retValue); }
public CreateTemplateCode CreateBoardInterface(Guid uid, string name, string description, Guid boardGuid, string meta, Guid intefaceType) { var boardInterface = Db.BoardInterfaces.SingleOrDefault(a => a.ObjId == uid); var retValue = CreateTemplateCode.Updated; if (boardInterface == null) { boardInterface = new BoardInterface(); boardInterface.ObjId = uid; boardInterface.This2BoardType = boardGuid; retValue = CreateTemplateCode.Created; } boardInterface.Name = name; boardInterface.Description = description; boardInterface.This2InterfaceType = intefaceType; boardInterface.Meta = meta; if (retValue == CreateTemplateCode.Created) { Db.BoardInterfaces.Add(boardInterface); } else { Db.BoardInterfaces.Update(boardInterface); } return(retValue); }
public IList <BoardInterface> GetBoardInterfaces() { var list = new List <BoardInterface>(); var this2BoardType = new Guid("2153e8f3f0e0428b9713a17855795179"); var virt = new BoardInterface { ObjId = new Guid("840e94cfa86b483b87a47226d0494c99"), This2BoardType = this2BoardType, This2InterfaceType = GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Virtual), Name = "Virtual", Description = "Virtual", Meta = "virt://" }; var eth = new BoardInterface { ObjId = new Guid("6a210ef8a7e646058d1b1eb5752e6080"), This2BoardType = this2BoardType, This2InterfaceType = GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Ethernet), Name = "Ethernet", Description = "Ethernet", Meta = "eth://" }; list.Add(virt); list.Add(eth); return(list); }
public void Run(BoardInterface b) { if (this.Valid(b) && (!b.Initializing || this.RunWhileInitializing)) { this.Perform(b); } }
public Game() { InitializeComponent(); board = new Board(); BoardInterface boardInterface = new BoardInterface(panelCheckers, this); }
// variables used for testing //public int addPieces; //public bool colsTested = false; //public int[] colsToTest = {5}; // Use this for initialization void Start() { var difficulty = PreGameSettings.getDifficulty(); board = new BoardControl(6, 4, FieldPrefab, white, black); currentPlayer = new AiControl(difficulty, board, "white"); waitingPlayer = new HumanPlayerControl(board, "player1", "black"); }
public static void Main() { System.Console.WriteLine("The graphics program will begin now."); BoardInterface Board_app = new BoardInterface(); Application.Run(Board_app); System.Console.WriteLine("This graphics program has ended. Bye."); } //End of Main function
protected override void Perform(BoardInterface b) { try { SendKeys.Send(Text); } catch (InvalidOperationException) { } }
public override void SetBoardInterface(BoardInterface board) { base.SetBoardInterface(board); if (this.LedPin != null) { _board.OutputPins.Add(this.LedPin); _board.PinSet += BoardInterface_PinSet; } }
public Placement choosePlacement(ShipInterface ship, BoardInterface board) { ConsoleGraphics.showField(board, 70); bool isVertical = checkIsVertical(); Console.WriteLine("Введите кординату X(1 - 10):"); string answ = Console.ReadLine(); if (answ == "пауза") { throw new PauseException(); } int x = int.Parse(answ); Console.WriteLine("Введите кординату Y(1 - 10):"); answ = Console.ReadLine(); if (answ == "пауза") { throw new PauseException(); } int y = int.Parse(answ); Position position = null; BoardInterface boardToShow = board.Clone() as BoardInterface; try { position = new Position(x, y); boardToShow.placeShip(ship, position, isVertical); } catch { Console.WriteLine("данные введены неправильно, введите заново"); return(choosePlacement(ship, board)); } Console.Clear(); ConsoleGraphics.showField(boardToShow, 70); while (true) { Console.WriteLine("Вы уверены в своём выборе?"); answ = Console.ReadLine(); if (answ == "да") { return(new Placement(position, isVertical)); } else if (answ == "нет") { return(choosePlacement(ship, board)); } } }
// Use this for initialization public HumanPlayerControl(BoardInterface board, string name, string color) { this.board = board; this.playerColor = color; if (color.Equals("white")) { opponentColor = "black"; } else { opponentColor = "white"; } }
public void loadGame(string filename) { using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate)) { BinaryFormatter formatter = new BinaryFormatter(); Game newGame = formatter.Deserialize(fs) as Game; board1 = newGame.board1; board2 = newGame.board2; player1 = newGame.player1; player2 = newGame.player2; Player1Ready = newGame.Player1Ready; Player2Ready = newGame.Player2Ready; } }
// Use this for initialization public AiControl(int confusion, BoardInterface board, string color) { this.confusion = confusion; this.board = board; this.playerColor = color; if (color.Equals("white")) { opponentColor = "black"; } else { opponentColor = "white"; } }
public Game(PlayerInterface player1, PlayerInterface player2) { this.player1 = player1; this.player2 = player2; board1 = new Board(); board2 = new Board(); OnPause = false; Ships = new Dictionary <string, ShipInterface>(); Ships.Add("Aircraft carrier", new Ship(5)); Ships.Add("Battleship", new Ship(4)); Ships.Add("Destroyer", new Ship(3)); Ships.Add("Submarine", new Ship(3)); Ships.Add("Patrol boat", new Ship(2)); }
public Placement choosePlacement(ShipInterface ship, BoardInterface board) { Random rnd = new Random(); while (true) { try { Position position = new Position(rnd.Next(1, 10), rnd.Next(1, 10)); bool isVertical = rnd.Next(0, 1) == 1; BoardInterface tempBoard = board.Clone() as BoardInterface; tempBoard.placeShip(ship, position, isVertical); return(new Placement(position, isVertical)); } catch { } } }
public static void showField(BoardInterface board, int positionLeft) { int coursorLeft = Console.CursorLeft; int coursorTop = Console.CursorTop; Console.SetCursorPosition(positionLeft, 0); Console.Write("# 1 2 3 4 5 6 7 8 9 10#"); Console.SetCursorPosition(positionLeft - 1, 1); for (int i = 1; i <= 10; i++) { string label = (i / 10 == 1)? $"{i}" : $" {i}"; Console.Write(label); for (int j = 1; j <= 10; j++) { Position position = new Position(j, i); try { switch (board.getStatus(position)) { case ShipStatus.INTACT: Console.Write(" *"); break; case ShipStatus.HIT: Console.Write(" X"); break; case ShipStatus.SUNK: Console.Write(" #"); break; } } catch (InvalidPositionException e) { Console.Write(" "); } } Console.Write($" {i}"); Console.SetCursorPosition(positionLeft - 1, i + 1); } Console.CursorLeft += 1; Console.Write("# 1 2 3 4 5 6 7 8 9 10#"); Console.SetCursorPosition(coursorLeft, coursorTop); }
private void checkStatus(Position position, PlayerInterface currPlayer, BoardInterface enemyBoard) { try { switch (enemyBoard.getStatus(position)) { case ShipStatus.HIT: currPlayer.shotResult(position, ShotStatus.HIT); break; case ShipStatus.SUNK: currPlayer.shotResult(position, ShotStatus.SUNK); break; } } catch { currPlayer.shotResult(position, ShotStatus.MISS); } }
protected override void Perform(BoardInterface b) { Logger.Log("RunScriptAction: FileName: \"{0}\" Arguments: \"{1}\"", FileName, Arguments); try { ProcessStartInfo startInfo = new ProcessStartInfo(FileName, Arguments); startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; Process p = Process.Start(startInfo); p.WaitForExit(); String stdout = p.StandardOutput.ReadToEnd(); if (!String.IsNullOrWhiteSpace(stdout)) { Logger.Log("RunScriptAction: Output:\n{0}", stdout); MessageBox.Show(stdout); } } catch (Win32Exception e) { String message = String.Format("An error occured while executing the script: FileName: \"{0}\" Arguments: \"{1}\"\n{2}", FileName, Arguments, e); Logger.Log(message); MessageBox.Show(message); } }
public IList <BoardInterface> GetBoardInterfaces() { var list = new List <BoardInterface>(); var this2BoardType = new Guid("2153e8f3f0e0428b9713a17855795179"); var virt = new BoardInterface { ObjId = new Guid("840e94cfa86b483b87a47226d0494c99"), This2BoardType = this2BoardType, This2InterfaceType = new Guid("177a91443f074fd2a71d51db61c51ad5"), Name = "Virtual", Description = "Virtual", Meta = "virt://" }; var usb1 = new BoardInterface { ObjId = new Guid("4e70490c4e104c20b76c27032d2bd318"), This2BoardType = this2BoardType, This2InterfaceType = new Guid("4a02532b4aa04b4ba6a77a0ab6dff5bd"), Name = "USB1", Description = "USB1", Meta = "/dev/ttyUSB0" }; var usb2 = new BoardInterface { ObjId = new Guid("b9e3446faa3b4f23b50faf36e859e785"), This2BoardType = this2BoardType, This2InterfaceType = new Guid("4a02532b4aa04b4ba6a77a0ab6dff5bd"), Name = "USB2", Description = "USB2", Meta = "/dev/ttyUSB1" }; var usb3 = new BoardInterface { ObjId = new Guid("f843ae5d95d44336909dae37de835266"), This2BoardType = this2BoardType, This2InterfaceType = new Guid("4a02532b4aa04b4ba6a77a0ab6dff5bd"), Name = "USB3", Description = "USB3", Meta = "/dev/ttyUSB2" }; var usb4 = new BoardInterface { ObjId = new Guid("13101395b05c42be9c0b7915303f9de4"), This2BoardType = this2BoardType, This2InterfaceType = new Guid("4a02532b4aa04b4ba6a77a0ab6dff5bd"), Name = "USB4", Description = "USB4", Meta = "/dev/ttyUSB3" }; var eth = new BoardInterface { ObjId = new Guid("6a210ef8a7e646058d1b1eb5752e6080"), This2BoardType = this2BoardType, This2InterfaceType = new Guid("c45eda9672464fa092399ebb52e7ed66"), Name = "Ethernet", Description = "Ethernet", Meta = "eth://" }; list.Add(virt); list.Add(usb1); list.Add(usb2); list.Add(usb3); list.Add(usb4); list.Add(eth); return(list); }
public override bool Valid(BoardInterface b) { return(b.OutputPins.Contains(Pin)); }
protected override void Perform(BoardInterface b) { b.TogglePin(Pin); }
public virtual void SetBoardInterface(BoardInterface board) { _board = board; }
public override bool Valid(BoardInterface b) { return(true); }
public abstract bool Valid(BoardInterface b);
protected abstract void Perform(BoardInterface b);
public IList <BoardInterface> GetBoardInterfaces() { var list = new List <BoardInterface>(); var this2BoardType = new Guid("2153e8f3f0e0428b9713a17855795179"); var virt = new BoardInterface { ObjId = new Guid("840e94cfa86b483b87a47226d0494c99"), This2BoardType = this2BoardType, This2InterfaceType = GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Virtual), Name = "Virtual", Description = "Virtual", Meta = "virt://" }; var usb1 = new BoardInterface { ObjId = new Guid("4e70490c4e104c20b76c27032d2bd318"), This2BoardType = this2BoardType, This2InterfaceType = GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Usb), Name = "USB1", Description = "USB1", Meta = "/dev/ttyUSB0" }; var usb2 = new BoardInterface { ObjId = new Guid("b9e3446faa3b4f23b50faf36e859e785"), This2BoardType = this2BoardType, This2InterfaceType = GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Usb), Name = "USB2", Description = "USB2", Meta = "/dev/ttyUSB1" }; var usb3 = new BoardInterface { ObjId = new Guid("f843ae5d95d44336909dae37de835266"), This2BoardType = this2BoardType, This2InterfaceType = GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Usb), Name = "USB3", Description = "USB3", Meta = "/dev/ttyUSB2" }; var usb4 = new BoardInterface { ObjId = new Guid("13101395b05c42be9c0b7915303f9de4"), This2BoardType = this2BoardType, This2InterfaceType = GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Usb), Name = "USB4", Description = "USB4", Meta = "/dev/ttyUSB3" }; var eth = new BoardInterface { ObjId = new Guid("6a210ef8a7e646058d1b1eb5752e6080"), This2BoardType = this2BoardType, This2InterfaceType = GuidTemplateTypeAttribute.GetFromEnum(InterfaceTypeEnum.Ethernet), Name = "Ethernet", Description = "Ethernet", Meta = "eth://" }; list.Add(virt); list.Add(usb1); list.Add(usb2); list.Add(usb3); list.Add(usb4); list.Add(eth); return(list); }
public override bool Valid(BoardInterface b) { return(!String.IsNullOrEmpty(Text)); }
// variables used for testing //public int addPieces; //public bool colsTested = false; //public int[] colsToTest = {5}; // Use this for initialization void Start() { board = new BoardControl(6, 4, FieldPrefab, white, black); currentPlayer = new AiControl(30, board, "white"); waitingPlayer = new HumanPlayerControl(board, "player1", "black"); }
protected override void Perform(BoardInterface b) { b.SetLed(SetToState); }
protected override void Perform(BoardInterface b) { b.SetPin(Pin, SetToState); }