예제 #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                if (currentScreen == gameScreens.mainMenuScreen)
                {
                    this.Exit();
                }
                else if (currentScreen == gameScreens.settingsOverlay){
                    settingsClosing = true;
                    //currentScreen = gameScreens.mainMenuScreen;
                }
                else if (currentScreen == gameScreens.gamePlayScreen)
                {
                    resetPause();
                    possiblePositions.Clear();
                    puckTouched = false;
                    currentScreen = gameScreens.pauseOverlay;
                }
                else if (currentScreen == gameScreens.pauseOverlay)
                {
                    pauseClosing = true;
                    nextScreen = gameScreens.gamePlayScreen;
                    //currentScreen = gameScreens.gamePlayScreen;
                }
                else if (currentScreen == gameScreens.winnersOverlay)
                {
                    resetCurrentGame();
                    winnersClosing = true;
                    nextScreen = gameScreens.gamePlayScreen;
                }
                else if (currentScreen == gameScreens.continueOverlay)
                {
                    continueClosing = true;
                    nextScreen = gameScreens.mainMenuScreen;
                }
                else if (currentScreen == gameScreens.helpScreen)
                {
                    currentScreen = gameScreens.mainMenuScreen;
                }
                else if (currentScreen == gameScreens.creditsScreen)
                {
                    currentScreen = gameScreens.mainMenuScreen;
                }
            }

            if (currentScreen == gameScreens.mainMenuScreen)
            {
                mainScreenTouchHanlder();
            }
            else if (currentScreen == gameScreens.settingsOverlay)
            {
                settingsOverlayTouchInputHandler(gameTime);
            }
            else if (currentScreen == gameScreens.gamePlayScreen)
            {
                getInputAndUpdateGame(gameTime);

            }
            else if (currentScreen == gameScreens.pauseOverlay)
            {
                pausedOverlayTouchInputHandler(gameTime);
            }
            else if (currentScreen == gameScreens.winnersOverlay)
            {
                winnersOverlayTouchInputHandler(gameTime);
            }
            else if (currentScreen == gameScreens.continueOverlay)
            {
                continueOverlayTouchInputHandler(gameTime);
            }
            else if (currentScreen == gameScreens.helpScreen)
            {
                helpScreenTouchHandler(gameTime);
            }
            else if (currentScreen == gameScreens.creditsScreen)
            {
                updateCreditsScreen(gameTime);
            }

            base.Update(gameTime);
        }
예제 #2
0
        void updateSettings(GameTime gameTime)
        {
            if (settingsClosing)
            {
                overlayBG2Pos -= settingsVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (overlayBG2Pos.Y <= -400)
                {
                    overlayBG2Pos.Y = -400;
                    currentScreen = gameScreens.mainMenuScreen;

                }
            }
            else
            {
                overlayBG2Pos += settingsVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (overlayBG2Pos.Y >= 65)
                {
                    overlayBG2Pos.Y = 65;
                }
            }
            System.Diagnostics.Debug.WriteLine("move by cpu: " + gameTime.ElapsedGameTime.TotalSeconds);

            settingsTextPos.Y = overlayBG2Pos.Y + 20;
            levelTextPos.Y = overlayBG2Pos.Y + 210;
            sfxTextPos.Y = overlayBG2Pos.Y + 110;
            sfxOnBtn.setRectByPos(sfxOnBtn.X, (int)overlayBG2Pos.Y + 91);
            sfxOffBtn.setRectByPos(sfxOffBtn.X, (int)overlayBG2Pos.Y + 91);

            okBtn.setRectByPos(okBtn.X, (int)overlayBG2Pos.Y + 280);

            levelBtn1.setRectByPos(levelBtn1.X, (int)overlayBG2Pos.Y + 194);
            levelBtn2.setRectByPos(levelBtn2.X, (int)overlayBG2Pos.Y + 194);
            levelBtn3.setRectByPos(levelBtn3.X, (int)overlayBG2Pos.Y + 194);
        }
예제 #3
0
        void updateWinnersOverlay(GameTime gameTime)
        {
            if (winnersClosing)
            {
                overlayBG1Pos -= settingsVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (overlayBG1Pos.Y <= -400)
                {
                    overlayBG1Pos.Y = -400;
                    currentScreen = nextScreen;
                }
            }
            else
            {
                overlayBG1Pos += settingsVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (overlayBG1Pos.Y >= 110)
                {
                    overlayBG1Pos.Y = 110;
                }
            }
            System.Diagnostics.Debug.WriteLine("move by cpu: " + gameTime.ElapsedGameTime.TotalSeconds);

            tigersWonTextPos.Y = overlayBG1Pos.Y + 20;
            goatsWonTextPos.Y = overlayBG1Pos.Y + 20;
            gameDrawnTextPos.Y = overlayBG1Pos.Y + 20;

            menuBtn.setRectByPos(280, (int)overlayBG1Pos.Y + 110);
            newGameBtn.setRectByPos(440, (int)overlayBG1Pos.Y + 110);
        }
