//Form method that runs when refresh is called. Also provies the graphic object that is //used to draw on the form private void GameForm_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; if (gameObjects != null) { foreach (GameObject gameObject in gameObjects) { if (gameObject is Player temp) { temp = (Player)gameObject; temp.Draw(g, temp.AdjustForXOffset(camera.GetXOffset()), temp.AdjustForYOffset(camera.GetYOffset()), currentPlayer); } else { gameObject.Draw(g, gameObject.AdjustForXOffset(camera.GetXOffset()), gameObject.AdjustForYOffset(camera.GetYOffset())); if (clickedObject is IClickToDrawText clickToDrawText) { g.DrawString(clickToDrawText.TextToDraw(), FormatManager.GetPlayerFont(), new SolidBrush(Color.Black), new PointF(0, windowHeight - FormatManager.GetPlayerFont().Height)); } } } } }
//Form method that runs when refresh is called. Also provies the graphic object that is //used to draw on the form private void GameForm_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; if (board != null) { foreach (Space space in board.GetBoardSpaces()) { space.Draw(g, space.AdjustForXOffset(camera.GetXOffset()), space.AdjustForYOffset(camera.GetYOffset())); if (clickedObject is IClickToDrawText clickToDrawText) { g.DrawString(clickToDrawText.TextToDraw(), FormatManager.GetPlayerFont(), new SolidBrush(Color.Black), new PointF(0, windowHeight - FormatManager.GetPlayerFont().Height * 2)); } } foreach (Player player in players) { player.Draw(g, player.AdjustForXOffset(camera.GetXOffset()), player.AdjustForYOffset(camera.GetYOffset()), currentPlayer, clientPlayerId); } } }
//Rendering player for server games. Includes the client id since server games use //client ids and is used in this method to display the client own infomation along with //the current player's information public void Draw(Graphics g, int xOffset, int yOffset, int currentPlayer, int clientId) { base.Draw(g, xOffset, yOffset); if (playerId == currentPlayer) { g.DrawString("Player " + playerId + " - Total Money - " + totalMoney.ToString("C2"), FormatManager.GetPlayerFont(), new SolidBrush(GetColor()), new PointF(0, 0)); } if (playerId == clientId) { float padding = FormatManager.GetGeneralFont().GetHeight() * 2; g.DrawString("You " + "- Total Money - " + totalMoney.ToString("C2"), FormatManager.GetPlayerFont(), new SolidBrush(GetColor()), new PointF(0, padding)); } }
//Rendering player for local games. Excludes the client id since local games do not use //client ids. public void Draw(Graphics g, int xOffset, int yOffset, int currentPlayer) { base.Draw(g, xOffset, yOffset); if (playerId == currentPlayer) { g.DrawString("Player " + playerId + " - Total Money - " + totalMoney.ToString("C2"), FormatManager.GetPlayerFont(), new SolidBrush(GetColor()), new PointF(0, 0)); } }