Example #1
0
        static public bool TankColission(byte where, Tank tank)
        {
            bool onSwamp = false;

            for (int i = 0; i < GameWindow.listSwamp.Count; i++)
            {
                if (tank.objectPicture.Bounds.IntersectsWith(GameWindow.listSwamp[i].Bounds))
                {
                    onSwamp = true;
                    if (GameWindow.listBonus.Count >= 1 && tank.objectPicture.Bounds.IntersectsWith(GameWindow.listBonus[0].Bounds))
                    {
                        tank.superLoaded = true;
                        GameWindow.panel1.Controls.Remove(GameWindow.listBonus[0]);
                        GameWindow.listBonus.RemoveAt(0);
                        if (!GameWindow.online)
                        {
                            Initialise.GenerateBonus();
                        }
                    }
                    break;
                }
            }
            if (onSwamp)
            {
                tank.OnSwamp();
            }
            else
            {
                tank.OffSwamp();
            }
            if (GameWindow.tank1.objectPicture.Bounds.IntersectsWith(GameWindow.tank2.objectPicture.Bounds))
            {
                tank.keyTank[where] = false;
                tank.ChangeDirection((byte)((where + 2) % 4));
                tank.TankMove((byte)((where + 2) % 4));
                tank.TankMove((byte)((where + 2) % 4));
                return(true);
            }
            else
            {
                if (WallColission(where, tank) == true)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #2
0
        public static void HostTimer()
        {
            client = server.AcceptTcpClient();
            byte[]        receivedBuff = new byte[7];
            NetworkStream stream       = client.GetStream();

            stream.Read(receivedBuff, 0, 7);


            for (int i = 0; i < 4; i++)
            {
                if (receivedBuff[i] == 1)
                {
                    if (GameWindow.onlinehost)
                    {
                        GameWindow.tank2.keyTank[i] = true;
                    }
                    if (!GameWindow.onlinehost)
                    {
                        GameWindow.tank1.keyTank[i] = true;
                    }
                }
                if (receivedBuff[i] == 0)
                {
                    if (GameWindow.onlinehost)
                    {
                        GameWindow.tank2.keyTank[i] = false;
                    }
                    if (!GameWindow.onlinehost)
                    {
                        GameWindow.tank1.keyTank[i] = false;
                    }
                }
            }
            if (receivedBuff[4] == 1)
            {
                if (!GameWindow.onlinehost && GameWindow.tank1.shoot == false && GameWindow.tank1.isDestroyed == false)
                {
                    PictureBox picbullet1 = new PictureBox();
                    GameWindow.bullet1 = new Bullet(ref GameWindow.tank1, GameWindow.tank1.pointDirection, ref picbullet1);
                    GameWindow.panel1.Controls.Add(picbullet1);
                    picbullet1.BringToFront();
                    GameWindow.tank1.shoot = true;
                    GameWindow.allEvents.gameEvent.Attach(GameWindow.bullet1);
                }
                if (GameWindow.onlinehost && GameWindow.tank2.shoot == false && GameWindow.tank2.isDestroyed == false)
                {
                    PictureBox picbullet2 = new PictureBox();
                    GameWindow.bullet2 = new Bullet(ref GameWindow.tank2, GameWindow.tank2.pointDirection, ref picbullet2);
                    GameWindow.panel1.Controls.Add(picbullet2);
                    picbullet2.BringToFront();
                    GameWindow.tank2.shoot = true;
                    GameWindow.allEvents.gameEvent.Attach(GameWindow.bullet2);
                }
            }
            if (receivedBuff[5] == 1)
            {
                GameWindow.Timers_off();
                MessageBox.Show("Your partner disconnected. Restarting game.", "Oooops!");
                Application.Restart();
            }

            if (!GameWindow.onlinehost)
            {
                GameWindow.bonusLocation = receivedBuff[6];
            }
            if (GameWindow.listBonus.Count < 1)
            {
                Initialise.GenerateBonus(GameWindow.bonusLocation);
            }
        }