示例#1
0
        /// <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
            score = 0;
            highestScore = 0;
            scoreSet = false;
            drawMessage = false;
            setEndRound = false;
            setStageProps = false;

            playerSprite = new Monster();

            //Init map base properties
            mapBase.sizeMap = 16;
            mapBase.humanCount = 512;
            mapBase.fearTime = 50;

            mState = Mouse.GetState();
            lastKeyboardState = Keyboard.GetState();
            screen = 0;
            newGame = true;

            //Init population of monster properties
            for (int x = 0; x < population.Length; x++)
            {
                population[x] = new monsterProps();
            }

            //debug section
            #region
            population[0].ID = "A";
            population[1].ID = "B";
            population[2].ID = "C";
            population[3].ID = "D";
            population[4].ID = "E";
            population[5].ID = "F";
            population[6].ID = "G";
            population[7].ID = "H";
            population[8].ID = "I";
            population[9].ID = "J";
            population[10].ID = "K";
            population[11].ID = "L";
            population[12].ID = "M";
            population[13].ID = "N";
            population[14].ID = "O";
            population[15].ID = "P";
            population[16].ID = "Q";
            population[17].ID = "R";
            population[18].ID = "S";
            population[19].ID = "T";
            #endregion

            //Init fearticles
            for (int i = 0; i < maxFearticles; i++)
            {
                fearticle[i] = new Particle();
            }

            initYayStrings();

            base.Initialize();
        }
