Exemplo n.º 1
0
 void Start()
 {
     mainSnake        = GameObject.FindGameObjectWithTag("SnakeMain").GetComponent <SnakeMove>();
     Speed            = mainSnake.speed - 0.5f;
     TailTargetObject = mainSnake.tallobject[mainSnake.tallobject.Count - 2];
     indx             = mainSnake.tallobject.IndexOf(gameObject);
 }
Exemplo n.º 2
0
    void OnJoinedRoom()
    {
        Debug.Log("OnJoinRoom");
        GameObject snkHead = PhotonNetwork.Instantiate("SnakeHead", imageTarget.transform.position, imageTarget.transform.rotation, 0);
        SnakeMove  me      = snkHead.GetComponent <SnakeMove>();

        playerName = nameInput.text;
        PhotonNetwork.playerName = playerName;
        me.NM = GameObject.Find("GameManager").GetComponent <NetworkManager>();
        //Score = new Hashtable();
        //if (PhotonNetwork.isMasterClient) {
        foreach (PhotonPlayer player in PhotonNetwork.playerList)
        {
            Score.Add(player.name, 0f);
        }
        //}

        snkHead.transform.SetParent(imageTarget.transform, false);
        SnakeMove move = snkHead.GetComponent <SnakeMove>();

        move.boundingBoxCenter = GameObject.Find("BoundingBoxCenter");
        move.ARPlane           = GameObject.Find("ARPlane");
        //startButton.gameObject.SetActive(false);
        //nameInput.gameObject.SetActive(false);
    }
Exemplo n.º 3
0
 void Awake()
 {
     if (instance != null)
     {
         Destroy(this.gameObject);
     }
     else
     {
         instance = this;
     }
 }
Exemplo n.º 4
0
    void Start()
    {
        snakeMoveScript = GameObject.FindGameObjectWithTag("SnakeHead").GetComponent <SnakeMove>();
        speed           = snakeMoveScript.speed + 3f;

        targetObject = snakeMoveScript.tailObjects[snakeMoveScript.tailObjects.Count - 2];

        index           = snakeMoveScript.tailObjects.IndexOf(gameObject);
        targetTransform = targetObject.transform;
        tailTransform   = gameObject.transform;
    }
Exemplo n.º 5
0
        private void Reset()
        {
            this.Hide();
            GameOver form = new GameOver();

            form.ShowDialog();
            this.Show();

            snake.Reset();
            food.Respawn(ClientSize);
            SnakeMove.Interval = 130;
            SnakeMove.Start();
        }
Exemplo n.º 6
0
    public void Dead(Collider2D player)
    {
        SnakeMove userControl = player.GetComponent <SnakeMove> ();

        //UserControl userControl= new GhostMove ();
        Instantiate(deadSnake, (Vector2)player.transform.position + new Vector2(UnityEngine.Random.Range(-0.5f, 0.5f), UnityEngine.Random.Range(-0.5f, 0.5f)), player.transform.rotation);
        List <GameObject> listBody = userControl.GetBody();

        for (int i = 0; i < listBody.Count; i++)
        {
            GameObject tmpDeadBody = Instantiate(deadSnake, (Vector2)listBody [i].transform.position + new Vector2(UnityEngine.Random.Range(-0.5f, 0.5f), UnityEngine.Random.Range(-0.5f, 0.5f)), listBody [i].transform.rotation);
            NetworkServer.Spawn(tmpDeadBody);
        }
        Destroy(player.gameObject);
    }
Exemplo n.º 7
0
 public EventBerry(SnakeField location, Coordinates coord, SnakeMove mover, int live)
 {
     Location = location;
     Position = coord;
     Mover    = mover;
     if (live > 0)
     {
         Live = live;
     }
     Mover.Add(Next);
     location.AddEventBerry(coord);
     if (!Beries.ContainsKey(location))
     {
         Beries.Add(location, new Dictionary <Coordinates, EventBerry>());
     }
     Beries[location].Add(coord, this);
 }
Exemplo n.º 8
0
 void OnTriggerEnter(Collider collision)
 {
     if (collision.gameObject.tag == "SnakeHead")
     {
         GameObject temp = Instantiate(blood, this.transform.position, Quaternion.identity);
         SnakeMove  sm   = collision.gameObject.transform.parent.gameObject.GetComponent <SnakeMove>();
         if (sm != null)
         {
             sm.PlayerEatten();
         }
         else
         {
             Debug.Log("0");
         }
         Destroy(temp, 2.0f);
         Debug.Log("Change to Death Sceen");
         Destroy(this.gameObject.gameObject);
     }
 }
