コード例 #1
0
ファイル: GameMaster.cs プロジェクト: runnerbos/Pacman
        public void Start()
        {
            Game game = (new Menu()).getGame();

            if (game.players.Length < 1 || game.players.Length > 4)
                throw new Exception("An invalid game was passed to the GameMaster.\nThe number of players is invalid.");

            //Some logic for creating players.

            switch (game.mode)
            {
                case ModeTypes.Battle:
                    rules = new BattleRules();
                    break;
                case ModeTypes.Classic:
                    rules = new ClassicRules();
                    break;
                case ModeTypes.GhostTag:
                    rules = new TagRules();
                    break;
            }
              //  elements.AddRange(rules.GetElements());
            elements.AddRange(PlayerElements);

            board = new Board(elements.ToArray(), rules);
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: EphemeralGeek/Pacman
 public Node(Board b, BoardUI UI)
 {
     Board = b;
     Handle = this;
     Location = Seek();
     CheckedBoard = new bool[Board.Width, Board.Height];
     All = new Dictionary<Point,Node>();
     Node.UI = UI;
 }
コード例 #3
0
ファイル: Path.cs プロジェクト: EphemeralGeek/Pacman
 public bool ContainsType(Enum.ElementTypes Type, Board B)
 {
     foreach (Point P in Points)
     {
         if (B.IsTypeAndAlive(Type, P))
             return true;
     }
     return false;
 }
コード例 #4
0
ファイル: WallSprite.cs プロジェクト: EphemeralGeek/Pacman
        public WallSprite(Element e, String path, double size, Board board)
            : base(e, size)
        {
            b = board;
            int ex = (int)e.X;
            int ey = (int)e.Y;
            int X = b.Width;
            int Y = b.Height;
            Element[,] c = new Element[X, Y];
            foreach (Element el in b.Elements)
            {
                int x1 = (int)el.X;
                int y1 = (int)el.Y;
                c[x1, y1] = el;

            }
            Path = wallpath(c,ex, ey);
        }
コード例 #5
0
ファイル: Sprite.cs プロジェクト: EphemeralGeek/Pacman
 public static Sprite getSprite(Element e, Board b, double size)
 {
     switch (e.et)
     {
         case PacManMulti.Enum.ElementTypes.Ghost:
             return new GhostSprite(e, Colors[r.Next(4)], size);
         case PacManMulti.Enum.ElementTypes.PacPlayer:
             return new PacSprite(e, size);
         case PacManMulti.Enum.ElementTypes.Wall:
             return new WallSprite(e, "fancywall/M", size, b);
         case PacManMulti.Enum.ElementTypes.PacDot:
             return new StaticSprite(e, "pacdot", size);
         case PacManMulti.Enum.ElementTypes.Fruit:
             return new StaticSprite(e, "fruit/banana", size);
         case PacManMulti.Enum.ElementTypes.Powerup:
             return new StaticSprite(e, "pacpowerup", size);
         case PacManMulti.Enum.ElementTypes.GhostSpawn:
             return new Spawn(e, "spawn", size);
         default:
             break;
     }
     return new GhostSprite(e, new Color(r.Next(255), r.Next(255), r.Next(255)), size);
 }
コード例 #6
0
ファイル: GameMaster.cs プロジェクト: EphemeralGeek/Pacman
        //END TEST CODE
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            //Create a list of players
            //logic = new GameLogicBattle(game.GetPlayers());

            logic = new GameLogicClassic();

            boardToShare = logic.GameLogicSetup(plays);

            start = new Start(BoardWidth, BoardHeight, 0, 0);
            setup = new Setup(BoardWidth, BoardHeight, 0, 0);
            playerSetup = new PlayerSetup(BoardWidth, BoardHeight, 0, 0);
            endScreen = new EndScreen(BoardWidth, BoardHeight, 0, 0);

            IsMouseVisible = true;
            mouseState = Mouse.GetState();
            previousMouseState = mouseState;
            padState = GamePad.GetState(PlayerIndex.One);
            prevPadState = padState;
            //screenCenter = new Point(((BoardWidth / 2)), 0);
            gameState = GameState.StartMenu;
            screenNumber = 0;
            //scoreBoard.Initialize(this);
            base.Initialize();
        }