예제 #4
0
 void switchToGamePlayScreen()
 {
     if (currentBoard.mGoatsIntoBoard == 0)
     {
         currentScreen = gameScreens.gamePlayScreen;
     }
     else
     {
         resetContinueOverlay();
         currentScreen = gameScreens.continueOverlay;
     }
 }
예제 #5
0
        void updatePause(GameTime gameTime)
        {
            if (pauseClosing)
            {
                overlayBG1Pos -= settingsVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (overlayBG1Pos.Y <= -400)
                {
                    overlayBG1Pos.Y = -400;
                    currentScreen = nextScreen;
                }
            }
            else
            {
                overlayBG1Pos += settingsVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (overlayBG1Pos.Y >= 110)
                {
                    overlayBG1Pos.Y = 110;
                }
            }
            System.Diagnostics.Debug.WriteLine("move by cpu: " + gameTime.ElapsedGameTime.TotalSeconds);

            pausedTextPos.Y = overlayBG1Pos.Y + 20;
            menuBtn.setRectByPos(240, (int)overlayBG1Pos.Y + 110);
            newGameBtn.setRectByPos(360, (int)overlayBG1Pos.Y + 110);
            resumeBtn.setRectByPos(480, (int)overlayBG1Pos.Y + 110);
        }
예제 #6
0
 void showSettingsOverlay()
 {
     currentScreen = gameScreens.settingsOverlay;
     resetSettings();
 }
예제 #7
0
 void showHelpScreen()
 {
     helpSection.resetScreen();
     currentScreen = gameScreens.helpScreen;
 }
예제 #8
0
 void showCreditsScreen()
 {
     currentScreen = gameScreens.creditsScreen;
     creditsection.reset();
 }
예제 #9
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()
        {
            // initialization logic

            initPosition();

            currentBoardVsGoat = new Board();
            currentBoardVsTiger = new Board();
            currentBoardTwoPlayer = new Board();

            fetchSavedState();
            fetchSavedSettings();

            currentBoard = currentBoardVsGoat;
            goatsCaptured = currentBoard.mGoatsIntoBoard - getGoatCount();
            gameStateVsGoat = new GameState();
            gameStateVsTiger = new GameState();
            gameStateTwoPlayer = new GameState();

            winner = nodeState.none;

            newMoveDone = false;
            puckTouched = false;
            currentMode = gameMode.vsTiger;
            currentScreen = gameScreens.mainMenuScreen;
            //currentMode = gameMode.vsGoat;

            helpSection = new ScrollContainer();
            creditsection = new CreditsSection();

            onePlayerBtnGoat = new gButton(470, 97);
            onePlayerBtnTiger = new gButton(485, 197);
            twoPlayerBtn = new gButton(475,297);
            settingsBtn = new gButton(555,20);
            helpBtn = new gButton(480, 20);
            creditsBtn = new gButton(630, 20);
            rateBtn = new gButton(465, 400);

            sfxOnBtn = new gButton(380,175);
            sfxOffBtn = new gButton(380,175);
            undoBtn = new gButton(648, 403);

            //level
            levelBtn1 = new gButton(378, 265);
            levelBtn2 = new gButton(458, 265);
            levelBtn3 = new gButton(538, 265);

            menuBtn = new gButton(280,240);
            newGameBtn = new gButton(440, 240);

            resumeBtn = new gButton(440,240);
            okBtn = new gButton(552,320);

            //settings level
            switch (level)
            {
                case 1: levelBtn1.pressed = true; break;
                case 2: levelBtn2.pressed = true; break;
                case 3: levelBtn3.pressed = true; break;
                default: levelBtn1.pressed = true; break;

            }

            base.Initialize();
        }
