Exemple #1
0
        /// <summary>
        /// Is called on receiving a result message of an own shot
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The shoot event arguments</param>
        void XmppManager_IncomingShotResult(object sender, ShootEventArgs e)
        {
            // Check, if the sended shot and the received shot message are talking from the same field
            if (SendedShot != null)
            {
                if (e.X == SendedShot.X && e.Y == SendedShot.Y)
                {
                    if (e.Result.ToLower().Equals("water"))
                    {
                        SoundManager.SoundWater.Play();
                        AppCache.CurrentMatch.ShootingPlayground.fields[e.Y, e.X].FieldState = FieldState.Water;
                    }
                    else
                    {
                        SoundManager.SoundExplosion.Play();
                        AppCache.CurrentMatch.ShootingPlayground.fields[e.Y, e.X].FieldState = FieldState.Hit;
                        // Here we still need logic, if a ship of the partner is destroyed!
                        if (e.ShipInfo != null)
                        {
                            Boolean stop = false;
                            for (int i = 0; (i < PartnerShips.Length && !stop); i++)
                            {
                                if (PartnerShips[i] == null)
                                {
                                    ShipType type = ShipType.AIRCRAFT_CARRIER;
                                    switch (e.ShipInfo.Size)
                                    {
                                        case 2:
                                            type = ShipType.DESTROYER;
                                            break;
                                        case 3:
                                            type = ShipType.SUBMARINE;
                                            break;
                                        case 4:
                                            type = ShipType.BATTLESHIP;
                                            break;
                                        case 5:
                                            type = ShipType.AIRCRAFT_CARRIER;
                                            break;
                                    }

                                    Ship s = new GameElemens.Ship(PartnerJID, type, e.ShipInfo.Orientation, ShootingPlayground.fields[e.ShipInfo.Y, e.ShipInfo.X]);
                                    s.IsDestroyed = true;
                                    PartnerShips[i] = s;
                                    stop = true;
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Warning: Coordinates of sended shot and received shot result are different!");
                }
                AppCache.CurrentMatch.ShootingPlayground.fields[e.Y, e.X].ResetColor();
                this.SendedShot = null;
                FooterMenu.RemoveButton("btnAttack");
                this.IsMyTurn = false;
                this.switchToShipviewerMode(false);

                // Lookup, if someone has won or lost
                JID looser = getLooser();
                if (looser != null && !GamestateSended)
                {
                    Partner.SendGamestate(looser.BareJID);
                    this.GamestateSended = true;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Is called on receiving a message with a shot from the partner
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The shoot event arguments</param>
        void XmppManager_IncomingShot(object sender, ShootEventArgs e)
        {
            // Only do something, if it is not my turn at the moment!
            if (!this.IsMyTurn)
            {

                if (AppCache.CurrentMatch.OwnPlayground.fields[e.Y, e.X].ReferencedShip == null)
                {
                    // Water
                    AppCache.CurrentMatch.OwnPlayground.fields[e.Y, e.X].FieldState = FieldState.Water;
                    SoundManager.SoundWater.Play();
                    Partner.TransferShotResult(e.X, e.Y, false, null);
                }
                else
                {
                    // Hitted a ship
                    AppCache.CurrentMatch.OwnPlayground.fields[e.Y, e.X].FieldState = FieldState.Hit;

                    /// Hier kracht es noch! Es ist kein Schiff referenziert!!
                    Ship sh = AppCache.CurrentMatch.OwnPlayground.fields[e.Y, e.X].ReferencedShip;
                    sh.HitOnField(AppCache.CurrentMatch.OwnPlayground.fields[e.Y, e.X]);
                    SoundManager.SoundExplosion.Play();
                    ShipInfo shipInfo = null;
                    if (sh.IsDestroyed)
                    {
                        shipInfo = new ShipInfo();
                        shipInfo.X = sh.StartField.X;
                        shipInfo.Y = sh.StartField.Y;
                        shipInfo.Size = sh.Size;
                        shipInfo.Orientation = sh.Orientation;
                        shipInfo.Destroyed = sh.IsDestroyed;
                    }

                    Partner.TransferShotResult(e.X, e.Y, true, shipInfo);
                    //AppCache.CurrentMatch.ShootingPlayground.fields[e.Y - 1, e.X - 1].ReferencedShip.H
                }
                this.IsMyTurn = true;
                this.switchToTargetMode(false);

                // Lookup, if someone has won or lost
                JID looser = getLooser();
                if (looser != null && !GamestateSended)
                {
                    Partner.SendGamestate(looser.BareJID);
                    this.GamestateSended = true;
                }
            }
        }
        protected virtual void OnIncomingShotResult(ShootEventArgs e)
        {
            EventHandler<ShootEventArgs> handler = IncomingShotResult;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                // Use the () operator to raise the event.
                handler(this, e);
            }
        }
Exemple #4
0
 /// <summary>
 /// Is called, when a field on the ShootingPlayground is selected as target
 /// </summary>
 /// <param name="sender">The Playground</param>
 /// <param name="e">The shoot event arguments</param>
 void ShootingPlayground_TargetSelected(object sender, ShootEventArgs e)
 {
     if (SendedShot == null)
     {
         Playground pgSender = (Playground)sender;
         pgSender.ResetFieldColors();
         Field selectedField = pgSender.fields[e.Y, e.X];
         selectedField.SetColor(FieldColor.Red);
         IconButton attack = new IconButton(TextureManager.IconAttack, "Attack", "btnAttack");
         attack.Click += new EventHandler<EventArgs>(attack_Click);
         FooterMenu.RemoveButton("btnAttack");
         FooterMenu.AddButton(attack);
         this.selectedField = selectedField;
     }
 }
        /// <summary>
        /// Is fired when a single field is selected when beeing the normal sized targeting map.
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnTargetSelected(ShootEventArgs e)
        {
            EventHandler<ShootEventArgs> handler = TargetSelected;

            // Event will be null if there are no subscribers
            if (handler != null)
            {
                // Use the () operator to raise the event.
                handler(this, e);
            }
        }