private void keyDownHandler(object sender, KeyEventArgs args) { if (collectionInProgress) { if (args.KeyCode == Keys.Q) { skip = true; } else { acceptKey = args.KeyCode + ""; try { danger = Int16.Parse(args.KeyValue + "") - 48; } catch { } } } if (args.KeyCode == Keys.Left || args.KeyCode == Keys.Right || args.KeyCode == Keys.Up || args.KeyCode == Keys.Down) { lastKey = args.KeyCode; switch (args.KeyCode) { case Keys.Up: gameState.Pacman.SetDirection(Direction.Up); break; case Keys.Down: gameState.Pacman.SetDirection(Direction.Down); break; case Keys.Left: gameState.Pacman.SetDirection(Direction.Left); break; case Keys.Right: gameState.Pacman.SetDirection(Direction.Right); break; } } if (args.KeyCode == Keys.Space) { if (gameState.Started) { gameState.PausePlay(); } else { gameState.ResumePlay(); } } if (args.KeyCode == Keys.R) { gameState.ReverseGhosts(); } if (args.KeyCode == Keys.S) { step = true; } }
// This utilizes the likes of the 2D array enum to determine whether or not // a pill has been eaten at a given co-ordinate protected override void ProcessNodeSimulated() { if (GameState.Map.NodeData[Node.X, Node.Y] == Node.NodeType.Pill || GameState.Map.NodeData[Node.X, Node.Y] == Node.NodeType.PowerPill) { if (GameState.Map.NodeData[Node.X, Node.Y] == Node.NodeType.PowerPill) { foreach (Ghosts.Ghost g in GameState.Ghosts) { g.Flee(); } eatGhostBonus = 200; score += 50; if (GameState.Controller != null) { GameState.Controller.EatPowerPill(); // GameState.PacmanMortal = true; } GameState.ReverseGhosts(); } else { score += 10; if (GameState.Controller != null) { GameState.Controller.EatPill(); } } GameState._pillsEaten++; GameState.Map.NodeData[Node.X, Node.Y] = Node.NodeType.None; GameState.Map.Nodes[Node.X, Node.Y].Type = Node.NodeType.None; GameState.Map.PillsLeft--; if (score >= 10000 && !gotExtraLife) { gotExtraLife = true; lives++; } } }