/// <summary> /// Draws the current state of the game to the screen. /// </summary> /// <remarks> /// What is drawn depends upon the state of the game. /// </remarks> public static void DrawScreen() { UtilityFunctions.DrawBackground(); switch (CurrentState) { case GameState.ViewingMainMenu: MenuController.DrawMainMenu(); break; case GameState.ViewingGameMenu: MenuController.DrawGameMenu(); break; case GameState.AlteringSettings: MenuController.DrawSettings(); break; case GameState.AlteringColor: MenuController.DrawColor(); break; case GameState.Deploying: DeploymentController.DrawDeployment(); break; case GameState.Discovering: DiscoveryController.DrawDiscovery(); break; case GameState.EndingGame: EndingGameController.DrawEndOfGame(); break; case GameState.ViewingHighScores: HighScoreController.DrawHighScores(); break; } UtilityFunctions.DrawAnimations(); SwinGame.RefreshScreen(); }
/// <summary> /// Handles the user SwinGame. /// </summary> /// <remarks> /// Reads key and mouse input and converts these into /// actions for the game to perform. The actions /// performed depend upon the state of the game. /// </remarks> public static void HandleUserInput() { //Read incoming input events SwinGame.ProcessEvents(); switch (CurrentState) { case GameState.ViewingMainMenu: MenuController.HandleMainMenuInput(); break; case GameState.ViewingGameMenu: MenuController.HandleGameMenuInput(); break; case GameState.AlteringSettings: MenuController.HandleSetupMenuInput(); break; case GameState.AlteringColor: MenuController.HandleColorMenuInput(); break; case GameState.Deploying: DeploymentController.HandleDeploymentInput(); break; case GameState.Discovering: DiscoveryController.HandleDiscoveryInput(); break; case GameState.EndingGame: EndingGameController.HandleEndOfGameInput(); break; case GameState.ViewingHighScores: HighScoreController.HandleHighScoreInput(); break; } UtilityFunctions.UpdateAnimations(); }
/// <summary> /// Draws the current state of the game to the screen. /// </summary> /// <remarks> /// What is drawn depends upon the state of the game. /// </remarks> public static void DrawScreen() { UtilityFunctions.DrawBackground(); switch (CurrentState) { case GameState.ViewingMainMenu: MenuController.DrawMainMenu(); break; case GameState.ViewingGameMenu: MenuController.DrawGameMenu(); break; case GameState.AlteringSettings: MenuController.DrawSettings(); break; case GameState.Deploying: DeploymentController.DrawDeployment(); break; case GameState.Discovering: DiscoveryController.DrawDiscovery(); break; case GameState.EndingGame: EndingGameController.DrawEndOfGame(); break; case GameState.ViewingHighScores: HighScoreController.DrawHighScores(); break; } UtilityFunctions.DrawAnimations(); //Lowered to 30 frames per second to see the splash and explosion animations SwinGame.RefreshScreen(60); }
/// <summary> /// Draws the game during the attack phase. /// </summary>s public static void DrawDiscovery() { const int SCORES_LEFT = 172; const int SHOTS_TOP = 157; const int HITS_TOP = 206; const int SPLASH_TOP = 256; if ((SwinGame.KeyDown(KeyCode.LeftShiftKey) | SwinGame.KeyDown(KeyCode.RightShiftKey)) & SwinGame.KeyDown(KeyCode.CKey)) { UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, true); } else { UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, false); } UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer); UtilityFunctions.DrawMessage(); SwinGame.DrawText(GameController.HumanPlayer.Shots.ToString(), Color.White, GameResources.GetFont("Menu"), SCORES_LEFT, SHOTS_TOP); SwinGame.DrawText(GameController.HumanPlayer.Hits.ToString(), Color.White, GameResources.GetFont("Menu"), SCORES_LEFT, HITS_TOP); SwinGame.DrawText(GameController.HumanPlayer.Missed.ToString(), Color.White, GameResources.GetFont("Menu"), SCORES_LEFT, SPLASH_TOP); }
/// <summary> /// Draws the deployment screen showing the field and the ships /// that the player can deploy. /// </summary> public static void DrawDeployment() { UtilityFunctions.DrawField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer, true); // Draw the Left/Right and Up/Down buttons if (_currentDirection == Direction.LeftRight) { SwinGame.DrawBitmap(GameResources.GameImage("LeftRightButton"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP); } else { SwinGame.DrawBitmap(GameResources.GameImage("UpDownButton"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP); } // DrawShips foreach (ShipName sn in Enum.GetValues(typeof(ShipName))) { int i; i = (int)sn - 1; if (i >= 0) { if (sn == _selectedShip) { SwinGame.DrawBitmap(GameResources.GameImage("SelectedShip"), SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT); } } } if (GameController.HumanPlayer.ReadyToDeploy) { SwinGame.DrawBitmap(GameResources.GameImage("PlayButton"), PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP); } SwinGame.DrawBitmap(GameResources.GameImage("RandomButton"), RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP); UtilityFunctions.DrawMessage(); }
/// <summary> /// Draws the current state of the game to the screen. /// </summary> /// <remarks> /// What is drawn depends upon the state of the game. /// </remarks> public static void DrawScreen() { UtilityFunctions.DrawBackground(); if (CurrentState == GameState.ViewingMainMenu) { MenuController.DrawMainMenu(); } else if (CurrentState == GameState.ViewingGameMenu) { MenuController.DrawGameMenu(); } else if (CurrentState == GameState.AlteringSettings) { MenuController.DrawSettings(); } else if (CurrentState == GameState.Deploying) { DeploymentController.DrawDeployment(); } else if (CurrentState == GameState.Discovering) { DiscoveryController.DrawDiscovery(); } else if (CurrentState == GameState.EndingGame) { EndingGameController.DrawEndOfGame(); } else if (CurrentState == GameState.ViewingHighScores) { HighScoreController.DrawHighScores(); } UtilityFunctions.DrawAnimations(); SwinGame.RefreshScreen(); }
/// <summary> /// Draw the end of the game screen, shows the win/lose state /// </summary> /// <remarks> /// Isuru: Updated to new swingame call /// </remarks> public static void DrawEndOfGame() { UtilityFunctions.DrawField(GameController.ComputerPlayer.PlayerGrid, GameController.ComputerPlayer, true); UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer); Rectangle toDraw = new Rectangle(); toDraw.X = 0; toDraw.Y = 250; toDraw.Width = SwinGame.ScreenWidth(); toDraw.Height = SwinGame.ScreenHeight(); //String whatShouldIPrint = "I have long variable names"; if (GameController.HumanPlayer.IsDestroyed) { SwinGame.DrawBitmap(GameResources.GameImage("YouLose"), 350, 120); //whatShouldIPrint = "YOU LOSE!"; } else { //whatShouldIPrint = "-- WINNER --"; SwinGame.DrawBitmap(GameResources.GameImage("YouWin"), 350, 120); } //SwinGame.DrawText(whatShouldIPrint, Color.White, Color.Transparent, GameResources.GameFont("ArialLarge"), FontAlignment.AlignCenter, toDraw); }
/// <summary> /// Draw the end of the game screen, shows the win/lose state /// </summary> public static void DrawEndOfGame() { Rectangle toDraw = default(Rectangle); string whatShouldIPrint = ""; UtilityFunctions.DrawField(GameController.ComputerPlayer.PlayerGrid, GameController.ComputerPlayer, true); UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer); toDraw.X = 0; toDraw.Y = 250; toDraw.Width = SwinGame.ScreenWidth(); toDraw.Height = SwinGame.ScreenHeight(); if (GameController.HumanPlayer.IsDestroyed) { whatShouldIPrint = "YOU LOSE!"; } else { whatShouldIPrint = "-- WINNER --"; } SwinGame.DrawText(whatShouldIPrint, Color.White, Color.Transparent, GameResources.GameFont("Square80"), FontAlignment.AlignCenter, toDraw); }
/// <summary> /// Handles the user SwinGame. /// </summary> /// <remarks> /// Reads key and mouse input and converts these into /// actions for the game to perform. The actions /// performed depend upon the state of the game. /// </remarks> public static void HandleUserInput() { //Read incoming input events SwinGame.ProcessEvents(); if (CurrentState == GameState.ViewingMainMenu) { MenuController.HandleMainMenuInput(); } else if (CurrentState == GameState.ViewingGameMenu) { MenuController.HandleGameMenuInput(); } else if (CurrentState == GameState.AlteringSettings) { MenuController.HandleSetupMenuInput(); } else if (CurrentState == GameState.Deploying) { DeploymentController.HandleDeploymentInput(); } else if (CurrentState == GameState.Discovering) { DiscoveryController.HandleDiscoveryInput(); } else if (CurrentState == GameState.EndingGame) { EndingGameController.HandleEndOfGameInput(); } else if (CurrentState == GameState.ViewingHighScores) { HighScoreController.HandleHighScoreInput(); } UtilityFunctions.UpdateAnimations(); }
/// <summary> /// Handles user input for the Deployment phase of the game. /// </summary> /// <remarks> /// Involves selecting the ships, deloying ships, changing the direction /// of the ships to add, randomising deployment, end then ending /// deployment /// </remarks> public static void HandleDeploymentInput() { if (SwinGame.KeyTyped(UtilityFunctions.EscapeKey)) { GameController.AddNewState(GameState.ViewingGameMenu); } if (SwinGame.KeyTyped(UtilityFunctions.UpKey) | SwinGame.KeyTyped(UtilityFunctions.DownKey)) { _currentDirection = Direction.UpDown; } if (SwinGame.KeyTyped(UtilityFunctions.LeftKey) | SwinGame.KeyTyped(UtilityFunctions.LeftKey)) { _currentDirection = Direction.LeftRight; } if (SwinGame.KeyTyped(UtilityFunctions.RandomKey)) { GameController.HumanPlayer.RandomizeDeployment(); } // ship colour change keys if (SwinGame.KeyTyped(UtilityFunctions.BlueKey)) { //GameController.CurrentShipColour = ShipColour.Blue; } if (SwinGame.KeyTyped(UtilityFunctions.PinkKey)) { //GameController.CurrentShipColour = ShipColour.Pink; } if (SwinGame.MouseClicked(MouseButton.LeftButton)) { ShipName selected = default(ShipName); selected = GetShipMouseIsOver(); if (selected != ShipName.None) { _selectedShip = selected; } else { DoDeployClick(); } if (GameController.HumanPlayer.ReadyToDeploy & UtilityFunctions.IsMouseInRectangle(PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP, PLAY_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT)) { GameController.EndDeployment(); } else if (UtilityFunctions.IsMouseInRectangle(UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT)) { _currentDirection = Direction.UpDown; } else if (UtilityFunctions.IsMouseInRectangle(LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT)) { _currentDirection = Direction.LeftRight; } else if (UtilityFunctions.IsMouseInRectangle(RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT)) { GameController.HumanPlayer.RandomizeDeployment(); } else if (UtilityFunctions.IsMouseInRectangle(PAINT_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT)) { if (GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour == ShipColour.Pink) { GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour = ShipColour.Blue; } else { GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour = ShipColour.Pink; } } } }
/// <summary> /// Handles the processing of user input when the Hotkeys menu is showing /// </summary> public static void HandleHotkeysMenuInput() { if (SwinGame.KeyTyped(UtilityFunctions.EscapeKey)) { GameController.SwitchState(GameState.ViewingGameMenu); } if (SwinGame.AnyKeyPressed()) { // Escape key if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() - HOTKEYS_BIND, 100, 50, 25)) { UtilityFunctions.EscapeKey = UtilityFunctions.KeyTyped(UtilityFunctions.EscapeKey); } // Up key if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() - HOTKEYS_BIND, 150, 50, 25)) { UtilityFunctions.UpKey = UtilityFunctions.KeyTyped(UtilityFunctions.UpKey); } // Down key if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() - HOTKEYS_BIND, 200, 50, 25)) { UtilityFunctions.DownKey = UtilityFunctions.KeyTyped(UtilityFunctions.DownKey); } // Left key if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() - HOTKEYS_BIND, 250, 50, 25)) { UtilityFunctions.LeftKey = UtilityFunctions.KeyTyped(UtilityFunctions.LeftKey); } // Random key if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() - HOTKEYS_BIND, 300, 50, 25)) { UtilityFunctions.RandomKey = UtilityFunctions.KeyTyped(UtilityFunctions.RandomKey); } // Blue key if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() - HOTKEYS_BIND, 350, 50, 25)) { UtilityFunctions.BlueKey = UtilityFunctions.KeyTyped(UtilityFunctions.BlueKey); } // Pink key if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() - HOTKEYS_BIND, 400, 50, 25)) { UtilityFunctions.PinkKey = UtilityFunctions.KeyTyped(UtilityFunctions.PinkKey); } // Cheats key if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() - HOTKEYS_BIND, 450, 50, 25)) { UtilityFunctions.CheatsKey = UtilityFunctions.KeyTyped(UtilityFunctions.CheatsKey); } // Maximise screen key if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() - HOTKEYS_BIND, 450, 50, 25)) { UtilityFunctions.MaxKey = UtilityFunctions.KeyTyped(UtilityFunctions.MaxKey); } } }
/// <summary> /// Draws the game during the attack phase. /// </summary>s public static void DrawDiscovery() { const int SCORES_LEFT = 172; const int SHOTS_TOP = 157; const int HITS_TOP = 206; const int SPLASH_TOP = 256; const int AI_LEFT = 50; const int AI_TOP = 350; if (UtilityFunctions.ShowShipsCheat) { UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, true); } else { UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, false); } UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer); UtilityFunctions.DrawMessage(); SwinGame.DrawText(GameController.HumanPlayer.Shots.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SHOTS_TOP); SwinGame.DrawText(GameController.HumanPlayer.Hits.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, HITS_TOP); SwinGame.DrawText(GameController.HumanPlayer.Missed.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SPLASH_TOP); SwinGame.DrawText(GameController.AiGameSetting(), Color.White, GameResources.GameFont("Menu"), AI_LEFT, AI_TOP); //Draws Ships foreach (ShipName sn in Enum.GetValues(typeof(ShipName))) { if (object.ReferenceEquals(GameController.ComputerPlayer.Ship(sn), null)) { } else { if (GameController.ComputerPlayer.Ship(sn).IsDestroyed) { int i = 0; i = (int)sn - 1; int rowTop = 122 + (2 + 40) * GameController.ComputerPlayer.Ship(sn).Row + 3; int colLeft = 349 + (2 + 40) * GameController.ComputerPlayer.Ship(sn).Column + 3; if (i >= 0) { string shipName = null; int shipHeight = 0; int shipWidth = 0; int cellHeight = 40; int SHIP_GAP = 3; int cellWidth = 40; int cellGap = 2; int j = (int)GameController.ComputerPlayer.Ship(sn).CurrentShipColour; if (GameController.ComputerPlayer.Ship(sn).Direction == Direction.LeftRight) { shipName = "ShipLR" + GameController.ComputerPlayer.Ship(sn).Size + "a" + j; shipHeight = cellHeight - (SHIP_GAP * 2); shipWidth = (cellWidth + cellGap) * GameController.ComputerPlayer.Ship(sn).Size - (SHIP_GAP * 2) - cellGap; } else { //Up down shipName = "ShipUD" + GameController.ComputerPlayer.Ship(sn).Size + "a" + j; shipHeight = (cellHeight + cellGap) * GameController.ComputerPlayer.Ship(sn).Size - (SHIP_GAP * 2) - cellGap; shipWidth = cellWidth - (SHIP_GAP * 2); } //FIX HERE!!! SwinGame.DrawBitmap(GameResources.GameImage(shipName), colLeft, rowTop); // SwinGame.FillRectangle(Color.LightBlue, SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT) //Else // SwinGame.FillRectangle(Color.Gray, SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT) } //SwinGame.DrawRectangle(Color.Black, SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT) //SwinGame.DrawText(sn.ToString(), Color.Black, GameFont("Courier"), SHIPS_LEFT + TEXT_OFFSET, SHIPS_TOP + i * SHIPS_HEIGHT) } } } }