Пример #1
0
        // PÕHILINE MEETOD, MIS JUHIB NUPPUDE LIIKUMIST
        private void moveCheckers(Player player, int steps, int mouse_x, int mouse_y, List<Nest> nests, Dice dice)
        {
            Prison prison = this.gameBoard.prison;
            if (steps == 0 && dice.rolledValues.Count>0)
            {
                steps = dice.rolledValues.Max();
            }

            //kui nupp on vangis
            Boolean nuppOnVangis = false;
            List<Checker> playerCheckersInPrison = new List<Checker>(15);
            foreach (Checker ch in player.checkers)
            {
                foreach (Checker chInPrison in prison.checkers)
                {
                    if (ch == chInPrison)
                    {
                        playerCheckersInPrison.Add(ch);
                        nuppOnVangis = true;
                    }
                }
            }

            //FIND CLICKED NEST OR PRISON
            Nest clickedNest = null;
            List<Nest> availableNests = findTargetNestsInOpponentsHome(player, steps);
            if (nuppOnVangis && availableNests.Count == 0)
            {
                    //mängija jääb vahele
                    player.currentMoves = 2;
                    dice.isDouble = false;
                    return;
            }

            if (!nuppOnVangis)
            {
                foreach (Nest n in nests)
                {
                    int max_y = n.height + n.y_location;
                    if (mouse_x > n.leftCorner && mouse_x < n.rightCorner && mouse_y > n.y_location && mouse_y < max_y)
                    {
                        clickedNest = n;
                        break;
                    }
                }
            }
            else
            {
                if (mouse_x > prison.prison_x && mouse_x < prison.rightEdge && mouse_y > prison.prison_y && mouse_y < prison.bottomEdge)
                {
                    if (nuppOnVangis && availableNests.Count == 0)
                    {
                        //mängija jääb vahele
                        player.currentMoves = 2;
                        dice.isDouble = false;
                        return;
                    }
                    if (playerCheckersInPrison.Count > 0)
                    {
                        Checker checkerInPrison = playerCheckersInPrison[0];
                        Nest nestToMoveTo = null;
                        foreach (Nest n in availableNests)
                        {
                            if (player.isOpponent && n.opponentNestID == steps)
                            {
                                nestToMoveTo = n;
                            }
                            else if (!player.isOpponent && n.paleyerNestID == steps)
                            {
                                nestToMoveTo = n; //moveCheckerIntoFreeNest(null, checkerInPrison, player, n);
                            }
                        }

                        if (nestToMoveTo != null && checkerInPrison != null)
                            if (dice.rolledValues.Count > 0)
                            {
                                if (targetNestContainsNOopponentsChecker(nestToMoveTo, player))
                                {
                                    moveCheckerIntoFreeNest(clickedNest, checkerInPrison, player, nestToMoveTo);
                                    prison.checkers.Remove(checkerInPrison);
                                }
                                else if (targetNestContainsONEopponentsChecker(nestToMoveTo, player))
                                {
                                    Checker opponentsOneChecker = nestToMoveTo.Checkers[0];
                                    nestToMoveTo.Checkers.Remove(opponentsOneChecker);
                                    moveCheckerIntoFreeNest(null, checkerInPrison, player, nestToMoveTo);
                                    prison.checkers.Remove(checkerInPrison);
                                    prison.addChecker(opponentsOneChecker, nestToMoveTo);
                                }

                                playerCheckersInPrison.Remove(checkerInPrison);
                                /////////////////////
                                //kasutatud täringuväärtus nullida:
                                if (player.checkers.Contains(checkerInPrison))
                                {
                                    for (int i = 0; i < dice.rolledValues.Count; i++)
                                    {
                                        if (dice.rolledValues[i] == steps)
                                        {
                                            dice.rolledValues[i] = 0;
                                            break;
                                        }
                                    }

                                    //lisa playerile käikudelogisse
                                    player.currentMoves++;
                                    Moves playerMove = new Moves(player, null, nestToMoveTo, checkerInPrison);
                                    player.moves.Add(playerMove);
                                }
                            }

                    }
                }
            }

            //FIND NESTs, WHERE PLAYER HAS checkers currently
            List<Nest> palyerHasCheckersInNests = findPlayerCurrentNests(gameBoard, player);
            //find all available target nests
            List<Nest> targetNests = findTargetNests(player, steps, palyerHasCheckersInNests);

            //kas on vabu Nest-e, kuhu käia
            //is there any available target Nests for the player
            if (targetNests.Count == 0)
            {
                //mängija jääb vahele
                player.currentMoves = 2;
                dice.isDouble = false;
                return;
            }

            //MANAGE OTHER STATES
            // player has some free Nests where to go and defenitely goes somewhere
            if (clickedNest != null)
            {
                int countCheckersInCurrentNest = clickedNest.Checkers.Count;
                //kui klikitud nest ei olnud tühi
                if (countCheckersInCurrentNest > 0)
                {
                    if (dice.rolledValues.Count > 0)
                    {
                        Checker remCh = clickedNest.Checkers[countCheckersInCurrentNest - 1];
                        Nest nextNest = findTargetNest(clickedNest, player, steps);

                        /**/
                        //kui Player-i kõik nupud on tema kodus
                        if (player.allCheckersAreInHomeArea() == true)
                        {
                            int maxNestPositionForChecker = 0;
                            List<Nest> filledHomeNests = new List<Nest>(6);
                            Nest maxNest = null;
                            Checker movable = null;

                            foreach (Nest n in gameBoard.Nests)
                            {
                                foreach (Checker ch_in_homeNest in player.checkersInHome)
                                {
                                    if (n.Checkers.Contains(ch_in_homeNest))
                                    {
                                        filledHomeNests.Add(n);
                                    }
                                }
                            }

                            foreach (Nest n in filledHomeNests)
                            {
                                if (!player.isOpponent && n.paleyerNestID > maxNestPositionForChecker)
                                {
                                    maxNestPositionForChecker = n.paleyerNestID;
                                    maxNest = n;
                                }
                                else if (player.isOpponent && n.opponentNestID > maxNestPositionForChecker)
                                {
                                    maxNestPositionForChecker = n.opponentNestID;
                                    maxNest = n;
                                }
                            }

                            int new_stepMax = dice.rolledValues.Max();
                            if (maxNestPositionForChecker <= new_stepMax)
                            {
                                movable = maxNest.Checkers[0];
                                player.jar.addChecker(maxNest.Checkers[0]);
                                for (int i = 0; i < dice.rolledValues.Count; i++)
                                {
                                    if (dice.rolledValues[i] == new_stepMax)
                                    {
                                        dice.rolledValues[i] = 0;
                                        break;
                                    }
                                }
                                //lisa playerile käikudelogisse
                                player.currentMoves++;
                                if (movable != null)
                                {
                                    Moves playerMove = new Moves(player, clickedNest, player.jar, movable);
                                    player.moves.Add(playerMove);
                                }
                                return;
                            }

                        }
                       /* */
                        //kui target pole null!!
                        if (nextNest != null)
                        {
                            if (targetNestContainsNOopponentsChecker(nextNest, player))
                            {
                                moveCheckerIntoFreeNest(clickedNest, remCh, player, nextNest);
                            }
                            else if (targetNestContainsONEopponentsChecker(nextNest, player))
                            {
                                Checker opponentsOneChecker = nextNest.Checkers[0];
                                nextNest.Checkers.Remove(opponentsOneChecker);
                                moveCheckerIntoFreeNest(clickedNest, remCh, player, nextNest);
                                gameBoard.prison.addChecker(opponentsOneChecker, nextNest);
                            }

                            /////////////////////
                            //kasutatud täringuväärtus nullida:
                            if (player.checkers.Contains(remCh) && targetNests.Contains(nextNest))
                            {
                                for (int i = 0; i < dice.rolledValues.Count; i++)
                                {
                                    if (dice.rolledValues[i] == steps)
                                    {
                                        dice.rolledValues[i] = 0;
                                        break;
                                    }
                                }

                                //lisa playerile käikudelogisse
                                player.currentMoves++;
                                Moves playerMove = new Moves(player, clickedNest, nextNest, remCh);
                                player.moves.Add(playerMove);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            nurkall = this.Content.Load<Texture2D>("nurk_all");
            nurkylal = this.Content.Load<Texture2D>("nurk_ylal");
            gameBoardTexture = this.Content.Load<Texture2D>("board");
            imageCheckerBlue = this.Content.Load<Texture2D>("checkers/checkrBLUE");
            imageCheckerRed = this.Content.Load<Texture2D>("checkers/checkrRED");
            jarTexture = this.Content.Load<Texture2D>("jar");
            imageCheckerRedInJar = this.Content.Load<Texture2D>("checkers/checkrREDinJar");
            imageCheckerBlueInJar = this.Content.Load<Texture2D>("checkers/checkrBLUEinJar");

            //Font
            font = this.Content.Load<SpriteFont>("score");

            //button:dice
            Texture2D texture;
            texture = this.Content.Load<Texture2D>("roll");
            myFont = this.Content.Load<SpriteFont>("score");
            dice = new Dice(texture, myFont, spriteBatch);
            //button:done
            //imageDone = this.Content.Load<Texture2D>("done");
            //this.doneButton = new Done(imageDone, myFont, spriteBatch);
        }