private void btnEndTurn_Click(object sender, EventArgs e) { if (activePlayer == 1) { activePlayer = 2; } else { activePlayer = 1; } lblTurn.Text = "Ходит " + activePlayer + "-й игрок"; activeShip = null; drawSavedImages(); for (int count = 0; count < allShips.Count; count++) { allShips[count].refill(); allShips[count].statusRefresh(ref bmBackground, ref bmFull); } objectManager.moveMeteors(cMap, bmBackground, bmFull); if (objectManager.whether2createMeteor() == 1) { Meteor newMeteor = objectManager.meteorCreate(cMap); if (newMeteor != null) { Graphics g = Graphics.FromImage(bmFull); g.DrawImage(newMeteor.objectImg, new Rectangle(newMeteor.x - boxWidth / 6, newMeteor.y - boxHeight / 6, boxWidth / 3, boxHeight / 3)); g.DrawString(newMeteor.currentHealth.ToString(), new Font("Arial", 8.0F), Brushes.Red, new PointF(cMap.boxes[newMeteor.boxId].xpoint1 + 20, cMap.boxes[newMeteor.boxId].ypoint1 - 25)); } } shipsCount(); pictureMap.Refresh(); }
public Meteor meteorCreate(combatMap cMap) { int flag = 1; int box4meteor = 0; int meteorHealth; int meteorDmg; int xWay = Constants.RIGHT; int yWay = Constants.MEDIUM_TOP; Meteor newMeteor = null; int i; Random rand = new Random(); int randomNum = rand.Next(1, 100) % 4; // место появления и направление полёта switch (randomNum) { case 1: // left box4meteor = rand.Next(0, cMap.height); for (i = 0; i < 10; i++) { if (cMap.boxes[box4meteor].spaceObject != null) { box4meteor += 1; if (box4meteor >= cMap.height - 1) { box4meteor = 0; } } else { break; } } if (i == 10) { flag = 0; } xWay = Constants.RIGHT; if (rand.Next(1, 100) > 50) { yWay = Constants.MEDIUM_TOP; } else { yWay = Constants.MEDIUM_BOTTOM; } break; case 2: // top box4meteor = cMap.getBoxByCoords(rand.Next(0, cMap.width / 2 - 1) * 2, 0).id; for (i = 0; i < 10; i++) { if (cMap.boxes[box4meteor].spaceObject != null) { box4meteor += cMap.height * 2; if (box4meteor > cMap.width + 1) { box4meteor = 0; } } else { break; } } if (i == 10) { flag = 0; } if (rand.Next(1, 100) > 50) { xWay = Constants.RIGHT; } else { xWay = Constants.LEFT; } yWay = Constants.MEDIUM_BOTTOM; break; case 3: // right box4meteor = rand.Next(cMap.boxes.Count - 1 - cMap.height, cMap.boxes.Count - 1); for (i = 0; i < 10; i++) { if (cMap.boxes[box4meteor].spaceObject != null) { box4meteor += 1; if (box4meteor > cMap.boxes.Count - 1) { box4meteor = cMap.boxes.Count - cMap.height; } } else { break; } } if (i == 10) { flag = 0; } xWay = Constants.LEFT; if (rand.Next(1, 100) > 50) { yWay = Constants.MEDIUM_TOP; } else { yWay = Constants.MEDIUM_BOTTOM; } break; case 0: // bottom box4meteor = cMap.getBoxByCoords(rand.Next(0, cMap.width / 2 - 1) * 2 + 1, cMap.height * 2 - 1).id; for (i = 0; i < 10; i++) { if (cMap.boxes[box4meteor].spaceObject != null) { box4meteor += cMap.height * 2; if (box4meteor > cMap.boxes.Count - 1) { box4meteor = cMap.height - 1; } } else { break; } } if (i == 10) { flag = 0; } if (rand.Next(1, 100) > 50) { xWay = Constants.RIGHT; } else { xWay = Constants.LEFT; } yWay = Constants.MEDIUM_TOP; break; } if (flag == 1) { meteorHealth = rand.Next(1, 150); meteorDmg = meteorHealth / 4; newMeteor = new Meteor(cMap, box4meteor, meteorHealth, meteorDmg, xWay, yWay); meteors.Add(newMeteor); cMap.boxes[box4meteor].spaceObject = newMeteor; } return(newMeteor); }