static void Main(string[] args) { ConsoleKeyInfo cki; Console.TreatControlCAsInput = true; Levels level1 = new Levels(); Labyrinthe laby = new Labyrinthe(level1.level1); Pacman pacman = new Pacman(); Ghost ghost1 = new Ghost(); Ghost ghost2 = new Ghost(10); Ghost ghost3 = new Ghost(20); Ghost ghost4 = new Ghost(30); pacman.setPlace(laby); ghost1.setPlace(laby); laby.printLaby(pacman); do { cki = Console.ReadKey(); pacman.move(cki.Key, laby); ghost1.move(laby, pacman); ghost2.move(laby, pacman); ghost3.move(laby, pacman); ghost4.move(laby, pacman); laby.printLaby(pacman); } while (cki.Key != ConsoleKey.Escape); }
private bool allowedDir(Labyrinthe laby, string dir) { switch (dir) { case "top": return(laby.allowToGo(x - 1, y)); case "bottom": return(laby.allowToGo(x + 1, y)); case "right": { if (x == 10 && y == 18) { return(true); } else { return(laby.allowToGo(x, y + 1)); } } case "left": { if (x == 10 && y == 0) { return(true); } else { return(laby.allowToGo(x, y - 1)); } } default: return(false); } }
public virtual void move(ConsoleKey key, Labyrinthe laby) { switch (key) { case ConsoleKey.UpArrow: { if (laby.allowToGo(x - 1, y)) { x--; } } break; case ConsoleKey.DownArrow: { if (laby.allowToGo(x + 1, y)) { x++; } } break; case ConsoleKey.RightArrow: { if (x == 10 && y == 18) { y = 0; laby.laby[10, 18].setStatement("eated"); } else if (laby.allowToGo(x, y + 1)) { y++; } } break; case ConsoleKey.LeftArrow: { if (x == 10 && y == 0) { y = 18; laby.laby[10, 0].setStatement("eated"); } else if (laby.allowToGo(x, y - 1)) { y--; } } break; default: { } break; } setPlace(laby); }
public override void setPlace(Labyrinthe level) { if (super) { level.laby[x, y].setStatement("superhero"); } else { base.setPlace(level); } }
public void death(Labyrinthe laby) { if (life > 0) { life--; laby.laby[x, y].setStatement("eated"); x = 12; y = 9; } else if (life == 0) { laby.gameOver(); } }
private void takeDirection(Labyrinthe laby, string dir) { laby.laby[x, y].rollbackStatement(); switch (dir) { case "top": { x--; } break; case "bottom": { x++; } break; case "right": { if (x == 10 && y == 18) { y = 0; } else { y++; } } break; case "left": { if (x == 10 && y == 0) { y = 18; } else { y--; } } break; } previous_dir = dir; }
public void move(Labyrinthe laby, Pacman pacman) { int num_dir; int indexRandom = 0; bool forwardPossible = false; bool turnsrightPossible = false; bool turnsleftPossible = false; if (alive) { foreach (string dirtocheck in dirToCheck()) { if (allowedDir(laby, dirtocheck)) { if (0 == dirtocheck.CompareTo(convertDir("forward"))) { indexRandom += 2; forwardPossible = true; } else if (0 == dirtocheck.CompareTo(convertDir("turnsright"))) { indexRandom += 1; turnsrightPossible = true; } else if (0 == dirtocheck.CompareTo(convertDir("turnsleft"))) { indexRandom += 1; turnsleftPossible = true; } } } num_dir = randomNumber(indexRandom); if (forwardPossible && num_dir <= 1) { takeDirection(laby, convertDir("forward")); } else if (forwardPossible && turnsleftPossible && turnsrightPossible) { if (num_dir == 2) { takeDirection(laby, convertDir("turnsright")); } if (num_dir == 3) { takeDirection(laby, convertDir("turnsleft")); } } else if (!forwardPossible && turnsrightPossible && turnsleftPossible) { if (num_dir == 0) { takeDirection(laby, convertDir("turnsright")); } if (num_dir == 1) { takeDirection(laby, convertDir("turnsleft")); } } else if (!forwardPossible && !turnsleftPossible) { takeDirection(laby, convertDir("turnsright")); } else if (!forwardPossible && !turnsrightPossible) { takeDirection(laby, convertDir("turnsleft")); } if (x == pacman.x && y == pacman.y) { if (pacman.super) { death(pacman); } else { pacman.death(laby); } } setPlace(laby); } else { respawn_time--; if (respawn_time == 0) { alive = true; x = 10; y = 9; } } }
public virtual void setPlace(Labyrinthe level) { level.laby[x, y].setStatement(name); }
public override void move(ConsoleKey key, Labyrinthe laby) { if (super) { super_time--; } if (super_time == 0) { super = false; } switch (key) { case ConsoleKey.UpArrow: { if (laby.allowToGo(x - 1, y)) { x--; if (laby.toEat(x, y)) { points += 100; laby.nbGums--; if (laby.laby[x, y].getStatement().CompareTo("supercandy") == 0) { super = true; super_time = 15; } } laby.eatGum(x + 1, y); } } break; case ConsoleKey.DownArrow: { if (laby.allowToGo(x + 1, y)) { x++; if (laby.toEat(x, y)) { points += 100; laby.nbGums--; if (laby.laby[x, y].getStatement().CompareTo("supercandy") == 0) { super = true; super_time = 15; } } laby.eatGum(x - 1, y); } } break; case ConsoleKey.RightArrow: { if (x == 10 && y == 18) { y = 0; laby.laby[10, 18].setStatement("eated"); } else if (laby.allowToGo(x, y + 1)) { y++; if (laby.toEat(x, y)) { points += 100; laby.nbGums--; if (laby.laby[x, y].getStatement().CompareTo("supercandy") == 0) { super = true; super_time = 15; } } laby.eatGum(x, y - 1); } } break; case ConsoleKey.LeftArrow: { if (x == 10 && y == 0) { y = 18; laby.laby[10, 0].setStatement("eated"); } else if (laby.allowToGo(x, y - 1)) { y--; if (laby.toEat(x, y)) { points += 100; laby.nbGums--; if (laby.laby[x, y].getStatement().CompareTo("supercandy") == 0) { super = true; super_time = 15; } } laby.eatGum(x, y + 1); } } break; default: { } break; } if (laby.nbGums == 0) { laby.endGame(); } setPlace(laby); }