Example #1
0
        private void StartTheGame(string Player1Name, string Player2Name)
        {
            //FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            //WindowState = FormWindowState.Maximized;
            //label1.Text = this.Width + " " + this.Height;
            Controls.Clear();
            this.WindowState = FormWindowState.Maximized;
            NewGame          = new NewGame(this.Width, this.Height, Player1Name, Player2Name);
            Bullets          = new List <Bullet>();

            MClicked = false;
            QClicked = false;
            MTime    = 0;
            QTime    = 0;

            nextGame     = false;
            nextGameTime = 0;

            SceneNumber = 0;

            gameOver         = false;
            totalGamesPlayed = 11;
            clock2Started    = false;
            Initialize_Timer();
        }
Example #2
0
        void ClockTick(object sender, EventArgs e)
        {
            //
            // Timer tick event handler
            //
            if (nextGame)
            {
                Bullets.Clear();
                nextGameTime += 15;
                if (nextGameTime > 3000)
                {
                    if (NewGame.Player1.Points + NewGame.Player2.Points >= totalGamesPlayed)
                    {
                        gameOver = true;
                        this.Controls.Clear();
                        Invalidate();
                        //Clock2.Start();
                    }
                    else
                    {
                        this.Controls.Clear();
                        NewGame.Player1.Tank.IsTankBurned = false;
                        NewGame.Player1.Tank.IsTankBurned = false;
                        NewGame.Player1.Tank.Image        = Resources.BrownTank;
                        NewGame.Player2.Tank.Image        = Resources.BrownTank;
                        SceneNumber++;
                        NewGame.GenerateScene(SceneNumber);
                        NewGame.Player1.RefreshTanks(Tank.Position.LeftToRight);
                        NewGame.Player2.RefreshTanks(Tank.Position.RightToLeft);
                        nextGame = false;
                    }
                    nextGameTime = 0;
                }
            }
            else
            {
                if (MClicked)
                {
                    MTime += 15;
                    if (MTime > 200)
                    {
                        MClicked = false;
                        MTime    = 0;
                    }
                }

                if (QClicked)
                {
                    QTime += 15;
                    if (QTime > 200)
                    {
                        QClicked = false;
                        QTime    = 0;
                    }
                }

                Movement(NewGame.ActualScene);
            }
        }
