static void Main(string[] args) { CharMap cm = new CharMap(); Frame so = new Frame(); System.Diagnostics.Debug.WriteLine(cm == null); Player player = new Player(cm); Enemy troll = new Enemy(cm, 10); KeyListener list = new KeyListener(); player.AddCharacter(); so.Output(cm); while (playing) { Thread.Sleep(10); list.ReadKey(player,so,cm); } }
public void Output(CharMap cm) { Console.CursorVisible = false; CenteredConsole(cm.Length,cm.Rows,(113- cm.Length),(33 - cm.Rows)); for (int i = 0; i < cm.Length; i++) { for (int j = 0; j < cm.Rows; j++) { if (CharMap.Map[i, j].Repaint) { Console.SetCursorPosition(CenterX + i, CenterY + j); Console.BackgroundColor = CharMap.Map[i, j].BackgroundColor; Console.ForegroundColor = CharMap.Map[i, j].ForegroundColor; Console.Write(CharMap.Map[i, j].Char); CharMap.Map[i, j].Repaint = false; } if(j == cm.Length - 1) { Console.WriteLine(); } } Console.ForegroundColor = ConsoleColor.Gray; Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition(cm.Length + CenterX * 2, cm.Rows + CenterY * 2); } if (Program.playing == false) { Console.Clear(); string text = (Program.win == true ? "You Won!" : "Game Over!") + " Press ESC to Quit"; CenteredConsole(text.Length,2,(113 - text.Length),(33 - 2)); Console.SetCursorPosition(CenterX, CenterY); Console.Write(text); } }
public Enemy(CharMap cm , int num) { this.cm = cm; AddTroll(num); }
public void ReadKey(Player p,Frame so,CharMap cm) { ConsoleKeyInfo key = new ConsoleKeyInfo(); while(key.Key != ConsoleKey.Escape) { key = Console.ReadKey(); switch(key.Key) { case ConsoleKey.LeftArrow: if(p.GamePlayer.Char != (char)PlayerMov.Left) { p.GamePlayer.Char = (char)PlayerMov.Left; break; } p.Move(-1, 0); break; case ConsoleKey.RightArrow: if (p.GamePlayer.Char != (char)PlayerMov.Right) { p.GamePlayer.Char = (char)PlayerMov.Right; break; } p.Move(1, 0); break; case ConsoleKey.DownArrow: if (p.GamePlayer.Char != (char)PlayerMov.Down) { p.GamePlayer.Char = (char)PlayerMov.Down; break; } p.Move(0, 1); break; case ConsoleKey.UpArrow: if(p.GamePlayer.Char != (char)PlayerMov.Up) { p.GamePlayer.Char = (char)PlayerMov.Up; break; } p.Move(0, -1); break; case ConsoleKey.Escape: Program.playing = false; break; default: Console.Write("\b \b"); break; } p.GamePlayer.Repaint = true; so.Output(cm); } }
public Player(CharMap cm) { this.cm = cm; }