質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Visual Studio 2010

Microsoft Visual Studio 2010はMicrosoftが提供している統合開発環境(IDE)です。

Visual Studio 2012

Microsoft Visual Studio 2012は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2010の次のバージョンです

Visual Studio 2013

Microsoft Visual Studio 2013は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2012の次のバージョンです

Q&A

0回答

669閲覧

ライツアウトのプログラム作成について

kannnn

総合スコア3

Visual Studio 2010

Microsoft Visual Studio 2010はMicrosoftが提供している統合開発環境(IDE)です。

Visual Studio 2012

Microsoft Visual Studio 2012は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2010の次のバージョンです

Visual Studio 2013

Microsoft Visual Studio 2013は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2012の次のバージョンです

0グッド

0クリップ

投稿2022/06/13 06:14

編集2022/06/14 07:04

ライツアウトのプログラムがうまく作動しません.
visual studio2019,windowsフォームアプリケーションにて作業しています。
ライツアウトというゲームは画像のような5x5でできている赤と青の色を一色にすればクリアというものです。今回はすべて青になった場合をクリアとします。イメージ説明
関数number(x)はクリックしたボタンとその四方が赤であれば青に、青であれば赤にするよう作りました。(ボタン番号は左から123…となります。)
以下プログラムを書きましたが,リセットボタン以外のボタンを押しても色がどこも変わりません。修正点ありましたらよろしくお願いします。

Private Sub Button26_Click(sender As System.Object, e As System.EventArgs) Handles Button26.Click

Dim ary As Integer() = New Integer() {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 'Fisher-Yatesアルゴリズムでシャッフルする Dim rng As New System.Random() Dim n As Integer = ary.Length While n > 1 n -= 1 Dim k As Integer = rng.Next(n + 1) Dim tmp As Integer = ary(k) ary(k) = ary(n) ary(n) = tmp End While light(Button1, ary(0)) light(Button2, ary(1)) light(Button3, ary(2)) light(Button4, ary(3)) 省略 light(Button24, ary(23)) light(Button25, ary(24)) End Sub
Public Sub light(o As Object, num As Integer) If num = 1 Then o.backcolor = Color.Red Else o.backcolor = Color.Cyan End If End Sub Dim mybutton(25) As Object Private Sub number(x As Integer) mybutton(1) = Button1.BackColor mybutton(2) = Button2.BackColor mybutton(3) = Button3.BackColor mybutton(4) = Button4.BackColor 省略 mybutton(22) = Button22.BackColor mybutton(23) = Button23.BackColor mybutton(24) = Button24.BackColor mybutton(25) = Button25.BackColor If (x - 1) > 0 And x <> (1 And 6 And 11 And 16 And 21) Then If mybutton(x - 1) = Color.Red Then mybutton(x - 1) = Color.Cyan ElseIf mybutton(x - 1) = Color.Cyan Then mybutton(x - 1) = Color.Red End If End If If (x + 1) < 26 And x <> (5 And 10 And 15 And 20 And 25) Then If mybutton(x + 1) = Color.Red Then mybutton(x + 1) = Color.Cyan ElseIf mybutton(x + 1) = Color.Cyan Then mybutton(x + 1) = Color.Red End If End If If (x - 5) < 26 And x - 5 > 0 Then If mybutton(x - 5) = Color.Red Then mybutton(x - 5) = Color.Cyan ElseIf mybutton(x - 5) = Color.Cyan Then mybutton(x - 5) = Color.Red End If End If If (x + 5) < 26 And x <> (21 And 22 And 23 And 24 And 25) Then If mybutton(x + 5) = Color.Red Then mybutton(x + 5) = Color.Cyan ElseIf mybutton(x + 5) = Color.Cyan Then mybutton(x + 5) = Color.Red End If End If End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim x As Integer=1 number(x) End Sub 以降button25まで End Class

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問