| 分類:[C#]
Visual C#のフォームアプリケーションでスロットマシーンゲームを作ろうと考えています。 8個の画像を用意して3箇所の表示場所に順番に表示させていくプログラムを考えました。 キーボードで止めるためスレッドを使っています。重要そうな部分だけ書いていきます。
public int Reel; Picture[0] = pictureBox1; Picture[1] = pictureBox2; Picture[2] = pictureBox3; Picture[3] = pictureBox4; Picture[4] = pictureBox5; Picture[5] = pictureBox6; Picture[6] = pictureBox7; Picture[7] = pictureBox8; private void Start() { while (Stopper == 0) { Thread.Sleep(10); Starting(); } }
protected delegate void StartEventHandler(); protected void Starting() {
if (InvokeRequired) { StartEventHandler reh = new StartEventHandler(Starting); Invoke(reh); } else { //Pictureを1.2.3.4.5.6.7.8.1.2.3...と順に表示していく else if (Reel == 7) { Zugara.Run(Picture[7], Picture[0], Picture[1]);
Thread.Sleep(300); Reel=0; } //Thread.Sleep(1); else if (Reel == 6) { Zugara.Run(Picture[6], Picture[7], Picture[0]); Thread.Sleep(300); Reel++; } else { Zugara.Run(Picture[Reel], Picture[(Reel + 1)], Picture[(Reel + 2)]); Thread.Sleep(300); Reel++; } } }
//Zugara.cs
public void Run(PictureBox picturebox1, PictureBox picturebox2, PictureBox picturebox3) { this.MyPictureBox1 = picturebox1; this.MyPictureBox2 = picturebox2; this.MyPictureBox3 = picturebox3; Redraw(); this.MyPictureBox1.Refresh(); this.MyPictureBox2.Refresh(); this.MyPictureBox3.Refresh();
}
private void Redraw() { MyPictureBox1.Location = new Point(175, 80); MyPictureBox2.Location = new Point(175, 135); MyPictureBox3.Location = new Point(175, 190); }
これで動かすと、2週目のPicture[0]がMyPictureBox1に表示されるべき部分で前の画像が表示されたままになってしまいます。 MypictureBox1だけでなくMypictureBox2、MypictureBox3の挙動も正常のようには見えないです(同じ画像が2連続で表示されるなど)。 上書きを重ねているのでどこかおかしな所が出る可能性はありますが、原因がわかりません。解決に協力お願いします。 |