private void timer1_Tick(object sender, EventArgs e) { if (screwdriverIsMoving) { game.MoveScrewdriver(); } else { game.ReturnScrewdriver(); } if (game.CheckLockpickDurability()) { game.NewLockpick(); lockpicksUsed++; LockpicksUsedLabel.Text = "Lockpicks used: " + lockpicksUsed; } if (game.CheckLockState()) { game.NewScrewdriverAndLock(); score++; LocksOpenedLabel.Text = "Locks opened: " + score; } PlayingBoard.Refresh(); }
/// <summary> /// Creates the set number of Player objects /// </summary> /// <param name="numofPlyers">Number of players</param> public void AddPlayersToBoard(int numofPlyers) { for (int i = 0; i < numofPlyers; i++) { Player player; switch (i) { case 0: player = new Player(0, 0); Players[i] = player; PlayingBoard[0, 0].Controls.Add(Players[i]); player.BringToFront(); break; case 1: player = new Player(PlayingBoard.GetLength(0) - 1, 0); Players[i] = player; PlayingBoard[PlayingBoard.GetLength(0) - 1, 0].Controls.Add(Players[i]); player.BringToFront(); break; case 2: player = new Player(0, PlayingBoard.GetLength(1) - 1); Players[i] = player; PlayingBoard[0, PlayingBoard.GetLength(1) - 1].Controls.Add(Players[i]); player.BringToFront(); break; case 3: player = new Player(PlayingBoard.GetLength(0) - 1, PlayingBoard.GetLength(1) - 1); Players[i] = player; PlayingBoard[PlayingBoard.GetLength(0) - 1, PlayingBoard.GetLength(1) - 1].Controls.Add(Players[i]); player.BringToFront(); break; default: break; } } }
public void GetAllFields_WithOneStonesSet_ReturnsTheSetStone() { var objectUnderTest = new PlayingBoard().SetStone(0, 0, this._sampleStoneOne); var result = objectUnderTest.GetAllFields(); result.Should().Contain(this._sampleStoneOne); }
public Form1() { InitializeComponent(); SetParameters(); game.Start(); PlayingBoard.Refresh(); LockpicksUsedLabel.Text = "Lockpicks used: 0"; LocksOpenedLabel.Text = "Locks opened: 0"; }
public void GetAllLines_ReturnsTenLines() { var pb = new PlayingBoard(); var result = pb.GetAllLines(); result.Should().NotBeNull(); result.Should().HaveCount(10); }
public void Ctor_WithNextStoneAlreadyPresentOnPlayingField_ThrowsArgumentException() { var playfield = new PlayingBoard(); playfield = playfield.SetStone(0, 0, this._sampleStone); Action call = () => Substitute.For <GameStateBase>(playfield, this._sampleStone, Player.One); call.ShouldThrow <TargetInvocationException>().WithInnerException <ArgumentException>(); }
public void Ctor_WithANonNullPlayfieldAndANotSetNextStone_DoesNotThrowAnException() { var notSetStone = new Stone(Size.High, Surface.Flat, Color.Black, Shape.Square); var playfield = new PlayingBoard(); playfield = playfield.SetStone(0, 0, this._sampleStone); Action call = () => Substitute.For <GameStateBase>(playfield, notSetStone, Player.One); call.ShouldNotThrow(); }
public UIActionState TryTakeScreenshot(bool perform) { if (perform) { Rectangle bounds = PlayingBoard.Bounds; using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) { PlayingBoard.DrawToBitmap(bitmap, new Rectangle(0, 0, bounds.Width, bounds.Height)); Clipboard.SetImage(bitmap); } } return(UIActionVisibility.Enabled); }
public PlayController(Team teamWhite, Team teamBlack, PlayingBoard playingBoard) { TeamWhite = teamWhite; TeamBlack = teamBlack; TeamChange(); PlayingBoard = playingBoard; for (int i = 0; i < 3; i++) { for (int j = 0; j < playingBoard.NumX; j++) { if ((i + j) % 2 == 1) { TeamBlack.AddFigure(i, j); } if ((playingBoard.NumY - i - 1 + j) % 2 == 1) { TeamWhite.AddFigure(playingBoard.NumY - i - 1, j); } } } PlayingBoard.AddFigure(TeamBlack.Figures); PlayingBoard.AddFigure(TeamWhite.Figures); }
/// <summary> /// Places the Tile objects from the PlayingBoard matrix /// </summary> /// <param name="control">Which control the objects should be added</param> public void PlaceTiles(Control control) { int y = 70, x = 70; for (int i = 0; i < PlayingBoard.GetLength(0); i++) { for (int j = 0; j < PlayingBoard.GetLength(1); j++) { if (PlayingBoard[i, j] != null) { control.Controls.Add(PlayingBoard[i, j]); PlayingBoard[i, j].Location = new Point(y, x); x += 60; } else { x += 60; } } x = 70; y += 60; } control.Controls.Add(FreeTile); }
static void Main(string[] args) { PlayingBoard playingBoard = new PlayingBoard(); Team blackTeam = new Team(TeamColor.black, playingBoard); Team whiteTeam = new Team(TeamColor.white, playingBoard); PlayController playController = new PlayController(whiteTeam, blackTeam, playingBoard); do { Console.BackgroundColor = ConsoleColor.DarkYellow; Console.ForegroundColor = ConsoleColor.Green; Console.Write($"|{"",2}|"); for (int j = 0; j < playingBoard.NumX; j++) { Console.Write($"{j,6}|"); } Console.WriteLine(); for (int i = 0; i < playingBoard.NumY; i++) { Console.Write($"|{i,2}|"); for (int j = 0; j < playingBoard.NumX; j++) { var figB = blackTeam.Figures.Find(f => f.PozX == j && f.PozY == i); if (figB != null) { Console.ForegroundColor = ConsoleColor.Black; Console.Write($"{"black",6}"); Console.ForegroundColor = ConsoleColor.Green; } var figW = whiteTeam.Figures.Find(f => f.PozX == j && f.PozY == i); if (figW != null) { Console.ForegroundColor = ConsoleColor.White; Console.Write($"{"white",6}"); Console.ForegroundColor = ConsoleColor.Green; } if (figB == null && figW == null) { Console.Write($"{"",6}"); } Console.Write("|"); } Console.WriteLine(); } if (playController.CurrentTeam == blackTeam) { Console.WriteLine("Ходят черные"); } else { Console.WriteLine("Ходят белые"); } Console.WriteLine("Выберите фигуру:"); Console.WriteLine("Введите номер строки:"); int y; var GO = playController.CanGo().ToArray(); var FIG = playController.MustFight().ToArray(); var resY = playController.CanGo().Select(f => f.PozY).ToArray(); while (!(int.TryParse(Console.ReadLine(), out y)) || !(resY.Contains(y))) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверно ввели: так как нет такого номера. Введите заново!"); Console.ForegroundColor = ConsoleColor.Green; } Console.WriteLine("Введите номер столбца:"); int x; var resX = playController.CanGo().Where(f => f.PozY == y).Select(f => f.PozX).ToArray(); while (!(int.TryParse(Console.ReadLine(), out x)) || !(resX.Contains(x))) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверно ввели: так как нет такого номера. Введите заново!"); Console.ForegroundColor = ConsoleColor.Green; } Console.WriteLine("Введите номер строки куда пойдет:"); int yNew; while (!(int.TryParse(Console.ReadLine(), out yNew))) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверно ввели: так как нет такого номера. Введите заново!"); Console.ForegroundColor = ConsoleColor.Green; } Console.WriteLine("Введите номер столбец куда пойдет:"); int xNew; while (!(int.TryParse(Console.ReadLine(), out xNew))) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Неверно ввели: так как нет такого номера. Введите заново!"); Console.ForegroundColor = ConsoleColor.Green; } playController.Move(y, x, yNew - y, xNew - x); Console.WriteLine(new String('-', 90)); playController.TeamChange(); }while (true); Console.ReadLine(); }
private void PlayingBoard_MouseMove(object sender, MouseEventArgs e) { game.MoveLockpick(e.Location); PlayingBoard.Refresh(); }
/// <summary> /// Makes the specific row shift /// </summary> /// <param name="which_row"></param> /// <param name="left">Whether the row shift should happen from the left or the right</param> /// <param name="panel">Which control panel has the freetile placed in it</param> public void ShiftBoardRows(int which_row, bool left, Panel panel) { Control[] panel_array = new Control[1]; //Was Tile //Clones the tile, then sets the 'Enabled' property to false then removes the tile from the panel's control then add the edited tile Tile tile = (Tile)panel.Controls[0]; tile.Enabled = false; panel.Controls.RemoveAt(0); panel.Controls.Add(tile); panel.Controls.CopyTo(panel_array, 0); List <Control[]> tiles = new List <Control[]>(); // Was Tile //Fills a list with the copies of the Tile objects inside the panels for (int i = 0; i < PlayingBoard.GetLength(0); i++) { for (int j = 0; j < PlayingBoard.GetLength(1); j++) { if (i == which_row) { Control[] array = new Control[4]; //Was Tile PlayingBoard[j, i].Controls.CopyTo(array, 0); tiles.Add(array); } } } //If the free tile was placed in a right row control panel if (left) { for (int i = 0; i < PlayingBoard.GetLength(0); i++) { for (int j = 1; j < PlayingBoard.GetLength(1); j++) { if (i == which_row) { PlayingBoard[j, i].Controls.Clear(); PlayingBoard[j, i].Controls.AddRange(tiles[j - 1]); } } } PlayingBoard[0, which_row].Controls.Clear(); PlayingBoard[0, which_row].Controls.AddRange(panel_array); FreeTile.Controls.Clear(); tiles.Last().Last().Enabled = true; FreeTile.Controls.AddRange(tiles.Last()); panel.Controls.Clear(); } //If the free tile was placed in a left row control panel else { for (int i = PlayingBoard.GetLength(0); i > 0; i--) { for (int j = PlayingBoard.GetLength(1) - 1; j > 0; j--) { if (i == which_row) { PlayingBoard[j - 1, i].Controls.Clear(); PlayingBoard[j - 1, i].Controls.AddRange(tiles[j]); } } } PlayingBoard[PlayingBoard.GetLength(0) - 1, which_row].Controls.Clear(); PlayingBoard[PlayingBoard.GetLength(0) - 1, which_row].Controls.AddRange(panel_array); FreeTile.Controls.Clear(); tiles.First().First().Enabled = true; FreeTile.Controls.AddRange(tiles.First()); panel.Controls.Clear(); } }
/// <summary> /// Makes the specific columns shift /// </summary> /// <param name="which_colmun"></param> /// <param name="top">Whether the column shift should happen from the top or the bottom</param> /// <param name="panel">Which control panel has the freetile placed in it</param> public void ShiftBoardColumns(int which_colmun, bool top, Panel panel) { Control[] panel_array = new Control[1]; //Was Tile //Clones the tile, then sets the 'Enabled' property to false then removes the tile from the panel's control then add the edited tile Tile tile = (Tile)panel.Controls[0]; tile.Enabled = false; panel.Controls.RemoveAt(0); panel.Controls.Add(tile); panel.Controls.CopyTo(panel_array, 0); List <Control[]> tiles = new List <Control[]>(); //Was TIle //Fills a list with the copies of the Tile objects inside the panels for (int i = 0; i < PlayingBoard.GetLength(0); i++) { for (int j = 0; j < PlayingBoard.GetLength(1); j++) { if (j == which_colmun) { Control[] array = new Control[4]; //Was Tile PlayingBoard[j, i].Controls.CopyTo(array, 0); tiles.Add(array); } } } //If the free tile was placed in a top column control panel if (top) { for (int i = 1; i < PlayingBoard.GetLength(0); i++) { for (int j = 0; j < PlayingBoard.GetLength(1); j++) { if (j == which_colmun) { PlayingBoard[j, i].Controls.Clear(); PlayingBoard[j, i].Controls.AddRange(tiles[i - 1]); } } } PlayingBoard[which_colmun, 0].Controls.Clear(); PlayingBoard[which_colmun, 0].Controls.AddRange(panel_array); FreeTile.Controls.Clear(); tiles.Last().First().Enabled = true; FreeTile.Controls.AddRange(tiles.Last()); panel.Controls.Clear(); } //If the free tile was placed in a bottom column control panel else { for (int i = PlayingBoard.GetLength(0) - 1; i > 0; i--) { for (int j = PlayingBoard.GetLength(1); j > 0; j--) { if (j == which_colmun) { PlayingBoard[j, i - 1].Controls.Clear(); PlayingBoard[j, i - 1].Controls.AddRange(tiles[i]); } } } PlayingBoard[which_colmun, PlayingBoard.GetLength(0) - 1].Controls.Clear(); PlayingBoard[which_colmun, PlayingBoard.GetLength(0) - 1].Controls.AddRange(panel_array); FreeTile.Controls.Clear(); tiles.First().First().Enabled = true; FreeTile.Controls.AddRange(tiles.First()); panel.Controls.Clear(); } }
/// <summary> /// Places some controls needed for gameplay /// </summary> /// <param name="control">Which control the object should be added</param> public void PlaceGameControls(Control control) { if (PlayingBoard.GetLength(0) == 7) { int y = 10, x = 130; Panel column1_top = new Panel(), column2_top = new Panel(), column3_top = new Panel(), column1_bottom = new Panel(), column2_bottom = new Panel(), column3_bottom = new Panel(); ControlPanelsColumns = new Panel[] { column1_top, column2_top, column3_top, column1_bottom, column2_bottom, column3_bottom }; for (int i = 0; i < 2; i++) { int j = 0; while (true) { if (i != 0 && j == 0) { j = 3; } ControlPanelsColumns[j].AllowDrop = true; ControlPanelsColumns[j].Size = new Size(50, 50); ControlPanelsColumns[j].BorderStyle = BorderStyle.Fixed3D; ControlPanelsColumns[j].Location = new Point(x, y); ControlPanelsColumns[j].DragEnter += Board_DragEnter; ControlPanelsColumns[j].DragDrop += Panel_DragDrop; control.Controls.Add(ControlPanelsColumns[j]); x += 120; j++; if (j % 3 == 0 && (j != 3 || i == 0)) { break; } } x = 130; y += 480; } y = 130; x = 10; Panel row1_left = new Panel(), row2_left = new Panel(), row3_left = new Panel(), row1_right = new Panel(), row2_right = new Panel(), row3_right = new Panel(); ControlPanelsRows = new Panel[] { row1_left, row2_left, row3_left, row1_right, row2_right, row3_right }; for (int i = 0; i < 2; i++) { int j = 0; while (true) { if (i != 0 && j == 0) { j = 3; } ControlPanelsRows[j].AllowDrop = true; ControlPanelsRows[j].Size = new Size(50, 50); ControlPanelsRows[j].BorderStyle = BorderStyle.Fixed3D; ControlPanelsRows[j].Location = new Point(x, y); ControlPanelsRows[j].DragEnter += Board_DragEnter; ControlPanelsRows[j].DragDrop += Panel_DragDrop; control.Controls.Add(ControlPanelsRows[j]); y += 120; j++; if (j % 3 == 0 && (j != 3 || i == 0)) { break; } } y = 130; x += 480; } } else { int y = 10, x = 130; Panel column1_top = new Panel(), column2_top = new Panel(), column3_top = new Panel(), column4_top = new Panel(), column1_bottom = new Panel(), column2_bottom = new Panel(), column3_bottom = new Panel(), column4_bottom = new Panel(); ControlPanelsColumns = new Panel[] { column1_top, column2_top, column3_top, column4_top, column1_bottom, column2_bottom, column3_bottom, column4_bottom }; for (int i = 0; i < 2; i++) { int j = 0; while (true) { if (i != 0 && j == 0) { j = 4; } ControlPanelsColumns[j].AllowDrop = true; ControlPanelsColumns[j].Size = new Size(50, 50); ControlPanelsColumns[j].BorderStyle = BorderStyle.Fixed3D; ControlPanelsColumns[j].Location = new Point(x, y); ControlPanelsColumns[j].DragEnter += Board_DragEnter; ControlPanelsColumns[j].DragDrop += Panel_DragDrop; control.Controls.Add(ControlPanelsColumns[j]); x += 120; j++; if (j % 4 == 0 && (j != 4 || i == 0)) { break; } } x = 130; y += 600; } y = 130; x = 10; Panel row1_left = new Panel(), row2_left = new Panel(), row3_left = new Panel(), row4_left = new Panel(), row1_right = new Panel(), row2_right = new Panel(), row3_right = new Panel(), row4_right = new Panel(); ControlPanelsRows = new Panel[] { row1_left, row2_left, row3_left, row4_left, row1_right, row2_right, row3_right, row4_right }; for (int i = 0; i < 2; i++) { int j = 0; while (true) { if (i != 0 && j == 0) { j = 4; } ControlPanelsRows[j].AllowDrop = true; ControlPanelsRows[j].Size = new Size(50, 50); ControlPanelsRows[j].BorderStyle = BorderStyle.Fixed3D; ControlPanelsRows[j].Location = new Point(x, y); ControlPanelsRows[j].DragEnter += Board_DragEnter; ControlPanelsRows[j].DragDrop += Panel_DragDrop; control.Controls.Add(ControlPanelsRows[j]); y += 120; j++; if (j % 4 == 0 && (j != 4 || i == 0)) { break; } } y = 130; x += 600; } } Button button = new Button(); button.Size = new Size(50, 50); button.Location = new Point(1100, 160); button.Text = "OK"; button.Click += button_Click; control.Controls.Add(button); }
/// <summary> /// Fills the PlayingBoard matrix with objects. Creates the FreeTile /// </summary> public void FillBoardWithTile() { for (int x = 0; x < PlayingBoard.GetLength(0); x++) { for (int y = 0; y < PlayingBoard.GetLength(1); y++) { Panel panel = new Panel(); panel.Size = new Size(50, 50); panel.AllowDrop = true; panel.BorderStyle = BorderStyle.Fixed3D; panel.DragEnter += Board_DragEnter; panel.DragDrop += Player_DragDrop; PlayingBoard[x, y] = panel; //Sets the properties of the fixed tiles (e.g: starting locations) if (y % 2 == 0 && x % 2 == 0) { Tile tile = new Tile(random); #region Starting Locations if ((y * PlayingBoard.GetLength(0)) + (x + 1) == 1) { tile.PathRight = true; tile.PathDown = true; tile.PathUp = false; tile.PathLeft = false; } else if ((y * PlayingBoard.GetLength(0)) + (x + 1) == PlayingBoard.GetLength(0)) { tile.PathDown = true; tile.PathLeft = true; tile.PathUp = false; tile.PathRight = false; } else if ((y * PlayingBoard.GetLength(0)) + (x + 1) == (PlayingBoard.GetLength(0) * PlayingBoard.GetLength(0)) - (PlayingBoard.GetLength(0) - 1)) { tile.PathUp = true; tile.PathRight = true; tile.PathDown = false; tile.PathLeft = false; } else if ((y * PlayingBoard.GetLength(0)) + (x + 1) == (PlayingBoard.GetLength(0) * PlayingBoard.GetLength(0))) { tile.PathUp = true; tile.PathLeft = true; tile.PathRight = false; tile.PathDown = false; } #endregion #region Other Fix Tiles else if (y == 0) { tile.PathRight = true; tile.PathDown = true; tile.PathLeft = true; tile.PathUp = false; } else if (y == PlayingBoard.GetLength(0) - 1) { tile.PathUp = true; tile.PathRight = true; tile.PathLeft = true; tile.PathDown = false; } else if (x == 0) { tile.PathUp = true; tile.PathRight = true; tile.PathDown = true; tile.PathLeft = false; } else if (x == PlayingBoard.GetLength(1) - 1) { tile.PathUp = true; tile.PathDown = true; tile.PathLeft = true; tile.PathRight = false; } #endregion tile.Size = new Size(50, 50); tile.DetermineTilePicture(); //PlayingBoard[x, y].Enabled = false; PlayingBoard[x, y].Controls.Add(tile); } //Adds the non-fixed tiles to the board matrix else { Tile tile = new Tile(random); tile.Size = new Size(50, 50); tile.DetermineTilePicture(); PlayingBoard[x, y].Controls.Add(tile); } } } }