Exemple #1
0
 /// <summary>
 /// Creates a new match instance
 /// </summary>
 /// <param name="mid">The ID of the match</param>
 /// <param name="own">The own Jabber-ID</param>
 /// <param name="partner">The Jabber-ID of the game partner</param>
 public Match(String mid, JID own, JID partner)
 {
     this.MatchState = Enum.MatchState.ShipPlacement;
     this.PartnerDice = -1;
     this.OwnDice = -1;
     this.PartnersPreDice = -1;
     this.SendedShot = null;
     this.GamestateSended = false;
     this.MatchID = mid;
     this.OwnJID = own;
     this.PartnerJID = partner;
     this.Started = DateTime.Now;
     this.rnd = new Random(DateTime.Now.Millisecond);
     this.MatchWinner = null;
 }
Exemple #2
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 #3
0
 /// <summary>
 /// Is called, when an attack button is clicked
 /// </summary>
 /// <param name="sender">The clicked button</param>
 /// <param name="e">The event arguments</param>
 void attack_Click(object sender, EventArgs e)
 {
     // If this.SendetShot != null, the confirmation of a sended shot has not already be received.
     if (this.SendedShot == null)
     {
         IconButton btnAttack = (IconButton)sender;
         btnAttack.Icon = TextureManager.IconAttackSW;
         this.SendedShot = new GameElemens.Shot(selectedField.X, selectedField.Y);
         Partner.Shoot(selectedField.X, selectedField.Y);
     }
 }