Вход/Регистрация
Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 6: Программирование на Visual Basic искусственного интеллекта. Продолжение 2
вернуться

Жарков Валерий

Шрифт:

''' <param name="score"></param>

''' <remarks></remarks>

Public Shared Sub UpdateScores(ByVal score As Integer)

Dim tops(3) As HighScore

Dim scoreKey As RegistryKey = Registry.CurrentUser. _

CreateSubKey("Software\VBSamples\Collapse\HighScores")

tops(0) = New HighScore(scoreKey.GetValue("Place0").ToString)

tops(1) = New HighScore(scoreKey.GetValue("Place1").ToString)

tops(2) = New HighScore(scoreKey.GetValue("Place2").ToString)

If score > tops(2).Score Then

Dim name As String = InputBox("New high score of " & _

score & " for:")

tops(3) = New HighScore(" :0")

tops(3).Name = name

tops(3).Score = score

Array.Sort(tops)

Array.Reverse(tops)

scoreKey.SetValue("Place0", tops(0).ToString)

scoreKey.SetValue("Place1", tops(1).ToString)

scoreKey.SetValue("Place2", tops(2).ToString)

End If

scoreKey.Close

End Sub

''' <summary>

''' Set up the entries for new scores.

''' </summary>

''' <remarks></remarks>

Shared Sub SetUpHighScores

Dim scoreKey As RegistryKey = Registry.CurrentUser. _

CreateSubKey("Software\VBSamples\Collapse\HighScores")

If scoreKey.GetValue("Place1") Is Nothing Then

scoreKey.SetValue("Place0", " :0")

scoreKey.SetValue("Place1", " :0")

scoreKey.SetValue("Place2", " :0")

End If

scoreKey.Close

End Sub

''' <summary>

''' Reset scores.

''' </summary>

''' <remarks></remarks>

Shared Sub ResetScores

Dim scoreKey As RegistryKey = Registry.CurrentUser. _

CreateSubKey("Software\VBSamples\Collapse\HighScores")

scoreKey.SetValue("Place0", " :0")

scoreKey.SetValue("Place1", " :0")

scoreKey.SetValue("Place2", " :0")

scoreKey.Close

End Sub

End Class

По второму варианту, в панели Solution Explorer выполняем правый щелчок по имени проекта и в контекстном меню выбираем Add, New Item, в панели Add New Item выделяем шаблон Code File, в окне Name записываем имя PointTranslator.vb и щёлкаем кнопку Add. В проект (и в панель Solution Explorer) добавляется этот файл, открывается пустое окно редактирования кода, в которое записываем код со следующего листинга.

Листинг 20.20. Новый файл.

''' <summary>

''' Form coordinates have the top, left as (0,0). For the game grid,

''' it is easier to have the bottom left of the grid as (0,0). This

''' translates the points.

''' </summary>

''' <remarks></remarks>

Public Class PointTranslator

Private Shared graphicsValue As Graphics

Private Shared height As Integer

Public Shared Property Graphics As Graphics

Get

Return graphicsValue

End Get

Set(ByVal Value As Graphics)

graphicsValue = Value

height = CInt(graphicsValue.VisibleClipBounds.Height)

End Set

End Property

' Translates an (X,Y) point from the top left to

' an (X, Y) point from the bottom left.

Public Shared Function TranslateToBL(ByVal topleft As Point) _

As Point

Dim newPoint As Point

newPoint.X = topleft.X

newPoint.Y = height – topleft.Y

Return newPoint

End Function

Public Shared Function TranslateToTL(ByVal bottomleft As Point) _

As Point

Dim newPoint As Point

newPoint.X = bottomleft.X

newPoint.Y = height – bottomleft.Y

Return newPoint

End Function

End Class

После этих добавлений ( Block.vb, Grid.vb, HighScore.vb, HighScores.vb, PointTranslator.vb) в панели Solution Explorer должны быть файлы, показанные выше. Дважды щёлкая по имени файла, любой файл можно открыть, изучить и редактировать.

Теперь в наш проект добавляем переменные и методы, связанные с формой Form2 для вывода результатов игры.

Открываем файл Form2.vb (например, по схеме: File, Open, File) и в классе Form2 нашего проекта записываем следующее свойство.

Листинг 20.21. Свойство.

Public Property SoundOn As Boolean

Get

Return Me.isSoundOn.Checked

End Get

Set(ByVal Value As Boolean)

Me.isSoundOn.Checked = Value

End Set

End Property

  • Читать дальше
  • 1
  • ...
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • ...

Ебукер (ebooker) – онлайн-библиотека на русском языке. Книги доступны онлайн, без утомительной регистрации. Огромный выбор и удобный дизайн, позволяющий читать без проблем. Добавляйте сайт в закладки! Все произведения загружаются пользователями: если считаете, что ваши авторские права нарушены – используйте форму обратной связи.

Полезные ссылки

  • Моя полка

Контакты

  • chitat.ebooker@gmail.com

Подпишитесь на рассылку: