布尔被设置为False时,它再次访问? [英] Boolean being set to False whenever it is accessed again?
问题描述
每当我尝试对变量进行操作,它会立即被设置为false。这种方法应该是将完全
财产上的盒存放在
box_list
对象code>为True。它找到正确的箱子和更改属性,但每当它再次访问时,它变成为假。
公用Sub DefineFilled()
昏暗的船由于新船(没什么,没什么,没什么,没什么,没什么,没什么,没什么)
暗淡x As中整数= 0
昏暗y为整数= 0 船= AirCraftCarrier
如果ship.has_moved然后
Debug.Print()
对于我作为整数= 0〜ship.length - 1
X = ship.space_filled(I,0)'space_filled是存储每个点该船舶在网格占用一个列表
Y = ship.space_filled(I,1)
PlayerBoard.box_list(X,Y)。全= TRUE设置变量设置为true Debug.Print(PlayerBoard.box_list(X,Y)。全)打印变量假
下一个
万一
结束小组
修改1:PlayerBoard定义
(在主)
公共PlayerBoard作为董事会私人小组Main_Load(BYVAL发件人为System.Object的,BYVAL E上System.EventArgs)把手MyBase.Load
PlayerBoard =新局(TILE_SIZE,330,Color.Silver)
结束小组
(局级)
公共类板
昏暗_box_list(,)作为盒
公共财产box_list()作为盒(,)
得到
返回_box_list
到底得的
设置(BYVAL值作为盒(,))
_box_list =价值
结束设定
高端物业 的Public Sub New(BYVAL POS_X整数,BYVAL POS_Y整数,BYVAL colourp对于Color)
使用ReDim _box_list(10,10)
结束小组
编辑2:如何box_list定义(在板级)
私人小组BuildBoard() y的为整数= 0〜9
当x为整数= 0〜9
点心盒作为新箱(X,Y,新图片框)
随着盒
.image.Location =新点(START_LOCATION(0)+ X * TILE_SIZE,start_location,其中(1)+ Y * TILE_SIZE)
.image.Size =新的大小(TILE_SIZE,TILE_SIZE)
.image.BackColor =颜色
.image.BorderStyle = BorderStyle.FixedSingle
结束与
box_list(X,Y)=箱
Main.Controls.Add(box_list(X,Y)在图像配)
下一个
下一个结束小组
修改3:框定义
公共类箱
昏暗_image作为PictureBox的
公共财产的图像()作为PictureBox的
得到
返回_image
到底得的
设置(BYVAL值作为PictureBox的)
_image =价值
结束设定
高端物业
昏暗_full由于布尔
公共财产全()为布尔
得到
返回_full
到底得的
设置(BYVAL值作为布尔)
_full =全
结束设定
高端物业 的Public Sub New(BYVAL location_x整数,BYVAL location_y整数,BYVAL imagep作为PictureBox的)
图像= imagep
结束小组末级
您与此code问题是在完全
属性>箱类。
您有它写成现在这个样子:
公共财产全()为布尔
得到
返回_full
到底得的
设置(BYVAL值作为布尔)
_full =全
结束设定
高端物业
应该是这样的:
公共财产全()为布尔
得到
返回_full
到底得的
设置(BYVAL值作为布尔)
_full =价值
结束设定
高端物业
您当前code递归设置属性回其自身的价值。因此,它下榻假
。
Whenever I try to operate on a variable, it instantly gets set to false. This method is supposed to turn the full
property on the box
object stored in box_list
to True. It finds the correct boxes and changes the property, but whenever it is accessed again, it turns to false.
Public Sub DefineFilled()
Dim ship As New Ship(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
Dim x As Integer = 0
Dim y As Integer = 0
ship = AirCraftCarrier
If ship.has_moved Then
Debug.Print("")
For i As Integer = 0 To ship.length - 1
x = ship.space_filled(i, 0) 'space_filled is a list that stores each point that the ship takes up on the grid
y = ship.space_filled(i, 1)
PlayerBoard.box_list(x, y).full = True 'Sets variable to True
Debug.Print(PlayerBoard.box_list(x, y).full) 'Prints variable as False
Next
End If
End Sub
Edit 1: PlayerBoard definition
(In Main)
Public PlayerBoard As Board
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PlayerBoard = New Board(tile_size, 330, Color.Silver)
End Sub
(Board class)
Public Class Board
Dim _box_list(,) as Box
Public Property box_list() As Box(,)
Get
Return _box_list
End Get
Set(ByVal value As Box(,))
_box_list = value
End Set
End Property
Public Sub New(ByVal pos_x As Integer, ByVal pos_y As Integer, ByVal colourp As Color)
ReDim _box_list(10, 10)
End Sub
Edit 2: How box_list is defined (In board class)
Private Sub BuildBoard()
For y As Integer = 0 To 9
For x As Integer = 0 To 9
Dim box As New Box(x, y, New PictureBox)
With box
.image.Location = New Point(start_location(0) + x * tile_size, start_location(1) + y * tile_size)
.image.Size = New Size(tile_size, tile_size)
.image.BackColor = colour
.image.BorderStyle = BorderStyle.FixedSingle
End With
box_list(x, y) = box
Main.Controls.Add(box_list(x, y).image)
Next
Next
End Sub
Edit 3: Definition of box
Public Class Box
Dim _image As PictureBox
Public Property image() As PictureBox
Get
Return _image
End Get
Set(ByVal value As PictureBox)
_image = value
End Set
End Property
Dim _full As Boolean
Public Property full() As Boolean
Get
Return _full
End Get
Set(ByVal value As Boolean)
_full = full
End Set
End Property
Public Sub New(ByVal location_x As Integer, ByVal location_y As Integer, ByVal imagep As PictureBox)
image = imagep
End Sub
End Class
Your problem with this code is in the full
property on the Box
class.
You have it written like this now:
Public Property full() As Boolean
Get
Return _full
End Get
Set(ByVal value As Boolean)
_full = full
End Set
End Property
It should be this:
Public Property full() As Boolean
Get
Return _full
End Get
Set(ByVal value As Boolean)
_full = value
End Set
End Property
Your current code is recursively setting the property back to its own value. Hence it is staying false
.
这篇关于布尔被设置为False时,它再次访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!