Exemplo n.º 9
0
    private void Awake()
    {
        renderer     = GetComponent <Renderer>();
        snakeMove    = GetComponent <SnakeMove>();
        snakeSensors = GetComponent <SnakeMouth>();

        Restarter.Instance.Register(this);

        objectColor = colorScheme.GetObjectColorsById(new ColorId[1] {
            startColorId
        })[0];

        segments.First().SetSegmentAhead(transform);

        for (int i = 1; i < segments.Count; i++)
        {
            segments[i].SetSegmentAhead(segments[i - 1].transform);
        }

        startSegments = segments.ToArray();
    }
Exemplo n.º 10
0
        static void Main()
        {
            Queue <Position> snakeElements = new Queue <Position>();

            SnakeInitializer.Start(snakeElements);
            int direction = 0;

            ConsoleStart.SetHeightAndWidth();

            Random randomNumberGenerator = new Random();


            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo userinput = Console.ReadKey();
                    direction = UserControls.Move(userinput);
                }
                SnakeMove.Move(snakeElements, direction, randomNumberGenerator);
            }
        }
Exemplo n.º 11
0
        private void SnakeMove_Tick(object sender, EventArgs e)
        {
            //erase
            gfx.DrawImage(Properties.Resources.background_desert_design_elements_vector_585961, new Rectangle(0, 0, ClientSize.Width, ClientSize.Height));
            //update
            food.Update();
            snake.Update();

            if (snake.Head().hitbox.IntersectsWith(food.hitbox))
            {
                food.Respawn(ClientSize);
                snake.Grow();
                foodcount++;
                if (snake.Length % 5 == 0 && SnakeMove.Interval > 50)
                {
                    SnakeMove.Interval -= 10;
                    speed++;
                }
            }
            label2.Text = $"Food Eaten: {foodcount}";
            label3.Text = $"Speed:{speed}";
            if (snake.Head().Offscreen(ClientSize.Width, ClientSize.Height) == true || snake.c9llide() == true)
            {
                SnakeMove.Stop();
                MessageBox.Show("You Lose! Foool!");
                Reset();
            }
            //draw
            gfx.DrawString("SnakeX", label1.Font, Brushes.Red, label1.Location);
            snake.Draw(gfx);
            food.Draw(gfx);


            //SnakeMove.Interval = 100;

            backgroundImage.Image = bitmap;
        }
Exemplo n.º 12
0
    //Use this for initialization

    void Awake()
    {
        _instance = this;

        moveDic = new Vector3(0, 0, moveSpeed);
    }
