예제 #1
0
파일: Grid.cs 프로젝트: Hykrow/VirusWar
    public void ExtendSnake(Vector2 pos)
    {
        print("canPlay: " + canPlay);
        if (!canPlay)
        {
            return;
        }

        Vector2 FoundPosition = FindPosition(pos);

        if (playerRank == 1)
        {
            Vector2 firstCheck = new Vector2(19, 35);
            Vector2 secCheck   = new Vector2(20, 35);

            Vector2 thirdCheck  = new Vector2(19, 36);
            Vector2 fourthCheck = new Vector2(20, 36);

            if (FoundPosition == firstCheck || FoundPosition == secCheck || FoundPosition == thirdCheck || FoundPosition == fourthCheck)
            {
                return;
            }
        }
        else
        {
            Vector2 firstCheck = new Vector2(19, 4);
            Vector2 secCheck   = new Vector2(20, 4);

            Vector2 thirdCheck  = new Vector2(19, 3);
            Vector2 fourthCheck = new Vector2(20, 3);

            if (FoundPosition == firstCheck || FoundPosition == secCheck || FoundPosition == thirdCheck || FoundPosition == fourthCheck)
            {
                return;
            }
        }
        Snake          SnakeToAdd                = GetSnakeFromPosition(FoundPosition);
        CreatingSnakes CreatingSnakesToAdd       = GetCreatingSnakesFromPosition(FoundPosition);
        CreatingSnakes CreatingSnakesButTheWhole = GetCreatingSnakesFromPositionButTheWholeOne(FoundPosition);

        print("ExtendingSnake");
        bool goodSnake = true;

        print("creating snakes values: " + GetCreatingSnakesFromPosition(FoundPosition));
        if (CreatingSnakesToAdd != null)
        {
            print("creating snakes is null");
        }
        else
        {
            print("it is not nullllllsqdqdq");
        }
        //these conditions are used to check if we dont create a tail part on ourselves.
        if (tailLimit < 5 && !isAnyCreatingSnakesHere(FoundPosition))
        {
            // here maybe replce it by the CreatingSnakesToAdd.name
            if (CreatingSnakesButTheWhole.name == "nope")
            {
                if (CreatingSnakesList.Count != 0)
                {
                    return;
                }
                print("creating a new creating snake");

                //we initalize the snakeLock so they cant move 2 snakes at the same time;
                if (SnakeToAdd.name != "nope" && snakeLock == null)
                {
                    if (!IsThisSnakeOurs(SnakeToAdd.name))
                    {
                        return;
                    }

                    snakeLock = SnakeToAdd.name;
                    print("snakeName: " + SnakeToAdd.name);
                }

                print("snakeToAddName: " + snakeLock);
                //if there are no creatingSnakes near, we create a new one instead;
                if (!IsThisSnakeOurs(snakeLock))
                {
                    return;
                }
                CreatingSnakes newCreatingSnakes = new CreatingSnakes();
                newCreatingSnakes.name = snakeLock;
                newCreatingSnakes.addCube(FoundPosition, true);
                CreatingSnakesList.Add(newCreatingSnakes);
                tailLimit++;
                canValidate = true;
            }

            else
            {
                //whenever a creating snake is already created at this pos, this get callled
                print("a creating snake is already created");
                //we need to add this here so it doesnt pick the head of the snake but the one of the Creating Snakes
                bool crtSnk = false;
                if (CreatingSnakesButTheWhole.name != "nope")
                {
                    print("Creating snakes but the whole name is not null");
                    if (IsAnyCreatingSnakesFromPositionButTheWholeOneBool(FoundPosition))
                    {
                        print("this shits good fn"); crtSnk = true;
                    }
                    else
                    {
                        print("this shit isnt gooddd");
                    }
                }
                else
                {
                    print("The name is null");
                }


                if (snakeLock == CreatingSnakesToAdd.name && crtSnk)
                {
                    CreatingSnakesToAdd.addCube(FoundPosition, true);
                    tailLimit++;
                    canValidate = true;
                }
            }
            //}
        }
        print("taillimit is ok");
    }
