예제 #1
0
 private EventHandler generateMenuLeave(int i)
 {
     return((o, e) => {
         MenuItemList mi = this.getMenu(i);
         // Occupy
         if (mi.SelectedValue == OCCUPY)
         {
             this.errorMessages = "This position is already occupied.";
             if (this.multiplayerInfo.TakePosition(i))
             {
                 this.errorMessages = "";
             }
         }
         // Open
         if (mi.SelectedValue == OPEN)
         {
             this.errorMessages = "You cannot open this position.";
             if (this.multiplayerInfo.EmptyPosition(i))
             {
                 this.errorMessages = "";
             }
         }
         // Closed
         if (mi.SelectedValue == CLOSED)
         {
             this.errorMessages = "Currently, you cannot close a position.";
             if (this.multiplayerInfo.ClosePosition(i))
             {
                 this.errorMessages = "";
             }
         }
     });
 }
예제 #2
0
        private AI createAI(MenuItemList mi, bool pacMan = false)
        {
            // Single player
            if (!this.MultiPlayer)
            {
                if (mi.SelectedIndex == 0)
                {
                    return(new AIPlayer());
                }
                if (mi.SelectedIndex == 1)
                {
                    return(new AIRandom());
                }
                if (mi.SelectedIndex == 2)
                {
                    if (pacMan)
                    {
                        return(new AISimplePacMan());
                    }
                    else
                    {
                        return(new AISimpleGhost());
                    }
                }
                if (mi.SelectedIndex == 3)
                {
                    if (pacMan)
                    {
                        return(new AIEuclidianPacMan());
                    }
                    else
                    {
                        return(new AIEuclidianGhost());
                    }
                }
                return(null);
            }

            // Multi player
            if (mi.SelectedValue == Settings.Get.Name)
            {
                if (this.multiplayerInfo.IsHost())
                {
                    return(new AIServer(this.multiplayerInfo.Server, this.multiplayerInfo));
                }
                else
                {
                    return(new AIClient(this.multiplayerInfo.Client, this.multiplayerInfo));
                }
            }
            if (LobbyScreen.ConstList.Contains(mi.SelectedValue))
            {
                return(null);
            }
            return(new AISim());
        }
예제 #3
0
 private void finishCreatingMenus()
 {
     for (int i = 0; i < Level.MAXPLAYERCOUNT; i++)
     {
         MenuItemList mi = this.getMenu(i);
         if (this.MultiPlayer)
         {
             mi.OnDeselected += this.generateMenuLeave(i);
         }
         this.AddMenuItem(mi);
     }
 }
예제 #4
0
        public LobbyScreen(ScreenManager sM, BackgroundLevel bgLevel = null, MultiPlayerInfo mpInfo = null)
            : base(sM)
        {
            // Some settings
            if (bgLevel == null)
            {
                this.bgLevel = new BackgroundLevel(this.screenManager);
            }
            else
            {
                this.bgLevel = bgLevel;
            }
            this.errorMessages   = "";
            this.multiplayerInfo = mpInfo;
            this.MenuSize        = this.screenManager.ScreenResolution - 150 * Vector2.UnitX;
            this.NrOfColumns     = 2;
            this.PositionMenuScreen(MenuItem.HorizontalAlign.Center, MenuItem.VerticalAlign.Top);
            this.FavMenuItem.TextAlign          = MenuItem.HorizontalAlign.Left;
            this.HorizontalAndVerticalArrowKeys = true;

            // Start and back buttons
            MenuItem miStart = new MenuItem("Start", sM.Graphics);

            if (!this.MultiPlayer || this.multiplayerInfo.IsHost())
            {
                miStart.OnClick += (o, e) => { this.Start(); }
            }
            ;
            this.AddMenuItem(miStart);
            this.miBack          = new MenuItem("Back", sM.Graphics);
            this.miBack.OnClick += (o, e) => { this.Remove(); };
            this.AddMenuItem(this.miBack, 1);

            // The player dropdowns
            List <string> options = new List <string>()
            {
                Settings.Get.Name, "Stupid", "Normal", "Euclidian", NONE
            };

            this.miPacMan   = new MenuItemList("PacMan", new List <string>(options), sM.Graphics);
            this.miMsPacMan = new MenuItemList("Ms PacMan", new List <string>(options), sM.Graphics);
            this.miGhosts   = new MenuItemList[4];
            for (int i = 0; i < this.miGhosts.Length; i++)
            {
                this.miGhosts[i] = new MenuItemList(Ghost.GetName(i), new List <string>(options), sM.Graphics);
            }
            if (this.MultiPlayer)
            {
                this.managePlayersMP();
            }
            this.finishCreatingMenus();

            // The maps
            MenuItem[] miMaps = new MenuItem[6];
            for (int i = 0; i < miMaps.Length; i++)
            {
                miMaps[i]          = new MenuItem("Map " + i.ToString(), sM.Graphics);
                miMaps[i].OnClick += generateSetMap(i);
                this.AddMenuItem(miMaps[i], 1);
            }

            // Colour the menus (and position them)
            this.FastLayout(this.FavMenuItem);
            miBack.TextAlign = MenuItem.HorizontalAlign.Right;

            // Set the PacMan and ghost colours
            this.miPacMan.SelectedColour    = Color.Yellow;
            this.miMsPacMan.SelectedColour  = Color.Yellow;
            this.miGhosts[0].SelectedColour = Color.Red;
            this.miGhosts[1].SelectedColour = Color.DeepPink;
            this.miGhosts[2].SelectedColour = Color.Cyan;
            this.miGhosts[3].SelectedColour = Color.Orange;

            // Position the menus (override previous positioning)
            this.positionMenuItems(miStart, miMaps);

            // Load the values
            this.Load();

            // Subscribe to the multiplayer info events
            if (this.MultiPlayer)
            {
                this.multiplayerInfo.OnRefresh += (o, e) => { this.managePlayersMP(); }
            }
            ;
        }
예제 #5
0
 bool notSelected(MenuItemList mi)
 {
     return(mi.SelectedValue != NONE && mi.SelectedValue != OPEN);
 }