public IScreen Start() { Game.Network.Header.Add(new NetworkLibrary.Utilities.Header("prog", "shooter")); Game.Network.OnWarningOccured += new NetworkLibrary.Exceptions.delegateWarning(Network_OnWarningOccured); Game.Network.OnNotificationOccured += new NetworkLibrary.Exceptions.delegateNotification(Network_OnNotificationOccured); string message; if (_host) message = "Initialising host and starting\nto listen on port 33060."; else message = "Initialising client and connecting\nto ip " + _ip + " on port 33060."; Menu m = new Menu(Label.CreateLabelArrayFromText(message)); m.Start(-1, 3, false); try { if (_host) (Game.Network as ConnectionHost).StartBroadcasting(); else (Game.Network as ConnectionClient).Connect(_ip, 33060); m.Clear(); return RegisterDefault(_host); } catch (Exception e) { string err; if (_host) err = "Error while starting host on port 33060:\n\n "; else err = "Error while connecting to " + _ip + " on port 33060:\n\n "; m = new Menu(Label.CreateLabelArrayFromText(err + e.Message)); m.Start(-1, 4); m.Clear(); return new MultiPlayer(); } }
public IScreen Start() { Menu m = new Menu("Multiplayer", "Hot Seat", "Direct IP", "Internet", "-", "Back to Main Menu"); int selected; IScreen next; do { switch (selected = m.Start(5, 8)) { case 0: if ((next = HotSeat()) != null) { m.Clear(); return next; } break; case 1: if ((next = DirectIP()) != null) { m.Clear(); return next; } break; } } while (selected != 4); return new Main(); }
public static void DisplayConnectionError(object reason) { string errReason = ""; if (reason is Exception) errReason = (reason as Exception).Message; else errReason = (string)reason; Menu m = new Menu("Connection lost", Label.CreateLabelArrayFromText("Connection to host has ended. The error message was:\n " + errReason)); m.Start(-1, 5, false); }
public Lobby(Game game) { _game = game; _players = new Label[] { new Label("<empty slot> "), new Label("<empty slot>"), new Label("<empty slot>"), new Label("<empty slot>") }; _chat = new Label[] { new Label(), new Label(), new Label(), new Label(), new Label() }; _mainMenu = new Menu("Chat", _chat); _menuSettings = new Menu("Game Settings", new OptionNumeric("Health", _game.DefaultHealth, 10, 1000, 10), new OptionValue(" Map", "<none>", 0), new Option("-"), new Option("-", 1)); _menuPlayers = new Menu("Lobby", _players); _menuSettings.MakeTight = _menuPlayers.MakeTight = true; _menuSettings.MaxLength = 51; }
protected void Config() { Menu m = new Menu("", "Player 1", "Player 2", "Player 3", "Player 4", "-", "Back"); int selected; do { selected = m.Start(26, 7); if (selected < 5) ConfigPlayer(selected); } while (selected != 5); m.Clear(); }
public static string AskInput(string name, int length, int x, int y) { OptionTextbox t = new OptionTextbox(name, length); Menu m = new Menu("", t, new Option("-"), new Option("Create game", 0), new Option("Back", 1)); switch (m.Start(x, y)) { case 0: m.Clear(); return t.Text; default: m.Clear(); return null; } }
private IScreen HotSeat() { OptionNumeric num = new OptionNumeric("Number of Players", 2, 2, 4); Menu m = new Menu("", num, new Option("-"), new Option("Create Game", 0), new Option("Back", 1)); switch (m.Start(35, 7)) { case 0: m.Clear(); return SelectMap(num.Value); default: m.Clear(); return null; } }
public IScreen Start() { Menu m = new Menu("Options", "Config", "-", "Back to Main Menu"); int selected; do { switch (selected = m.Start(3, 9)) { case 0: Config(); break; } } while (selected != 2); m.Clear(); return new Main(); }
public IScreen Start() { Menu m = new Menu("Main Menu", "Single Player", "Multiplayer", "-", "Options", "-", "Exit"); int selected = m.Start(-1, 5); m.Clear(); switch (selected) { case 0: return new SinglePlayer(); case 1: return new MultiPlayer(); case 3: return new Options(); default: return null; } }
private IScreen DirectIP() { Menu m = new Menu("", "Host a game", "Join a game", "-", "Back"); int selected = m.Start(35, 7); if (selected == 3) { m.Clear(); return null; } string name = CommonOptions.AskInput("Name", 12, 35, 7); if (string.IsNullOrEmpty(name)) return DirectIP(); if (selected == 0) return InitialiseNetGame(name, null); else { string ip = CommonOptions.AskInput("Ip", 15, 35, 7); if (string.IsNullOrEmpty(ip)) return DirectIP(); return InitialiseNetGame(name, ip); } }
public IScreen Start() { Menu m = new Menu("Single player", "Story Mode", "Custom Game", "-", "Back to Main Menu"); int selected; IScreen next; do { switch (selected = m.Start(5, 8)) { case 0: if ((next = CommonOptions.StartNewGame(true, 1, new Map())) != null) return next; break; case 1: if ((next = CustomGame()) != null) return next; break; } } while (selected != 3); return new Main(); }
public IScreen Start() { _active = true; Game.Network.OnDisconnected += Network_OnDisconnected; Game.Network.RegisterEvent((int)PacketCode.NewPlayer, NewPlayer); Game.Network.RegisterEvent((int)PacketCode.Chat, NewChat); Game.Network.RegisterEvent((int)PacketCode.StartGame, StartGame); Game.Network.RegisterEvent((int)CorePacketCode.PropertyUpdated, UpdateGameSettings); Game.Network.RegisterEvent((int)PacketCode.PlayerDisconnected, PlayerDisconnected); _menuPlayers.Start(60, 2, false); _menuSettings.Start(3, 2, false); UpdatePlayers(); OptionTextbox t = new OptionTextbox(_game.CurrentPlayer.Name, 70 - _game.CurrentPlayer.Name.Length - 2); _mainMenu.MakeTight = true; _mainMenu.Options.Add(new OptionHr()); _mainMenu.Options.Add(t); _mainMenu.Options.Add(new Option("Senda", 0)); if (Game.Network.NetworkType == NetworkLibrary.Core.NetworkType.Host) { _mainMenu.Options.Add(new Option("-")); _mainMenu.Options.Add(new Option("Configure", 1)); _mainMenu.Options.Add(new Option("Start Game", 2)); } _mainMenu.Options.Add(new Option("-")); _mainMenu.Options.Add(new Option("Exit Lobby", 3)); do { int sel = _mainMenu.Start(-1, 10); if (!Game.Network.NetworkConnection.Connected) return new Main(); switch (sel) { case 0: Game.Network.SendEvent((int)PacketCode.Chat, _game.CurrentPlayer.Name + ": " + t.Text, true); t.Text = ""; break; case 1: ConfigureGame(); break; case 2: if (PrepareStartGame()) { while (_game.Board == null) System.Threading.Thread.Sleep(100); } break; case 3: Game.Network.Disconnect(); return new Main(); } } while (_game.Board == null); if (Game.Network.NetworkType == NetworkType.Client) { _game.Board = Game.Network.NetworkDataHandler.RequestInstance<Board>(); if (_game.Players[0].Unit != _game.Board.Units[0]) { } if (_game.Board == null) { Menu m = new Menu(Label.CreateLabelArrayFromText("Invalid response received from host. Retrying in 1 sec.")); m.Start(-1, 8); System.Threading.Thread.Sleep(1000); _game.Board = Game.Network.NetworkDataHandler.RequestInstance<Board>(); if (_game.Board == null) { m = new Menu(Label.CreateLabelArrayFromText("Invalid response received from host, disconnecting.")); m.Start(-1, 8); Game.Network.Disconnect(); return new Main(); } } } _active = false; return new Shop(_game); }
bool PrepareStartGame() { if (_game.Map == null) { Menu m = new Menu(Label.CreateLabelArrayFromText("You have to choose a map before\nyou can start the game.")); m.Start(-1, 8); return false; } int players = 0; for (int i = 0; i < _game.Players.Length; i++) if (_game.Players[i] != null) players++; int maxAllowed = _game.Map.MaxPlayersAllowed(); if (players > maxAllowed) { Menu m = new Menu(Label.CreateLabelArrayFromText(string.Format("This map does not support so many players.\nMaximum allowed numbers of players for this map is {0}."))); m.Start(-1, 8); return false; } int width, height; Game.Network.SendEvent((int)PacketCode.StartGame, _game.Map.ReadMap(out width, out height), true); return true; }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Screen_Width = graphics.GraphicsDevice.Viewport.Width; Screen_Height = graphics.GraphicsDevice.Viewport.Height; if (Draw_Background == true) { Background_Texture = Content.Load<Texture2D>("Grass_Background2"); } Screen_Rectangle = new Rectangle(0, 0, Screen_Width, Screen_Height); Hud = new HUD(); Hud.Font = Content.Load<SpriteFont>("gameFont"); Hud.Lives = 3; Hud.Score = 0; Hud.Wave = 0; Tree1 = Content.Load<Texture2D>("Tree1"); Random Generate_Tree_Position = new Random(); int Tree_Position1_X = Generate_Tree_Position.Next(100, Screen_Width / 2 - 80), Tree_Position1_Y = Generate_Tree_Position.Next(100, Screen_Height / 2 - 105); int Tree_Position2_X = Generate_Tree_Position.Next(100, Screen_Width / 2 - 80), Tree_Position2_Y = Generate_Tree_Position.Next(Screen_Height / 2 + 105, Screen_Height - 215); int Tree_Position3_X = Generate_Tree_Position.Next(Screen_Width / 2 + 80, Screen_Width - 165), Tree_Position3_Y = Generate_Tree_Position.Next(100, Screen_Height / 2 - 105); int Tree_Position4_X = Generate_Tree_Position.Next(Screen_Width / 2 + 80, Screen_Width - 165), Tree_Position4_Y = Generate_Tree_Position.Next(Screen_Height / 2 + 105, Screen_Height - 215); //int Tree_Position5_X = Generate_Tree_Position.Next(800, 1100), Tree_Position5_Y = Generate_Tree_Position.Next(50, 400); //int Tree_Position6_X = Generate_Tree_Position.Next(800, 1100), Tree_Position6_Y = Generate_Tree_Position.Next(500, 800); Tree_Position1 = new Vector2(Tree_Position1_X, Tree_Position1_Y); Tree_Position2 = new Vector2(Tree_Position2_X, Tree_Position2_Y); Tree_Position3 = new Vector2(Tree_Position3_X, Tree_Position3_Y); Tree_Position4 = new Vector2(Tree_Position4_X, Tree_Position4_Y); //Tree_Position5 = new Vector2(Tree_Position5_X, Tree_Position5_Y); //Tree_Position6 = new Vector2(Tree_Position6_X, Tree_Position6_Y); Hero_Bullet = Content.Load<Texture2D>("Hero_Bullet"); for (int i = 0; i < 10; i++) { Hero_Bullets.Add(new Bullet()); } Hero_Grenade = Content.Load<Texture2D>("Hero_Grenade"); for (int i = 0; i < 4; i++) { Hero_Grenades.Add(new Grenade()); } Explosion = Content.Load<Texture2D>("Explosion"); Hero_Stand_Right = Content.Load<Texture2D>("Hero_Stand_Right"); Hero_Move_Right = Content.Load<Texture2D>("Hero_Move_Right"); Hero_Stand_Left = Content.Load<Texture2D>("Hero_Stand_Left"); Hero_Move_Left = Content.Load<Texture2D>("Hero_Move_Left"); Hero_Stand_Up = Content.Load<Texture2D>("Hero_Stand_Up"); Hero_Move_Up = Content.Load<Texture2D>("Hero_Move_Up"); Hero_Stand_Down = Content.Load<Texture2D>("Hero_Stand_Down"); Hero_Move_Down = Content.Load<Texture2D>("Hero_Move_Down"); Hero_Heart = Content.Load<Texture2D>("Hero_Heart"); Crosshair_Final = Content.Load<Texture2D>("Crosshair_Final"); Shield_Final = Content.Load<Texture2D>("Shield_Final"); Hero_Start_Position = new Vector2(Screen_Width / 2, Screen_Height / 2); Hero = new HeroSprite(Hero_Stand_Right, Hero_Move_Right, Hero_Stand_Left, Hero_Move_Left, Hero_Stand_Up, Hero_Move_Up, Hero_Stand_Down, Hero_Move_Down, Shield_Final, Hero_Start_Position); Powerup_Godmode = Content.Load<Texture2D>("Powerup_Godmode"); Powerup_Gun = Content.Load<Texture2D>("Powerup_Gun"); Powerup_Speed = Content.Load<Texture2D>("Powerup_Speed"); Powerup_Heart = Content.Load<Texture2D>("Powerup_Heart"); Powerup_Spawn_Rate = 400; for (int i = 0; i < 4; i++) { Powerups.Add(new Powerup()); } Enemy_Tank_ShootRight = Content.Load<Texture2D>("Enemy_Tank_ShootRight"); Enemy_Tank_StandRight = Content.Load<Texture2D>("Enemy_Tank_StandRight"); Enemy_Tank_ShootLeft = Content.Load<Texture2D>("Enemy_Tank_ShootLeft"); Enemy_Tank_StandLeft = Content.Load<Texture2D>("Enemy_Tank_StandLeft"); Enemy_Tank_Bullet = Content.Load<Texture2D>("Enemy_Tank_Bullet"); for (int i = 0; i < 4; i++) { Enemy_Tanks.Add(new EnemySprite()); } for (int i = 0; i < 20; i++) { Enemy_Tank_Bullets.Add(new Bullet()); } Enemy_Grunt_ShootRight = Content.Load<Texture2D>("Enemy_Grunt_ShootRight"); Enemy_Grunt_StandRight = Content.Load<Texture2D>("Enemy_Grunt_StandRight"); Enemy_Grunt_ShootLeft = Content.Load<Texture2D>("Enemy_Grunt_ShootLeft"); Enemy_Grunt_StandLeft = Content.Load<Texture2D>("Enemy_Grunt_StandLeft"); Enemy_Grunt_Bullet = Content.Load<Texture2D>("Hero_Bullet"); for (int i = 0; i < 4; i++) { Enemy_Grunts.Add(new EnemySprite()); } for (int i = 0; i < 20; i++) { Enemy_Grunt_Bullets.Add(new Bullet()); } Enemy_Charger_AttackRight = Content.Load<Texture2D>("Enemy_Charger_AttackRight"); Enemy_Charger_RunRight = Content.Load<Texture2D>("Enemy_Charger_RunRight"); Enemy_Charger_AttackLeft = Content.Load<Texture2D>("Enemy_Charger_AttackLeft"); Enemy_Charger_RunLeft = Content.Load<Texture2D>("Enemy_Charger_RunLeft"); for (int i = 0; i < 4; i++) { Enemy_Chargers.Add(new EnemySprite()); } //Menu_Background = Content.Load<Texture2D>("Menu_Background"); Menu_Background = Content.Load<Texture2D>("Grass_Background2"); Texture2D Help = Content.Load<Texture2D>("Help"); Menu = new Menu(Content.Load<SpriteFont>("gameFont"), graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height, Crosshair_Final, Help); GameOver_Background = Content.Load<Texture2D>("Game_Over_Screen"); }
public IScreen Start() { if (Game.Network != null) Game.Network.RegisterEvent((int)PacketCode.ClearBullet, ClearBullet); Console.Clear(); while (Console.KeyAvailable) Console.ReadKey(true); _game.InitialiseGame(); int numPlayers = _game.NumberOfPlayers; if (_game.InStoryMode) { Menu m; if (_game.StoryLevel == 0) { m = new Menu("Tutorial", Label.CreateLabelArrayFromText( "\nFirst time player? Here is some info you might\nwant to know:\n\n" + "Weapons:\n p = Pistol (Ammo: 7, Speed: slow, Damage: 15hp)\n" + " m = Machine gun (Ammo: 50, Speed: fast, Damage: 5hp)\n" + "Other:\n D = Door\n X = Locked door, need a key to open\n k = Key, need to open locked doors\n\n e = Enemies, shoot them\n")); m.Start(-1, 5); m.Clear(); } _game.Board.ParseMapText(); m = new Menu(Label.CreateLabelArrayFromText("\n" + _game.Board.Map.MapText)); m.Start(-1, 3); m.Clear(); } Console.CursorVisible = false; _game.Board.DrawBase(); int alive = 0; do { if (Game.Network != null && !Game.Network.NetworkConnection.Connected) return new Main(); if (!_game.InCutSchene) _game.Board.Update(); _game.Board.Draw(); System.Threading.Thread.Sleep(10); alive = 0; for (int i = 0; i < _game.Players.Length; i++) if (_game.Players[i] != null) if (_game.Players[i].Unit.Health > 0) alive++; if (alive == 1 && numPlayers > 1 && !_game.Board.Coop) _game.Won = true; } while (!Game.KeyIsDown((int)System.Windows.Forms.Keys.Escape) && !_game.Won && alive > 0); while (Console.KeyAvailable) Console.ReadKey(true); if (alive == 0) { Menu m = new Menu("Game Over", Label.CreateLabelArrayFromText( "You lost the game. ")); m.Start(-1, 5); System.Threading.Thread.Sleep(1000); m.Clear(); } if (_game.Won) { _game.Won = false; if (_game.InStoryMode) { if (_game.LoadStoryMode()) { Menu m = new Menu("You won", Label.CreateLabelArrayFromText( "Congratulations, you just won the game!")); m.Start(-1, 5); System.Threading.Thread.Sleep(2000); m.Clear(); } else { _game.Board = null; return new Shop(_game); } } else { if (_game.Board.Coop) { Menu m = new Menu("You won", Label.CreateLabelArrayFromText( "Congratulations, you people won the level!")); m.Start(-1, 5); System.Threading.Thread.Sleep(2000); m.Clear(); } else { string name = ""; for (int i = 0; i < _game.Players.Length; i++) if (_game.Players[i] != null) if (_game.Players[i].Unit.Health > 0) { name = _game.Players[i].Name; break; } Menu m = new Menu(name + " won", Label.CreateLabelArrayFromText( "Congratulations " + name + ", you are the winner!")); m.Start(-1, 5); System.Threading.Thread.Sleep(2000); m.Clear(); } } } return new Main(); }
public static Map SelectMap(int x, int players) { int offset = 0, option = 0; string savePath = "maps"; if (!Directory.Exists(savePath)) return null; IOption[] options = new IOption[14]; if (_maps == null) _maps = new List<FileInfo>(); else _maps.Clear(); _maps.AddRange(new DirectoryInfo(savePath).GetFiles("*.map")); for (int i = 0; i < _maps.Count; i++) using (StreamReader r = new StreamReader(_maps[i].OpenRead())) { string raw = r.ReadToEnd(); if (players == 1 && raw.IndexOf('E') < 0) { _maps.RemoveAt(i); i--; } else if (raw.IndexOf(players.ToString()) < 0) { _maps.RemoveAt(i); i--; } } OptionDual d = new OptionDual(); d.FirstValue = -2; d.SecondValue = -1; Menu m; options[0] = d; options[1] = new Option("-"); options[12] = new Option("-"); options[13] = new Option(" Back ", _maps.Count); do { if (option == -2) offset--; else if (option == -1) offset++; if (offset > 0) d.FirstButton = "Previous"; else d.FirstButton = "-"; if (offset < _maps.Count / 10) d.SecondButton = "Next"; else d.SecondButton = "-"; for (int i = 0; i < 10 && (i + offset * 10) < _maps.Count; i++) { string name = _maps[i + offset * 10].Name.Replace(".map", ""); if (players > 1) { using (StreamReader r = new StreamReader(_maps[i + offset * 10].OpenRead())) { string raw = r.ReadToEnd(); if (raw.IndexOf('E') >= 0) name += " (co-op)"; else name += " (vs)"; } } options[i + 2] = new Option(name, i + offset * 10); } if (offset == _maps.Count / 10) for (int i = (_maps.Count % 10); i < 10; i++) options[i + 2] = new Option("-", 0); m = new Menu(options); m.Clear(); } while ((option = m.Start(x, 3)) < 0); m.Clear(); if (option == _maps.Count) return null; else return new Map(_maps[option].FullName); }
void PlayerSelectionChanged(object source, NetworkEventArgs args) { int[] values = args.Data as int[]; DrawOption(values[0], _playerSelection[values[0]], false); _playerSelection[values[0]] = values[1]; if (_playerSelection[values[0]] != -1) DrawOption(values[0], _playerSelection[values[0]], true); else { DrawOption(values[0], _guns.Count, true); if (_playerSelection[0] == -1 && _playerSelection[1] == -1) { Menu m = new Menu(Label.CreateLabelArrayFromText("Press any key to continue.")); m.Start(-1, 5); } } args.Forward(); }
public static IScreen StartNewGame(bool story, int players, Map map) { OptionTextbox[] textboxes = new OptionTextbox[players]; for (int i = 0; i < players; i++) textboxes[i] = new OptionTextbox("Player " + (i + 1), 12); Menu m = new Menu(new Option("-"), new Option("Start Game", 0), new Option("Back", 1)); m.Options.InsertRange(0, textboxes); switch (m.Start(35, 7)) { case 0: for (int i = 0; i < players; i++) if (string.IsNullOrEmpty(textboxes[i].Text)) { m.Clear(); Menu msub = new Menu(Label.CreateLabelArrayFromText( "\nYou have to specify a name in\norder to start a new game.")); msub.Start(-1, 20); msub.Clear(); return StartNewGame(story, players, map); } Game g = new Game(); for (int i = 0; i < players; i++) { Player p = new Player(i); p.Name = textboxes[i].Text; g.Players[i] = p; } for (int i = players; i < 4; i++) g.Players[i] = null; if (story) g.LoadStoryMode(); else g.Map = map; g.CustomGame = !story; if (Game.Network != null) { Game.Network.Dispose(); Game.Network = null; } return new Shop(g); } m.Clear(); return null; }
protected void ConfigPlayer(int index) { OptionKey[] keys = new OptionKey[] { new OptionKey("Up"), new OptionKey("Down"), new OptionKey("Left"), new OptionKey("Right"), new OptionKey("Shoot"), new OptionKey("Change")}; switch (index) { case 0: keys[0].Key = Properties.Settings.Default.player1_up; keys[1].Key = Properties.Settings.Default.player1_down; keys[2].Key = Properties.Settings.Default.player1_left; keys[3].Key = Properties.Settings.Default.player1_right; keys[4].Key = Properties.Settings.Default.player1_action; keys[5].Key = Properties.Settings.Default.player1_interact; break; case 1: keys[0].Key = Properties.Settings.Default.player2_up; keys[1].Key = Properties.Settings.Default.player2_down; keys[2].Key = Properties.Settings.Default.player2_left; keys[3].Key = Properties.Settings.Default.player2_right; keys[4].Key = Properties.Settings.Default.player2_action; keys[5].Key = Properties.Settings.Default.player2_interact; break; case 2: keys[0].Key = Properties.Settings.Default.player3_up; keys[1].Key = Properties.Settings.Default.player3_down; keys[2].Key = Properties.Settings.Default.player3_left; keys[3].Key = Properties.Settings.Default.player3_right; keys[4].Key = Properties.Settings.Default.player3_action; keys[5].Key = Properties.Settings.Default.player3_interact; break; default: keys[0].Key = Properties.Settings.Default.player4_up; keys[1].Key = Properties.Settings.Default.player4_down; keys[2].Key = Properties.Settings.Default.player4_left; keys[3].Key = Properties.Settings.Default.player4_right; keys[4].Key = Properties.Settings.Default.player4_action; keys[5].Key = Properties.Settings.Default.player4_interact; break; } for (int i = 0; i < 6; i++) keys[i].UpdateKeyName(); Menu m = new Menu(keys[0], keys[1], keys[2], keys[3], keys[4], keys[5], new Option("-"), new Option("Back", 0)); m.Start(40, 6); switch (index) { case 0: Properties.Settings.Default.player1_up = keys[0].Key; Properties.Settings.Default.player1_down = keys[1].Key; Properties.Settings.Default.player1_left = keys[2].Key; Properties.Settings.Default.player1_right = keys[3].Key; Properties.Settings.Default.player1_action = keys[4].Key; Properties.Settings.Default.player1_interact = keys[5].Key; break; case 1: Properties.Settings.Default.player2_up = keys[0].Key; Properties.Settings.Default.player2_down = keys[1].Key; Properties.Settings.Default.player2_left = keys[2].Key; Properties.Settings.Default.player2_right = keys[3].Key; Properties.Settings.Default.player2_action = keys[4].Key; Properties.Settings.Default.player2_interact = keys[5].Key; break; case 2: Properties.Settings.Default.player3_up = keys[0].Key; Properties.Settings.Default.player3_down = keys[1].Key; Properties.Settings.Default.player3_left = keys[2].Key; Properties.Settings.Default.player3_right = keys[3].Key; Properties.Settings.Default.player3_action = keys[4].Key; Properties.Settings.Default.player3_interact = keys[5].Key; break; default: Properties.Settings.Default.player4_up = keys[0].Key; Properties.Settings.Default.player4_down = keys[1].Key; Properties.Settings.Default.player4_left = keys[2].Key; Properties.Settings.Default.player4_right = keys[3].Key; Properties.Settings.Default.player4_action = keys[4].Key; Properties.Settings.Default.player4_interact = keys[5].Key; break; } Properties.Settings.Default.Save(); m.Clear(); }
private void UpdatePlayerSelection(int playerIndex, int newValue) { _playerSelection[playerIndex] = newValue; if (Game.Network != null) { Game.Network.SendEvent((int)PacketCode.PlayerSelectionChanged, new int[] { playerIndex, _playerSelection[playerIndex] }); if (newValue == -1 && (_playerSelection[0] != -1 || _playerSelection[1] != -1)) { Menu m = new Menu(Label.CreateLabelArrayFromText("Waiting for other player. ")); m.Start(-1, 5); } } }
protected IScreen RegisterDefault(bool host) { Game.Network.NetworkDataHandler.RegisterTypeFromAssembly(System.Reflection.Assembly.GetCallingAssembly()); Menu m; if (host) { m = new Menu(Label.CreateLabelArrayFromText("Registering default types and initialising lobby.")); m.Start(-1, 3, false); Game game = new Game(); Player p = new Player(0); p.Name = _name; game.Players[0] = p; game.CurrentPlayer = p; Game.Network.NetworkDataHandler.RegisterRecursive(game); m.Clear(); return new Lobby(game); } else { m = new Menu(Label.CreateLabelArrayFromText("Connected to host. retreaving game data and initialising lobby.")); m.Start(-1, 3, false) ; Game game = Game.Network.NetworkDataHandler.RequestInstance<Game>(); m.Clear(); int index = 0; for (; index < game.Players.Length; index++) { if (game.Players[index] == null) break; } if (index == 4) throw new Exception("Connection was allowed but the game was full"); Player p = new Player(index); p.Controls = new PlayerControls(0); p.Name = _name; game.Players[index] = p; game.CurrentPlayer = p; Game.Network.NetworkDataHandler.RegisterRecursive(p); Game.Network.SendEvent((int)PacketCode.NewPlayer, p); return new Lobby(game); } }
private IScreen InitialiseNetGame(string name, string ip) { Menu m = new Menu(Label.CreateLabelArrayFromText("Initialising the network library and\nloading network plugins.")); m.Start(32, 7, false); try { IScreen s; if (string.IsNullOrEmpty(ip)) s = new NetGame(name); else s = new NetGame(name, ip); m.Clear(); return s; } catch (Exception e) { m = new Menu(Label.CreateLabelArrayFromText("Error while initialising network library:\n " + e.Message)); m.Start(32, 7); m.Clear(); return null; } }