예제 #2
0
파일: Grid.cs 프로젝트: Hykrow/VirusWar
    public void CreateSnake()
    {
        Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        pos.z = 0;
        if (FindPosition(pos)[0] == 600)
        {
            return;
        }
        if (GetSnakesFromStrictPositionButEvenTheDestroyed(FindPosition(pos)).name != "nope")
        {
            return;
        }
        if (creatingSnake && canPlay)
        {
            Vector3 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            bool goodCase = false;

            int findCaseX = Mathf.RoundToInt(FindPosition(pz)[0]);
            int findCaseY = Mathf.RoundToInt(FindPosition(pz)[1]);

            print(playerRank);

            if (playerRank == 1)
            {
                if (findCaseX == 18 && findCaseY == 35)
                {
                    goodCase          = true;
                    creatingSnakeName = "a";
                }
                if (findCaseX == 18 && findCaseY == 36)
                {
                    goodCase          = true;
                    creatingSnakeName = "b";
                }


                if (findCaseX == 19 && findCaseY == 37)
                {
                    goodCase          = true;
                    creatingSnakeName = "c";
                }
                if (findCaseX == 19 && findCaseY == 34)
                {
                    goodCase          = true;
                    creatingSnakeName = "d";
                }


                if (findCaseX == 20 && findCaseY == 37)
                {
                    goodCase          = true;
                    creatingSnakeName = "e";
                }
                if (findCaseX == 20 && findCaseY == 34)
                {
                    goodCase          = true;
                    creatingSnakeName = "f";
                }


                if (findCaseX == 21 && findCaseY == 36)
                {
                    goodCase          = true;
                    creatingSnakeName = "g";
                }
                if (findCaseX == 21 && findCaseY == 35)
                {
                    goodCase          = true;
                    creatingSnakeName = "h";
                }
            }
            else if (playerRank == 2)
            {
                print("this is player2");


                if (findCaseX == 18 && findCaseY == 35 - 32)
                {
                    goodCase          = true;
                    creatingSnakeName = "i";
                }
                if (findCaseX == 18 && findCaseY == 36 - 32)
                {
                    goodCase          = true;
                    creatingSnakeName = "j";
                }


                if (findCaseX == 19 && findCaseY == 37 - 32)
                {
                    goodCase          = true;
                    creatingSnakeName = "k";
                }
                if (findCaseX == 19 && findCaseY == 34 - 32)
                {
                    goodCase          = true;
                    creatingSnakeName = "l";
                }


                if (findCaseX == 20 && findCaseY == 37 - 32)
                {
                    goodCase          = true;
                    creatingSnakeName = "m";
                }
                if (findCaseX == 20 && findCaseY == 34 - 32)
                {
                    goodCase          = true;
                    creatingSnakeName = "n";
                }


                if (findCaseX == 21 && findCaseY == 36 - 32)
                {
                    goodCase          = true;
                    creatingSnakeName = "o";
                }
                if (findCaseX == 21 && findCaseY == 35 - 32)
                {
                    goodCase          = true;
                    creatingSnakeName = "p";
                }
            }



            if (!isAnyThingHere(FindPosition(pz)))
            {
                print("creating second head");
                if (goodCase && snakeLock == null)
                {
                    Vector2 snakePos = NormalizePosition(FindPosition(pz));
                    //Create a snake in the list CreatingSnakes, so it can be cancelled before validating the turn
                    CreatingSnakes creatingSnakes = new CreatingSnakes();
                    creatingSnakes.name = creatingSnakeName;
                    creatingSnakes.addCube(FindPosition(pz), true);
                    print("creating snake's name is " + creatingSnakes.name);

                    CreatingSnakesList.Add(creatingSnakes);
                    canValidate = true;
                    canPlay     = false;
                }
            }

            creatingSnake = false;
        }
    }