コード例 #1
0
        public override void Init()
        {
            #region Setup Display
            #region Canvas
            playCanvas = new Canvas();
            playCanvas.Width = Constants.ScreenWidth;
            playCanvas.Height = Constants.ScreenHeight;
            playCanvas.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            playCanvas.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            playCanvas.MouseLeftButtonDown += MouseDownClick;
            width = Constants.ScreenWidth - 50;
            height = Constants.ScreenHeight;

            
            #endregion
            #region Background
            background = new Background(Constants.GameBackgroundPath);
            playCanvas.Background = background.GetBrush();
            #endregion
            #region Setup Panel
            gp = new GamePanel(this.game);
            gp.HorizontalAlignment = HorizontalAlignment.Right;
            gp.VerticalAlignment = VerticalAlignment.Center;
            gp.Margin = new Thickness(Constants.ScreenWidth - 60, 0, 20, 0);
            gp.shootButton.Click += Shoot;
            #endregion
            #endregion
            #region Setup Assets
            cross = new PointerCross();
            cm = new CollisionManager(width, height);
            rn = new Randomizer();
            #region amount
            if (Constants.ObjectSize * AmountOfShips <= (Constants.ObjectSize/2 + Constants.ObjectSize * (2 * AmountOfShips))+Constants.ObjectSize/2)
            {
                amount = AmountOfShips;
            }
            else
            {
                amount = 6;
            }
            playerAmount = amount;
            enemyAmount = amount;
            #endregion
            #region Setup Coordinates
            pCoordinates = new int[amount][];
            eCoordinates = new int[amount][];
            for (int i = 0; i < amount; i++)
            {
                pCoordinates[i] = new int[2];
                eCoordinates[i] = new int[2];
                pCoordinates[i][0] = 100;
                pCoordinates[i][1] = (Constants.ObjectSize/2 + Constants.ObjectSize * (2 * i));
                eCoordinates[i][0] = width - 100;
                eCoordinates[i][1] = Constants.ObjectSize  + Constants.ObjectSize*(2*i);
            }
            #endregion
            gameobjects = new List<GameObject>();
            players = new Player[amount];
            enemies = new Computer[amount];
            #endregion
            #region Setup Ships
            SetupShips();
            GameObject.SetGameState(this);
            player = true;
            computer = false;
            #endregion
            #region Setup Controls
            ai = new AI(this);
            game.PlayTime.Start();
            #endregion
        }
コード例 #2
0
        public override void Init()
        {
             #region Setup Display

            #region Window
            menuScreen = new Canvas();
            menuScreen.Height = Constants.ScreenHeight;
            menuScreen.Width = Constants.ScreenWidth;
            menuScreen.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            menuScreen.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            background = new Background(Constants.MenuBackgroundPath);
            menuScreen.Background = background.GetBrush();
            title = new Title();
            title.Margin = new Thickness(Constants.ScreenWidth / 2 -430, Constants.ScreenHeight / 2 - 320, 0, 0);
            title.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            title.VerticalAlignment = System.Windows.VerticalAlignment.Center;
             #endregion

            #region Panel
            buttons = new MenuPanel(this);
            buttons.Margin = new Thickness(Constants.ScreenWidth / 2 - buttons.width / 2, Constants.ScreenHeight - (buttons.height * 1.5), 0, 0);
            #endregion

             #endregion

            #region Setup Decoration

            #region Random
            r = new Randomizer();
            angle = new Randomizer(r.Next());
            speed = new Randomizer(r.Next() * angle.Next());
            xpos = new Randomizer(r.Next() * speed.Next());
            ypos = new Randomizer(r.Next() * xpos.Next());
            Constants.SelectedEnemy = xpos.Next(0, 1);
            Constants.SelectedShip = ypos.Next(0, 1);
            #endregion

            #region Create decor
            int amount = r.Next(10, 20);
            int pamount = amount / 2;
            int eamount = amount - pamount;
            players = new Player[pamount];
            enemies = new Computer[eamount];
            list = new List<GameObject>();

            for (int i = 0; i < players.Length; i++)
            {
                players[i] = new Player(xpos.Next(128, Constants.ScreenWidth - 128), ypos.Next(64, Constants.ScreenHeight - 64), i);
                players[i].SetAngle(angle.Next(0, 360));
                players[i].SetSpeed(speed.Next(3, 6));
                players[i].UpdateMovement();
                list.Add(players[i]);
               
            }
            for (int i = 0; i < enemies.Length; i++)
            {
                enemies[i] = new Computer(xpos.Next(128, Constants.ScreenWidth - 128), ypos.Next(64, Constants.ScreenHeight - 64), i);
                enemies[i].SetAngle(angle.Next(0, 360));
                enemies[i].SetSpeed(speed.Next(3, 6));
                enemies[i].UpdateMovement();
                list.Add(enemies[i]);
               
            }
            #endregion

            Constants.SelectedEnemy = 0;
            Constants.SelectedShip = 0;
            #endregion

        }