public static void HandleEndOfGameInput() { if (SwinGame.MouseClicked(MouseButton.LeftButton)) { if (SwinGame.PointInRect(SwinGame.MousePosition(), 500, 500, 200, 99)) { //gameState = GameState.PlayingGame; //myBoard = new Board (); //myBoard.GenerateBlock (); //check for matching, delete matching blocks and generate new blocks until there is no matching blocks in it //while (myBoard.CheckMatching ()) //{ // myBoard.CheckMatching (); // myBoard.GenerateBlock (); //} SwinGame.PlaySoundEffect(UIController.GameSound("button")); SwinGame.ResetTimer(UIController.gameTimer); myBoard.Score = 0; UIController.EndTime = 60; GameState = GameState.PlayingGame; } else if (SwinGame.PointInRect(SwinGame.MousePosition(), 60, 500, 200, 99)) { SwinGame.PlaySoundEffect(UIController.GameSound("button")); gameState = GameState.ViewingGameMenu; } } }
public static void HandleRankinginput() { if (SwinGame.MouseClicked(MouseButton.LeftButton)) { if (SwinGame.PointInRect(SwinGame.MousePosition(), 280, 500, 200, 99)) { //Go back to the game menu page SwinGame.PlaySoundEffect(UIController.GameSound("button")); gameState = GameState.ViewingGameMenu; } } }
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; } } }
public void GenerateBlock2() { List <ColorBlock> colorBlocks = new List <ColorBlock> (); BlockFactory myFactory = new BlockFactory(); int a = 12, b = 12; //a for x position, b for y position of blocks while (b < 500) { for (int x = 0; x < 9; x++) { for (int y = 0; y < 9; y++) { if (_blocks [x, y] == null || _blocks [x, y].Color == Color.Black) { colorBlocks.Add(_blocks [x, y]); AddBlock(x, y, myFactory.CreateRandBlock(a, b)); } else if (_blocks [x, y].Color == Color.Wheat) { colorBlocks.Add(_blocks [x, y]); AddBlock(x, y, myFactory.CreateTimerBlock(a, b)); } else if (_blocks [x, y].Color == Color.Grey) { colorBlocks.Add(_blocks [x, y]); AddBlock(x, y, myFactory.CreateRainbowBlock(a, b)); } //increment x position a += 59; } //reset x position to 12 and increment y position a = 12; b += 69; } } List <Sprite> _destroyedSprites = new List <Sprite> (); Sprite sprite = SwinGame.CreateSprite(SwinGame.BitmapNamed("destroyedani"), SwinGame.AnimationScriptNamed("destroyedanimation")); foreach (ColorBlock block in colorBlocks) { sprite = SwinGame.CreateSprite(SwinGame.BitmapNamed("destroyedani"), SwinGame.AnimationScriptNamed("destroyedanimation")); SwinGame.SpriteStartAnimation(sprite, "dematerialize"); SwinGame.SpriteSetX(sprite, block.X - 20); SwinGame.SpriteSetY(sprite, block.Y - 15); _destroyedSprites.Add(sprite); } if (!sprite.AnimationHasEnded) { SwinGame.PlaySoundEffect(UIController.GameSound("explosion")); SwinGame.PauseTimer("timer"); } do { //SwinGame.DrawAllSprites(); foreach (Sprite _sprite in _destroyedSprites) { SwinGame.DrawSprite(_sprite); } SwinGame.RefreshScreen(60); SwinGame.UpdateAllSprites(); } while(!sprite.AnimationHasEnded); if (sprite.AnimationHasEnded && UIController.TimerPaused == false) { SwinGame.ResumeTimer("timer"); } }
public static void Main() { //Open the game window SwinGame.OpenGraphicsWindow("Bejeweled", 750, 630); //549, 700 UIController.LoadResources(); SwinGame.PlayMusic(UIController.GameMusic("Background")); //generate blocks for the board GameController.Board.GenerateBlock(); //check for matching, delete matching blocks and generate new blocks until there is no matching blocks in it while (GameController.Board.CheckMatching()) { GameController.Board.CheckMatching(); GameController.Board.GenerateBlock(); } //initialize the score to 0 GameController.Board.Score = 0; //Run the game loop while (false == SwinGame.WindowCloseRequested() && GameController.GameState != GameState.Quitting) { //Fetch the next batch of UI interaction SwinGame.ProcessEvents(); //Clear the screen and draw the framerate SwinGame.ClearScreen(Color.Black); if (GameController.GameState == GameState.ViewingGameMenu) { UIController.DrawMenuPage(); GameController.HandleUserInput(); } //show the instruction page if (GameController.GameState == GameState.ViewingGameInstruction) { UIController.DrawInstructionPage(); GameController.HandleUserInput(); } //if player chose to start the game, display the board and start the game if (GameController.GameState == GameState.PlayingGame) { //Draw game board GameController.Board.DrawBoard(); SwinGame.StopMusic(); //when time reaches 1 minute, show the final score page if (UIController.TimeTicks >= UIController.EndTime) { GameController.GameState = GameState.EndingGame; SwinGame.PlaySoundEffect(UIController.GameSound("endgame")); } GameController.HandleUserInput(); GameController.Board.GenerateBlock2(); } if (GameController.GameState == GameState.ViewingHighScore) { UIController.DrawRanking(); HighScore.DrawHighScores(); GameController.HandleRankinginput(); } //if the game ends, show the final score page if (GameController.GameState == GameState.EndingGame) { UIController.DrawEndGame(); HighScore.ReadUserScore(GameController.Board.Score); //GameController.HandleUserInput (); //GameController.HandleEndOfGameInput (); //HighScore.ReadUserScore (GameController.Board.Score); } if (GameController.GameState == GameState.EndingRanking) { UIController.DrawEndRanking(); HighScore.DrawHighScores(); GameController.HandleEndOfGameInput(); } SwinGame.RefreshScreen(60); SwinGame.UpdateAllSprites(); } UIController.FreeResources(); }
public static void HandleGamePlayInput() { //SwinGame.ProcessEvents (); //pressing P to pause game if (SwinGame.KeyTyped(KeyCode.vk_p)) { if (!UIController.TimerPaused) { SwinGame.PauseTimer("timer"); UIController.TimerPaused = true; } else { SwinGame.ResumeTimer("timer"); UIController.TimerPaused = false; } } if (SwinGame.MouseClicked(MouseButton.LeftButton)) { myBoard.SelectBlockAt(SwinGame.MousePosition()); firstSelected = myBoard.SelectedBlock; if (firstSelected != null) { SwinGame.PlaySoundEffect(UIController.GameSound("leftclick")); } if (SwinGame.PointInRect(SwinGame.MousePosition(), 565, 400, 160, 71)) //menu button { //Go back to the game menu page SwinGame.PlaySoundEffect(UIController.GameSound("button")); gameState = GameState.ViewingGameMenu; } else if (SwinGame.PointInRect(SwinGame.MousePosition(), 565, 480, 160, 71)) //exit button { SwinGame.PlaySoundEffect(UIController.GameSound("button")); SwinGame.Delay(300); gameState = GameState.Quitting; } else if (SwinGame.PointInRect(SwinGame.MousePosition(), 565, 320, 160, 71)) { if (!UIController.TimerPaused) { SwinGame.PlaySoundEffect(UIController.GameSound("button")); SwinGame.PauseTimer("timer"); UIController.TimerPaused = true; } else { SwinGame.PlaySoundEffect(UIController.GameSound("button")); SwinGame.ResumeTimer("timer"); UIController.TimerPaused = false; } } } if (SwinGame.MouseClicked(MouseButton.RightButton)) { myBoard.SelectBlockAt(SwinGame.MousePosition()); secondSelected = myBoard.SelectedBlock; if (secondSelected != null) { SwinGame.PlaySoundEffect(UIController.GameSound("rightclick")); } } //Swap the selected blocks if (firstSelected != null && secondSelected != null) { myBoard.Swap(firstSelected, secondSelected); if (myBoard.CheckMatching() == true) { SwinGame.PlaySoundEffect(UIController.GameSound("match")); } if (myBoard.CheckMatching() == false) { myBoard.Swap(firstSelected, secondSelected); SwinGame.PlaySoundEffect(UIController.GameSound("errormatch")); firstSelected = null; secondSelected = null; } } //if there is matching of blocks in the board, check the matching, else swap the blocks back to original places if (myBoard.CheckMatching()) { myBoard.CheckMatching(); firstSelected = null; secondSelected = null; } else { myBoard.Swap(firstSelected, secondSelected); } }