private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Down) { Game.MoveDirection = Direction.Down; } else if (e.KeyCode == Keys.Up) { Game.MoveDirection = Direction.Up; } else if (e.KeyCode == Keys.Left) { Game.MoveDirection = Direction.Left; } else if (e.KeyCode == Keys.Right) { Game.MoveDirection = Direction.Right; } else if (e.KeyCode == Keys.Enter) { if (MSGBox.OnCloseEvent != null) { MSGBox.OnCloseEvent(sender, e); } } else if (e.KeyCode == Keys.P || e.KeyCode == Keys.Pause) { Game.Paused = !Game.Paused; } else { return; } if (!Game.Paused) { Game.Refresh(); } }
public static void Start(GameStartMode mode) { switch (mode) { case GameStartMode.SinglePlayer: MSGBox.ShowMSGBox("New singleplayer game", "Size:", MSGBoxType.SizeInput, new EventHandler <string>(delegate(object s, string inp) { int input = int.Parse(inp); if (input > 5) { GameRenderer.Panel.CreateGraphics().FillRectangle(new SolidBrush(Color.Black), new Rectangle(new Point(), GameRenderer.Panel.Size)); //int xy = GameRenderer.Panel.Size.Width / input; //GameSize = new Point(xy, xy); if (GameRenderer.Panel.Size.Width / input < 3 || GameRenderer.Panel.Size.Height / input < 3) { Game.Paused = true; return; } GameSize = new Point(GameRenderer.Panel.Size.Width / input, GameRenderer.Panel.Size.Height / input); Game.Reset(); Form1.TimerEnabled = true; } else { Game.Paused = true; } })); break; case GameStartMode.MultiPlayer: if (Game.Player.Name == "Player") { MSGBox.ShowMSGBox("Please change your username from default.", "", MSGBoxType.Text); break; } MSGBox.ShowMSGBox("New multiplayer game", "Name:\nMax. players:", MSGBoxType.MultipleInput, new EventHandler <string>(delegate(object s, string input) { string[] strs = input.Split('\n'); int num = 0; if (int.TryParse(strs[1], out num)) { var match = new NetMatch { Name = strs[0], MaxPlayers = num, OwnerIP = Network.GetIPs(), OwnerName = Player.Name }; match.Players.Add(Game.Player); Game.Reset(); Network.CreateGame(match); } else { Game.Paused = true; } })); break; case GameStartMode.Connect: if (Game.Player.Name == "Player") { MSGBox.ShowMSGBox("Please change your username from default.", "", MSGBoxType.Text); break; } //string matches = Network.Matches.Combine<NetMatch, string>((match, combiner) => combiner += match.Name + " " + match.Players.Count + "/" + match.MaxPlayers + " " + match.OwnerName + "\n"); string inputs = "IP:"; MSGBox.ShowMSGBox("Connect to game", inputs, MSGBoxType.MultipleInput, new EventHandler <string>(delegate(object s, string input) { IPAddress address; if (IPAddress.TryParse(input.Replace("\n", ""), out address)) { Game.Reset(); Network.Connect(new NetMatch { OwnerIP = new IPAddress[] { address } }); //Game.Reset(false); - On successfull connect event } else { Game.Paused = true; } })); break; default: throw new ArgumentException(); } }
public static void Stop() { MSGBox.ShowMSGBox("Game over!", "", MSGBoxType.Text); Game.Paused = true; Network.Leave(); //2015.08.29. }