Пример #1
0
    CreatingSnakes GetCreatingSnakesFromPosition(Vector2 position)
    {
        foreach (CreatingSnakes snk in CreatingSnakesList)
        {
            if (snk.body.Count == 0)
            {
                break;
            }
            var pos = snk.body[0];
            if (pos[0] == position[0])
            {
                print(snk.name);
                if (Mathf.RoundToInt(pos[1]) == Mathf.RoundToInt(position[1] - 1) || Mathf.RoundToInt(pos[1]) == Mathf.RoundToInt((position[1] + 1)))
                {
                    print("SKKKKTRTRT"); return(snk);
                }
                print("WTF");
            }
            else if (pos[1] == position[1])
            {
                print("hello yeeeeee");

                if (pos[0] == position[0] - 1 || pos[0] == position[0] + 1)
                {
                    return(snk);
                }
            }
        }

        CreatingSnakes newSnake = new CreatingSnakes();

        newSnake.name = "nope";
        return(newSnake);
    }
Пример #2
0
    CreatingSnakes GetCreatingSnakesFromPositionButTheWholeOne(Vector2 position)
    {
        foreach (CreatingSnakes snk in CreatingSnakesList)
        {
            foreach (Vector2 pos in snk.body)
            {
                if (pos[1] == position[1] - 1 || pos[1] == position[1] + 1)
                {
                    return(snk);
                }



                else if (pos[0] == position[0] - 1 || pos[0] == position[0] + 1)
                {
                    return(snk);
                }
            }
        }

        CreatingSnakes newSnake = new CreatingSnakes();

        newSnake.name = "nope";
        return(newSnake);
    }
Пример #3
0
    CreatingSnakes GetCreatingSnakesFromStrictPositionButOur(Vector2 position)
    {
        foreach (CreatingSnakes snk in CreatingSnakesList)
        {
            foreach (Vector2 bdy in snk.body)
            {
                if (bdy[0] == position[0] && bdy[1] == position[1] && IsThisSnakeOurs(snk.name))
                {
                    return(snk);
                }
            }
        }

        CreatingSnakes newSnake = new CreatingSnakes();

        newSnake.name = "nope";
        return(newSnake);
    }
Пример #4
0
    public void OnResetValues()
    {
        print("cancelling");
        if (CreatingSnakesList.Count != 0)
        {
            canValidate = false;

            if (snakeLock == null)
            {
                if (CreatingSnakesList.Count == 0)
                {
                    return;
                }
                print("this shit");

                CreatingSnakes CreatingSnakeToDelete = GetCreatingSnakesFromName(creatingSnakeName);
                print(creatingSnakeName);
                print(CreatingSnakeToDelete.name);

                CreatingSnakeToDelete.DestroyIO();
                CreatingSnakeToDelete.body.Clear();
                CreatingSnakesList.Clear();
            }
            else
            {
                CreatingSnakes CreatingSnakeToDelete = GetCreatingSnakesFromName(snakeLock);
                CreatingSnakeToDelete.DestroyIO();
                CreatingSnakeToDelete.body.Clear();
                CreatingSnakesList.Clear();
            }
        }
        creatingSnake = false;

        snakeLock = null;
        canPlay   = true;
        tailLimit = 0;
    }
Пример #5
0
    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");
    }
Пример #6
0
    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;
        }
    }