protected void DrawSomething(Graphics gfx, Coordinates lastTurnShotCoorinates, string what, Color transparent) { var image = ShipPainter.GetBitmapResource(what); image.MakeTransparent(transparent); gfx.DrawImage(image, new Point(lastTurnShotCoorinates.X * 51, lastTurnShotCoorinates.Y * 51)); }
public Bitmap DrawFleetScreen(Fleet fleet, ShipPainter shipPainter, int width, int height) { var bitmap = new Bitmap(width, height); using (Graphics gfx = Graphics.FromImage(bitmap)) { gfx.FillRectangle(Brushes.Aqua, new RectangleF(0, 0, width, height)); foreach (var ship in fleet.Ships.Where(s => s.IsAfloat)) { shipPainter.DrawShip(gfx, ship); } if (this.CurrentGame.CurrentPlayersShots != null) { var shotsAtThisPlayer = this.CurrentGame.CurrentPlayersShots.ContainsKey(fleet.Player) ? this.CurrentGame.CurrentPlayersShots[fleet.Player] : new List <HitNotification>(); foreach (var lastTurnShot in shotsAtThisPlayer) { if (lastTurnShot.WasAHit) { DrawSomething(gfx, lastTurnShot.Coordinates, "Explosion", Color.Black); } else { DrawSomething(gfx, lastTurnShot.Coordinates, "Splash", Color.FromArgb(13, 27, 39)); } } } for (int i = 1; i < 10; i++) { gfx.DrawLine(Pens.Black, new Point(0, (i * 51)), new Point(this.pictureBox1.Width, (i * 51))); // horizontal gfx.DrawLine(Pens.Black, new Point((i * 51), 0), new Point((i * 51), this.pictureBox1.Height)); // vertical } //StringFormat format = new StringFormat(); //format.LineAlignment = StringAlignment.Center; //format.Alignment = StringAlignment.Center; //gfx.DrawString(GetTitleText(), // new Font(FontFamily.GenericMonospace, 22), // Brushes.Black, // new RectangleF(0, 0, width, height), // format); } return(bitmap); }
private void DrawMenu(Graphics gfx, Bitmap bitmap, bool alignTop, bool drawBackground, int indexOffset, int[] selectedIndicies, params string[] menuItems) { if (Timer.Interval != 25) { this.Timer.Interval = 25; } if (BackgroundImage == null) { BackgroundImage = ShipPainter.GetBitmapResource("Menu"); } var distanceFromTheTop = 275; var distanceFromTheBottom = 50; var spacing = 55; if (drawBackground == true) { gfx.DrawImage(BackgroundImage, new Rectangle(0, 0, this.pictureBox1.Width, this.pictureBox1.Height)); } for (int i = 0; i < menuItems.Count(); i++) { int yPosition = alignTop ? distanceFromTheTop + (i * spacing) : this.pictureBox1.Height - distanceFromTheBottom - (spacing * menuItems.Count()) + (i * spacing); var selected = selectedIndicies.Contains(i + indexOffset); var highlighted = SelectedMenuIndex == i + indexOffset && (ScrollingXPos / 10) % 2 == 0; var brush = highlighted ? Brushes.White : selected ? Brushes.Green : Brushes.Black; gfx.DrawString(menuItems.ElementAt(i), new Font(FontFamily.GenericMonospace, 36, FontStyle.Bold), brush, new PointF(10, yPosition)); } }
public void DrawGameScreen() { var bitmap = new Bitmap(this.pictureBox1.Width, pictureBox1.Height); var shipPainter = new ShipPainter(); bool twoRows = this.CurrentGame.Players.Count() > 3; int playersWidth = twoRows ? 3 * 275 : this.CurrentGame.Players.Count() * 275; int xBuffer = (this.pictureBox1.Width - playersWidth - 300) / 2; int yBuffer = 100; int i = 0; int x = 0; int y = 0; StringFormat format; using (var gfx = Graphics.FromImage(bitmap)) { gfx.FillRectangle(Brushes.Aqua, 0, 0, this.pictureBox1.Width, this.pictureBox1.Height); foreach (var fleet in this.CurrentGame.Fleets) { var fleetScreen = DrawFleetScreen(fleet, shipPainter, 550, 550); GetCoords(i, this.CurrentGame.Fleets.Count(), out x, out y); // fleet board gfx.DrawImage(fleetScreen, new Rectangle(xBuffer + (x * 275), yBuffer + (y * (275 + 75)), 275, 275), new Rectangle(0, 0, 550, 550), GraphicsUnit.Pixel); // ship's names format = new StringFormat(); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Center; gfx.DrawString(fleet.Player.Name, new Font(FontFamily.GenericMonospace, 12), Brushes.Black, new Rectangle(xBuffer + (x * 275), yBuffer + (y * (275 + 75)) + 275, 275, 75), format); // red border if (this.CurrentGame.PlayerWhosTurnItIs.Equals(fleet)) { gfx.DrawRectangle(Pens.Red, new Rectangle(xBuffer + (x * 275), yBuffer + (y * (275 + 75)), 274, 274)); } i++; } // scores StringBuilder sb = new StringBuilder(); foreach (var score in this.CurrentGame.ScoresPerPlayer.OrderByDescending(s => s.Value)) { sb.AppendLine($"{score.Value} - {score.Key.Name}"); } format = new StringFormat(); //format.LineAlignment = StringAlignment.Near; //format.Alignment = StringAlignment.Near; gfx.DrawString(sb.ToString(), new Font(FontFamily.GenericMonospace, 12), Brushes.Black, new Rectangle(this.pictureBox1.Width - 300, yBuffer, 300, this.pictureBox1.Height - yBuffer), format); i++; } this.UpdateScreen(bitmap); }