示例#1
0
        //this function needs to be fixed up very badly!!
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            borders = new Vector3[4];
            borders[0] = new Vector3(20, 0, 0);
            borders[1] = new Vector3(-20, 0, 0);
            borders[2] = new Vector3(20, 0, -2000);
            borders[3] = new Vector3(-20, 0, -2000);

            map = new FieldMap((int)Math.Abs(borders[0].X - borders[3].X) / squareSize,
                (int)(Math.Abs(borders[0].Z - borders[3].Z) / squareSize));

            if (gameType == GameType.Hide || gameType == GameType.Seek)
            {
                items = new Item[numOfItems];
                for (int i = 0; i < numOfItems; i++)
                {
                    items[i] = new Rock(Game, new Vector3(0, 0, -10 * i), new Vector3(1, 1, 1), 0, this);
                    //tell map that this place is off-limits
                    //this is not correct because we have negative x coordinates!!!
                    map.addBlock((int)items[i].location.X / squareSize, (int)-items[i].location.Z / squareSize);
                    //depending on item size may need to block 2 or more squares?
                }

                hiders = new Hider[numOfHiders];
                for (int i = 0; i < numOfHiders; i++)
                {
                    hiders[i] = new Hider(Game, this);
                    //tell map that this place is off-limits
                    //this is not correct because we have negative x coordinates!!!
                    map.addBlock((int)hiders[i].location.X / squareSize, (int)-hiders[i].location.Z / squareSize);
                }
                gamePhase = GamePhase.Counting;
            }

            else if (gameType == GameType.HidePractice)
            {
                hiders = null;
                items = new Item[1];
                items[0] = new Rock(Game, new Vector3(0, 0, -10), new Vector3(1, 1, 1), 0, this);
            }

            else // gameType == SeekPractice
            {
                hiders = new Hider[1];
                hiders[0] = new Hider(Game, this);
                items = new Item[2];
                items[0] = new Rock(Game, new Vector3(5, 0, -10), new Vector3(1, 1, 1), 0, this);
                items[1] = new Rock(Game, new Vector3(-5, 0, -10), new Vector3(1, 1, 1), 0, this);
            }

            if (gameType == GameType.Hide)
                seeker = new Seeker(Game, this, countNum);
            else
                seeker = null;

            if (gameType == GameType.Hide || gameType == GameType.HidePractice)
            {
                meHider = new MeHider(Game, this);
                meSeeker = null;
            }
            else
            {
                meSeeker = new MeSeeker(Game, this, countNum);
                meHider = null;
            }

            base.Initialize();
        }
示例#2
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            //initialize game space borders
            borders = new Vector3[4];
            borders[0] = new Vector3(20, 0, 0);
            borders[1] = new Vector3(-20, 0, 0);
            borders[2] = new Vector3(20, 0, -2000);
            borders[3] = new Vector3(-20, 0, -2000);

            //create map
            int sizeX = (int)Math.Abs(borders[0].X - borders[3].X) / squareSize;
            int sizeY = (int)(Math.Abs(borders[0].Z - borders[3].Z) / squareSize);
            map = new FieldMap(sizeX, sizeY);

            //if game is a real game and not a practice
            if (gameType == GameType.Hide || gameType == GameType.Seek)
            {
                Random rand = new Random(10);
                items = new Item[numOfItems];
                for (int i = 0; i < numOfItems; i++)
                {
                    //choose space on map which has no item in it yet
                    FieldNode node = null;
                    int x;
                    int y;
                    do
                    {
                        x = rand.Next(sizeX);
                        y = rand.Next(sizeY);
                        node = new FieldNode(x, y);
                    } while (!map.isAvailable(node));
                    //find optimal location in space for item
                    Vector3 loc = Rock.findBestLoc(nodeToLoc(node), ItemType.Rock);
                    items[i] = new Rock(Game, loc, new Vector3(0.4f, 0.4f, 0.4f), 0, i);
                    map.addItem(items[i], x, y);
                }
            }

            hiders = new Hider[numOfHiders];
            //if human player is a hider
            if (gameType == GameType.Hide)
            {
                //create human hider
                humanPlayer = new HumanHider(Game, new Vector3(0, 0, 0), 5, 10, 0);
                hiders[0] = (Hider)humanPlayer;
                //create rest of hiders to be virtual players
                for (int i = 1; i < numOfHiders; i++)
                    hiders[i] = new VirtualHider(Game, new Vector3(10 * i, 0, 0) + borders[1], 5, 10, i + 1);
                //create virtual seeker
                seeker = new VirtualSeeker(Game, new Vector3(5, 0, 0), 5, 10, 1, countNum);
            }
            //if human player is a seeker
            else if (gameType == GameType.Seek)
            {
                //create human seeker
                humanPlayer = new HumanSeeker(Game, new Vector3(0, 0, 0), 5, 10, 0, countNum);
                seeker = (Seeker)humanPlayer;
                //create all hiders to be virtual players
                for (int i = 0; i < numOfHiders; i++)
                    hiders[i] = new VirtualHider(Game, new Vector3(5 * i, 0, 0), 5, 10, i + 1);
            }
            if (gameType == GameType.HidePractice)
            {
                numOfItems = 1;
                numOfHiders = 1;
                items = new Item[1];
                items[0] = new Rock(Game, new Vector3(0, 0, -20), new Vector3(1f, 1f, 1f), 0, 1);
                Console.WriteLine("only item: " + items[0]);
                hiders = new Hider[1];
                humanPlayer = new HumanHider(Game, new Vector3(0, 0, 0), 5, 10, 0);
                hiders[0] = (Hider)humanPlayer;
                seeker = null;
            }
            else if (gameType == GameType.SeekPractice)
            {
                numOfItems = 2;
                numOfHiders = 1;
                items = new Item[2];

            //TODO: is this the right place for intialization?
            //      if so, get the missing parameters to here,
            //      or alternatively, put Tree & Billboard intialization elsewhere!

                //BillboardSystem bbs = BillboardSystem.factory(2, graphicsDevice, BasicEffect);
                items[0] = new /*Tree*/Rock(Game, new Vector3(20, 0, -20), new Vector3(0.4f, 0.4f, 0.4f), 0, 1);
                items[1] = new /*Tree*/Rock(Game, new Vector3(-20, 0, -20), new Vector3(0.4f, 0.4f, 0.4f), 0, 2);

                hiders = new Hider[1];
                hiders[0] = new VirtualHider(Game, new Vector3(10, 0, 0), 5, 10, 2);
                seeker = new HumanSeeker(Game, new Vector3(0, 0, 0), 5, 10, 1, 0);
                humanPlayer = (HumanPlayer)seeker;
                Random rand = new Random();
                int i = rand.Next(2);
                ((VirtualHider)hiders[0]).skipSearch(items[i]);
                ((HumanSeeker)seeker).skipCounting();
            }
            else
            {
                //tell map that locations of all players are off-limits
                for (int i = 0; i < numOfHiders; i++)
                    map.addBlock((int)Math.Abs(hiders[i].Location.X - borders[1].X) / squareSize, (int)-(hiders[i].Location.Z / squareSize));
                map.addBlock((int)Math.Abs((seeker.Location.X - borders[1].X)) / squareSize, (int)-seeker.Location.Z / squareSize);
            }
            base.Initialize();
        }