예제 #1
0
        private FullSnake _Snake; // Temporary snake.

        #endregion Fields

        #region Constructors

        /*
         * Constructor of NetworkCOntainer
         *      - Initialize variables.
         * */
        public NetworkContainer()
        {
            _Msg = "000";
            _Snake = new FullSnake();
            _Fruit = new Fruit();
            _Insect = new Insect();
            _ListWalls = new ListWalls();
            _Nickname = "";
            _Score = 0;

            _HasBeenModified = false;
        }
예제 #2
0
파일: Wall.cs 프로젝트: Genjo15/Snake
        private int _Y; // Position in Y.

        #endregion Fields

        #region Constructors

        /*
         * Constructor of Wall
         *      - Initialize variables
         * */
        public Wall(int width, int height, FullSnake snake, Fruit fruit, Insect insect, List<Wall> listWall)
        {
            int tmpX, tmpY;

            _Side = width / 54 - 2;
            _RandomNumber = new Random();
            tmpX = Generate_X(width);
            tmpY = Generate_Y(height);

            while(!CheckPositions(tmpX,tmpY,snake,fruit,insect,listWall))
            {
                tmpX = Generate_X(width);
                tmpY = Generate_Y(height);
            }

            _X = tmpX;
            _Y = tmpY;
        }
예제 #3
0
파일: Wall.cs 프로젝트: Genjo15/Snake
        /*
         * Check if temporary X & Y are on the snake, the fruit, the insect, or a wall
         * */
        private Boolean CheckPositions(int x, int y, FullSnake fullSnake, Fruit fruit, Insect insect, List<Wall> listWalls)
        {
            Boolean ok = true;

            for (int i = 0; i < fullSnake.Get_SnakeSize(); i++)
            {
                if ((x == fullSnake.Get_Snake()[i].Get_X()) && (y == fullSnake.Get_Snake()[i].Get_Y()))
                {
                    ok = false;
                    //Console.WriteLine("Wall appeared on the snake");
                }
            }

            if (x == fruit.Get_X() && y == fruit.Get_Y())
            {
                ok = false;
                //Console.WriteLine("Wall appeared on the fruit");
            }

            if (((insect.Get_X() == x) && (insect.Get_Y() == y)) || ((insect.Get_X() == (x + (_Side / 2 + 1))) && (insect.Get_Y() == y)) || ((insect.Get_X() == x) && (insect.Get_Y() == (y + (_Side / 2) + 1))) || ((insect.Get_X() == (x + (_Side / 2 + 1))) && (insect.Get_Y() == (y + (_Side / 2) + 1))))
            {
                ok = false;
                //Console.WriteLine("Wall appeared on the insect");
            }

            if(listWalls != null)
                for (int z = 0; z < listWalls.Count(); z++)
                {
                    if ((x == listWalls[z].Get_X()) && (z == listWalls[z].Get_Y()))
                    {
                        ok = false;
                        //Console.WriteLine("Wall appeared on a wall");
                    }
                }

            return ok;
        }
예제 #4
0
 //////////////
 // Set _Insect
 public void Set_Insect(Insect insect)
 {
     _Insect = insect;
 }
예제 #5
0
파일: Game.cs 프로젝트: Genjo15/Snake
        /*
         * Method for initializing the Game:
         *      - Initialize object for playing.
         *      - Initialize timers (one for the game progress, one for the insect).
         *      - initialize the thread for graphical rendering.
         * */
        public void InitializeGame()
        {
            _FullSnake = new FullSnake(this.gameBoardPictureBox.Width);
            _Fruit = new Fruit(this.gameBoardPictureBox.Width, this.gameBoardPictureBox.Height);
            _Insect = new Insect(this.gameBoardPictureBox.Width, this.gameBoardPictureBox.Height, -666, -666);
            if (_Multiplayer)
                _ListWalls = new ListWalls();

            _Score = 0;
            _TimerInterval = 70;
            _Direction = 1;
            _GameOver = false;
            _InsectIsPresent = false;
            _InGame = true;

            _Timer = new Timer();
            _Timer.Interval = _TimerInterval;
            _Timer.Tick += new EventHandler(TimerTick);

            _InsectTimer = new Timer();
            _InsectTimer.Interval = 1000;
            _InsectTimer.Tick += new EventHandler(InsectTimerTick);

             _RenderThread = new System.Threading.Thread(new System.Threading.ThreadStart(Render));
             _RenderThread.Name = "RenderThread";
             _RenderThread.IsBackground = true;
        }
예제 #6
0
파일: Render.cs 프로젝트: Genjo15/Snake
        //////////////////////////////
        // Display of the mini insect
        public void RenderMiniInsect(Insect insect, PictureBox miniGameBoardPictureBox)
        {
            if (_MiniInsect.Parent != miniGameBoardPictureBox)
                miniGameBoardPictureBox.Controls.Add(_MiniInsect);

            _MiniInsect.Location = new System.Drawing.Point(insect.Get_X()/2, insect.Get_Y()/2);
        }
예제 #7
0
파일: Render.cs 프로젝트: Genjo15/Snake
        ////////////////////////
        // Display of the insect
        public void RenderInsect(Insect insect, PictureBox gameBoardPictureBox)
        {
            if (_Insect.Parent != gameBoardPictureBox)
                gameBoardPictureBox.Controls.Add(_Insect);

            _Insect.Location = new System.Drawing.Point(insect.Get_X(), insect.Get_Y());
        }