Beispiel #1
0
        /*********************** THE MAIN GAME FUNCTION ***********************/
        // All controls and snake movements are implemented in here.
        public bool Game_Playing()
        {
            lb_level.Text = "LEVEL-" + mygame.game_level.ToString();
            lb_point.Text = mygame.point.ToString() + "/" + mygame.level_point.ToString();

            if (mygame.point >= mygame.level_point)
            {
                //for loading the next level
                Clear_Level();
                return(true);
            }

            if (mygame.Did_Snake_Crash_Byself(mygame.snake_route))            // controll if snake crashed to byself or wall
            {
                MyGame_timer.Enabled = false;
                wait_timer.Enabled   = true;
                mygame.wait_time     = 20;
                return(true);
            }

            /*Snake route is setting in here  */
            if (mygame.snake_route == 1)
            {
                mygame.Move_Snake_Up();
            }
            else if (mygame.snake_route == 2)
            {
                mygame.Move_Snake_Right();
            }
            else if (mygame.snake_route == 3)
            {
                mygame.Move_Snake_Down();
            }
            else if (mygame.snake_route == 4)
            {
                mygame.Move_Snake_Left();
            }

            /*Adding new node to snake*/
            mygame.Add_Snake_Node(mygame.node_x, mygame.node_y);
            mygame.snake_area_x.Add_Node(mygame.node_x);
            mygame.snake_area_y.Add_Node(mygame.node_y);
            mygame.snake_route_temp = mygame.snake_route;



            if (!mygame.eated)
            {
                mygame.Delete_Snake_Node(mygame.snake_area_x.first.value, mygame.snake_area_y.first.value);
                mygame.snake_area_x.Delete_First_Node();
                mygame.snake_area_y.Delete_First_Node();
            }
            else
            {
                mygame.eated = false;
            }

            if (!mygame.bait_bool)
            {
                mygame.Find_Coordinate_For_Bait();
                if (!mygame.Control_Bait_Coordinate())
                {
                    mygame.Add_New_Bait(mygame.bait.X, mygame.bait.Y);
                }
            }

            /* control if snake eated the bait */
            if (mygame.Did_Snake_Eat_The_Bait())
            {
                mygame.Eated_Sound();
                mygame.Find_Coordinate_For_Bait();

                if (!mygame.Control_Bait_Coordinate())
                {
                    mygame.Add_New_Bait(mygame.bait.X, mygame.bait.Y);
                }

                else
                {
                    mygame.bait_bool = false;
                }

                mygame.eated  = true;
                mygame.point += 10;
                if (MyGame_timer.Interval > 40)
                {
                    MyGame_timer.Interval--;
                }
            }

            pictureBox1.Image = mygame.bmp;
            pictureBox1.Refresh();



            if ((mygame.node_x > (mygame.game_width / mygame.node_length - 1)) && mygame.snake_route == 2)
            {
                mygame.node_x = 0;
                mygame.Add_Snake_Node(mygame.node_x, mygame.node_y);
                mygame.snake_area_x.Add_Node(mygame.node_x);
                mygame.snake_area_y.Add_Node(mygame.node_y);
                if (!mygame.eated)
                {
                    mygame.Delete_Snake_Node(mygame.snake_area_x.first.value, mygame.snake_area_y.first.value);
                    mygame.snake_area_x.Delete_First_Node();
                    mygame.snake_area_y.Delete_First_Node();
                }
                else
                {
                    mygame.eated = false;
                }
            }
            else if (mygame.node_x < 0 && mygame.snake_route == 4)
            {
                mygame.node_x = (mygame.game_width / mygame.node_length - 1);
                mygame.Add_Snake_Node(mygame.node_x, mygame.node_y);
                mygame.snake_area_x.Add_Node(mygame.node_x);
                mygame.snake_area_y.Add_Node(mygame.node_y);
                if (!mygame.eated)
                {
                    mygame.Delete_Snake_Node(mygame.snake_area_x.first.value, mygame.snake_area_y.first.value);
                    mygame.snake_area_x.Delete_First_Node();
                    mygame.snake_area_y.Delete_First_Node();
                }
                else
                {
                    mygame.eated = false;
                }
            }
            if ((mygame.node_y > (mygame.game_height / mygame.node_length - 1)) && mygame.snake_route == 3)
            {
                mygame.node_y = 0;
                mygame.Add_Snake_Node(mygame.node_x, mygame.node_y);
                mygame.snake_area_x.Add_Node(mygame.node_x);
                mygame.snake_area_y.Add_Node(mygame.node_y);
                if (!mygame.eated)
                {
                    mygame.Delete_Snake_Node(mygame.snake_area_x.first.value, mygame.snake_area_y.first.value);
                    mygame.snake_area_x.Delete_First_Node();
                    mygame.snake_area_y.Delete_First_Node();
                }
                else
                {
                    mygame.eated = false;
                }
            }
            else if (mygame.node_y < 0 && mygame.snake_route == 1)
            {
                mygame.node_y = (mygame.game_height / mygame.node_length - 1);
                mygame.Add_Snake_Node(mygame.node_x, mygame.node_y);
                mygame.snake_area_x.Add_Node(mygame.node_x);
                mygame.snake_area_y.Add_Node(mygame.node_y);
                if (!mygame.eated)
                {
                    mygame.Delete_Snake_Node(mygame.snake_area_x.first.value, mygame.snake_area_y.first.value);
                    mygame.snake_area_x.Delete_First_Node();
                    mygame.snake_area_y.Delete_First_Node();
                }
                else
                {
                    mygame.eated = false;
                }
            }
            return(true);
        }