Esempio n. 1
0
        /// <summary>
        /// Shoot method with starting conditions to compensate for network delay
        /// </summary>
        /// <param name="target">Where is bulet traveling to</param>
        /// <param name="shootOrgin">Where shot was fired</param>
        /// <param name="shootRotation">How was weapon rotated during shoot</param>
        public void Shoot(Vector2f target, Vector2f shootOrgin, float shootRotation, Player player, bool sendToServer)
        {
            if (Ammo != 0 && Reloading != true && ShootTimer.ElapsedTime.AsMilliseconds() > AttackSpeed)
            {
                ShootTimer.Restart();

                // maybe figure out how to make this Vector2f -> Vector2 -> Vector2f mess cleaner later
                const float projectileSpeed  = 10f;
                Vector2     normalizedTarget = new Vector2(target.X, target.Y);
                normalizedTarget = Vector2.Normalize(normalizedTarget);
                Vector2f   myTarget = new Vector2f(normalizedTarget.X, normalizedTarget.Y);
                Projectile bullet   = new Projectile(myTarget * projectileSpeed, ProjectileSprite, shootOrgin, shootRotation);
                Projectiles.Add(bullet);
                ChangeAmmo(-1);


                Sound sound = ResourceHolderFacade.GetInstance().Sounds.Get(SoundIdentifier.GenericGun);
                sound.Volume = ResourceHolderFacade.GetInstance().CurrentVolume.GetVolume();
                sound.Play();

                if (sendToServer)
                {
                    var shootEventData = new ShootEventData(player.ToDTO(), target, this.Position, this.Rotation);
                    //GameState.GetInstance().ConnectionManager.Connection.SendAsync("ShootEventServer", shootEventData);
                    GameState.GetInstance().ConnectionManagerProxy.Connection.SendAsync("ShootEventServer", shootEventData);
                }
            }
        }
Esempio n. 2
0
 private void Game_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!saved && !isFinished)
     {
         if (MessageBox.Show("Do you want to leave the game?", "Leave Game",
                             MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
         {
             e.Cancel = true;
             return;
         }
     }
     state          = new State();
     state.Computer = computer;
     state.Player   = player;
     state.Score    = score;
     state.Turn     = Turn;
     state.Mute     = MuteClicked;
     ComputerTimer.Stop();
     ShootTimer.Stop();
 }
Esempio n. 3
0
        private void ShootBtn_Click(object sender, EventArgs e) //Fireball
        {
            if (ShootTimer.Enabled == false)                    //Are you already Shooting?
            {
                if (ReloadTimer.Enabled == false)               //Are you already reloading?
                {
                    if (Cap > 0)                                //U got bullets?
                    {
                        ShootTimer.Start();                     //start timer for progress bar
                        coin += +(CoinUp * 5);                  //add coin + coin Upgrade
                        Cap--;                                  //decrease ammo amount
                        Shoot++;                                //add shot
                        Xp++;                                   //add Xp
                        #region FireSound
                        ////////////////////////////////////////////////////////////////////////
                        try
                        {
                            SoundPlayer sndplayr = new
                                                   SoundPlayer(ClickingGame.Properties.Resources.FBsound);
                            sndplayr.Play();
                        }                                                                       //Plays fireball sound
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message + ": " + ex.StackTrace.ToString(),
                                            "Error");
                        }
                        ///////////////////////////////////////////////////////////////////////
                        #endregion
                    }

                    label5.Text = Convert.ToString(Shoot); //Adds Exp per shot
                    lbl20.Text  = Convert.ToString(Shoot); //Adds Shots
                    label3.Text = Convert.ToString(Cap);   //Shows Capacity each time user clicks shoot
                    label7.Text = Convert.ToString(coin);  //Shows coins amount each time user clicks shoot
                }
            }
        }
Esempio n. 4
0
        private void ComputerTimer_Tick(object sender, EventArgs e)
        {
            label2.Text   = Turn ? "Your turn" : "Bot's turn";
            lblScore.Text = score.ToString();
            if (score < 0)
            {
                lblScore.ForeColor = Color.Red;
            }
            else if (score > 0)
            {
                lblScore.ForeColor = Color.Green;
            }
            if (!Turn)
            {
                dgvComputer.Enabled = false;
                ShootTimer.Start();
            }
            if (Turn)
            {
                dgvComputer.Enabled = true;
                ShootTimer.Stop();
            }

            if (computer.Won())
            {
                isFinished = true;

                ComputerTimer.Interval = 999999999;
                ShootTimer.Interval    = 999999999;
                ShootTimer.Stop();

                ShootTimer.Enabled    = false;
                ComputerTimer.Enabled = false;
                dgvComputer.Enabled   = false;
                ShootTimer.Enabled    = false;


                if (score > 0)
                {
                    View.InputScore form = new View.InputScore();
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        saveFile(form.winnerName, score);
                    }
                }

                ComputerTimer.Dispose();
            }
            if (player.Won())
            {
                isFinished             = true;
                ComputerTimer.Enabled  = false;
                dgvComputer.Enabled    = false;
                ComputerTimer.Interval = 999999999;
                ShootTimer.Interval    = 999999999;
                ShootTimer.Stop();
                dgvComputer.Enabled = false;
                ShootTimer.Dispose();
                ComputerTimer.Dispose();
                computer.ShowEndShips(dgvComputer);

                if (MessageBox.Show("YOU LOST! Do you want to play a new game?", "LOST", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    newGame();
                }
            }
        }