예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        //WindowManager.instance.ScreenSizeChangeEvent += Instance_ScreenSizeChangeEvent;

        DetectPossibleMoves.SetBooleans();
        GamePieces.FindGameBlocks();
        GamePieces.FindGamePieces();

        clickAndDropScript = gameObject.GetComponent <ClickAndDrop>();
        gameOverCanvas     = GameObject.FindGameObjectWithTag("GameOverCanvas");
        restartButton      = GameObject.FindGameObjectWithTag("RestartButton");
        changeColorButton  = GameObject.FindGameObjectWithTag("ChangeColor");
        highScoreIcon      = GameObject.FindGameObjectWithTag("HighScoreIcon");

        background = GameObject.FindGameObjectWithTag("BlurBG");

        gameOverCanvas.SetActive(false);
        restartButton.SetActive(false);
        changeColorButton.SetActive(true);
        background.SetActive(false);
        highScoreIcon.SetActive(true);


        // Change BG
        var camera = (Camera)FindObjectOfType(typeof(Camera));

        camera.backgroundColor = SetColor.GetColor("Background");

        // Change Grid
        AnimateGrid.SetGrid();

        UpdateColor();
    }
예제 #2
0
    List <LinePieces> GetRows()
    {
        List <LinePieces> lines = new List <LinePieces> ();
        LinePieces        line;
        List <GamePiece>  pieces = new List <GamePiece> ();

        for (float x = 1.5f; x < 7.5; x += 1.5f)
        {
            line = new LinePieces();

            pieces = GamePieces.Where(z => z.transform.position.x == x).ToList();

            /* Allow blank spaces to be skipped (not necessary when new pieces drop into place when others dissappear)
             * for(int x = 0; x < pieces.Count; x++)
             * {
             *  GamePiece piece = new GamePiece();
             *  GamePiece piece = new GamePiece();
             *
             *  piece = pieces[x];
             *  nextPiece = pieces[x+1];
             *
             *  if (piece.transform.position.y + 1 != pieces
             * }
             */

            line.AddLine(pieces);
            lines.Add(line);
        }
        return(lines);
    }
예제 #3
0
        public void SelectGamePiece(int x, int y)
        {
            //checks to see if there is a game piece on that square
            if (GamePiecesArray[x, y] == null)
            {
                return;
            }

            //if (GamePiecesArray[x, y].isPlayerX != isPlayerXTurn)
            //    return;

            //currentPlayer.turn

            if (GamePiecesArray[x, y].pieceIdentity != currentPlayer.getIdentity())
            {
                return;
            }


            currentMove.Begin.row = y;
            currentMove.Begin.col = x;

            selectedGamePiece = GamePiecesArray[x, y];

            //DO NOT DEBUG NEXT LINE
            previousMat             = selectedGamePiece.GetComponent <MeshRenderer>().material;
            selectedMat.mainTexture = previousMat.mainTexture;
            selectedGamePiece.GetComponent <MeshRenderer>().material = selectedMat;
        }
예제 #4
0
    private void SetPiece(GameObject prefab, Vector2Int coordinates)
    {
        GameObject pieceObject = Instantiate(prefab, _pieceHolder.transform);

        if (!GetTile(coordinates, out Tile tile))
        {
            return;
        }

        //Sets the piece's transform position/Rotation
        pieceObject.transform.position = tile.transform.position + PIECE_ADJUSTMENT;
        if (GameController.Instance.PlayerColor == PieceColor.Red)
        {
            pieceObject.transform.localEulerAngles += new Vector3(0, 0, 180);
        }

        //Sets the piece's reference to the current board tile
        tile.CurrentPiece = pieceObject.GetComponent <GamePiece>();

        //Sets the tile reference to the current piece
        //A little janky but it only needs to be set like this at the start of the game
        tile.CurrentPiece.CurrentTile = tile;

        GamePieces.Add(tile.CurrentPiece);
    }
예제 #5
0
        private GamePieces genNextPiece()
        {
            GamePieces pieceType = (GamePieces)Enum.GetValues(typeof(GamePieces)).GetValue(_random.Next(0, 7));
            GamePieces temp      = _nextPiece;

            _nextPiece = pieceType;
            return(temp);
        }
예제 #6
0
 private void Update()
 {
     // If there are no more game pieces to play, spawn more
     if (GamePieces.CountGamePieces() <= 0)
     {
         SpawnPiecees();
         DetectPossibleMoves.DidNewBlocksSpawn = true;
     }
 }
