C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


(過去ログ 154 を表示中)
■89311 / )  リバーシゲームの開発
□投稿者/ ルシフェル (1回)-(2018/11/20(Tue) 10:21:15)

分類:[VBScript] 

初めて使わせて頂きます
環境は、Visual Studio Community2017を使っています、windows10です。
使用言語はVisual Basicのユニバーサルwindowです。

リバーシのゲームを製作しています。
私がしたい事は、緑の番のマスをクリックするとx=0 y=0と表示させたいです。
エラーが出てしまったのでどなたかコードの修正お願いします。
どこがが間違っているようです

Public NotInheritable Class MainPage
    Inherits Page

    Public Const Size = 8
    Private CellMargin As Thickness = New Thickness(6)

    Protected Overrides Sub OnNavigatedTo(
    e As Navigation.NavigationEventArgs)

        Dim gridSize = Window.Current.Bounds.Width
        If gridSize > Window.Current.Bounds.Height Then _
            gridSize = Window.Current.Bounds.Height
        Dim cellSize = (gridSize - 60) / Size

        Dim cd As ColumnDefinition
        Dim rd As RowDefinition
        For i = 0 To Size - 1
            cd = New ColumnDefinition()
            cd.Width = New Windows.UI.Xaml.GridLength(
                cellSize)
            GridGameField.ColumnDefinitions.Add(cd)

            rd = New RowDefinition()
            rd.Height = New Windows.UI.Xaml.GridLength(
                cellSize)
            GridGameField.RowDefinitions.Add(rd)
        Next

        Dim cell As Windows.UI.Xaml.Shapes.Rectangle
        For i = 0 To Size - 1
            For j = 0 To Size - 1
                cell = New Windows.UI.Xaml.Shapes.Rectangle()
                cell.Fill = New SolidColorBrush(
                  Windows.UI.Colors.Green)
                cell.SetValue(Grid.ColumnProperty, i)
                cell.SetValue(Grid.RowProperty, j)
                cell.Margin = CellMargin
                AddHandler cell.Tapped,
                    AddressOf RectangleTapped
                GridGameField.Children.Add(cell)

            Next
        Next
    End Sub
End Class

Private Async Sub RectangleTapped(sender As Object, e As TappedRoutedEventArgs)

    Dim r As Windows.UI.Xaml.Shapes.Rectangle = sender
    Dim x = r.GetValue(Grid.ColumnProperty)
    Dim y = r.GetValue(Grid.RowProperty)
    Await ShowMessage("x=" & x & "y=" & y)
End Sub

Private Async Function ShowMessage(s As String) As Task
    Dim md = New Windows.UI.Popups.MessageDialog(s)
    Await md.ShowAsync()
End Function

End Class

どなたかご教示お願いします。

返信 編集キー/


管理者用

- Child Tree -