public static Control GetAnyControlAt(TableLayoutPanel pp, int col, int row) { bool fnd = false; Control sendCC = null; foreach (Control cc in pp.Controls) { if (pp.GetCellPosition(cc).Column == col) { if (pp.GetCellPosition(cc).Row == row) { sendCC = cc; fnd = true; break; } } } if (fnd == true) { return(sendCC); } else { return(null); } }
public static void SwapCells (this TableLayoutPanel table, TableLayoutPanelCellPosition cell1, TableLayoutPanelCellPosition cell2) { var c1 = table.GetControlFromPosition(cell1.Column, cell1.Row); var c2 = table.GetControlFromPosition(cell2.Column, cell2.Row); var pos1 = table.GetCellPosition(c1); table.SetCellPosition(c1, table.GetCellPosition(c2)); table.SetCellPosition(c2, pos1); }
public void TableLayoutPanel_SetCellPosition_MultipleTimes_GetReturnsExpected() { var control = new ScrollableControl(); var panel = new TableLayoutPanel(); panel.SetCellPosition(control, new TableLayoutPanelCellPosition(1, 1)); Assert.Equal(new TableLayoutPanelCellPosition(1, 1), panel.GetCellPosition(control)); panel.SetCellPosition(control, new TableLayoutPanelCellPosition(2, 2)); Assert.Equal(new TableLayoutPanelCellPosition(2, 2), panel.GetCellPosition(control)); }
public void TableLayoutPanel_GetCellPosition_NoSuchControl_ReturnsExpected() { var control = new ScrollableControl(); var panel = new TableLayoutPanel(); Assert.Equal(new TableLayoutPanelCellPosition(-1, -1), panel.GetCellPosition(control)); }
public void TableLayoutPanel_SetCellPosition_ValidControl_GetReturnsExpected(TableLayoutPanelCellPosition value) { var control = new ScrollableControl(); var panel = new TableLayoutPanel(); panel.SetCellPosition(control, value); Assert.Equal(value, panel.GetCellPosition(control)); }
private void Form1_Load(object sender, EventArgs e) { // some content var panel = new TableLayoutPanel { Dock = DockStyle.Fill, ColumnCount = 5, RowCount = 2 }; for (var y = 0; y < 2; y++) { for (var x = 0; x < 5; x++) { var control = new Button { Text = $@"X = {x}, Y = {y}" }; panel.Controls.Add(control, x, y); } } // swap button var button = new Button { Dock = DockStyle.Fill, Text = @"Clicky !" }; button.Click += (o, args) => { var dictionary = panel.Controls .Cast <Control>() .ToDictionary(k => k, v => panel.GetCellPosition(v)); foreach (var pair in dictionary) { var position = pair.Value; position.Row ^= 1; // simple row swap panel.SetCellPosition(pair.Key, position); } }; // add to form var container = new SplitContainer { Dock = DockStyle.Fill, Orientation = Orientation.Horizontal, SplitterWidth = 5, BorderStyle = BorderStyle.Fixed3D }; container.Panel1.Controls.Add(panel); container.Panel2.Controls.Add(button); Controls.Add(container); }
public void TableLayoutPanel_GetCellPosition_InvalidRow_ThrowsArgumentOutOfRangeException() { var control = new ScrollableControl(); var panel = new TableLayoutPanel(); panel.SetCellPosition(control, new TableLayoutPanelCellPosition { Row = -2 }); Assert.Throws <ArgumentOutOfRangeException>("row", () => panel.GetCellPosition(control)); }
private void Button_MouseDown(object sender, MouseEventArgs e) { var x = cells.GetCellPosition((Control)sender).Column; var y = cells.GetCellPosition((Control)sender).Row; timer.Start(); if (e.Button == MouseButtons.Right) { presenter.MarkCell(x, y); minesCount.Text = Convert.ToString(NotFoundMinesCount); } else if (e.Button == MouseButtons.Left) { presenter.OpenCell(x, y); } PutImageToCell(x, y); }
public Control GetControlAt(TableLayoutPanel panel, int column, int row) { foreach (Control control in panel.Controls) { var cellPosition = panel.GetCellPosition(control);// mb($"{control.Name} - {cellPosition.Column} _ {cellPosition.Row}"); if (cellPosition.Column == column && cellPosition.Row == row) { return(control); } } return(null); }
/// <summary> /// if player can move, will move; else shows error message /// </summary> /// <param name="parentTLP"></param> /// <param name="selectedControl"></param> public void MovePlayer(TableLayoutPanel parentTLP, Control selectedControl) { if (lastControl != selectedControl) { controlPosX = parentTLP.GetCellPosition(selectedControl).Column; controlPosY = parentTLP.GetCellPosition(selectedControl).Row; EqualAxis(); if (xIsOk && yIsOk) { foreach (PictureBox pb in dangers) { //if (parentTLP.Controls.IndexOf(lastControl) == parentTLP.Controls.IndexOf(pb)) //{ // lastControl.BackColor = Color.Red; //} //else //{ // lastControl.BackColor = SystemColors.Control; //} if (parentTLP.Controls.IndexOf(selectedControl) == parentTLP.Controls.IndexOf(pb)) { //damage player MessageBox.Show("You got damaged"); } } lastControl.BackColor = SystemColors.Control; playerPosX = controlPosX; playerPosY = controlPosY; selectedControl.BackColor = SystemColors.Highlight; lastControl = selectedControl; } else { MessageBox.Show("Can't go there!"); } } }
protected void ScaleToCell(Control control, TableLayoutPanel tableLayoutPanel, string text = null) { var rowHeights = tableLayoutPanel.GetRowHeights(); var columnWidths = tableLayoutPanel.GetColumnWidths(); var position = tableLayoutPanel.GetCellPosition(control); var rectangle = new Rectangle(0, 0, columnWidths[position.Column], rowHeights[position.Row]); rectangle.Width = (int)(rectangle.Width * 0.9f); rectangle.Height = (int)(rectangle.Height * 0.9f); Scale(control, rectangle, text); }
public static Control GetAnyControlAt(this TableLayoutPanel panel, int column, int row) { Control foundControl = null; foreach (Control control in panel.Controls) { var cellPosition = panel.GetCellPosition(control); if (cellPosition.Column == column && cellPosition.Row == row) { return(foundControl); } } }
void BuildEnemyField(TableLayoutPanel field) { Action <Button> onClick = (b) => { if (world.GameState == GameStates.Game) { if (!world.canShoot) { MessageBox.Show("Больше нельзя стрелять"); return; } var shotAttempt = world.TryShoot(field.GetCellPosition(b).Row, field.GetCellPosition(b).Column); if (!shotAttempt) { MessageBox.Show("Сюда нельзя стрелять"); return; } var cell = world.enemyField[field.GetCellPosition(b).Row, field.GetCellPosition(b).Column]; b.Image = Converter.GetResource(cell); listBox1.ForeColor = Color.Black; listBox1.Items.Add($"Вы стреляете по позиции X: {field.GetCellPosition(b).Row} Y: {field.GetCellPosition(b).Column}"); if (Ship.IsShip(cell)) { listBox1.Items.Add("Вы подбили корабль!"); if (Ship.IsDead(world.enemyField, new Point(field.GetCellPosition(b).Row, field.GetCellPosition(b).Column))) { listBox1.Items.Add("Вы потопили корабль!"); } } else { listBox1.Items.Add("Промах"); } UpdateListBox(); if (world.canShoot) { endTurn.BackColor = Color.Orange; endTurn.Text = "Передать ход"; } else { endTurn.BackColor = Color.GreenYellow; endTurn.Text = "Ход завершен"; } endTurn.Enabled = true; if (world.enemyShipCount == 0) { MessageBox.Show("ПОБЕДА!!!"); listBox1.Items.Add("Победа!"); return; } } }; FieldConstructor.BuildField(field, onClick); }
private void CmdAddRack_Click(object sender, EventArgs e) { FrmAjoutRack f = new FrmAjoutRack(); f.ShowDialog(dcDesign.Parent); Rack r = GestionRack.GetRack(); if (r != null) { Button cmdAddRack = (Button)sender; TableLayoutPanelCellPosition cellNewRack = dcDesign.GetCellPosition(cmdAddRack); dcDesign.ColumnCount++; dcDesign.Controls.Remove(cmdAddRack); dcDesign.Controls.Add(r.GetRackDesign(), cellNewRack.Column, cellNewRack.Row); dcDesign.Controls.Add(cmdAddRack, cellNewRack.Column + 1, cellNewRack.Row); rows[cellNewRack.Row].AddRack(r); } }
void MakeMove(object sender, EventArgs e) { var position = table.GetCellPosition((Control)sender); var im = (PictureBox)sender; im.ImageLocation = im.ImageLocation == $"images//cat1.png" ? $"images//cat0.png" : $"images//cat1.png"; if (CheckWin()) { timer.Stop(); time = 10; label.Text = "10"; difficult += 30; score += difficult; Controls.Remove(table); StartGame(); } }
void MakeMove(object sender, EventArgs e) { var position = table.GetCellPosition((Control)sender); var btn = (Button)sender; btn.BackColor = btn.BackColor == Color.DarkMagenta ? Color.Yellow : Color.DarkMagenta; if (CheckWin()) { timer.Stop(); time = 10; label.Text = "10"; difficult += 30; score += difficult; Controls.Remove(table); StartGame(); } }
protected LinkLabel ReplaceWithLinklable(Control ctl, string value) { LinkLabel r = null; if (ctl != null) { value = (value == null ? string.Empty : value); r = new LinkLabel(); r.Name = "lnk_" + ctl.Name; r.Location = ctl.Location; r.Width = ctl.Width; r.Margin = ctl.Margin; r.Anchor = ctl.Anchor; r.Dock = ctl.Dock; r.Text = value; r.TextAlign = ContentAlignment.MiddleLeft; r.Links.Add(0, value.Length, value); r.TabIndex = ctl.TabIndex; r.Tag = ctl.Tag; r.Enter += new EventHandler(OnControlEnter); r.Leave += new EventHandler(OnControlLeave); Control ctlParent = ctl.Parent; TableLayoutPanel tblParent = ctlParent as TableLayoutPanel; if (tblParent != null) { TableLayoutPanelCellPosition pos = tblParent.GetCellPosition(ctl); int colSpan = tblParent.GetColumnSpan(ctl); tblParent.Controls.Remove(ctl); ctl.Dispose(); tblParent.Controls.Add(r, pos.Column, pos.Row); tblParent.SetColumnSpan(r, colSpan); } else if (ctlParent != null) { ctlParent.Controls.Remove(ctl); ctl.Dispose(); ctlParent.Controls.Add(r); } } return(r); }
protected TextBox ReplaceWithTextbox(Control ctl, string value) { TextBox r = null; if (ctl != null) { r = new TextBox(); r.Name = "txt_" + ctl.Name; r.ReadOnly = true; r.BackColor = SystemColors.Window; r.Location = ctl.Location; r.Width = ctl.Width; r.Margin = ctl.Margin; r.Anchor = ctl.Anchor; r.Dock = ctl.Dock; r.Text = value; r.TabIndex = ctl.TabIndex; r.Tag = ctl.Tag; r.Enter += new EventHandler(OnControlEnter); r.Leave += new EventHandler(OnControlLeave); Control ctlParent = ctl.Parent; TableLayoutPanel tblParent = ctlParent as TableLayoutPanel; if (tblParent != null) { TableLayoutPanelCellPosition pos = tblParent.GetCellPosition(ctl); int colSpan = tblParent.GetColumnSpan(ctl); tblParent.Controls.Remove(ctl); ctl.Dispose(); tblParent.Controls.Add(r, pos.Column, pos.Row); tblParent.SetColumnSpan(r, colSpan); } else if (ctlParent != null) { ctlParent.Controls.Remove(ctl); ctl.Dispose(); ctlParent.Controls.Add(r); } } return(r); }
// http://stackoverflow.com/questions/7142138/tablelayoutpanel-getcontrolfromposition-does-not-get-non-visible-controls-how-d // TableLayoutPanel GetControlFromPosition does not get non-visible controls. How do you access a non-visible control at a specified position? public static Control GetAnyControlAt(this TableLayoutPanel panel, int column, int row) { { Control control = panel.GetControlFromPosition(column, row); if (control != null) { return(control); } } foreach (Control control in panel.Controls) { var cellPosition = panel.GetCellPosition(control); if (cellPosition.Column == column && cellPosition.Row == row) { return(control); } } return(null); }
protected Label ReplaceWithLable(Control ctl, string value) { Label r = null; if (ctl != null) { r = new Label(); r.Name = "lbl_" + ctl.Name; r.Location = ctl.Location; r.Width = ctl.Width; r.Margin = ctl.Margin; r.Dock = ctl.Dock; r.Anchor = ctl.Anchor; r.Text = value; r.TextAlign = ContentAlignment.MiddleRight; r.TabIndex = ctl.TabIndex; r.Tag = ctl.Tag; r.Click += new EventHandler(this.OnLabelClick); Control ctlParent = ctl.Parent; TableLayoutPanel tblParent = ctlParent as TableLayoutPanel; if (tblParent != null) { TableLayoutPanelCellPosition pos = tblParent.GetCellPosition(ctl); int colSpan = tblParent.GetColumnSpan(ctl); tblParent.Controls.Remove(ctl); ctl.Dispose(); tblParent.Controls.Add(r, pos.Column, pos.Row); tblParent.SetColumnSpan(r, colSpan); } else if (ctlParent != null) { ctlParent.Controls.Remove(ctl); ctl.Dispose(); ctlParent.Controls.Add(r); } } return(r); }
private void fncDoEnchant(TableLayoutPanel table, object sender, String enchant) { if (textBox100.Text == "") { MessageBox.Show("対象IDを指定してください。"); return; } Button btn = (Button)sender; TableLayoutPanelCellPosition pos = table.GetCellPosition(btn); pos.Column -= 1; Control c = table.GetControlFromPosition(pos.Column, pos.Row); String player = textBox100.Text; refForm.fncAddUser(player); String strOutput = ""; strOutput += "enchant " + player + " " + enchant + " " + c.Text + " force"; refForm.fncExecuteCommand(strOutput); }
void ColorPresetControl_Navigate(object sender, GridNavigateEventArgs args) { Control c = (Control)sender; TableLayoutPanelCellPosition navFrom = tableLayout.GetCellPosition(c); TableLayoutPanelCellPosition navTo = navFrom; bool navigateOffPresets = false; bool forward = false; switch (args.Navigate) { case GridNavigateEventArgs.Direction.Up: if (navFrom.Row <= 0) { navigateOffPresets = true; } else { navTo.Row--; } break; case GridNavigateEventArgs.Direction.Down: if (navFrom.Row >= tableLayout.RowCount - 1) { navigateOffPresets = true; forward = true; } else { navTo.Row++; } forward = true; break; case GridNavigateEventArgs.Direction.Left: if (navFrom.Column <= 0) { if (navFrom.Row <= 0) { navigateOffPresets = true; } else { navTo.Row--; navTo.Column = tableLayout.ColumnCount - 1; } } else { navTo.Column--; } break; case GridNavigateEventArgs.Direction.Right: if (navFrom.Column >= tableLayout.ColumnCount - 1) { if (navFrom.Row >= tableLayout.RowCount - 1) { forward = true; navigateOffPresets = true; } else { navTo.Column = 0; navTo.Row++; } } else { navTo.Column++; } break; default: break; } if (navigateOffPresets) { Navigate(new NavigateEventArgs(forward)); } else { tableLayout.GetControlFromPosition(navTo.Column, navTo.Row).Select(); } }
private TableLayoutPanelCellPosition getSquarePosition(Button i_Button) { return(m_GameBoard.GetCellPosition(i_Button)); }
private void HandleSimpleUIntControlEvent(object sender, SUICEventArgs e) { Control UIntControl = sender as Control; TableLayoutPanelCellPosition pos = TableLayoutPanel.GetCellPosition(UIntControl); if (EventHandler != null) { switch (e.Message) { case SUICMessage.Return: EventHandler(this, new UITableEventArgs(UITableMessage.Return)); break; case SUICMessage.ValueChanged: EventHandler(this, new UITableEventArgs(UITableMessage.ValueChanged)); break; case SUICMessage.Left: if (pos.Column > 0) { pos.Column--; } else if (pos.Column == 0 && pos.Row > 0) { pos.Column = TableLayoutPanel.ColumnCount - 1; pos.Row--; } TableLayoutPanel.GetControlFromPosition(pos.Column, pos.Row).Select(); break; case SUICMessage.Right: if (pos.Column < TableLayoutPanel.ColumnCount - 1) { pos.Column++; } else if (pos.Column == TableLayoutPanel.ColumnCount - 1 && pos.Row < TableLayoutPanel.RowCount - 1) { pos.Column = 0; pos.Row++; } TableLayoutPanel.GetControlFromPosition(pos.Column, pos.Row).Select(); break; case SUICMessage.Up: if (pos.Row > 0) { pos.Row--; } TableLayoutPanel.GetControlFromPosition(pos.Column, pos.Row).Select(); break; case SUICMessage.Down: if (pos.Row < TableLayoutPanel.RowCount - 1) { pos.Row++; } TableLayoutPanel.GetControlFromPosition(pos.Column, pos.Row).Select(); break; case SUICMessage.Pos1: TableLayoutPanel.GetControlFromPosition(0, 0).Select(); break; } } }
public void TableLayoutPanel_GetCellPosition_NullControl_ThrowsArgumentNullException() { var panel = new TableLayoutPanel(); Assert.Throws <ArgumentNullException>("control", () => panel.GetCellPosition(null)); }
public void SpecifyMap(TableLayoutPanel container, PictureBox initialControl) { lastControl = container.Controls[0]; PlayerPosX = container.GetCellPosition(lastControl).Column; PlayerPosY = container.GetCellPosition(lastControl).Row; }
/// <summary> /// When the DataGridView is visible for the first time a panel is created. /// The DataGridView is then removed from the parent control and added as /// child to the newly created panel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void changeParent() { if (!DesignMode && Parent != null) { summaryControl.InitialHeight = this.refBox.Height; summaryControl.Height = summaryControl.InitialHeight; summaryControl.BackColor = this.RowHeadersDefaultCellStyle.BackColor; summaryControl.ForeColor = Color.Transparent; summaryControl.RightToLeft = this.RightToLeft; panel.Bounds = this.Bounds; panel.BackColor = this.BackgroundColor; panel.Dock = this.Dock; panel.Anchor = this.Anchor; panel.Padding = this.Padding; panel.Margin = this.Margin; panel.Top = this.Top; panel.Left = this.Left; panel.BorderStyle = this.BorderStyle; Margin = new Padding(0); Padding = new Padding(0); Top = 0; Left = 0; summaryControl.Dock = DockStyle.Bottom; this.Dock = DockStyle.Fill; if (this.Parent is TableLayoutPanel) { int rowSpan, colSpan; TableLayoutPanel tlp = this.Parent as TableLayoutPanel; TableLayoutPanelCellPosition cellPos = tlp.GetCellPosition(this); rowSpan = tlp.GetRowSpan(this); colSpan = tlp.GetColumnSpan(this); tlp.Controls.Remove(this); tlp.Controls.Add(panel, cellPos.Column, cellPos.Row); tlp.SetRowSpan(panel, rowSpan); tlp.SetColumnSpan(panel, colSpan); } else { Control parent = this.Parent; //remove DataGridView from ParentControls parent.Controls.Remove(this); parent.Controls.Add(panel); } this.BorderStyle = BorderStyle.None; panel.BringToFront(); hScrollBar.Top = refBox.Height + 2; hScrollBar.Width = this.Width; hScrollBar.Left = this.Left; summaryControl.Controls.Add(hScrollBar); hScrollBar.BringToFront(); panel.Controls.Add(this); spacePanel = new Panel(); spacePanel.BackColor = panel.BackColor; spacePanel.Height = summaryRowSpace; spacePanel.Dock = DockStyle.Bottom; panel.Controls.Add(spacePanel); panel.Controls.Add(summaryControl); resizeHScrollBar(); adjustSumControlToGrid(); adjustScrollbarToSummaryControl(); resizeHScrollBar(); } }
//Función de clickar nunha carta private void btnCarta_Click(object sender, EventArgs e) { if (indPrimario == -1 | indSecundario == -1) { partida.contMovementos++; lblMovementosEdit.Text = partida.contMovementos.ToString(); cartaSeleccionada = (PictureBox)sender; CartaLib.ucImaxe ucCartaSeleccionada = (CartaLib.ucImaxe)cartaSeleccionada.Parent; int col = tablaPanel.GetCellPosition(ucCartaSeleccionada).Column; int row = tablaPanel.GetCellPosition(ucCartaSeleccionada).Row; int contPosicion = 0; switch (row) { case 0: row = row + 1; break; case 1: row = row + 4; break; case 2: row = row + 7; break; case 3: row = row + 10; break; default: break; } contPosicion = row + col; cartaSeleccionada.Image = (Image)myManager.GetObject(partida.listaCartas[contPosicion - 1].rutaImagen); //guardo el primer índice pulsado if (indPrimario == -1) { indPrimario = contPosicion - 1; cartaSeleccionada1 = cartaSeleccionada; } else { indSecundario = contPosicion - 1; cartaSeleccionada2 = cartaSeleccionada; if (indPrimario == indSecundario) { cartaSeleccionada1.Image = (Image)myManager.GetObject(partida.listaCartas[indPrimario].rutaImagenReverso); cartaSeleccionada2.Image = (Image)myManager.GetObject(partida.listaCartas[indSecundario].rutaImagenReverso); indPrimario = -1; indSecundario = -1; } else if (partida.listaCartas[indPrimario].idCarta != partida.listaCartas[indSecundario].idCarta) { foreach (CartaLib.ucImaxe item in tablaPanel.Controls) { item.Enabled = false; } tTempo.Enabled = true; tTempo.Start(); foreach (CartaLib.ucImaxe item in tablaPanel.Controls) { item.Enabled = true; } } else { partida.contCantidadCartasXiradas++; partida.contCantidadCartasXiradas++; cartaSeleccionada1.Enabled = false; cartaSeleccionada2.Enabled = false; indPrimario = -1; indSecundario = -1; if (partida.contCantidadCartasXiradas == 16) { string nomeUsu = Microsoft.VisualBasic.Interaction.InputBox(StringResources.tiganas + "\n\n" + StringResources.teunome, StringResources.tiganas, StringResources.anonimo); if (nomeUsu.CompareTo("") != 0) { guardarMovementos(partida.contMovementos.ToString(), nomeUsu); } DialogResult result = MessageBox.Show(StringResources.desexas, StringResources.fin, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (result == DialogResult.Yes) { btnXogoNovo_Click(null, null); } else { Application.Exit(); } } } } } }
public GameScreen(int size, int playersCount, int realPlayersCount, List <string> playersNames) { this.Size = (int)Math.Sqrt(Math.Pow((double)(playersCount + 1), (double)playersCount)); this.game = new Core.Game(playersNames, playersCount, realPlayersCount); this.game.StartLevel(this.Size, this.Size, playersCount + 1); SoundPlayer gameMedia = new SoundPlayer(Properties.Resources.bensound_punky); SoundPlayer buttonClick = new SoundPlayer(Properties.Resources.button_click); gameMedia.PlayLooping(); var exitButton = new Button(); table = new TableLayoutPanel(); table.BackColor = Color.FromArgb(173, 216, 230); table.Location = new Point(2, 2); table.Size = new Size(76 * this.Size, 76 * this.Size); for (int i = 0; i < this.Size; i++) { table.RowStyles.Add(new RowStyle(SizeType.Percent, 100f / this.Size)); table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f / this.Size)); } for (int column = 0; column < this.Size; column++) { for (int row = 0; row < this.Size; row++) { var button = new Button(); button.BackColor = Color.FromArgb(255, 255, 255); button.Size = new Size(66, 66); button.FlatStyle = FlatStyle.Standard; button.Click += (senders, args) => { var position = table.GetCellPosition((Control)senders); this.game.CurrentLevel.MakeMove(position.Column, position.Row); this.Map = this.game.CurrentLevel.Map; ChangeMap(); if (!(this.game.CurrentLevel.Winner == null) || this.game.CurrentLevel.IsDraw == true) { string winnerName = ""; var draw = this.game.CurrentLevel.IsDraw; if (!(this.game.CurrentLevel.Winner == null)) { winnerName = game.CurrentLevel.Winner.Name; } this.Hide(); gameMedia.Stop(); GameOverScreen gameOver = new GameOverScreen(size, playersCount, realPlayersCount, playersNames, winnerName, draw); gameOver.Show(); } }; table.Controls.Add(button, column, row); } } // Game Screen Settins this.AutoScaleMode = AutoScaleMode.None; this.BackColor = Color.FromArgb(173, 216, 230); this.ClientSize = new Size(76 * this.Size, 76 * this.Size + 60); this.MinimumSize = new Size(76 * this.Size, 76 * this.Size + 60); this.StartPosition = FormStartPosition.CenterScreen; this.FormBorderStyle = FormBorderStyle.None; exitButton.Anchor = AnchorStyles.Left; exitButton.AutoSizeMode = AutoSizeMode.GrowAndShrink; exitButton.Cursor = Cursors.Hand; exitButton.FlatStyle = FlatStyle.Popup; exitButton.Font = new Font("MV Boli", 20.25F); exitButton.BackColor = Color.FromArgb(74, 118, 168); exitButton.ForeColor = Color.FromArgb(0, 0, 0); exitButton.ImageAlign = ContentAlignment.BottomCenter; exitButton.Location = new Point(ClientSize.Width / 2 - 90, ClientSize.Height - 50); exitButton.Text = "Main Menu"; exitButton.Size = new Size(180, 40); exitButton.Click += (sender, args) => { buttonClick.Play(); Thread.Sleep(150); gameMedia.Stop(); this.Hide(); var mainScreen = new MainScreen(this.Size, playersCount, realPlayersCount); mainScreen.Show(); }; Controls.Add(table); Controls.Add(exitButton); }
void BuildPlayerField(TableLayoutPanel field) { Action <Button> onClick = (b) => { if (world.GameState == GameStates.Preparing) { if (selectedShip == null) { MessageBox.Show("Выберите корабль"); } else if (selectedShip.Item3 == 0) { MessageBox.Show("Все корабли этого типа уже расставлены"); } else { var shipPlaced = world.TryPlaceShip(field.GetCellPosition(b).Row, field.GetCellPosition(b).Column, selectedShip.Item4, direction); if (!shipPlaced) { if (world.GetPlacedShipCount() == world.playerShipCount) { MessageBox.Show("Все корабли расставлены"); } else { MessageBox.Show("Здесь нельзя разместить корабль"); } } else { if (selectedShip.Item4 == 1) { b.Image = Converter.GetResource(world.playerField[field.GetCellPosition(b).Row, field.GetCellPosition(b).Column]); } else { var x = field.GetCellPosition(b).Row; var y = field.GetCellPosition(b).Column; b.Image = Converter.GetResource(world.playerField[x, y]); for (var i = 1; i < selectedShip.Item4; i++) { if (direction == ShipDirection.Right) { var nextButton = PlayerField.Controls[(y + i) * 10 + x] as Button; nextButton.Image = Converter.GetResource(world.playerField[x, y + i]); } else { var nextButton = PlayerField.Controls[y * 10 + x - i] as Button; nextButton.Image = Converter.GetResource(world.playerField[x - i, y]); } } } UpdateSelectedTuple(selectedShip, selectedShip.Item3 - 1); selectedShip.Item2.Text = selectedShip.Item3.ToString(); } } } //UpdateCell(field.GetCellPosition(b).Row, field.GetCellPosition(b).Column, field, world.playerField); }; FieldConstructor.BuildField(field, onClick); }