예제 #7
0
        public void SetValidCode()
        {
            GameBoard gb   = new GameBoard(GameLevels.Beginner);
            var       code = new GamePieces[] { GamePieces.Piece1, GamePieces.Piece2, GamePieces.Piece3 };

            gb.SetCode(code);
            for (int i = 0; i < code.Length; i++)
            {
                Assert.AreEqual(gb.SecretCode[i], code[i]);
            }
        }
예제 #8
0
        public GamePlayView(MainForm mainForm, Rectangle view = new Rectangle())
        {
            _view     = view;
            _mainForm = mainForm;
            _seed     = DateTime.Now.Millisecond;
            _random   = new Random(_seed);
            _blocks   = new List <GameBlock>(Constants.GRID_WIDITH * Constants.GRID_HEIGHT);
            GamePieces pieceType = (GamePieces)Enum.GetValues(typeof(GamePieces)).GetValue(_random.Next(0, 7));

            _gamePiece = GamePieceFactory.Instance.createGamePiece(pieceType);
            genNextPiece();
        }
예제 #9
0
        /// <summary>
        /// GameManager object constructor.
        ///
        /// Needs to be told what game_mode to run in, what game_piece we are using, and the start position.
        /// </summary>
        /// <param name="game_mode">GameMode Enum</param>
        /// <param name="game_piece">GamePieces Enum</param>
        /// <param name="colour">Colour Enum</param>
        /// <param name="x">Integer value for the X-Coordinate</param>
        /// <param name="y">Integer value for the Y-Coordinate</param>
        public GameManager(GameMode game_mode, GamePieces game_piece, Colour colour, int x, int y)
        {
            // Reset Chessboard:
            Chessboard.reset();

            // Set vars:
            this.game_mode       = game_mode;
            this.game_piece_type = game_piece;
            this.colour          = colour;
            this.start_x         = x;
            this.start_y         = y;
        }
예제 #10
0
        public void SetInvalidCode()
        {
            var gb   = new GameBoard(GameLevels.Beginner);
            var code = new GamePieces[] { GamePieces.Piece1, GamePieces.Piece2, GamePieces.Piece3, GamePieces.Piece4 };

            try
            {
                gb.SetCode(code);
            }
            catch (InvalidOperationException)
            {
                return;
            }
            Assert.Fail();
        }
예제 #11
0
    List <LinePieces> GetColumns()
    {
        List <LinePieces> lines  = new List <LinePieces> ();
        LinePieces        line   = new LinePieces();
        List <GamePiece>  pieces = new List <GamePiece> ();

        for (int y = 0; y < 6; y++)
        {
            line = new LinePieces();

            pieces = GamePieces.Where(z => z.transform.position.y == y).ToList();
            line.AddLine(pieces);
            lines.Add(line);
        }

        return(lines);
    }
예제 #12
0
        /// <summary>
        /// This is called every time the "Start Game" button is pressed.
        /// In turn, the GameManager object is re-instantiated, and the Game commences.
        /// </summary>
        /// <param name="gm">GameMode Enum.</param>
        /// <param name="gp">GamePiece Enum.</param>
        /// <param name="start_x">int Start X-Position.</param>
        /// <param name="start_y">int Start Y-Position.</param>
        /// <param name="num_games">int Number of Games to play.</param>
        public static void start_game(GameMode gm, GamePieces gp, int start_x, int start_y, int num_games)
        {
            // Instantiate Game Manager:
            game_manager = new GameManager(gm, gp, Colour.BLACK, start_x, start_y);

            // Play Game:
            List <Position> spaces = null;

            for (int i = 0; i < num_games; i++)
            {
                spaces = game_manager.play_game();
                Save.save_game(gm, gp, i + 1, spaces.Count);
            }

            // Update screen (only after last game):
            MainForm.__instance.update_table(spaces);
        }
예제 #13
0
        IEnumerator AnimatePiece(GamePieces piece, float x, float z)
        {
            float   waitTime       = 0.04f;
            Vector3 targetPosition = new Vector3(x, 0, z);

            while (true)
            {
                yield return(new WaitForSeconds(waitTime));

                float step = speed * waitTime;
                piece.transform.position = Vector3.MoveTowards(piece.transform.position, targetPosition, step);

                if (piece.transform.position == targetPosition)
                {
                    break;
                }
            }
        }
