Перевести с Microsoft Visual Basic на C#
Формулировка задачи:
Доброго времени суток!
Помогите пожалуйста перевести с VB на C#.
Dim Col As String Dim Down, Right, Vert, Gor, A As Integer Private Sub ComNew_Click() Col = vbBlack For Index = 0 To 63 Command1.Item(Index).BackColor = vbYellow Command1.Item(Index).Enabled = True Next Index Command1.Item(27).BackColor = vbWhite Command1.Item(28).BackColor = vbBlack Command1.Item(35).BackColor = vbBlack Command1.Item(36).BackColor = vbWhite Command1.Item(27).Enabled = False Command1.Item(28).Enabled = False Command1.Item(35).Enabled = False Command1.Item(36).Enabled = False Text1.Text = 2 Text2.Text = 2 End Sub Private Sub Command1_Click(Index As Integer) If Col = vbBlack Then Col = vbWhite Else Col = vbBlack End If Command1.Item(Index).BackColor = Col Command1.Item(Index).Enabled = False Vert = Index \ 8 + 1 Gor = 9 - (7 * Vert - (Index - Vert)) Down = 8 - Vert Right = 8 - Gor White = 0 Black = 0 For A = Down To 1 Step -1 If Command1.Item(Index + 8 * A).BackColor = Col Then If Command1.Item(Index + 8 * (A - 1)).Enabled = False Then Command1.Item(Index + 8 * (A - 1)).BackColor = Col Else End If End If Next A For A = Vert - 1 To 1 Step -1 If Command1.Item(Index - 8 * A).BackColor = Col Then If Command1.Item(Index - 8 * (A - 1)).Enabled = False Then Command1.Item(Index - 8 * (A - 1)).BackColor = Col End If End If Next A For A = Right To 1 Step -1 If Command1.Item(Index + A).BackColor = Col Then If Command1.Item(Index + A - 1).Enabled = False Then Command1.Item(Index + A - 1).BackColor = Col End If End If Next A For A = Gor - 1 To 1 Step -1 If Command1.Item(Index - A).BackColor = Col Then If Command1.Item(Index - A + 1).Enabled = False Then Command1.Item(Index - A + 1).BackColor = Col End If End If Next A For A = Down To 1 Step -1 If Command1.Item(Index + 7 * A).BackColor = Col Then If Command1.Item(Index + 7 * (A - 1)).Enabled = False Then Command1.Item(Index + 7 * (A - 1)).BackColor = Col Else End If End If Next A For A = Vert - 1 To 1 Step -1 If Command1.Item(Index - 7 * A).BackColor = Col Then If Command1.Item(Index - 7 * (A - 1)).Enabled = False Then Command1.Item(Index - 7 * (A - 1)).BackColor = Col End If End If Next A For A = Down - 1 To 1 Step -1 If Command1.Item(Index + 9 * A).BackColor = Col Then If Command1.Item(Index + 9 * (A - 1)).Enabled = False Then Command1.Item(Index + 9 * (A - 1)).BackColor = Col Else End If End If Next A For A = Vert - 2 To 1 Step -1 If Command1.Item(Index - 9 * A).BackColor = Col Then If Command1.Item(Index - 9 * (A - 1)).Enabled = False Then Command1.Item(Index - 9 * (A - 1)).BackColor = Col End If End If Next A For Index = 0 To 63 Select Case Command1.Item(Index).BackColor Case Is = vbWhite White = White + 1 Case Is = vbBlack Black = Black + 1 End Select Text1.Text = White Text2.Text = Black Next Index A = 0 For Index = 0 To 63 If Command1.Item(Index).Enabled = False Then A = A + 1 End If Next Index If A = 64 Then приглашение = "Игра закончена.Начните снова!" If White > Black Then сообщение = "Белые выиграли!" Else If White < Black Then сообщение = "Чёрные выиграли!" Else сообщение = "Ничья!" End If End If MsgBox сообщение, vbExclamation, приглашение End If End Sub Private Sub ComEnd_Click() End End Sub
Решение задачи: «Перевести с Microsoft Visual Basic на C#»
textual
Листинг программы
string Col; int Down; SUB private void ComNew_Click() { Col = vbBlack; int Right; int Vert; int Gor; int A; for (Index = 0; (Index <= 63); Index++) { Command1.Item[Index].BackColor = vbYellow; Command1.Item[Index].Enabled = true; } Command1.Item[27].BackColor = vbWhite; Command1.Item[28].BackColor = vbBlack; Command1.Item[35].BackColor = vbBlack; Command1.Item[36].BackColor = vbWhite; Command1.Item[27].Enabled = false; Command1.Item[28].Enabled = false; Command1.Item[35].Enabled = false; Command1.Item[36].Enabled = false; Text1.Text = 2; Text2.Text = 2; } private void Command1_Click(int Index) { if ((Col == vbBlack)) { Col = vbWhite; } else { Col = vbBlack; } Command1.Item[Index].BackColor = Col; Command1.Item[Index].Enabled = false; Vert = Index; (8 + 1); Gor = (9 - ((7 * Vert) - (Index - Vert))); Down = (8 - Vert); Right = (8 - Gor); White = 0; Black = 0; for (A = Down; (A <= 1); A = (A + -1)) { if ((Command1.Item[(Index + (8 * A))].BackColor == Col)) { if ((Command1.Item[(Index + (8 * (A - 1)))].Enabled == false)) { Command1.Item[(Index + (8 * (A - 1)))].BackColor = Col; } else { } } } for (A = (Vert - 1); (A <= 1); A = (A + -1)) { if ((Command1.Item[(Index - (8 * A))].BackColor == Col)) { if ((Command1.Item[(Index - (8 * (A - 1)))].Enabled == false)) { Command1.Item[(Index - (8 * (A - 1)))].BackColor = Col; } } } for (A = Right; (A <= 1); A = (A + -1)) { if ((Command1.Item[(Index + A)].BackColor == Col)) { if ((Command1.Item[(Index + (A - 1))].Enabled == false)) { Command1.Item[(Index + (A - 1))].BackColor = Col; } } } for (A = (Gor - 1); (A <= 1); A = (A + -1)) { if ((Command1.Item[(Index - A)].BackColor == Col)) { if ((Command1.Item[((Index - A) + 1)].Enabled == false)) { Command1.Item[((Index - A) + 1)].BackColor = Col; } } } for (A = Down; (A <= 1); A = (A + -1)) { if ((Command1.Item[(Index + (7 * A))].BackColor == Col)) { if ((Command1.Item[(Index + (7 * (A - 1)))].Enabled == false)) { Command1.Item[(Index + (7 * (A - 1)))].BackColor = Col; } else { } } } for (A = (Vert - 1); (A <= 1); A = (A + -1)) { if ((Command1.Item[(Index - (7 * A))].BackColor == Col)) { if ((Command1.Item[(Index - (7 * (A - 1)))].Enabled == false)) { Command1.Item[(Index - (7 * (A - 1)))].BackColor = Col; } } } for (A = (Down - 1); (A <= 1); A = (A + -1)) { if ((Command1.Item[(Index + (9 * A))].BackColor == Col)) { if ((Command1.Item[(Index + (9 * (A - 1)))].Enabled == false)) { Command1.Item[(Index + (9 * (A - 1)))].BackColor = Col; } else { } } } for (A = (Vert - 2); (A <= 1); A = (A + -1)) { if ((Command1.Item[(Index - (9 * A))].BackColor == Col)) { if ((Command1.Item[(Index - (9 * (A - 1)))].Enabled == false)) { Command1.Item[(Index - (9 * (A - 1)))].BackColor = Col; } } } for (Index = 0; (Index <= 63); Index++) { switch (Command1.Item[Index].BackColor) { } vbWhite; White = (White + 1); vbBlack; Black = (Black + 1); Text = Black; } A = 0; for (Index = 0; (Index <= 63); Index++) { if ((Command1.Item[Index].Enabled == false)) { A = (A + 1); } } if ((A == 64)) { 83; 0; 85 = "3@0 70:>=G5=0.0G=8B5 A=>20!"; H5 = "3@0 70:>=G5=0.0G=8B5 A=>20!"; if ((White > Black)) { ShiftRight(A, 1); 85 = "5;K5 2K83@0;8!"; I5 = "5;K5 2K83@0;8!"; } else if ((White < Black)) { ShiftRight(A, 1); 85 = "\'Q@=K5 2K83@0;8!"; I5 = "\'Q@=K5 2K83@0;8!"; } else { ShiftRight(A, 1); 85 = "8GLO!"; I5 = "8GLO!"; } MsgBox; ShiftRight(A, 1); I5 = 85; vbExclamation; 83; 0; H5 = 85; } } private void ComEnd_Click() { }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д