Exemplo n.º 1
0
        private void StartGame()
        {
            if (!online)
            {
                MessageBox.Show("Controls: \n-Player one: Arrows + Space  \n-Player two: WSAD + F   \n-Addition: Escape");
            }
            tank1Pic.Location = new Point(250, 400);
            tank2Pic.Location = new Point(250, 56);
            panel1.Location   = new Point(0, 0);
            panel1.Size       = new Size(500, 500);
            panel1.BackColor  = Color.FromArgb(111, 99, 91);
            this.Controls.Add(panel1);

            Initialise.GenerateMap(ref panel1, ref listWall, ref listSwamp, ref listBonus);
            Bitmap background = new Bitmap(panel1.Width, panel1.Height);

            panel1.DrawToBitmap(background, panel1.DisplayRectangle);
            panel1.BackgroundImage = background;

            Initialise.CreateTanks(ref tank1, ref tank2, ref tank1Pic, ref tank2Pic);
            Controls.Add(GameWindow.lifeT1);
            Controls.Add(GameWindow.lifeT2);
            allEvents.gameEvent.Attach(tank1);
            allEvents.gameEvent.Attach(tank2);
            gameTimer.Enabled = true;
        }
Exemplo n.º 2
0
 private void loadButton_Click(object sender, EventArgs e)
 {
     Initialise.SetVisibilityEnable(ref startButton, false);
     Initialise.SetVisibilityEnable(ref loadButton, false);
     Initialise.SetVisibilityEnable(ref socketButton, false);
     LoadGame(new Point(2, 2), new Point(452, 452));
 }
Exemplo n.º 3
0
        private void socketButton_Click(object sender, EventArgs e)
        {
            Initialise.SetVisibilityEnable(ref startButton, false);
            Initialise.SetVisibilityEnable(ref loadButton, false);
            Initialise.SetVisibilityEnable(ref socketButton, false);
            Initialise.SetVisibilityEnable(ref exit, false);
            buttonClient.Text = "Start Client";
            buttonHost.Text   = "Start Host";
            Initialise.SetVisibilityEnable(ref buttonHost, true);
            Initialise.SetVisibilityEnable(ref buttonClient, true);
            online = true;


            ipLabel.Text = "Yours DNS: " + SocketConnect.serverIp;
            //iphost.MapToIPv4().ToString() +
            ipLabel.Location = new Point(200, 100);
            ipLabel.Size     = new Size(200, 50);
            ipLabel.Enabled  = true;
            ipLabel.Visible  = true;
            this.Controls.Add(ipLabel);

            secondIP.Location = new Point(200, 150);
            ipLabel.Size      = new Size(200, 50);
            secondIP.Text     = "Insert DNS";
            secondIP.Enabled  = true;
            secondIP.Visible  = true;
            this.Controls.Add(secondIP);
        }
Exemplo n.º 4
0
        private void buttonClient_Click(object sender, EventArgs e)
        {
            SocketConnect.HostClientStart(8181, 8080, false);

            Initialise.SetVisibilityEnable(ref buttonHost, false);
            Initialise.SetVisibilityEnable(ref buttonClient, false);

            startButton.Text = "Start when both players ready";
            Initialise.SetVisibilityEnable(ref startButton, true);
        }
Exemplo n.º 5
0
 private void startButton_Click(object sender, EventArgs e)
 {
     Initialise.SetVisibilityEnable(ref startButton, false);
     Initialise.SetVisibilityEnable(ref loadButton, false);
     Initialise.SetVisibilityEnable(ref socketButton, false);
     Initialise.SetVisibilityEnable(ref exit, false);
     if (online == true)
     {
         timerHost.Enabled = true;
         timerSend.Enabled = true;
     }
     disconect = false;
     StartGame();
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Initialise.SetLocationAndSize(ref startButton, new Point(200, 200), new Size(150, 70));
            startButton.Text = "Start Local";
            Initialise.SetVisibilityEnable(ref startButton, true);

            Initialise.SetLocationAndSize(ref socketButton, new Point(200, 300), new Size(150, 70));
            socketButton.Text = "Start Online";
            Initialise.SetVisibilityEnable(ref socketButton, true);

            Initialise.SetLocationAndSize(ref loadButton, new Point(200, 400), new Size(150, 50));
            loadButton.Text = "Load";
            Initialise.SetVisibilityEnable(ref loadButton, false);

            Initialise.SetLocationAndSize(ref exit, new Point(200, 450), new Size(150, 50));
            exit.Text = "Exit";
            Initialise.SetVisibilityEnable(ref exit, true);
        }
Exemplo n.º 8
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);
            }
        }