public partial class Form1 : Form
{
Geyhound dog0;
Geyhound dog1;
Geyhound dog2;
Geyhound dog3;
public Form1()
{
InitializeComponent();
dog0 = new Geyhound();
dog0.Randomizer = new Random();
dog0.MyPictureBox = new PictureBox();
dog0.StartingPosition = pictureBox2.Location.X;
dog0.RacetrackLength = pictureBox1.Size.Width;
dog0.MyPictureBox = pictureBox2;
dog1 = new Geyhound();
dog1.Randomizer = new Random();
dog1.MyPictureBox = new PictureBox();
dog1.StartingPosition = pictureBox3.Location.X;
dog1.RacetrackLength = pictureBox1.Size.Width;
dog1.MyPictureBox = pictureBox3;
dog2 = new Geyhound();
dog2.Randomizer = new Random();
dog2.MyPictureBox = new PictureBox();
dog2.StartingPosition = pictureBox4.Location.X;
dog2.RacetrackLength = pictureBox1.Size.Width;
dog2.MyPictureBox = pictureBox4;
dog3 = new Geyhound();
dog3.Randomizer = new Random();
dog3.MyPictureBox = new PictureBox();
dog3.StartingPosition = pictureBox5.Location.X;
dog3.RacetrackLength = pictureBox1.Size.Width;
dog3.MyPictureBox = pictureBox5;
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
Geyhound[] dogs = new Geyhound[4];
dogs[0] = dog0;
dogs[1] = dog1;
dogs[2] = dog2;
dogs[3] = dog3;
Geyhound one = dogs[0];
Geyhound two = dogs[1];
Geyhound three = dogs[2];
Geyhound four = dogs[3];
one.Run();
two.Run();
three.Run();
four.Run();
if (one.Run())
{
timer1.Enabled = false;
}
else
{
timer1.Enabled = true;
}
if (two.Run())
{
timer1.Enabled = false;
}
else
{
timer1.Enabled = true;
}
if (three.Run())
{
timer1.Enabled = false;
}
else
{
timer1.Enabled = true;
}
if (four.Run())
{
timer1.Enabled = false;
}
else
{
timer1.Enabled = true;
}
}
}
物件
class Geyhound
{
public int StartingPosition;
public int RacetrackLength;
public PictureBox MyPictureBox = null;
public int Location = 0;
public Random Randomizer;
public int[] Picturebox_move ={1,2,3,4,5,6};
public bool Run()
{
int distance = Picturebox_move[Randomizer.Next(Picturebox_move.Length)];
Point p = MyPictureBox.Location;
p.X += distance;
MyPictureBox.Location = p;
if (MyPictureBox.Location.X >=RacetrackLength)
{
return true;
}
else
{
return false;
}
}
我想做的事4張PICTURE各代表一隻狗比賽跑步~先到終點的就贏~不過我用public Random Randomizer 後來跑出來四張圖都等速度前進耶~不知道哪裡錯了~麻煩大大了
這樣PO不知道好不是還是有大大可以加一下MSN討論~謝謝
a730919a@yahoo.com.tw