예제 #10
0
        void getInputAndUpdateGame(GameTime gameTime)
        {
            if (pieceTransition)
            {
                pieceTransitionHandler(gameTime);
                return;
            }

            //todo
            if (newMoveDone)
            {
                currentBoard.gameWon = CheckForWin();
                if (sfxStateOn)
                {
                    if (currentBoard.gameWon)
                    {
                        chimeEffect.Play();
                    }
                    effect.Play();
                }
                newMoveDone = false;
                //if (prevtime != null)
                //{
                //    System.Diagnostics.Debug.WriteLine(prevTotSeconds + "move by cpu prev time " + (gameTime.TotalGameTime.TotalSeconds - prevTotSeconds));
                //    double diff = gameTime.TotalGameTime.TotalSeconds - prevTotSeconds;
                //    if (diff > 0.5)
                //    {

                //        currentBoard = nextBoard;
                //        effect.Play();
                //    }
                //}
                //else
                //{
                //    newMoveDone = false;
                //}

            }

            if (currentBoard.gameWon)
            {
                currentScreen = gameScreens.winnersOverlay;
                resetWinnersOverlay();
                DeleteCurrentSavedFile();
                return;
            }

            if ((currentMode == gameMode.vsTiger && currentBoard.mTurnForPlayer) || (currentMode == gameMode.vsGoat && !currentBoard.mTurnForPlayer))
            {
                System.Diagnostics.Debug.WriteLine("move by cpu: " + currentBoard.mTurnForPlayer);

                /*
                int movesDepth = 4;
                if (currentBoard.mGoatsIntoBoard > 14)
                {
                    movesDepth = 4;
                }
                */

                Board next = currentBoard.FindNextMove(level+1);
                gameState.positionslist.Add(currentBoard.mValues);
                gameState.mGoatsIntoBoardList.Add(currentBoard.mGoatsIntoBoard);

                pieceTransitionStarter(next);

                prevtime = gameTime;
                //prevTotSeconds = gameTime.TotalGameTime.TotalSeconds;
                System.Diagnostics.Debug.WriteLine("value time elapse"+gameTime.ElapsedGameTime.TotalSeconds);
                System.Diagnostics.Debug.WriteLine("value time elapse" + gameTime.TotalGameTime.TotalSeconds);
                //find diff of position
                currentBoard = next;
                //nextBoard = next;
                newMoveDone = true;
                goatsCaptured = currentBoard.mGoatsIntoBoard - getGoatCount();

            }
            else
            {
                TouchCollection touches = TouchPanel.GetState();

                if (!touching && touches.Count > 0)
                {
                    touching = true;
                    TouchLocation touch = touches.First();
                    System.Diagnostics.Debug.WriteLine("X" + touch.Position.X + "Y" + touch.Position.Y);
                    //make a move by computer

                    undoBtn.handeTouch(touch);

                    if (currentBoard.mTurnForPlayer)
                        System.Diagnostics.Debug.WriteLine("moving: tiger");
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("moving: goat");
                    }
                    if (currentBoard.mTurnForPlayer)
                    {
                        if (puckTouched)
                        {
                            foreach (var tobemovedpos in possiblePositions)
                            {
                                System.Diagnostics.Debug.WriteLine("actual moving:" + tobemovedpos.X + tobemovedpos.Y + "puck" + grid[tobemovedpos.X, tobemovedpos.Y]);
                                if (getTouchArea(positions[tobemovedpos.X, tobemovedpos.Y]).Contains((int)touch.Position.X, (int)touch.Position.Y))
                                {
                                    System.Diagnostics.Debug.WriteLine("moving:" + tobemovedpos.X + tobemovedpos.Y + "puck" + grid[tobemovedpos.X, tobemovedpos.Y]);
                                    Board next = currentBoard.MakeMove(touchedPos, tobemovedpos);
                                    gameState.positionslist.Add(currentBoard.mValues);
                                    gameState.mGoatsIntoBoardList.Add(currentBoard.mGoatsIntoBoard);

                                    pieceTransitionStarter(next);
                                    currentBoard = next;
                                    newMoveDone = true;
                                    goatsCaptured = currentBoard.mGoatsIntoBoard - getGoatCount();

                                }

                            }
                            possiblePositions.Clear();
                            puckTouched = false;
                        }
                        else
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 6; j++)
                                {

                                    if (getTouchArea(positions[i, j]).Contains((int)touch.Position.X, (int)touch.Position.Y))
                                    {
                                        System.Diagnostics.Debug.WriteLine("touchedpos:" + i + j + "puck" + grid[i, j]);
                                        touchedPos = new Point(i, j);
                                        if (grid[i, j] == nodeState.tiger)
                                        {
                                            puckTouched = true;
                                            higPos = touchedPos;
                                            foreach (var move in currentBoard.GetShortMovesForTigerPuck(currentBoard.mValues, new Point(i, j)))
                                            {
                                                System.Diagnostics.Debug.WriteLine("possible pos:" + move.X + move.Y + "puck" + grid[i, j]);
                                                possiblePositions.Add(new Point(move.X, move.Y));

                                            }
                                            foreach (var move in currentBoard.GetCaptureMovesForTigerPuck(currentBoard.mValues, new Point(i, j)))
                                            {
                                                System.Diagnostics.Debug.WriteLine("possible pos:" + move.X + move.Y + "puck" + grid[i, j]);
                                                possiblePositions.Add(new Point(move.X, move.Y));

                                            }
                                        }

                                        //when touch for a piece is detected exit. prevent overlapping pieces touch
                                        i = 5; j = 6;

                                    }
                                }

                            }
                        }
                    }
                    else
                    {
                        if (puckTouched)
                        {
                            foreach (var tobemovedpos in possiblePositions)
                            {
                                System.Diagnostics.Debug.WriteLine("actual moving:" + tobemovedpos.X + tobemovedpos.Y + "puck" + grid[tobemovedpos.X, tobemovedpos.Y]);
                                if (getTouchArea(positions[tobemovedpos.X, tobemovedpos.Y]).Contains((int)touch.Position.X, (int)touch.Position.Y))
                                {
                                    System.Diagnostics.Debug.WriteLine("moving:" + tobemovedpos.X + tobemovedpos.Y + "puck" + grid[tobemovedpos.X, tobemovedpos.Y]);
                                    Board next = currentBoard.MakeMove(touchedPos, tobemovedpos);
                                    gameState.positionslist.Add(currentBoard.mValues);
                                    gameState.mGoatsIntoBoardList.Add(currentBoard.mGoatsIntoBoard);

                                    pieceTransitionStarter(next);

                                    currentBoard = next;
                                    newMoveDone = true;
                                    System.Diagnostics.Debug.WriteLine("value time elapse" + gameTime.TotalGameTime.TotalSeconds);
                                    prevtime = gameTime;
                                    prevTotSeconds = gameTime.TotalGameTime.TotalSeconds;

                                    goatsCaptured = currentBoard.mGoatsIntoBoard - getGoatCount();
                                }

                            }
                            possiblePositions.Clear();
                            puckTouched = false;
                        }
                        else
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 6; j++)
                                {

                                    if (getTouchArea(positions[i, j]).Contains((int)touch.Position.X, (int)touch.Position.Y))
                                    {
                                        System.Diagnostics.Debug.WriteLine("touchedpos:" + i + j + "puck" + grid[i, j]);
                                        touchedPos = new Point(i, j);
                                        if (currentBoard.mGoatsIntoBoard == 15 && grid[i, j] == nodeState.goat)
                                        {
                                            higPos = touchedPos;
                                            foreach (var move in currentBoard.GetMovesForGoatPuck(currentBoard.mValues, new Point(i, j)))
                                            {
                                                System.Diagnostics.Debug.WriteLine("possible pos:" + move.X + move.Y + "puck" + grid[i, j]);
                                                puckTouched = true;
                                                possiblePositions.Add(new Point(move.X, move.Y));

                                            }
                                        }
                                        else if (currentBoard.mGoatsIntoBoard < 15 && grid[i, j] == nodeState.none)
                                        {
                                            //higPos = touchedPos;
                                            Board next = currentBoard.MakeMove(new Point(i, j), new Point(i, j));
                                            gameState.positionslist.Add(currentBoard.mValues);
                                            gameState.mGoatsIntoBoardList.Add(currentBoard.mGoatsIntoBoard);

                                            pieceTransitionStarter(next);

                                            currentBoard = next;
                                            newMoveDone = true;
                                            prevTotSeconds = gameTime.TotalGameTime.TotalSeconds;
                                            System.Diagnostics.Debug.WriteLine("value time elapse" + gameTime.TotalGameTime.TotalSeconds);
                                            goatsCaptured = currentBoard.mGoatsIntoBoard - getGoatCount();
                                        }
                                    }
                                }

                            }
                        }
                    }

                    //System.Diagnostics.Debug.WriteLine("MOVE DONE FOR");

                }
                else if (touches.Count == 0)
                {
                    if (undoBtn.pressed)
                    {

                        if (gameState.positionslist.Count != 0 && !(gameState.positionslist.Count == 1 && (currentMode == gameMode.vsGoat || currentMode == gameMode.vsTiger)))
                        {

                            if (currentMode == gameMode.vsGoat || currentMode == gameMode.vsTiger)
                            {
                                gameState.positionslist.RemoveAt(gameState.positionslist.Count - 1);
                                gameState.mGoatsIntoBoardList.RemoveAt(gameState.mGoatsIntoBoardList.Count - 1);
                            }
                            currentBoard.mValues = gameState.positionslist.Last();
                            gameState.positionslist.RemoveAt(gameState.positionslist.Count - 1);

                            currentBoard.mGoatsIntoBoard = gameState.mGoatsIntoBoardList.Last();
                            gameState.mGoatsIntoBoardList.RemoveAt(gameState.mGoatsIntoBoardList.Count - 1);

                            if (currentMode == gameMode.twoPlayers)
                            {
                                currentBoard.mTurnForPlayer = !currentBoard.mTurnForPlayer;
                            }

                        }
                    }
                    goatsCaptured = currentBoard.mGoatsIntoBoard - getGoatCount();
                    undoBtn.pressed = false;
                    touching = false;

                }
            }
        }