Example #3
0
        private void SceneForm_Paint(object sender, PaintEventArgs e)
        {
            Graphics g     = e.Graphics;
            Color    color = NewGame.ActualScene.BackgroundColor;

            g.Clear(color);
            Pen pen = new Pen(color, 1);

            if (gameOver)
            {
                Clock.Stop();
                //string message = NewGame.Player1.Name + "\t" + NewGame.Player2.Name + "\n" +
                //    "Score: " + NewGame.Player1.Points + "\tScore: " + NewGame.Player2.Points + "\n\n\n" +
                //    "Winner is: " + (NewGame.Player1.Points > NewGame.Player2.Points ? NewGame.Player1.Name : NewGame.Player2.Name);



                //MessageBox.Show(message);

                //this.Hide();
                //ResultsScene rs = new ResultsScene();

                //rs.ShowDialog();
                //this.Close();



                //BACKGROUND

                background.Size = new Size(backgroundWidth, backgroundHeight);

                background.Location = new Point(locationX, locationY);
                //background.Image = Resources.BrownTankWinner;
                background.SizeMode    = PictureBoxSizeMode.StretchImage;
                background.BorderStyle = BorderStyle.Fixed3D;


                int newExitGameWidth  = 130;
                int newExitGameHeight = 60;

                // NEW GAME
                int left = 180;
                int top  = 393;

                newGamebtn.Size     = new Size(newExitGameWidth, newExitGameHeight);
                newGamebtn.Location = new Point(left, top + 3);
                newGamebtn.Image    = Resources.newGameBtn;
                newGamebtn.SizeMode = PictureBoxSizeMode.StretchImage;
                background.Controls.Add(newGamebtn);
                newGamebtn.BackColor   = Color.Transparent;
                newGamebtn.Click      += new EventHandler(newGamebtn_Click);
                newGamebtn.MouseEnter += new EventHandler(newGamebtn_MouseEnter);
                newGamebtn.MouseLeave += new EventHandler(newGamebtn_MouseLeave);

                //EXIT GAME

                exitGamebtn.Size     = new Size(newExitGameWidth, newExitGameHeight - 3);
                exitGamebtn.Location = new Point(left + 200, top);
                exitGamebtn.Image    = Resources.ExitBtn;
                exitGamebtn.SizeMode = PictureBoxSizeMode.StretchImage;
                background.Controls.Add(exitGamebtn);
                exitGamebtn.BackColor   = Color.Transparent;
                exitGamebtn.Click      += new EventHandler(exitGamebtn_Click);
                exitGamebtn.MouseEnter += new EventHandler(exitGamebtn_MouseEnter);
                exitGamebtn.MouseLeave += new EventHandler(exitGamebtn_MouseLeave);



                int ScoreX = left + 60;
                int ScoreY = top - 60;
                // LABEL SCORE

                score1.Text      = "SCORE:";
                score1.BackColor = Color.Transparent;
                score1.Font      = new Font("Microsoft Sans Serif", 12);
                score1.ForeColor = Color.White;
                score1.Location  = new Point(ScoreX, ScoreY);
                score1.Size      = new Size(70, 20);
                background.Controls.Add(score1);



                score2.Text      = "SCORE:";
                score2.BackColor = Color.Transparent;
                score2.Font      = new Font("Microsoft Sans Serif", 12);
                score2.ForeColor = Color.White;
                score2.Location  = new Point(ScoreX + 110, ScoreY);
                score2.Size      = new Size(70, 20);
                background.Controls.Add(score2);



                scoreFirstPlayer.Text      = NewGame.Player1.Points.ToString();
                scoreFirstPlayer.BackColor = Color.Transparent;
                scoreFirstPlayer.Font      = new Font("Microsoft Sans Serif", 12);
                scoreFirstPlayer.ForeColor = Color.White;
                background.Controls.Add(scoreFirstPlayer);
                scoreFirstPlayer.Location = new Point(ScoreX + 70, ScoreY);


                scoreSecondPlayer.Text      = "Pts";
                scoreSecondPlayer.BackColor = Color.Transparent;
                scoreSecondPlayer.Font      = new Font("Microsoft Sans Serif", 12);
                scoreSecondPlayer.ForeColor = Color.White;
                background.Controls.Add(scoreSecondPlayer);
                scoreSecondPlayer.Location = new Point(ScoreX + 110 + 70, ScoreY);

                if (NewGame.Player1.Points > NewGame.Player2.Points)
                {
                    //this.BackgroundImage = Resources.GreenTankWinner;
                    background.Image       = Resources.GreenTankWinner;
                    scoreFirstPlayer.Text  = NewGame.Player2.Points.ToString();
                    scoreSecondPlayer.Text = NewGame.Player1.Points.ToString();
                }
                else
                {
                    //this.BackgroundImage = Resources.BrownTankWinner;
                    background.Image       = Resources.BrownTankWinner;
                    scoreSecondPlayer.Text = NewGame.Player2.Points.ToString();
                    scoreFirstPlayer.Text  = NewGame.Player1.Points.ToString();
                }

                Controls.Add(background);
                MainScene.updateScores(NewGame.Player1.Name, NewGame.Player2.Name, NewGame.Player1.Points, NewGame.Player2.Points);
            }
            else
            {
                //g.DrawEllipse(pen, new Rectangle(new Point(100, 100), new Size(200, 300)));
                NewGame.DrawScene(pen, g, this);

                foreach (Bullet bullet in Bullets)
                {
                    bullet.Draw(g);
                }

                for (int i = Bullets.Count - 1; i >= 0; --i)
                {
                    if (Bullets[i].BulletTime > 5000)
                    {
                        Bullets.RemoveAt(i);
                    }
                }
            }
            pen.Dispose();
        }