コード例 #1
0
ファイル: Ship.cs プロジェクト: schiffchen/windows-phone
        /// <summary>
        /// Creates a new instance of a ship
        /// </summary>
        /// <param name="owner">The Jabber-ID of the owner</param>
        /// <param name="type">The type</param>
        /// <param name="or">The orientation</param>
        /// <param name="targetField">The target field, where the ship is placed</param>
        public Ship(JID owner, ShipType type, System.Windows.Controls.Orientation or, Field targetField)
        {
            this.Owner = owner;
            this.ShipType = type;
            this.IsPlaced = false;
            this.HitPoints = new Dictionary<int, bool>();
            this.Orientation = or;
            this.Position = targetField.Position;
            this.IsDestroyed = false;
            this.OverlayColor = Color.White;
            targetField.ReferencedShip = this;
            StartField = targetField;
            LoadTexture();

            for (int i = 0; i < this.Size; i++)
            {
                this.HitPoints.Add(i, false);
            }
        }
コード例 #2
0
ファイル: Match.cs プロジェクト: schiffchen/windows-phone
 /// <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;
     }
 }
コード例 #3
0
        /// <summary>
        /// Calculates the proportions and positions of all fields by taking the current scale rate of this playground
        /// </summary>
        private void CalculateFields()
        {
            bool firstStarted = false;
            if (fields == null)
            {
                firstStarted = true;
                fields = new Field[PLAYGROUND_SIZE, PLAYGROUND_SIZE];
            }

            for (int r = 0; r < PLAYGROUND_SIZE; r++)
            {
                for (int c = 0; c < PLAYGROUND_SIZE; c++)
                {
                    Vector2 pos = new Vector2((float)(GridLeft + (c * FieldWidth)), (float)(GridTop + (r * FieldHeight)));
                    if (fields[r, c] == null)
                    {
                        fields[r, c] = new Field(pos, new System.Windows.Size(FieldWidth, FieldHeight), c, r);
                    }
                    else
                    {
                        fields[r, c].SetProperties(pos, new System.Windows.Size(FieldWidth, FieldHeight));
                        if (fields[r, c].ReferencedShip != null)
                        {
                            fields[r, c].ReferencedShip.UpdatePosition();
                        }
                    }

                    // This global variables will only be set at the first time the calculating is done
                    if (firstStarted)
                    {
                        if (r == 0 && c == PLAYGROUND_SIZE - 1)
                        {
                            DeviceCache.RightOfMinimap = new Vector2((float)(pos.X + FieldWidth + 20), pos.Y);
                        }
                        else if (r == PLAYGROUND_SIZE - 1 && c == 0)
                        {
                            if (this.PlaygroundMode == Logic.Enum.PlaygroundMode.Normal)
                            {
                                DeviceCache.BelowGrid = Convert.ToInt32(pos.Y + FieldHeight + 20);
                            }
                            else
                            {
                                DeviceCache.BelowSmallGrid = Convert.ToInt32(pos.Y + FieldHeight + 20);
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: Ship.cs プロジェクト: schiffchen/windows-phone
 /// <summary>
 /// Starts the movement of this ship by removing all referenced fields
 /// </summary>
 public void StartMovement()
 {
     this.StartField = null;
     if (this.Fields != null)
     {
         foreach (Field f in this.Fields)
         {
             f.ReferencedShip = null;
         }
         this.Fields = null;
     }
 }
コード例 #5
0
ファイル: Ship.cs プロジェクト: schiffchen/windows-phone
 /// <summary>
 /// Hits the ship on a specific field.
 /// If the field is found in the Fields-List, the specific HitPoint will be changed.
 /// </summary>
 /// <param name="f"></param>
 public void HitOnField(Field f)
 {
     for (int i = 0; i < this.Fields.Count; i++)
     {
         if (this.Fields[i].Equals(f))
         {
             this.HitPoints[i] = true;
         }
     }
     CheckState();
 }
コード例 #6
0
ファイル: Ship.cs プロジェクト: schiffchen/windows-phone
 /// <summary>
 /// Glues the ship to its referenced fields
 /// </summary>
 public void GlueToFields()
 {
     if (this.Fields != null)
     {
         foreach (Field f in Fields)
         {
             f.ReferencedShip = null;
         }
     }
     List<Field> fields = CollissionManager.GetFields(AppCache.CurrentMatch.OwnPlayground, this);
     if (fields != null)
     {
         this.StartField = fields[0];
         this.Position = fields[0].Position;
         this.Fields = fields;
         foreach (Field f in fields)
         {
             f.ReferencedShip = this;
         }
     }
 }