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()); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); Views = new List<View>(); var Board = new PacManMulti.Logic.Board(); Board.Height = 10; Board.Width = 15; Random rand = new Random(); BoardUI BoardUI = new BoardUI(Board, Window.ClientBounds.Width, Window.ClientBounds.Height-30, 0, 30); for (int i = 0; i < 10; i++) { Element e = (Element)new PacPlayer(); e.X = rand.Next(15); e.Y = rand.Next(10); //e.P = new Point(rand.Next(15), rand.Next(10)); Sprite s = new SpriteDemo(e); Board.board.Add(e); BoardUI.RegisterSprite(s); } Views.Add(BoardUI); Views.Add(new Score(Window.ClientBounds.Width, 30, 0, 0)); foreach (View v in Views) { v.Initialize(this); } }
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(); }