コード例 #7
0
ファイル: GameMaster.cs プロジェクト: EphemeralGeek/Pacman
        public void setupPlay()
        {
            gameUI = new BoardUI(logic.B, BoardWidth, BoardHeight, 0, 0); //((Window.ClientBounds.Width / 2) + (.5 * BoardWidth)), ((Window.ClientBounds.Height / 2) + (.5 * BoardHeight)));
            plays.Clear();
            //plays.Add(new Element { et = ElementTypes.Ghost, X = 1, Y = 1 });

            ControllerScheme scheme = new ControllerScheme(ControllerTypes.Keyboard);
            scheme.Add(Keys.Up);
            scheme.Add(Keys.Down);
            scheme.Add(Keys.Left);
            scheme.Add(Keys.Right);
            scheme.Add(Keys.Enter);
            ControllerScheme scheme2 = new ControllerScheme(ControllerTypes.Keyboard);
            scheme2.Add(Keys.W);
            scheme2.Add(Keys.S);
            scheme2.Add(Keys.A);
            scheme2.Add(Keys.D);
            scheme2.Add(Keys.Enter);

            byte controllerNum = 0;
            byte keyboardNum = 0;
            for (int i = 0; i < playerSetup.players.Count(); i++)
            {
                //Keyboard controlled ghost
                if (playerSetup.players[i].controllerType == ControllerTypes.Keyboard && playerSetup.players[i].IsGhost)
                {
                    keyboardNum++;
                    Element e = new Element();
                    e.et = ElementTypes.Ghost;

                    if (keyboardNum == 1)
                    {
                        e.Control = new KeyboardInput(scheme);
                    }
                    else if (keyboardNum == 2)
                    {
                        e.Control = new KeyboardInput(scheme2);
                    }
                    else if (keyboardNum > 2 && e.et == ElementTypes.PacPlayer)
                    {
                        e.Control = new PacAI(e);
                    }
                    else if (keyboardNum > 2 && e.et == ElementTypes.Ghost)
                    {
                        e.Control = new GhostAI(e);
                    }

                    plays.Add(e);
                }
                //Keyboard controlled pacman
                else if (playerSetup.players[i].controllerType == ControllerTypes.Keyboard && !(playerSetup.players[i].IsGhost))
                {
                    keyboardNum++;
                    Element e = new Element();
                    e.et = ElementTypes.PacPlayer;

                    if (keyboardNum == 1)
                    {
                        e.Control = new KeyboardInput(scheme);
                    }
                    else if (keyboardNum == 2)
                    {
                        e.Control = new KeyboardInput(scheme2);
                    }
                    else if (keyboardNum > 2 && e.et == ElementTypes.PacPlayer)
                    {
                        e.Control = new PacAI(e);
                    }
                    else if (keyboardNum > 2 && e.et == ElementTypes.Ghost)
                    {
                        e.Control = new GhostAI(e);
                    }

                    plays.Add(e);
                }
                //AI controlled ghost
                else if ((playerSetup.players[i].controllerType == ControllerTypes.PacAI || playerSetup.players[i].controllerType == ControllerTypes.GhostAI) && (playerSetup.players[i].IsGhost))
                {
                    Element e = new Element();
                    e.et = ElementTypes.Ghost;
                    e.Control = new GhostAI(e);
                    e.IsAlive = true;
                    plays.Add(e);
                }
                //AI controlled pacman
                else if ((playerSetup.players[i].controllerType == ControllerTypes.PacAI || playerSetup.players[i].controllerType == ControllerTypes.GhostAI) && !(playerSetup.players[i].IsGhost))
                {
                    Element e = new Element();
                    e.et = ElementTypes.PacPlayer;
                    e.Control = new PacAI(e);
                    e.IsAlive = true;
                    plays.Add(e);
                }
                //Controller controlled pacman
                else if (playerSetup.players[i].controllerType == ControllerTypes.Xbox && !(playerSetup.players[i].IsGhost))
                {
                    controllerNum++;

                    Element e = new Element();
                    e.et = ElementTypes.PacPlayer;
                    if (controllerNum == 1)
                    {
                        e.Control = new ControllerInput(PlayerIndex.One);
                    }
                    else if (controllerNum == 2)
                    {
                        e.Control = new ControllerInput(PlayerIndex.Two);
                    }
                    else if (controllerNum == 3)
                    {
                        e.Control = new ControllerInput(PlayerIndex.Three);
                    }
                    else if (controllerNum == 4)
                    {
                        e.Control = new ControllerInput(PlayerIndex.Four);
                    }
                    else if (controllerNum > 4 && e.et == ElementTypes.PacPlayer)
                    {
                        //e.Control = new PacAI();
                    }
                    else if (controllerNum > 4 && e.et == ElementTypes.Ghost)
                    {
                        e.Control = new GhostAI(e);
                    }

                    plays.Add(e);
                }
                //Controller controlled ghost
                else if (playerSetup.players[i].controllerType == ControllerTypes.Xbox && (playerSetup.players[i].IsGhost))
                {
                    controllerNum++;

                    Element e = new Element();
                    e.et = ElementTypes.Ghost;
                    if (controllerNum == 1)
                    {
                        e.Control = new ControllerInput(PlayerIndex.One);
                    }
                    else if (controllerNum == 2)
                    {
                        e.Control = new ControllerInput(PlayerIndex.Two);
                    }
                    else if (controllerNum == 3)
                    {
                        e.Control = new ControllerInput(PlayerIndex.Three);
                    }
                    else if (controllerNum == 4)
                    {
                        e.Control = new ControllerInput(PlayerIndex.Four);
                    }
                    else if (controllerNum > 4 && e.et == ElementTypes.PacPlayer)
                    {
                        //e.Control = new PacAI();
                    }
                    else if (controllerNum > 4 && e.et == ElementTypes.Ghost)
                    {
                        e.Control = new GhostAI(e);
                    }

                    plays.Add(e);
                }

            }

            if (setup.gameMode == Setup.GameModes.Classic)
            {
                logic = new GameLogicClassic();
            }
            else if (setup.gameMode == Setup.GameModes.GhostHunt)
            {
                logic = new GameLogicGhostHunt();
            }

            boardToShare = logic.GameLogicSetup(plays);
            new Node(boardToShare, gameUI);
            Node.Handle.GenerateMatrix();

            List<Sprite> sprites = new List<Sprite>();

            foreach (Element Element in boardToShare.Elements)
            {
                Sprite gameSprite = Sprite.getSprite(Element, logic.B, (int)Math.Min(BoardWidth / logic.B.Width, BoardHeight / logic.B.Height));
                gameUI.RegisterSprite(gameSprite);

                //Assigning the elements within sprites names.
                if (gameSprite.Element.et == ElementTypes.Ghost)
                {
                    if (gameSprite.getColor() == Color.HotPink)
                        gameSprite.Element.Name = "Pinky";
                    else if (gameSprite.getColor() == Color.Cyan)
                        gameSprite.Element.Name = "Inky";
                    else if (gameSprite.getColor() == Color.Red)
                        gameSprite.Element.Name = "Blinky";
                    else if (gameSprite.getColor() == Color.Orange)
                        gameSprite.Element.Name = "Clyde";
                }
                else if (gameSprite.Element.et == ElementTypes.PacPlayer)
                {
                    gameSprite.Element.Name = "PacPlayer " + PacPlayerID;
                    PacPlayerID += 1;
                }

                if (gameSprite.Element.et == ElementTypes.Ghost ||
                    gameSprite.Element.et == ElementTypes.PacPlayer)
                    sprites.Add(gameSprite);
            }
            scoreManager = new ScoreManager(sprites);
            gameUI.LoadContent(Content);

            var aliveSprites =
                from m in plays.ToArray()
                where m.IsAlive
                where m.et == ElementTypes.PacPlayer ||
                m.et == ElementTypes.Ghost
                select m;
            scoreBoards = new SBoardManager(this, aliveSprites.ToArray());
        }
コード例 #8
0
ファイル: GameLogic.cs プロジェクト: EphemeralGeek/Pacman
 public GameLogic()
 {
     B = new Board();
     B.Width = 28;
     B.Height = 20;
 }
コード例 #9
0
ファイル: GameMaster.cs プロジェクト: EphemeralGeek/Pacman
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            List<Element> plays = new List<Element>();
            plays.Add(new Element { et = ElementTypes.Ghost, X = 1, Y = 1 });
            plays.Add(new Element { et = ElementTypes.PacPlayer, X = 5, Y = 2 });
            //logic = new GameLogicBattle(game.GetPlayers());
            logic = new GameLogicClassic();
            boardToShare = logic.GameLogicSetup(plays);
            gameUI = new BoardUI(logic.B, BoardWidth, BoardHeight, 0, 0); //((Window.ClientBounds.Width / 2) + (.5 * BoardWidth)), ((Window.ClientBounds.Height / 2) + (.5 * BoardHeight)));

            foreach(Element Element in plays){
                gameUI.RegisterSprite(new StaticSprite(Element, "images/pacdemo"));
            }

            base.Initialize();
        }