예제 #14
0
    //public static bool AnyMovesLeft()
    //{
    //    if (Block_I2_0) return true;
    //    if (Block_I3_0) return true;
    //    if (Block_I4_0) return true;
    //    if (Block_I5_0) return true;
    //    if (Block_I2_90) return true;
    //    if (Block_I3_90) return true;
    //    if (Block_I4_90) return true;
    //    if (Block_I5_90) return true;
    //    if (Block_O1) return true;
    //    if (Block_O2) return true;
    //    if (Block_O3) return true;
    //    if (Block_L2_0) return true;
    //    if (Block_L2_90) return true;
    //    if (Block_L2_270) return true;
    //    if (Block_L2_180) return true;
    //    if (Block_L3_0) return true;
    //    if (Block_L3_90) return true;
    //    if (Block_L3_180) return true;
    //    if (Block_L3_270) return true;
    //    return false;
    //}



    public static bool IsThereAValidMove()
    {
        bool value = false;

        foreach (var obj in GamePieces.WhatGamePieces())
        {
            var b = obj.name.Replace("(Clone)", "");;
            var r = obj.transform.localEulerAngles.z;
            value = Test(b, r);

            // Uncomment to see if avaliable move is valid to play
            //Debug.Log(b + " " + r + " " + value);
            if (value == true)
            {
                break;
            }
        }
        //Debug.Log("");

        return(value);
    }
예제 #15
0
        /// <summary>
        /// Saves the completed game to file.
        /// </summary>
        /// <param name="game_mode">GameMode Enum.</param>
        /// <param name="game_piece">GamePiece Enum.</param>
        /// <param name="game_num">int Game/Trial number.</param>
        /// <param name="spaces_reached">int Spaces hit by that piece.</param>
        public static void save_game(GameMode game_mode, GamePieces game_piece, int game_num, int spaces_reached)
        {
            string save_file = "Saved Games/";

            save_file += "RaymanJamal";
            save_file += game_mode.ToString();
            save_file += "_" + game_piece.ToString();
            save_file += ".txt.";

            string save_string = "";

            save_string += "Trial " + game_num + ": ";
            save_string += "The " + game_piece.ToString() + " ";
            save_string += "was able to successfully touch " + spaces_reached + " squares.";


            using (StreamWriter sw = new StreamWriter(save_file, true))
            {
                sw.WriteLine(save_string);
            }
        }