示例#2
0
        private void updatePreGame(GameTime gameTime)
        {
            //set up stage again
            loadStage(mapBase.sizeMap,mapBase.humanCount,mapBase.fearTime);
            setEndRound = false;
            setStageProps = false;
            canGo = false;

            if (!scoreSet)
            {
                population[0].thisScore = score;
                scoreSet = true;
            }
            //arrange all monsters by score
            bool hasFlipped = true;
            while (hasFlipped)
            {
                hasFlipped = false;
                for (int i = 0; i < population.Length - 1; i++)
                {
                    int score1 = population[i].thisScore;
                    int score2 = population[i + 1].thisScore;
                    if (score1 < score2)
                    {
                        //this works as long as you keep scoring higher each time but as soon as you let a 0 score sneak through it breaks
                        hasFlipped = true;
                        tempProps = population[i];
                        int tempScore = population[i].thisScore;
                        population[i] = population[i + 1];
                        population[i].thisScore = population[i + 1].thisScore;
                        population[i + 1] = tempProps;
                        population[i + 1].thisScore = tempScore;
                    }
                }
            }

            if (newGame)
            {
                //create random primer set of monsters to select from
                if (!selectedPop)
                {
                    for (int x = 0; x < population.Length; x++)
                    {
                        population[x].range = ((rand.Next(100)) / 10) + 20;
                        population[x].spd = ((rand.Next(20)) / 10) + 0.5f;
                        population[x].cost = (rand.Next(100)/10) + 20;
                        population[x].maxStam = (rand.Next(1000) / 10) + (population[x].cost * 2);
                        population[x].sReg = (rand.Next(20)/10);
                        population[x].rateScare = (rand.Next(100) / 10) + 50;
                        population[x].visiblity = (rand.Next(1000) / 10) + 100;
                    }
                    selectedPop = true;
                }

                //int rndInd = rand.Next(20);

                playerSprite.speed = population[0].spd;
                playerSprite.scareRange = population[0].range;
                playerSprite.maxStamina = population[0].maxStam;
                playerSprite.stamRegen = population[0].sReg;
                playerSprite.scareCost = population[0].cost;
                playerSprite.stamina = playerSprite.maxStamina;
                playerSprite.ROS = population[0].rateScare;
                playerSprite.fieldOfView = population[0].visiblity;

                //stamBarCenterBox = new Rectangle(stamBarLeftBox.X + stamBarLeftBox.Width, stamBarLeftBox.Y, (int)playerSprite.maxStamina - 4, stamBarCenterPart.Height);
                //stamBarRightBox = new Rectangle(stamBarCenterBox.X + stamBarCenterBox.Width, stamBarLeftBox.Y, stamBarRightEnd.Width, stamBarRightEnd.Height);

                score = 0;
                highestScore = 0;
            }
            else if(!newGame)
            {
                if (!runGACycle)
                {
                    //kill weakest
                    for (int i = 0; i < 4; i++)
                    {
                        //nulls out the lowest scoring 8 individuals
                        population[19-i].thisScore = 0;
                        population[19-i].range = 0;
                        population[19-i].spd = 0;
                        population[19-i].maxStam = 0;
                        population[19-i].cost = 0;
                        population[19-i].sReg = 0;
                        population[19-i].rateScare = 0;
                    }

                    //breed monsters
                    #region
                    for (int i = 0; i < 3; i = i + 2)
                    {
                        //offspring 1 - population[i] first half & population[i+1] second half
                        population[19 - i].thisScore = (population[i].thisScore + population[i + 1].thisScore)/2;
                        population[19 - i].range = (population[i].range+population[i+1].range)/2;
                        population[19 - i].spd = (population[i].spd+population[i+1].spd)/2;//i
                        population[19 - i].maxStam = (population[i].maxStam+population[i+1].maxStam)/2;//i
                        population[19 - i].cost = (population[i].cost+population[i+1].cost)/2;//i+1
                        population[19 - i].sReg = (population[i].sReg+population[i+1].sReg)/2;//i+1
                        population[19 - i].rateScare = (population[i].rateScare+population[i+1].rateScare)/2;//i+1
                        population[19 - i].visiblity = (population[i].visiblity+population[i+1].visiblity)/2;
                        //offspring 2 - population[i] second half & population[i+1] first half
                        population[19 - (i + 1)].thisScore = (population[i].thisScore + population[i + 1].thisScore)/2;
                        population[19 - (i + 1)].range = (population[i].range+population[i+1].range)/2;//i+1
                        population[19 - (i + 1)].spd = (population[i].spd+population[i+1].spd)/2;//i+1
                        population[19 - (i + 1)].maxStam = (population[i].maxStam+population[i+1].maxStam)/2;//i+1
                        population[19 - (i + 1)].cost = (population[i].cost+population[i+1].cost)/2;//i
                        population[19 - (i + 1)].sReg = (population[i].sReg+population[i+1].sReg)/2;//i
                        population[19 - (i + 1)].rateScare = (population[i].rateScare + population[i + 1].rateScare)/2;//i
                        population[19 - (i + 1)].visiblity = (population[i].visiblity+population[i+1].visiblity)/2;
                    }
                    #endregion

                    //mutate

                    //aiming for 10 iterations of mutations to occur.
                    //each attribute has 20% chance to mutate, %50 after that to go up or 50% down by 0.1.
                    for (int i = 0; i < 10; i++)
                    {
                        //10 times do this
                        //grab random index for population
                        int rPopIndex = 0;//try this with 0 -- rand.Next(19);//I think thats correct. I may need to change this to 20 if its not getting #19

                        //population[rPopIndex] attributes - conditional on some rate will mutate randomly up or down a small fraction of a point
                        int rAttr;

                        rAttr = rand.Next(100);
                        if (rAttr <= 5)
                        {
                            population[rPopIndex].range += 10;
                        }
                        else if (rAttr > 5 && rAttr <= 10)
                        {
                            if (population[rPopIndex].range > 11)
                            {
                                population[rPopIndex].range -= 10;
                            }
                        }

                        rAttr = rand.Next(100);
                        if (rAttr <= 5)
                        {
                            population[rPopIndex].spd += 0.2f;
                        }
                        else if (rAttr > 5 && rAttr <= 10)
                        {
                            population[rPopIndex].spd -= 0.2f;
                        }

                        rAttr = rand.Next(100);
                        if (rAttr <= 5)
                        {
                            population[rPopIndex].maxStam += 0.8f;
                        }
                        else if (rAttr > 5 && rAttr <= 10)
                        {
                            if(population[rPopIndex].maxStam >= 0.9f)
                            {
                                population[rPopIndex].maxStam -= 0.8f;
                            }
                        }

                        rAttr = rand.Next(100);
                        if (rAttr <= 5)
                        {
                            population[rPopIndex].cost += 0.5f;
                        }
                        else if (rAttr > 5 && rAttr <= 10)
                        {
                            population[rPopIndex].cost -= 0.5f;
                        }

                        rAttr = rand.Next(100);
                        if (rAttr <= 5)
                        {
                            population[rPopIndex].sReg += 0.2f;
                        }
                        else if (rAttr > 5 && rAttr <= 10)
                        {
                            population[rPopIndex].sReg -= 0.2f;
                        }

                        rAttr = rand.Next(100);
                        if (rAttr <= 5)
                        {
                            population[rPopIndex].rateScare += 0.5f;
                        }
                        else if (rAttr > 5 && rAttr <= 10)
                        {
                            population[rPopIndex].rateScare -= 0.5f;
                        }

                        rAttr = rand.Next(100);
                        if (rAttr <= 5)
                        {
                            population[rPopIndex].visiblity += 32;
                        }
                        else if (rAttr > 5 && rAttr <= 10)
                        {
                            if (population[rPopIndex].visiblity >= 33)
                            {
                                population[rPopIndex].visiblity -= 32;
                            }
                        }
                    }

                    //assign properties to playersprite
                    playerSprite.speed = population[0].spd;
                    playerSprite.scareRange = population[0].range;
                    playerSprite.maxStamina = population[0].maxStam;
                    playerSprite.stamRegen = population[0].sReg;
                    playerSprite.scareCost = population[0].cost;
                    playerSprite.stamina = playerSprite.maxStamina;
                    playerSprite.ROS = population[0].rateScare;
                    playerSprite.fieldOfView = population[0].visiblity;

                    //zero out score for next round
                    //score = 0;
                    //dont let it run GA again
                    runGACycle = true;
                }
            }

            stamBarCenterBox = new Rectangle(stamBarLeftBox.X + stamBarLeftBox.Width, stamBarLeftBox.Y, (int)playerSprite.maxStamina - 4, stamBarCenterPart.Height);
            stamBarRightBox = new Rectangle(stamBarCenterBox.X + stamBarCenterBox.Width, stamBarLeftBox.Y, stamBarRightEnd.Width, stamBarRightEnd.Height);

            backBPOS.X = ((GraphicsDevice.Viewport.Width / 6)*4) - backButton.Width / 4;
            startBPOS.X = backBPOS.X + 104;
            backBPOS.Y = (GraphicsDevice.Viewport.Height / 6)*5;
            startBPOS.Y = backBPOS.Y;

            backButtonBBox = new Rectangle((int)backBPOS.X, (int)backBPOS.Y, backButton.Width / 2, backButton.Height);
            startButtonBBox = new Rectangle((int)startBPOS.X, (int)startBPOS.Y, startButton.Width / 2, startButton.Height);

            if (mouseRect.Intersects(startButtonBBox))
            {

                startButtonRect = new Rectangle(startButton.Width / 2, 0, startButton.Width / 2, startButton.Height);
                if (mState.LeftButton == ButtonState.Pressed && !mouseRect.Intersects(backButtonBBox))
                {
                    buttonInstance.Volume = 0.75f;
                    buttonInstance.Play();
                    screen = 3;
                    roundStartTime = gameTime.TotalGameTime.TotalSeconds;
                    //zero out score for next round
                    score = 0;
                }
            }
            else
            {
                startButtonRect = new Rectangle(0, 0, startButton.Width / 2, startButton.Height);
            }

            if (mouseRect.Intersects(backButtonBBox))
            {

                backButtonRect = new Rectangle(backButton.Width / 2, 0, backButton.Width / 2, backButton.Height);
                if (mState.LeftButton == ButtonState.Pressed && !mouseRect.Intersects(startButtonBBox))
                {
                    buttonInstance.Volume = 0.75f;
                    buttonInstance.Play();
                    screen = 0;
                }
            }
            else
            {
                backButtonRect = new Rectangle(0, 0, backButton.Width / 2, backButton.Height);
            }

            // player selects monster to play
            //player presses start
            //start inGame with selected monster
        }