public virtual void SetDirection(PacMan pac) { if (this.IsStopped) { //Si va en direccion derecha o izquierda, cambia su direccion hacia arriba o abajo if (this.dir == 1 || this.dir == 2) { int num = random.Next(1, 100); if (num <= 50) { this.dir = 3; } else { this.dir = 4; } } else { //Si va en direccion hacia arriba o abajo, cambia su direccion hacia la derecha o izquierda int num = random.Next(1, 100); if (num <= 50) { this.dir = 2; } else { this.dir = 1; } } } //Se establece la direccion switch (this.dir) { case 1: this.direction = Direction.Left; break; case 2: this.direction = Direction.Right; break; case 3: this.direction = Direction.Up; break; case 4: this.direction = Direction.Down; break; default: break; } }
public Form1() { InitializeComponent(); pac = new PacMan(); this.walls = new List <PictureBox>(); this.dots = new List <PictureBox>(); this.wallhided = new List <PictureBox>(); this.ghosts = new List <Ghost>(); this.ghosts.Add(redGhost); this.ghosts.Add(redGhost2); this.ghosts.Add(redGhost3); this.ghosts.Add(redGhost4); //Se agrega cada elemento a su lista correspondiente foreach (PictureBox pic in this.Controls) { Type t = pic.GetType(); if (t == typeof(PictureBox)) { if ((String)pic.Tag == "wall") { this.walls.Add(pic); } else if ((String)pic.Tag == "dot") { this.dots.Add(pic); } else if ((String)pic.Tag == "wallhided") { this.wallhided.Add(pic); } } } }