Exemplo n.º 13
0
        static void SnakeStart(IDrawningRectangle <SignConsole> location, SnakeSettings settings, Action startWithClose)
        {
            settings.Event       = true;
            settings.EventChance = 0.50;
            Action stop           = default;
            var    GameDictionary = new Dictionary <GamesSquareValues, SignConsole>
            {
                { GamesSquareValues.snake, new SignConsole(' ', ConsoleColor.White) },
                { GamesSquareValues.snakeBerry, new SignConsole(' ', ConsoleColor.Red) },
                { GamesSquareValues.snakeWall, new SignConsole('X', ConsoleColor.Black) },
                { GamesSquareValues.nothing, new SignConsole(' ', ConsoleColor.Black) },
                { GamesSquareValues.snakeEventBerry, new SignConsole(' ', ConsoleColor.Green) }
            };
            var gameField = new ConsoleGameField(location.Width, location.Height, location, GameDictionary);

            location.Register((0, 0), gameField, gameField.GetCoordinates());

            var snakeMove = new SnakeMove((int)settings.StartSpeed);

            var snakeField = new SnakeField(gameField.Width, gameField.Height - 5, gameField);

            gameField.Register((0, 5), snakeField, snakeField.GetCoordinates());
            snakeField.Inicializated();
            var           bigChar = new Letters("First");
            BigPixelPrint scoreField, scoreField2 = null;
            Score         score, score2 = null;

            KeyPress.SetControl("Snake");
            Snake snake, snake2 = null;

            if (!settings.Multy)
            {
                snake      = new Snake(snakeField);
                scoreField = new BigPixelPrint(18, 5, location, bigChar);
                location.Register((location.Width / 2 - 9, 0), scoreField, scoreField.GetCoordinates());
                score = new Score(scoreField);
            }
            else
            {
                snake      = new Snake(snakeField, (snakeField.Width / 3, snakeField.Height / 2), Direction.direction.up);
                scoreField = new BigPixelPrint(18, 5, location, bigChar);
                location.Register((location.Width / 2 - 20, 0), scoreField, scoreField.GetCoordinates());
                score = new Score(scoreField);

                snake2      = new Snake(snakeField, (snakeField.Width / 3 * 2, snakeField.Height / 2), Direction.direction.down);
                scoreField2 = new BigPixelPrint(18, 5, location, bigChar);
                location.Register((location.Width / 2 + 2, 0), scoreField2, scoreField2.GetCoordinates());
                score2 = new Score(scoreField2);
                Berry.RandomBerry(snakeField);
            }
            Berry.RandomBerry(snakeField);

            snake.IsEat += (Snake) => Berry.RandomBerry(Snake.Location);
            snake.IsEat += (Snake) => snakeMove.Acceleration(((double)settings.Acceleration) / 100.0);
            snake.IsEat += (Snake) => score.Add();
            if (settings.Event)
            {
                snake.IsVeryEat += (Snake) => snakeMove.Acceleration(((double)settings.Acceleration) / 100.0);
                snake.IsVeryEat += (Snake) => score.Add(5);
                snake.IsEat     += (Snake) => EventBerry.RandomEventBerry(settings.EventMulty, snakeField, settings.EventChance, snakeMove, 50);
            }
            snake.Die += (Snake) => stop?.Invoke();
            snakeMove.Add(snake.Move);
            stop += () => snakeMove.Stop();
            stop += () => KeyPress.ResetControl();


            Keys[needOption.snakeUp].Set((obj, ar) => snake.Up());
            Keys[needOption.snakeDown].Set((obj, ar) => snake.Down());
            Keys[needOption.snakeLeft].Set((obj, ar) => snake.Left());
            Keys[needOption.snakeRigh].Set((obj, ar) => snake.Right());
            if (settings.Multy)
            {
                snake2.IsEat += (Snake) => Berry.RandomBerry(Snake.Location);
                snake2.IsEat += (Snake) => snakeMove.Acceleration((double)settings.Acceleration / 100);
                snake2.IsEat += (Snake) => score2.Add();
                if (settings.Event)
                {
                    snake2.IsVeryEat += (Snake) => snakeMove.Acceleration(((double)settings.Acceleration) / 100.0);
                    snake2.IsVeryEat += (Snake) => score2.Add(5);
                }
                snake2.Die += (Snake) => stop?.Invoke();
                snakeMove.Add(snake2.Move);

                Keys[needOption.secondSnakeUp].Set((obj, ar) => snake2.Up());
                Keys[needOption.secondSnakeDown].Set((obj, ar) => snake2.Down());
                Keys[needOption.secondSnakeLeft].Set((obj, ar) => snake2.Left());
                Keys[needOption.secondSnakeRigh].Set((obj, ar) => snake2.Right());
            }

            Keys[needOption.snakePause].Set((obj, ar) =>
            {
                snakeMove.Pause();
                void cont()
                {
                    gameField.Load();
                    score.Add(0);
                    snakeMove.Continue();
                    KeyPress.SetControl("Snake");
                }
                Pause(location, cont, exit);
            });

            snakeMove.Start();
            Keys[needOption.snakeUp].Set(null);
            Keys[needOption.snakeDown].Set(null);
            Keys[needOption.snakeLeft].Set(null);
            Keys[needOption.snakeRigh].Set(null);
            if (settings.Multy)
            {
                Keys[needOption.secondSnakeUp].Set(null);
                Keys[needOption.secondSnakeDown].Set(null);
                Keys[needOption.secondSnakeLeft].Set(null);
                Keys[needOption.secondSnakeRigh].Set(null);
            }
            Console.ReadKey(true);
            void exit()
            {
                snakeMove.Stop();
                gameField.Close();
                scoreField.Close();
                scoreField2?.Close();
                location.CancelRegistration(gameField);
                startWithClose();
                EventBerry.Clear(snakeField);
            }

            exit();
        }
Exemplo n.º 14
0
 public static void RandomEventBerry(bool multi, SnakeField location, double chanse, SnakeMove Mover, int time)
 {
     if (multi || (Beries.ContainsKey(location) ? Beries[location].Count == 0 : true))
     {
         chanse = Math.Min(1, Math.Max(0, chanse));
         var rnd    = new Random();
         var number = rnd.NextDouble();
         if (number < chanse)
         {
             Coordinates newCoord;
             while (true)
             {
                 newCoord = new Coordinates(rnd.Next(location.Width), rnd.Next(location.Height));
                 if (location.ReturnCell(newCoord) == GamesSquareValues.nothing)
                 {
                     new EventBerry(location, newCoord, Mover, time);
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 15
0
    // ---------------------------------------------------------------------------------------------------
    // DestroyInstance()
    // ---------------------------------------------------------------------------------------------------
    // Destroys the ScreenField instance
    // ---------------------------------------------------------------------------------------------------

    public void DestroyInstance()
    {
        print("Snake Instance destroyed");

        instance = null;
    }
Exemplo n.º 16
0
 private void Start()
 {
     snake = GameObject.Find("Snake").GetComponent <SnakeMove>();
 }