掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
デスピサロ (ID:147117)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
>使用後に Dispose を呼び出す必要があります。 おっしゃる通りです。手抜きしていました。 修正しました。 追加で,大当たりの判定を追加しました。 >シフト演算ですが、厳密に正確に言えばシフトしません。 厳密で正確に言わないシフト演算だったのですね。 もしかして「ビット演算」も「論理和」も厳密で正確に言わない パターンですか? Public Class Form1 Dim Slot(2) As Drum Dim WithEvents StartButton As New Button Dim StopButton(2) As Button Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For i As Integer = 0 To Slot.Length - 1 Slot(i) = New Drum Slot(i).SetBounds(i * 64, 0, 64, 64) AddHandler Slot(i).Stopped, AddressOf Drum_Stopped StopButton(i) = New Button StopButton(i).Text = "ストップ" StopButton(i).Tag = i StopButton(i).SetBounds(i * 64, 64, 64, 24) AddHandler StopButton(i).Click, AddressOf StopButton_Click StartButton.Text = "スタート" StartButton.SetBounds(64 * 3, 0, 64, 24) Next Me.Controls.AddRange(Slot) Me.Controls.AddRange(StopButton) Me.Controls.Add(StartButton) End Sub Private Sub Drum_Stopped(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim Stopped As Boolean = True For Each d As Drum In Slot Stopped *= d.Status = "Stopped" Next If Stopped Then Dim Fever As Boolean = True For Each d As Drum In Slot Fever *= Slot(0).DrumPosition = d.DrumPosition Next If Fever Then MessageBox.Show("大当たり", "おめでとう", MessageBoxButtons.OK) End If End If End Sub Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click For Each d As Drum In Slot d.Start() Next End Sub Private Sub StopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Slot(CInt(DirectCast(sender, Button).Tag)).Stop() End Sub Class Drum Inherits PictureBox Private WithEvents _Timer As New Timer Property DrumPosition As Integer Property Status As String = "Stopped" Public Event Stopped(ByVal sender As Object, ByVal e As EventArgs) Sub New() Dim DrumString As String() = New String() {"★", "◎", "□", "△", "◆", "♂", "★"} Me.Image = New Bitmap(32, 32 * DrumString.Length) Using g As Graphics = Graphics.FromImage(Me.Image) g.FillRectangle(Brushes.Green, Rectangle.Round(g.VisibleClipBounds)) For i As Integer = 0 To DrumString.Length - 1 g.DrawString(DrumString(i), New Font("MS ゴシック", 18), Brushes.White, New RectangleF(0, 32 * i + 4, 32, 32 - 4)) Next End Using Me._Timer.Interval = 10 End Sub Public Sub Start() Debug.Print(Me.Status) If Me._Status = "Stopped" Then Me._Status = "Rolling" Me._Timer.Start() End If End Sub Public Sub [Stop]() If Me._Status = "Rolling" Then Me._Status = "Stopping" End If End Sub Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs) pe.Graphics.DrawImage(Me.Image, Me.ClientRectangle, New Rectangle(0, Me._DrumPosition, 32, 32), GraphicsUnit.Pixel) End Sub Private Sub _Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _Timer.Tick Me._DrumPosition += CInt(IIf(Me._Status = "Rolling", 4, 1)) If Me._DrumPosition + 32 > Me.Image.Height Then Me._DrumPosition -= Me.Image.Height - 32 End If Me.Invalidate() If Me._Status = "Stopping" AndAlso Me._DrumPosition Mod 32 = 0 Then Me._Status = "Stopped" Me._Timer.Stop() RaiseEvent Stopped(Me, New EventArgs) End If End Sub Private Sub Drum_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed Me._Timer.Dispose() End Sub End Class End Class
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.