Beispiel #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;
        }
Beispiel #2
0
        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;
        }
Beispiel #3
0
        /*
         * 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;
        }
Beispiel #4
0
 //////////////
 // Set _Insect
 public void Set_Insect(Insect insect)
 {
     _Insect = insect;
 }
Beispiel #5
0
        /*
         * 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;
        }
Beispiel #6
0
        //////////////////////////////
        // 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);
        }
Beispiel #7
0
        ////////////////////////
        // 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());
        }