コード例 #1
0
ファイル: CommonOptions.cs プロジェクト: TheThing/Shooter
 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;
     }
 }
コード例 #2
0
ファイル: Lobby.cs プロジェクト: TheThing/Shooter
        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);
        }
コード例 #3
0
ファイル: CommonOptions.cs プロジェクト: TheThing/Shooter
        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;
        }