private static void EndLoadingScreen(int width, int height) { SwinGame.ProcessEvents(); const int processDelay = 500; SwinGame.Delay(processDelay); SwinGame.ClearScreen(); SwinGame.RefreshScreen(); SwinGame.FreeFont(_LoadingFont); SwinGame.FreeBitmap(_Background); SwinGame.FreeBitmap(_Animation); SwinGame.FreeBitmap(_LoaderEmpty); SwinGame.FreeBitmap(_LoaderFull); // SV: commented out as this causes a memory access violation. //Audio.FreeSoundEffect(_StartSound); SwinGame.ChangeScreenSize(width, height); }
private static void PlaySwinGameIntro() { const int ANI_CELL_COUNT = 11; Audio.PlaySoundEffect(_startSound); SwinGame.Delay(200); for (int i = 0; i <= ANI_CELL_COUNT - 1; i++) { SwinGame.DrawBitmap(_background, 0, 0); SwinGame.Delay(20); SwinGame.RefreshScreen(); SwinGame.ProcessEvents(); } SwinGame.Delay(1500); }
/// <summary> /// Wait a short period to simulate the think time /// </summary> private void Delay() { int i = 0; for (i = 0; i <= 150; i++) { //Dont delay if window is closed if (SwinGame.WindowCloseRequested()) { return; } // Disabled delay for debugging (for quicker games) SwinGame.Delay(5); SwinGame.ProcessEvents(); SwinGame.RefreshScreen(); } }
/// <summary> /// Wait a short period to simulate the think time /// </summary> private void Delay() { int i = 0; for (i = 0; i <= 150; i++) { //Dont delay if window is closed if (SwinGame.WindowCloseRequested) { return; } SwinGame.Delay(5); SwinGame.ProcessEvents(); SwinGame.RefreshScreen(); } }
/// <summary> /// Checks the results of the attack and switches to /// Ending the Game if the result was game over. /// </summary> /// <param name="result">the result of the last /// attack</param> /// <remarks>Gets the AI to attack if the result switched /// to the AI player.</remarks> private void CheckAttackResult(AttackResult result) { switch (result.Value) { case ResultOfAttack.Miss: { Rectangle toDraw = new Rectangle(); string whatShouldIPrint; //UtilityFunctions.DrawField(GameController.Instance.ComputerPlayer.PlayerGrid, GameController.Instance.ComputerPlayer, true); toDraw.X = 0; toDraw.Y = 250; toDraw.Width = SwinGame.ScreenWidth(); toDraw.Height = SwinGame.ScreenHeight(); if (_theGame.Player == HumanPlayer) { whatShouldIPrint = "Your turn"; } else { whatShouldIPrint = "AIs turn"; } SwinGame.DrawText(whatShouldIPrint, Color.White, Color.Transparent, GameResources.Instance.GameFont("ArialLarge"), FontAlignment.AlignCenter, toDraw); // orignialy draw text lines SwinGame.RefreshScreen(); SwinGame.Delay(1000); if (_theGame.Player == ComputerPlayer) { AIAttack(); } break; } case ResultOfAttack.GameOver: { SwitchState(GameState.EndingGame); break; } } }
// Clear loading screen private static void EndLoadingScreen(int width, int height) { SwinGame.ProcessEvents(); SwinGame.Delay(500); SwinGame.ClearScreen(); SwinGame.RefreshScreen(); SwinGame.FreeFont(_loadingFont); SwinGame.FreeBitmap(_background); SwinGame.FreeBitmap(_animation); SwinGame.FreeBitmap(_loaderEmpty); SwinGame.FreeBitmap(_loaderFull); // TODO(Xavier): This causes the game to crash // Audio.FreeSoundEffect (_StartSound); SwinGame.ChangeScreenSize(width, height); }
private static void PlaySwinGameIntro() { const int ANI_CELL_COUNT = 11; Audio.PlaySoundEffect(_StartSound, UtilityFunctions.VolumeLevel); SwinGame.Delay(200); int i; for (i = 0; i <= ANI_CELL_COUNT - 1; i++) { SwinGame.DrawBitmap(_Background, 0, 0); SwinGame.Delay(20); SwinGame.RefreshScreen(60); SwinGame.ProcessEvents(); } SwinGame.Delay(1500); }
// Prepares the background private static void PlaySwinGameIntro() { const int ANI_CELL_COUNT = 11; Audio.PlaySoundEffect(_StartSound); SwinGame.Delay((uint)200); int i = 0; for (i = 0; i <= ANI_CELL_COUNT - 1; i++) { SwinGame.DrawBitmap(_Background, 0, 0); SwinGame.Delay((uint)20); SwinGame.RefreshScreen(); SwinGame.ProcessEvents(); } SwinGame.Delay((uint)1500); // Geez, how long does this need to be? Consider this to be a FIXME for issue #7 }
/// <summary> /// The IMPOSSIBLE AI takes its attacks until it destroy a ship. /// </summary> /// <returns>The result of the last attack</returns> public override AttackResult ImpAIAttack() { AttackResult result = default(AttackResult); int row = 0; int column = 0; //keep hitting until a ship is destroyed do { SwinGame.Delay(200); GenerateCoords(ref row, ref column); //generate coordinates for shot result = _game.ImpAIShoot(row, column); //take shot ProcessShot(row, column, result); } while (result.Value != ResultOfAttack.Destroyed && result.Value != ResultOfAttack.Miss && result.Value != ResultOfAttack.GameOver && !SwinGame.WindowCloseRequested()); return(result); }
private static void PlaySwinGameIntro() { const int ANI_CELL_COUNT = 11; Audio.PlaySoundEffect(_StartSound); SwinGame.Delay(Conversions.ToUInteger(200)); int i; for (i = 0; i <= ANI_CELL_COUNT - 1; i++) { SwinGame.DrawBitmap(_Background, (float)0, (float)0); SwinGame.Delay(Conversions.ToUInteger(20)); SwinGame.RefreshScreen(); SwinGame.ProcessEvents(); } SwinGame.Delay(Conversions.ToUInteger(1500)); }
/// <summary> /// Plays the SwinGame intro, called on startup after loading is finished /// </summary> /// <TODO> /// Add in the call for the SwinGame intro /// </TODO> private static void PlaySwinGameIntro() { const int Ani_Cell_Count = 11; Audio.PlaySoundEffect(_StartSound); SwinGame.Delay(200); int i; for (i = 0; i <= Ani_Cell_Count - 1; i++) { SwinGame.DrawBitmap(_Background, 0, 0); SwinGame.Delay(20); SwinGame.RefreshScreen(); SwinGame.ProcessEvents(); } SwinGame.Delay(1500); }
/// <summary> /// Loads all the game resourses /// </summary> public static void LoadResources() { ShowLoadingScreen(); ShowMessage("Loading _fonts...", 0); Load_fonts(); SwinGame.Delay(300); ShowMessage("Loading _images...", 1); Load_images(); SwinGame.Delay(300); ShowMessage("Loading _sounds effects...", 2); Load_sounds(); SwinGame.Delay(300); ShowMessage("Loading music...", 3); LoadMusic(); SwinGame.Delay(500); EndLoadingScreen(); }
private static void PlaySwinGameIntro() { const int ANI_CELL_COUNT = 11; Audio.PlaySoundEffect("StartSound"); SwinGame.Delay(200); int i; for (i = 0; (i <= (ANI_CELL_COUNT - 1)); i++) { SwinGame.DrawBitmap("loadBackground", 0, 0); SwinGame.Delay(20); SwinGame.RefreshScreen(); SwinGame.ProcessEvents(); } SwinGame.Delay(1500); }
private static void PlaySwinGameIntro() { const int ANI_CELL_COUNT = 11; Audio.PlaySoundEffect(_StartSound); SwinGame.Delay(200); int i; for (i = 0; (i // play the intro by refreshing screen and draw the screen <= (ANI_CELL_COUNT - 1)); i++) { SwinGame.DrawBitmap(_Background, 0, 0); SwinGame.Delay(20); SwinGame.RefreshScreen(); SwinGame.ProcessEvents(); } SwinGame.Delay(1500); }
/// <summary> /// Wait a short period to simulate the think time /// </summary> private void Delay() { int i = 0; for (i = 0; i <= 150; i++) { //Dont delay if window is closed /// <summary> /// Fix the bug by adding bracket () because function is needed to be add /// </summary> if (SwinGame.WindowCloseRequested()) { return; } SwinGame.Delay(5); SwinGame.ProcessEvents(); SwinGame.RefreshScreen(); } }
/// <summary> /// Wait here until next game tick is due. /// </summary> public void Wait() { // Record the current time to make sure it doesn't change uint current = _timer.Ticks; // Check method should wait if (_nextTick > current) { SwinGame.Delay(_nextTick - current); } // Update next tick time _nextTick += _tickDuration; // Check if timer needs to be rebased if (_nextTick > TICK_REBASE_LIMIT) { RebaseTimer(); } }
/// <summary> /// The Resources Class stores all of the Games Media Resources, such as Images, Fonts /// Sounds, Music. /// </summary> public static void LoadResources() { int width = 0; int height = 0; const int WINDOW_WIDTH = 800; const int WINDOW_HEIGHT = 600; const int DELAY = 100; width = SwinGame.ScreenWidth(); height = SwinGame.ScreenHeight(); SwinGame.ChangeScreenSize(WINDOW_WIDTH, WINDOW_HEIGHT); ShowLoadingScreen(); ShowMessage("Loading fonts...", 0, false); LoadFonts(); SwinGame.Delay(DELAY); ShowMessage("Loading images...", 1, false); LoadImages(); SwinGame.Delay(DELAY); ShowMessage("Loading sounds...", 2, false); LoadSounds(); SwinGame.Delay(DELAY); ShowMessage("Loading music...", 3, false); LoadMusic(); SwinGame.Delay(DELAY); SwinGame.Delay(DELAY); ShowMessage("Game loaded...", 5, true); SwinGame.Delay(DELAY); // SV: uncommented this, and commented out the line // in the method that was causing the memory access violation. EndLoadingScreen(width, height); }
/// <summary> /// Playes the SwinGame intro animation /// </summary> private static void PlaySwinGameIntro() { const int ANI_X = 143; const int ANI_Y = 134; const int ANI_W = 546; const int ANI_H = 327; const int ANI_V_CELL_COUNT = 6; const int ANI_CELL_COUNT = 11; Audio.PlaySoundEffect(_StartSound); SwinGame.Delay(200); int i = 0; for (i = 0; i <= ANI_CELL_COUNT - 1; i++) { SwinGame.DrawBitmap(_Background, 0, 0); SwinGame.DrawBitmapPart(_Animation, (i / ANI_V_CELL_COUNT) * ANI_W, (i % ANI_V_CELL_COUNT) * ANI_H, ANI_W, ANI_H, ANI_X, ANI_Y); SwinGame.Delay(20); SwinGame.RefreshScreen(); SwinGame.ProcessEvents(); } SwinGame.Delay(1500); }
/// <summary> /// The player hit the top of the cards "snap"! :) /// Check if the top two cards' ranks match. /// </summary> public void PlayerHit(int player) { //TODO: consider deducting score for miss hits??? if (player >= 0 && player < _score.Length && // its a valid player IsStarted && // and the game is started _topCards [0] != null && _topCards [0].Rank == _topCards [1].Rank) // and its a match { _score[player]++; SwinGame.OpenAudio(); SwinGame.LoadSoundEffectNamed("Slap", "snap.wav"); SwinGame.PlaySoundEffect("Slap"); SwinGame.Delay(2000); SwinGame.CloseAudio(); } else if (player >= 0 && player < _score.Length) { _score[player]--; } // stop the game... _started = false; _gameTimer.Stop(); }
public static void HandleGameMenuInput() { //SwinGame.ProcessEvents(); if (SwinGame.MouseClicked(MouseButton.LeftButton)) { if (SwinGame.PointInRect(SwinGame.MousePosition(), 253, 226, 261, 59)) { //start the game and timer gameState = GameState.PlayingGame; RestartGame(); SwinGame.StartTimer(UIController.gameTimer); SwinGame.PlaySoundEffect(UIController.GameSound("startgame")); } else if (SwinGame.PointInRect(SwinGame.MousePosition(), 253, 302, 261, 59)) { //show the instructions SwinGame.PlaySoundEffect(UIController.GameSound("button")); gameState = GameState.ViewingGameInstruction; } else if (SwinGame.PointInRect(SwinGame.MousePosition(), 253, 375, 261, 59)) { //quit the game SwinGame.PlaySoundEffect(UIController.GameSound("button")); gameState = GameState.ViewingHighScore; //break; } else if (SwinGame.PointInRect(SwinGame.MousePosition(), 253, 449, 261, 59)) { //quit the game SwinGame.PlaySoundEffect(UIController.GameSound("button")); SwinGame.Delay(300); gameState = GameState.Quitting; //break; } } }
/// <summary> /// The game menu was clicked, perform the button's action. /// </summary> /// <param name="button">the button pressed</param> private static void PerformGameMenuAction(int button) { switch (button) { case GAME_MENU_RETURN_BUTTON: GameController.EndCurrentState(); break; case GAME_MENU_SURRENDER_BUTTON: GameController.EndCurrentState(); //end game menu GameController.EndCurrentState(); //end game break; case GAME_MENU_QUIT_BUTTON: //GameController.AddNewState(GameState.Quitting); var myBit = SwinGame.LoadBitmap("ExitConfirmation.png"); SwinGame.DrawBitmap("ExitConfirmation.png", 160, 150); SwinGame.RefreshScreen(); SwinGame.Delay(5000); break; } }
/// <summary> /// Listens for attacks to be completed. /// </summary> /// <param name="sender">the game</param> /// <param name="result">the result of the attack</param> /// <remarks> /// Displays a message, plays sound and redraws the screen /// </remarks> private static void AttackCompleted(object sender, AttackResult result) { bool isHuman = _myGame.Player == HumanPlayer; if (isHuman) { UtilityFunctions.Message = "You " + result.ToString(); } else { UtilityFunctions.Message = "The _ai " + result.ToString(); } switch (result.Value) { case ResultOfAttack.Destroyed: { PlayHitSequence(result.Row, result.Column, isHuman); if (Extentions.MusicPlaying == true) { Audio.PlaySoundEffect(GameResources.GetSound("Sink")); } else if (Extentions.MusicPlaying == false) { } break; } case ResultOfAttack.GameOver: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameResources.GetSound("Sink")); while (Audio.SoundEffectPlaying(GameResources.GetSound("Sink"))) { SwinGame.Delay(10); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed) { if (Extentions.MusicPlaying == true) { Audio.PlaySoundEffect(GameResources.GetSound("Lose")); } } else { if (Extentions.MusicPlaying == true) { Audio.PlaySoundEffect(GameResources.GetSound("Winner")); } } break; } case ResultOfAttack.Hit: { PlayHitSequence(result.Row, result.Column, isHuman); break; } case ResultOfAttack.Miss: { PlayMissSequence(result.Row, result.Column, isHuman); break; } case ResultOfAttack.ShotAlready: { if (Extentions.MusicPlaying == true) { Audio.PlaySoundEffect(GameResources.GetSound("Error")); } break; } } }
public static void Main() { //Open the game window SwinGame.OpenGraphicsWindow("GameMain", 900, 700); //SwinGame.ShowSwinGameSplashScreen(); TBoard BoardCell = new TBoard(); TBlockShape BlockShape = null; //Run the game loop while (false == SwinGame.WindowCloseRequested()) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.Black); //assign random shape to the parent TBlockShape BlockShape if (BlockShape == null) { Random Rnd = new Random(); switch (Rnd.Next(7)) { case 0: BlockShape = new TBlockShapeA(); break; case 1: BlockShape = new TBlockShapeB(); break; case 2: BlockShape = new TBlockShapeC(); break; case 3: BlockShape = new TBlockShapeD(); break; case 4: BlockShape = new TBlockShapeE(); break; case 5: BlockShape = new TBlockShapeF(); break; case 6: BlockShape = new TBlockShapeG(); break; } } BlockShape.DrawShape(); BoardCell.DrawBoard(); BlockShape.DropDown(); //Checks for the condition whether it's ready to land. if (BoardCell.CheckLanding(BlockShape.GetBlocks)) { BoardCell.BlockLanding(BlockShape.GetBlocks); if (BoardCell.GameEnd == true) { BoardCell.ClearCell(); SwinGame.ClearScreen(); SwinGame.LoadBitmapNamed("gameover", "SwinGameAni.png"); SwinGame.DrawBitmap("gameover", 330, 300); SwinGame.RefreshScreen(); SwinGame.Delay(5000); SwinGame.ReleaseAllResources(); BoardCell.GameEnd = false; BoardCell.LineClearCount = 0; BoardCell.Score = 0; } BoardCell.EraseFullLine(); BlockShape = null; } if (SwinGame.KeyTyped(KeyCode.vk_LEFT)) { BlockShape.MoveLeft(); } if (SwinGame.KeyTyped(KeyCode.vk_RIGHT)) { BlockShape.MoveRight(); } if (SwinGame.KeyTyped(KeyCode.vk_DOWN)) { //BlockShape.MoveDown(); } if (SwinGame.KeyTyped(KeyCode.vk_UP)) { BlockShape.Rotate(); } //SwinGame.DrawFramerate(0,0); //Draw onto the screen SwinGame.RefreshScreen(20); } }
/// <summary> /// Listens for attacks to be completed. /// </summary> /// <param name="sender">the game</param> /// <param name="result">the result of the attack</param> /// <remarks> /// Displays a message, plays sound and redraws the screen /// </remarks> private static void AttackCompleted(object sender, AttackResult result) { bool isHuman; isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer); if (isHuman) { UtilityFunctions.Message = "You " + result.ToString(); } else { UtilityFunctions.Message = "The AI " + result.ToString(); } switch (result.Value) { case ResultOfAttack.Destroyed: PlayHitSequence(result.Row, result.Column, isHuman); if (GameResources.statusEffect == true) { Audio.PlaySoundEffect(GameResources.GameSound("Sink")); } break; case ResultOfAttack.GameOver: PlayHitSequence(result.Row, result.Column, isHuman); if (GameResources.statusEffect == true) { Audio.PlaySoundEffect(GameResources.GameSound("Sink")); } if (GameResources.statusEffect == true) { while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink"))) { SwinGame.Delay(5); SwinGame.RefreshScreen(); } } if (HumanPlayer.IsDestroyed) { Audio.PlaySoundEffect(GameResources.GameSound("Lose")); } else { Audio.PlaySoundEffect(GameResources.GameSound("Winner")); } break; case ResultOfAttack.Hit: PlayHitSequence(result.Row, result.Column, isHuman); break; case ResultOfAttack.Miss: PlayMissSequence(result.Row, result.Column, isHuman); break; case ResultOfAttack.ShotAlready: if (GameResources.statusEffect == true) { Audio.PlaySoundEffect(GameResources.GameSound("Error")); } break; } }
/// <summary> /// Listens for attacks to be completed. /// </summary> /// <param name="sender">the game</param> /// <param name="result">the result of the attack</param> /// <remarks> /// Displays a message, plays sound and redraws the screen /// </remarks> private static void AttackCompleted(object sender, AttackResult result) { bool isHuman; isHuman = (_theGame.Player == HumanPlayer); if (isHuman) { UtilityFunctions.Message = "You " + result.ToString(); } else { UtilityFunctions.Message = "The AI " + result.ToString(); } var switchExpr = result.Value; switch (switchExpr) { case ResultOfAttack.Destroyed: { PlayHitSequence(result.Row, result.Column, isHuman); if (Variables._isMute == false) //mute extension { Audio.PlaySoundEffect(GameResources.GameSound("Sink")); } break; } case ResultOfAttack.GameOver: { PlayHitSequence(result.Row, result.Column, isHuman); if (Variables._isMute == false) //mute extension { Audio.PlaySoundEffect(GameResources.GameSound("Sink")); } while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink"))) { SwinGame.Delay(10); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed) { if (Variables._isMute == false) //mute extension { Audio.PlaySoundEffect(GameResources.GameSound("Lose")); } } else { if (Variables._isMute == false) //mute extension { Audio.PlaySoundEffect(GameResources.GameSound("Winner")); } } break; } case ResultOfAttack.Hit: { PlayHitSequence(result.Row, result.Column, isHuman); break; } case ResultOfAttack.Miss: { PlayMissSequence(result.Row, result.Column, isHuman); break; } case ResultOfAttack.ShotAlready: { if (Variables._isMute == false) //mute extension { Audio.PlaySoundEffect(GameResources.GameSound("Error")); } break; } } }
/// <summary> /// Listens for attacks to be completed. /// </summary> /// <param name="sender">the game</param> /// <param name="result">the result of the attack</param> /// <remarks> /// Displays a message, plays sound and redraws the screen /// </remarks> private static void AttackCompleted(object sender, AttackResult result) { bool isHuman = false; isHuman = object.ReferenceEquals(_theGame.Player, HumanPlayer); Console.WriteLine(result.ToString()); if (isHuman) { if (result.ToString().Contains("destroyed")) { Message = "You destroyed the enemies" + result.ToString().Replace("destroyed", ""); } else { Message = "You " + result.ToString(); } } else { if (result.ToString().Contains("destroyed")) { Message = "The enemy destroyed your" + result.ToString().Replace("destroyed", ""); } else { Message = "The AI " + result.ToString(); } } switch (result.Value) { case ResultOfAttack.Destroyed: PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameSound("Sink")); break; case ResultOfAttack.GameOver: PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameSound("Sink")); while (Audio.SoundEffectPlaying(GameSound("Sink"))) { SwinGame.Delay(10); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed) { Audio.PlaySoundEffect(GameSound("Lose")); } else { Audio.PlaySoundEffect(GameSound("Winner")); } break; case ResultOfAttack.Hit: PlayHitSequence(result.Row, result.Column, isHuman); break; case ResultOfAttack.Miss: PlayMissSequence(result.Row, result.Column, isHuman); break; case ResultOfAttack.ShotAlready: Audio.PlaySoundEffect(GameSound("Error")); break; } }
/// <summary> /// ''' Listens for attacks to be completed. /// ''' </summary> /// ''' <param name="sender">the game</param> /// ''' <param name="result">the result of the attack</param> /// ''' <remarks> /// ''' Displays a message, plays sound and redraws the screen /// ''' </remarks> private static void AttackCompleted(object sender, AttackResult result) { bool isHuman; isHuman = _theGame.Player == HumanPlayer; if (isHuman) { Message = "You " + result.ToString(); } else { Message = "The AI " + result.ToString(); } switch (result.Value) { case object _ when ResultOfAttack.Destroyed: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameSound("Sink")); break; } case object _ when ResultOfAttack.GameOver: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameSound("Sink")); while (Audio.SoundEffectPlaying(GameSound("Sink"))) { SwinGame.Delay(10); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed) { Audio.PlaySoundEffect(GameSound("Lose")); } else { Audio.PlaySoundEffect(GameSound("Winner")); } break; } case object _ when ResultOfAttack.Hit: { PlayHitSequence(result.Row, result.Column, isHuman); break; } case object _ when ResultOfAttack.Miss: { PlayMissSequence(result.Row, result.Column, isHuman); break; } case object _ when ResultOfAttack.ShotAlready: { Audio.PlaySoundEffect(GameSound("Error")); break; } } }
/// <summary> /// Listens for attacks to be completed. /// </summary> /// <param name="sender">the game</param> /// <param name="result">the result of the attack</param> /// <remarks> /// Displays a message, plays sound and redraws the screen /// </remarks> private static void AttackCompleted(object sender, AttackResult result) { bool isHuman; isHuman = _theGame.Player == HumanPlayer; if (isHuman) { Message = "You " + result.ToString(); } else { Message = "The AI " + result.ToString(); } var switchExpr = result.Value; switch (switchExpr) { case var @case when @case == ResultOfAttack.Destroyed: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameSound["Sink"]); break; } case var case1 when case1 == ResultOfAttack.GameOver: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameSound["Sink"]); while (Audio.SoundEffectPlaying(GameSound["Sink"])) { SwinGame.Delay(10); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed) { Audio.PlaySoundEffect(GameSound["Lose"]); } else { Audio.PlaySoundEffect(GameSound["Winner"]); } break; } case var case2 when case2 == ResultOfAttack.Hit: { PlayHitSequence(result.Row, result.Column, isHuman); break; } case var case3 when case3 == ResultOfAttack.Miss: { PlayMissSequence(result.Row, result.Column, isHuman); break; } case var case4 when case4 == ResultOfAttack.ShotAlready: { Audio.PlaySoundEffect(GameSound["Error"]); break; } } }
/// <summary> /// ''' Listens for attacks to be completed. /// ''' </summary> /// ''' <param name="sender">the game</param> /// ''' <param name="result">the result of the attack</param> /// ''' <remarks> /// ''' Displays a message, plays sound and redraws the screen /// ''' </remarks> private static void AttackCompleted(object sender, AttackResult result) { bool isHuman; isHuman = _theGame.Player == HumanPlayer; if (isHuman) { UtilityFunctions.Message = "You " + result.ToString(); } else { UtilityFunctions.Message = "The AI " + result.ToString(); } switch (result.Value) { case ResultOfAttack.Destroyed: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameResources.GameSound("Shipdestroyed")); if (isHuman) { shipleft--; showshipleft = ("There are " + shipleft.ToString() + " enemy Ship left"); } break; } case ResultOfAttack.GameOver: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameResources.GameSound("Sink")); while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink"))) { SwinGame.Delay(2); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed) { Audio.PlaySoundEffect(GameResources.GameSound("Lose")); } else { Audio.PlaySoundEffect(GameResources.GameSound("Winner")); } break; } case ResultOfAttack.Hit: { PlayHitSequence(result.Row, result.Column, isHuman); break; } case ResultOfAttack.Miss: { if (isHuman) { missleft--; showmissleft = ("You can only miss " + missleft.ToString() + " more times"); } PlayMissSequence(result.Row, result.Column, isHuman); break; } case ResultOfAttack.ShotAlready: { Audio.PlaySoundEffect(GameResources.GameSound("Error")); break; } } }
// <summary> // Listens for attacks to be completed. // </summary> // <param name="sender">the game</param> // <param name="result">the result of the attack</param> // <remarks> // Displays a message, plays sound and redraws the screen // </remarks> private static void AttackCompleted(object sender, AttackResult result) { bool isHuman; isHuman = _theGame.Player == HumanPlayer; if (isHuman) { UtilityFunctions.Message = "You " + result.ToString(); } else { UtilityFunctions.Message = "The AI " + result.ToString(); } switch (result.Value) { case var @case when @case == ResultOfAttack.Destroyed: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameResources.GameSound("Sink")); break; } case var case1 when case1 == ResultOfAttack.GameOver: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameResources.GameSound("Sink")); while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink"))) { SwinGame.Delay(3); SwinGame.RefreshScreen(); EndingGameController.DrawEndOfGame(); // fixed the delay issue with the audio sound effect when the game ends } if (HumanPlayer.IsDestroyed) { Audio.PlaySoundEffect(GameResources.GameSound("Lose")); } else { Audio.PlaySoundEffect(GameResources.GameSound("Winner")); } break; } case var case2 when case2 == ResultOfAttack.Hit: { PlayHitSequence(result.Row, result.Column, isHuman); break; } case var case3 when case3 == ResultOfAttack.Miss: { PlayMissSequence(result.Row, result.Column, isHuman); break; } case var case4 when case4 == ResultOfAttack.ShotAlready: { Audio.PlaySoundEffect(GameResources.GameSound("Error")); break; } } }