private void CelebrateWinner(IScaleable winner) { Point winnerPoint = new Point(winner.PosX, winner.PosY); Point labelWinnerPoint = new Point(winner.PosX, winner.PosY - 25); Controls.Add(new Label { Location = labelWinnerPoint, AutoSize = true, BackColor = Color.Black, ForeColor = Color.Green, Text = winner.Name + "\nWINNER" }); string name = @"..\..\" + winner.Name + ".gif"; string sound = @"..\..\" + winner.Name + ".wav"; PictureBox pb = new PictureBox() { Location = winnerPoint, Size = new Size(200, 100), ImageLocation = name, BackColor = Color.Transparent, SizeMode = PictureBoxSizeMode.StretchImage, }; Controls.Add(pb); pb.BringToFront(); _anthemSound = new SoundPlayer(sound); _anthemSound.Play(); }
/// <summary> /// Method for create a path between two objects that have X and Y coordinates /// </summary> /// <param name="begin"></param> /// <param name="end"></param> private void CreateMissilePath(IScaleable begin, IScaleable end) { double distance = Math.Sqrt((Math.Pow(begin.PosX - end.PosX, 2) + Math.Pow(begin.PosY - end.PosY, 2))); int offset = (int)(Scaling.GetInstance().FactorX * 12); //Offset is depending on scaling! _hittedTarget = GetHittedRandomTarget(end.PosX, end.PosY, offset); offset *= (int)(distance * 0.01); //Offset is now depending on distance and scaling! int last = _path.Length - 1; int start = last / 2; //Start with index of midpoint between start and goal int current = start; _path[0] = new Point(begin.PosX, begin.PosY); //Set the starting point (index 0) in array _path[last] = _hittedTarget; //Set the target point (last index) in array while (start != 0) //Loop sets the rest of the points in array { //Make the current point to a midpoint between the closest defined points _path[current] = GetRandMidpoint(_path[current - start], _path[current + start], offset); current = current + 2 * start; //Increase current index two times the start value if (current >= last) //If the end of array is reached { start = start / 2; //Set a new starting index current = start; offset = offset / 4; } } }
public static void Main() { TextObject text = new TextObject("Hello"); IScaleable scaleable = (IScaleable)text; scaleable.ScaleX(0.5f); scaleable.ScaleY(0.5f); }
private void CreateMapLabel(IScaleable obj) //for test { Controls.Add( new Label { Name = "MapObj" + obj.Name, AutoSize = true, Location = new Point(obj.PosX, obj.PosY), ForeColor = Color.Ivory, BackColor = Color.Transparent, Text = obj.Name, }); }
private void UpdateMapLabel(IScaleable obj) { Control [] MapLabels = Controls.Find("MapObj" + obj.Name, true); for (int i = 0; i < MapLabels.Length; i++) { MapLabels[i].Location = new Point(obj.PosX, obj.PosY); if (mapLabelsCheckBox.Checked == true) { MapLabels[i].Visible = true; } else { MapLabels[i].Visible = false; } } }
private void DisplayDefeated(IScaleable defender) { Point defenderPoint = new Point(defender.PosX, defender.PosY); Controls.Add(new Label { Location = defenderPoint, AutoSize = true, BackColor = Color.Black, ForeColor = Color.Red, Text = defender.Name + "\nDEFEATED" }); warActivityLabel.Text += "\n" + defender + " defeated!"; Point nextToDefenderPoint = new Point(defenderPoint.X - 30, defenderPoint.Y - 30); PictureBox gifPB = new PictureBox() { Location = nextToDefenderPoint, Size = new Size(40, 40), ImageLocation = @"..\..\bomb.gif", BackColor = Color.Transparent, SizeMode = PictureBoxSizeMode.StretchImage }; Controls.Add(gifPB); gifPB.SendToBack(); }
/// <summary> /// Adds the object so that scaling factors can be applied. /// </summary> /// <param name="obj">Objects that implements the IScaleable interface.</param> public void Add(IScaleable obj) { _scaleableObjects.Add(obj); }