package HTWGraphicsObject; import System.Drawing.*; import System.Windows.Forms.*; import System.Resources.*; import Wumpus.*; import JoeWumpusMapAndPlayer.*; // This class draws all the graphics for Hunt The Wumpus. So far all the graphics are unscaled. //The Images.resx file, as well as the Images.Designer.jsl file, are key components of this class. public class HTWGraphics { private Images pix = new Images(); private Graphics graphics; private RectangleF bounds; public HTWGraphics(Graphics theGraphics) { graphics = theGraphics; bounds = graphics.get_VisibleClipBounds(); } /** * Draws the current room and connections, hazards, hints, and the inventory * A couple things I am not displaying as of now: PlayerInfo.PLAYER_NAME, PlayerInfo.CAVE_NAME, RoomInfo.roomNumber * * @param room information about the cave layout * @param player information about the player * @param graphics the graphics object for the method */ public void drawCave(RoomInfo room, PlayerInfo player) { graphics.Clear(Color.get_Black()); Image cave = pix.get_HTWCaveSkeleton(); graphics.DrawImage(cave, bounds); float height = bounds.get_Height(); float width = bounds.get_Width(); //Draws all tunnels int i = 0; while (i < 3) { if (room.getConnections()[0] >= 0) { Image nTunnel = pix.get_Ntunnel(); RectangleF NRect = new RectangleF((float).32 * width, (float).18 * height, (float) .38 * width, (float) .1 * height); graphics.DrawImage(nTunnel, NRect); i++; } if (room.getConnections()[1] >= 0) { Image neTunnel = pix.get_NEtunnel(); graphics.DrawImageUnscaled(neTunnel, 527, 132); i++; } if (room.getConnections()[2] >= 0) { Image seTunnel = pix.get_SEtunnel(); graphics.DrawImageUnscaled(seTunnel, 528, 435); i++; } if (room.getConnections()[3] >= 0) { Image sTunnel = pix.get_Stunnel(); graphics.DrawImageUnscaled(sTunnel, 250, 670); i++; } if (room.getConnections()[4] >= 0) { Image swTunnel = pix.get_SWtunnel(); graphics.DrawImageUnscaled(swTunnel, -3, 434); i++; } if (room.getConnections()[5] >= 0) { Image nwTunnel = pix.get_NWtunnel(); graphics.DrawImageUnscaled(nwTunnel, -1, 133); i++; } i = 3; } //Draws all warnings and possible actions if (room.wumpusWarning()) { Image wumpusAlert = pix.get_WumpusWarning(); graphics.DrawImageUnscaled(wumpusAlert, 15, 69); } if (room.pitWarning()) { Image pitAlert = pix.get_PitWarning(); graphics.DrawImageUnscaled(pitAlert, 15, 85); } if (room.batWarning()) { Image batsAlert = pix.get_BatsWarning(); graphics.DrawImageUnscaled(batsAlert, 15, 100); } Image moveOption = pix.get_Move(); graphics.DrawImageUnscaled(moveOption, 225, 72); if (player.ARROWS >= 1) { Image shootArrow = pix.get_ShootArrow(); graphics.DrawImageUnscaled(shootArrow, 225, 90); } if (player.COINS >= 1) { Image buyArrows = pix.get_BuyArrow(); Image buySecret = pix.get_BuySecret(); graphics.DrawImageUnscaled(buyArrows, 370, 72); graphics.DrawImageUnscaled(buySecret, 370, 90); } //Displays the number of coins, arrows, turns, and the score FontFamily fontFamily = new FontFamily("Arial"); RectangleF stats1 = new RectangleF((float) .4 * width, (float) .01 * height, (float) .2 * width, (float) .1 * height); RectangleF stats2 = new RectangleF((float).7 * width, (float).1 * height, (float).2 * width, (float).1 * height); RectangleF stats3 = new RectangleF((float).7 * width, (float).1 * height, (float).2 * width, (float).1 * height); RectangleF stats4 = new RectangleF((float).7 * width, (float).1 * height, (float).2 * width, (float).1 * height); graphics.DrawString(player.TURNS + "", new Font(fontFamily, 25, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(Color.get_White()), stats1, StringFormat.get_GenericDefault()); //graphics.DrawString(player.COINS + " " + player.ARROWS, new Font(fontFamily, 35, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(Color.get_Black()), 525, 55); //Draws possible hazard if (room.pitPresent()) { //draw pit } if (room.batsPresent()) { //draw bat(s) //Note: Do bats even need to be displayed, since they fly away? (there is already the drawBat() method for this event) } //Draws the wumpus if there is a wumpus in the room if (room.wumpusPresent()) { Image wumpus = pix.get_Wumpus(); graphics.DrawImageUnscaled(wumpus, 240, 219); } } /** * Displays graphics for the superbat event * @param graphics the graphics object for the method */ public void drawBat() { //called whenever necessary by GameControl Image superbat = pix.get_SuperBat(); graphics.DrawImage(superbat, bounds); } /** * Draws the final game screen for a win * @param graphics the graphics object for the method */ public void drawWin() { //called if game is won } /** * Draws the final game screen for a loss * @param graphics the graphics object for the method */ public void drawLose() { //called if game is lost } /** * Draws the start screen * @param graphics the graphics object for the method */ public void drawStartScreen() { graphics.Clear(Color.get_Black()); Image start = pix.get_HuntTheWumpus(); graphics.DrawImage(start, bounds); } /** * Draws the player falling in a pit * @param graphics the graphics object for the method * @param fall whether the player dies in the pit */ public void drawPit(boolean fall) { } }