예제 #16
0
        private void StartRound(Snake[] Snakes)
        {
            _Round++;
            _RoundStartTime = DateTime.Now;
            _Snakes         = Snakes.ToArray();

            _GameMatrix = new GamePieces[Width][];

            for (int w = 0; w < Width; w++)
            {
                _GameMatrix[w] = new GamePieces[Height];
            }

            for (int x = 0; x <= _RightEdge; x++)
            {
                for (int y = 0; y <= _BottomEdge; y++)
                {
                    if (y == _TopEdge || y == _BottomEdge || x == _LeftEdge || x == _RightEdge)
                    {
                        _GameMatrix[x][y] = GamePieces.Wall;
                    }
                    else
                    {
                        _GameMatrix[x][y] = GamePieces.Blank;
                    }
                }
            }

            if (_Snakes.Length > 0)
            {
                _GameMatrix[_Snakes[0].Points[0].X][_Snakes[0].Points[0].Y] = GamePieces.Snake;
                if (_Snakes.Length > 1)
                {
                    _GameMatrix[_Snakes[1].Points[0].X][_Snakes[1].Points[0].Y] = GamePieces.Snake;
                    if (_Snakes.Length > 2)
                    {
                        _GameMatrix[_Snakes[2].Points[0].X][_Snakes[2].Points[0].Y] = GamePieces.Snake;
                        if (_Snakes.Length > 3)
                        {
                            _GameMatrix[_Snakes[3].Points[0].X][_Snakes[3].Points[0].Y] = GamePieces.Snake;
                        }
                    }
                }
            }

            _ApplePosition = new Point(Convert.ToInt32(Math.Ceiling(_RightEdge / 2.0)), Convert.ToInt32(Math.Ceiling(_BottomEdge / 2.0)));
            _GameMatrix[_ApplePosition.X][_ApplePosition.Y] = GamePieces.Apple;

            Console.Clear();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetCursorPosition(98, 1);
            Console.WriteLine(@"  ___       _   _   _     ___           _ ");
            Console.SetCursorPosition(98, 2);
            Console.WriteLine(@" | _ ) __ _| |_| |_| |___/ __|_ _  __ _| |_____ ");
            Console.SetCursorPosition(98, 3);

            Console.WriteLine(@" | _ \/ _` |  _|  _| / -_)__ \ ' \/ _` | / / -_)");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.SetCursorPosition(98, 4);
            Console.WriteLine(@" |___/\__,_|\__|\__|_\___|___/_||_\__,_|_\_\___|");



            Console.SetCursorPosition(99, 31);
            Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(@"Up/Down: ");
            Console.ForegroundColor = ConsoleColor.White; Console.Write("Change Speed");
            Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("  K:");
            Console.ForegroundColor = ConsoleColor.White; Console.Write(" Kill All Snakes");
            Console.SetCursorPosition(99, 32);

            Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(@"M: ");
            Console.ForegroundColor = ConsoleColor.White; Console.Write("Change Mode");
            Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("   B:");
            Console.ForegroundColor = ConsoleColor.White; Console.Write(" Change Match Type");

            Console.SetCursorPosition(99, 33);
            Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(@"S: ");
            Console.ForegroundColor = ConsoleColor.White; Console.Write("Change Initial Size");
            Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("  G: ");
            Console.ForegroundColor = ConsoleColor.White; Console.Write("Change Growth Factor");

            Console.SetCursorPosition(99, 34);
            Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(@"T: ");
            Console.ForegroundColor = ConsoleColor.White; Console.Write("Change Match Time Limit");
            Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(@"  Esc: ");
            Console.ForegroundColor = ConsoleColor.White; Console.Write("Restart");

            Console.ForegroundColor = ConsoleColor.Green;
            Console.SetCursorPosition(115, 35);
            Console.WriteLine(@"       ---_ ......._-_--.        ");
            Console.SetCursorPosition(115, 36);
            Console.Write(@"      ("); Console.ForegroundColor = ConsoleColor.White; Console.Write(@"|"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"\ /      / /"); Console.ForegroundColor = ConsoleColor.White; Console.Write(@"|"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@" \  \       ");
            Console.SetCursorPosition(115, 37);
            Console.WriteLine(@"      /  /     .'  -=-'   `.     ");
            Console.SetCursorPosition(115, 38);
            Console.WriteLine(@"     /  /    .'             )    ");
            Console.SetCursorPosition(115, 39);
            Console.WriteLine(@"   _/  /   .'        _.)   /     ");
            Console.SetCursorPosition(115, 39);
            Console.WriteLine(@"  / o   o        _.-' /  .'      ");
            Console.SetCursorPosition(115, 40);
            Console.WriteLine(@"  \          _.-'    / .'*|      ");
            Console.SetCursorPosition(115, 41);
            Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"   \______.-'//    .'.'"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(@" \"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"*|      ");
            Console.SetCursorPosition(115, 42);
            Console.ForegroundColor = ConsoleColor.White; Console.Write(@"    \|  \ |"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(@" //   .'.'"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(@" _ |"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"*|      ");
            Console.SetCursorPosition(115, 43);
            Console.ForegroundColor = ConsoleColor.White; Console.Write(@"     `   \|"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"//  .'.'"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(@"_ _ _|"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"*|      ");
            Console.SetCursorPosition(115, 44);
            Console.ForegroundColor = ConsoleColor.White; Console.Write(@"      .  ."); Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"// .'.' "); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(@"| _ _ \"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"*|      ");
            Console.SetCursorPosition(115, 45);
            Console.ForegroundColor = ConsoleColor.White; Console.Write(@"      \`"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"-"); Console.ForegroundColor = ConsoleColor.White; Console.Write(@"|\"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"_/ /"); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(@"    \ _ _ \"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"*\     ");
            Console.SetCursorPosition(115, 46);
            Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"       `"); Console.ForegroundColor = ConsoleColor.Red; Console.Write(@"/"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"'\__/      "); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(@"\ _ _ \"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"*\    ");
            Console.SetCursorPosition(115, 47);
            Console.ForegroundColor = ConsoleColor.Red; Console.Write(@"      /^|"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"            "); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(@"\ _ _ \"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"*    ");
            Console.SetCursorPosition(115, 48);
            Console.ForegroundColor = ConsoleColor.Red; Console.Write(@"     '  `             "); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(@"\ _ _ \"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"  ");
            Console.SetCursorPosition(115, 49);
            Console.ForegroundColor = ConsoleColor.Green; Console.Write(@"                       "); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(@"\_"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"  ");

            for (int y = 0; y <= _BottomEdge; y++)
            {
                for (int x = 0; x <= _RightEdge; x++)
                {
                    SetCursorPosition(x, y);
                    if (_GameMatrix[x][y] == GamePieces.Wall)
                    {
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    else if (_GameMatrix[x][y] == GamePieces.Apple)
                    {
                        Console.ForegroundColor = ConsoleColor.Magenta;
                    }
                    Console.Write((char)_GameMatrix[x][y]);
                }
            }

            GameLoop();

            if (_Speed == _MaxSpeed)
            {
                Thread.Sleep(500);
            }
            else
            {
                Thread.Sleep(2000);
            }
        }
예제 #17
0
 public void addNextBlock(GamePieces nextPiece)
 {
     _nextBlock.detail = nextPiece;
 }
 public void AddGamePiece(ConnectFourPiece piece)
 {
     GamePieces.Add(piece);
 }
예제 #19
0
 public override int GetHashCode()
 {
     return(Weighting.GetHashCode() ^ Response.GetHashCode() ^ NumberOfTimesSeen.GetHashCode() ^ GamePieces.GetHashCode());
 }
예제 #20
0
파일: Score.cs 프로젝트: vahnilah/100Puzzle
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0) || Input.GetMouseButton(0))
        {
            _runUpdate       = true;
            _gatherScoreTime = 0f;
        }

        if (_runUpdate == true)
        {
            _gatherScoreTime += Time.deltaTime;
            if (_gatherScoreTime > _waitTime)
            {
                _gatherScoreTime = 0f;
                _runUpdate       = false;
            }

            if (DetectPossibleMoves.IsGameOver == true)
            {
                // Condenced game update score below for game over text w/o animation
                totalScoreText.text = PlayedScore.ToString();
                int diff             = TotalScore - PlayedScore;
                int loops            = 10;
                int valueToIncrement = diff / loops;
                int temp             = PlayedScore + valueToIncrement;
                totalScoreText.text     = temp.ToString();
                GameOverInfo.totalScore = temp;

                TotalScore = temp;
            }
            else
            {
                if (GamePieces.CountGameBlocksOutsideGrid() != outsidePieces)
                {
                    previous1     = outsidePieces;
                    outsidePieces = GamePieces.CountGameBlocksOutsideGrid();
                }

                if (GamePieces.HasAnGamePieceBeenPlayedToUpdateScore == true)
                {
                    isThereValidMoves = DetectPossibleMoves.IsThereAValidMove();

                    GamePieces.HasAnGamePieceBeenPlayedToUpdateScore = false;

                    previous3 = previous2;
                    previous2 = outsidePieces;
                    if (previous3 != 0)
                    {
                        blockPlayed = Math.Abs(previous2 - previous3);
                        //Debug.Log(blockPlayed);

                        // Adjust score
                        int max = Math.Max(PlayedScore, TotalScore);
                        PlayedScore = max;
                        TotalScore  = max;

                        // Update scores on played & total
                        PlayedScore += blockPlayed;
                        TotalScore  += blockPlayed;

                        // If rows were cleared, add them to total score & played score when complete
                        int clear = GameGrid.howManyRowsColsWereFilled;
                        if (clear > 0)
                        {
                            GetRowsClears(GameGrid.howManyRowsColsWereFilled);
                        }
                        GameGrid.howManyRowsColsWereFilled = 0;

                        //PrintScore();
                        UpdateScore();
                    }

                    //Debug.Log(previous1 + " , " + previous2 + " , " + previous3);


                    //int blocksPlayed =
                }

                if (!isThereValidMoves && !saved)
                {
                    if (TotalScore > HighScore)
                    {
                        SaveData.SetHighScore(TotalScore, HighScore);
                        SavedData data = new SavedData();
                        data.Save(SaveData);
                    }

                    //Debug.Log("Game Over");
                    DetectPossibleMoves.IsGameOver = true;

                    saved = true;
                }
            }
        }
    }
예제 #21
0
        public GamePiece createGamePiece(GamePieces piece)
        {
            int centerBlock = Constants.GRID_WIDITH / 2;

            GameBlock b1;
            GameBlock b2;
            GameBlock b3;
            GameBlock b4;

            switch (piece)
            {
            case GamePieces.L_RIGHT:
                b1       = new GameBlock(location: new Point(centerBlock, -3));
                b1.Color = Constants.L_RIGHT_PIECE_COLOR;
                b2       = new GameBlock(location: new Point(centerBlock, -2));
                b2.Color = Constants.L_RIGHT_PIECE_COLOR;
                b3       = new GameBlock(location: new Point(centerBlock, -1));
                b3.Color = Constants.L_RIGHT_PIECE_COLOR;
                b4       = new GameBlock(location: new Point(centerBlock + 1, -1));
                b4.Color = Constants.L_RIGHT_PIECE_COLOR;

                return(new GamePiece(new GameBlock[] { b1, b2, b3, b4 }, b2));

            case GamePieces.L_LEFT:
                b1       = new GameBlock(location: new Point(centerBlock, -3));
                b1.Color = Constants.L_LEFT_PIECE_COLOR;
                b2       = new GameBlock(location: new Point(centerBlock, -2));
                b2.Color = Constants.L_LEFT_PIECE_COLOR;
                b3       = new GameBlock(location: new Point(centerBlock, -1));
                b3.Color = Constants.L_LEFT_PIECE_COLOR;
                b4       = new GameBlock(location: new Point(centerBlock + 1, -3));
                b4.Color = Constants.L_LEFT_PIECE_COLOR;

                return(new GamePiece(new GameBlock[] { b1, b2, b3, b4 }, b2));

            case GamePieces.BLOCK:
                b1       = new GameBlock(location: new Point(centerBlock, -1));
                b1.Color = Constants.BLOCK_PIECE_COLOR;
                b2       = new GameBlock(location: new Point(centerBlock, -2));
                b2.Color = Constants.BLOCK_PIECE_COLOR;
                b3       = new GameBlock(location: new Point(centerBlock + 1, -2));
                b3.Color = Constants.BLOCK_PIECE_COLOR;
                b4       = new GameBlock(location: new Point(centerBlock + 1, -1));
                b4.Color = Constants.BLOCK_PIECE_COLOR;

                return(new GamePiece(new GameBlock[] { b1, b2, b3, b4 }, null));

            case GamePieces.T:
                b1       = new GameBlock(location: new Point(centerBlock, -1));
                b1.Color = Constants.T_PIECE_COLOR;
                b2       = new GameBlock(location: new Point(centerBlock - 1, -1));
                b2.Color = Constants.T_PIECE_COLOR;
                b3       = new GameBlock(location: new Point(centerBlock + 1, -1));
                b3.Color = Constants.T_PIECE_COLOR;
                b4       = new GameBlock(location: new Point(centerBlock, -2));
                b4.Color = Constants.T_PIECE_COLOR;

                return(new GamePiece(new GameBlock[] { b1, b2, b3, b4 }, b1));

            case GamePieces.LINE:
                b1       = new GameBlock(location: new Point(centerBlock, -4));
                b1.Color = Constants.LINE_GAME_PIECE_COLOR;
                b2       = new GameBlock(location: new Point(centerBlock, -3));
                b2.Color = Constants.LINE_GAME_PIECE_COLOR;
                b3       = new GameBlock(location: new Point(centerBlock, + -2));
                b3.Color = Constants.LINE_GAME_PIECE_COLOR;
                b4       = new GameBlock(location: new Point(centerBlock, + -1));
                b4.Color = Constants.LINE_GAME_PIECE_COLOR;

                return(new GamePiece(new GameBlock[] { b1, b2, b3, b4 }, b2));

            case GamePieces.CURVE_LEFT:
                b1       = new GameBlock(location: new Point(centerBlock, -3));
                b1.Color = Constants.CURVE_LEFT_PIECE_COLOR;
                b2       = new GameBlock(location: new Point(centerBlock, -2));
                b2.Color = Constants.CURVE_LEFT_PIECE_COLOR;
                b3       = new GameBlock(location: new Point(centerBlock - 1, -2));
                b3.Color = Constants.CURVE_LEFT_PIECE_COLOR;
                b4       = new GameBlock(location: new Point(centerBlock - 1, -1));
                b4.Color = Constants.CURVE_LEFT_PIECE_COLOR;

                return(new GamePiece(new GameBlock[] { b1, b2, b3, b4 }, b2));

            case GamePieces.CURVE_RIGHT:
                b1       = new GameBlock(location: new Point(centerBlock, -3));
                b1.Color = Constants.CURVE_RIGHT_PEICE_COLOR;
                b2       = new GameBlock(location: new Point(centerBlock, -2));
                b2.Color = Constants.CURVE_RIGHT_PEICE_COLOR;
                b3       = new GameBlock(location: new Point(centerBlock + 1, -2));
                b3.Color = Constants.CURVE_RIGHT_PEICE_COLOR;
                b4       = new GameBlock(location: new Point(centerBlock + 1, -1));
                b4.Color = Constants.CURVE_RIGHT_PEICE_COLOR;

                return(new GamePiece(new GameBlock[] { b1, b2, b3, b4 }, b2));
            }
            return(null);
        }
        public void MakeMove(Position origin, Position destiny)
        {
            Piece takenPiece = ChessMove(origin, destiny);

            if (IsInCheck(CurrentPlayer))
            {
                UndoChessMove(origin, destiny, takenPiece);
                throw new BoardExceptions("You can not put your self in check");
            }

            Piece movedPiece = Board.GetPiece(destiny);

            //Special move: Pawn Promotion
            if (movedPiece is Pawn)
            {
                if ((movedPiece.Color == Color.White && destiny.Line == 0) || (movedPiece.Color == Color.Black && destiny.Line == 7))
                {
                    Board.RemovePiece(destiny);
                    GamePieces.Remove(movedPiece);
                    Console.WriteLine("Type the kind of piece you want to promote your pawn to");
                    Console.Write("(QUEEN / ROOK / KNIGHT / BISHOP): ");
                    string playerChoice = Console.ReadLine();
                    if (!ScreenController.CheckPlayerChoice(playerChoice))
                    {
                        throw new BoardExceptions("Not valid option");
                    }
                    playerChoice = playerChoice.ToLower();
                    switch (playerChoice)
                    {
                    case "queen":
                    {
                        Piece newPiece = new Queen(movedPiece.Color, Board);
                        Board.AddressPiece(newPiece, destiny);
                        GamePieces.Add(newPiece);
                        break;
                    }

                    case "rook":
                    {
                        Piece newPiece = new Rook(movedPiece.Color, Board);
                        Board.AddressPiece(newPiece, destiny);
                        GamePieces.Add(newPiece);
                        break;
                    }

                    case "knight":
                    {
                        Piece newPiece = new Knight(movedPiece.Color, Board);
                        Board.AddressPiece(newPiece, destiny);
                        GamePieces.Add(newPiece);
                        break;
                    }

                    case "bishop":
                    {
                        Piece newPiece = new Bishop(movedPiece.Color, Board);
                        Board.AddressPiece(newPiece, destiny);
                        GamePieces.Add(newPiece);
                        break;
                    }
                    }
                }
            }
            //EndGame Pawn Promotion

            if (IsInCheck(EnemyIs(CurrentPlayer)))
            {
                PlayerInCheck = true;
            }
            else
            {
                PlayerInCheck = false;
            }

            if (IsInCheckMate(EnemyIs(CurrentPlayer)))
            {
                EndGame = true;
            }
            else
            {
                Turn++;
                MudaJogador();
            }

            //Special move: en passant
            if (movedPiece is Pawn && (destiny.Line == origin.Line + 2 || destiny.Line == origin.Line - 2))
            {
                VulnerableToEnPassant = movedPiece;
            }
            else
            {
                VulnerableToEnPassant = null;
            }
        }
 public void StartNewPiece(char column, int line, Piece piece)
 {
     Board.AddressPiece(piece, new ChessPosition(column, line).TranslateChessToZeroBased());
     GamePieces.Add(piece);
 }
예제 #24
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0) || Input.GetMouseButton(0))
        {
            _canUpdateColor  = true;
            _canUpdateGrid   = true;
            _gatherColorTime = 0f;
        }

        // Set the color of the grid
        if (AnimateGrid.setGrid == false && _updateOnce == true)
        {
            //_gatherGridTime += Time.deltaTime;
            //if (_gatherGridTime > _waitTime)
            //_canUpdateGrid = false;

            AnimateGrid.SetGrid();
            AnimateGrid.setGrid = true;

            // Changel Text on Labels
            GameObject[] textLabels = GameObject.FindGameObjectsWithTag("ScoreText");
            // Set UI Text to objects to access
            //Debug.Log(objs.Length);
            foreach (var i in textLabels)
            {
                var t = i.GetComponent <Text>();
                if (t.name.Equals("HighScore"))
                {
                    if (SetColor.GetDarkMode() == true)
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                    else
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                }
                if (t.name.Equals("CurrentScore"))
                {
                    if (SetColor.GetDarkMode() == true)
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                    else
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                }
            }

            _updateOnce = false;
        }

        // Change colors to Light / Dark mode
        if (SetColor.WillChangeColor == true && _canUpdateColor == true)
        {
            _gatherColorTime += Time.deltaTime;
            if (_gatherColorTime > _waitTime)
            {
                _canUpdateColor = false;
            }

            UpdateColor();


            SetColor.WillChangeColor = false;
        }

        // Restart game
        if (GameOverInfo.RestartGame == true)
        {
            gameOverCanvas.SetActive(false);
            restartButton.SetActive(false);
            background.SetActive(false);
            GameOverInfo.RestartGame = false;
            AnimateGrid.setGrid      = false;
            SetColor.WillChangeColor = true;
            _updateOnce = true;

            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }

        // Check if Game Over
        if (DetectPossibleMoves.IsGameOver == true)
        {
            if (triggerOnce == true)
            {
                GameOver();

                //Debug.Log("Game Over");
                triggerOnce = false;
            }
        }
        else
        {
            if (!checkedAvaliablePieces || DetectPossibleMoves.DidNewBlocksSpawn)
            {
                DetectPossibleMoves.SetBooleans();

                DetectPossibleMoves.AnalyzeGrid();

                DetectPossibleMoves.IsThereAValidMove();

                checkedAvaliablePieces = true;
                GamePieces.HasAnGamePieceBeenPlayedToUpdateScore = true;
            }

            // Logic for the grid
            GamePieces.FindGameBlocks();
            GamePieces.FindGamePieces();
            GamePieces.WhereAreGamePiecesToPlay();
            AnimateGrid.FindBackgroundBlocks();

            /* If the left (main) mouse click is released
             * remove cleared blocks */
            if (Input.GetMouseButtonUp(0) || isMouseReleased)
            {
                if (GamePieces.isAPlayValid)
                {
                    GameGrid.UpdatePlayedPiecesOnGrid(this);
                }

                UpdateGameLogic();

                getRefresh      = true;
                isMouseReleased = false;

                UpdateAnimation();
            }

            if (GamePieces.isAPlayValid)
            {
                if (GamePieces.isAPlayValid)
                {
                    GameGrid.UpdatePlayedPiecesOnGrid(this);
                }

                checkedAvaliablePieces = false;
            }
        }
    }
예제 #25
0
        public void MoveGamePiece(int x, int y)
        {
            //if (selectedGamePiece.isMoveValid(x, y))
            //{
            //    GamePiecesArray[selectedGamePiece.CurrentX, selectedGamePiece.CurrentY] = null;

            //    //move the piece to the new location
            //    if (GamePiecesArray[x, y] != null)
            //        return;
            //    selectedGamePiece.transform.position = GetTileCenter(x, y);
            //    GamePiecesArray[x, y] = selectedGamePiece;
            //    isPlayerXTurn = !isPlayerXTurn;
            //}

            currentMove.End.row = y;
            currentMove.End.col = x;

            if (game.movePiece(currentPlayer.getIdentity(), currentMove))
            {
                if (game.pieceLastTaken != null)
                {
                    removedGamePiece = GamePiecesArray[game.pieceLastTaken.col, game.pieceLastTaken.row];

                    Destroy(removedGamePiece.GetComponent <MeshRenderer>());
                    //activeGamePieces.Remove();
                    GamePiecesArray[game.pieceLastTaken.col, game.pieceLastTaken.row] = selectedGamePiece;

                    Destroy(removedGamePiece.GetComponent <GamePieces>());
                    //GamePiecesArray[game.pieceLastTaken.X, game.pieceLastTaken.Y] = null;
                }

                GamePiecesArray[currentMove.Begin.col, currentMove.Begin.row] = null;
                //GamePiecesArray[currentMove.End.col, currentMove.End.row] = selectedGamePiece;

                StartCoroutine(AnimatePiece(selectedGamePiece, GetTileCenter(x, y).x, GetTileCenter(x, y).z));

                //selectedGamePiece.transform.localPosition = GetTileCenter(x, y);
                GamePiecesArray[x, y] = selectedGamePiece;



                selectedGamePiece.GetComponent <MeshRenderer>().material = previousMat;
                selectedGamePiece = null;


                if (currentPlayer.getIdentity() == identity.X)
                {
                    currentPlayer = PlayerO;
                }
                else
                {
                    currentPlayer = PlayerX;
                }
            }

            else
            {
                //Unhighlight the piece if we are playing locally
                if (!currentPlayer.isAI() && !currentPlayer.isNetwork())
                {
                    if (selectedGamePiece.GetComponent <MeshRenderer>())
                    {
                        selectedGamePiece.GetComponent <MeshRenderer>().material = previousMat;
                    }
                    selectedGamePiece = null;
                }
            }
        }