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 ReadUserScore(int value) { NewFont("maven_pro_regular", "maven_pro_regular.ttf", 14); const int fromleft = 325; const int inputtop = 500; if (_Scores.Count == 0) { LoadScores(); } //GameController.GameState = GameState.ViewingHighScore; if (value > _Scores [_Scores.Count - 1].score) { Score s = new Score(); s.score = value; int x = 0; x = fromleft + SwinGame.TextWidth(_Fonts ["maven_pro_regular"], "Name: "); SwinGame.StartReadingText(Color.White, namesize, _Fonts ["maven_pro_regular"], x, inputtop); while (SwinGame.ReadingText()) { SwinGame.ProcessEvents(); UIController.DrawEndGame(); DrawHighScores(); SwinGame.DrawText("Name: ", Color.White, fromleft, inputtop); SwinGame.RefreshScreen(60); } s.Name = SwinGame.TextReadAsASCII(); if (s.Name.Length == 3) { s.Name = s.Name + new string (Convert.ToChar(" "), 3 - s.Name.Length); _Scores.RemoveAt(_Scores.Count - 1); _Scores.Add(s); _Scores.Sort(); SaveScores(); GameController.GameState = GameState.EndingRanking; } else { while (s.Name.Length != 3) { if (value > _Scores [_Scores.Count - 1].score) { s.score = value; x = fromleft + SwinGame.TextWidth(_Fonts ["maven_pro_regular"], "Name: "); SwinGame.StartReadingText(Color.White, namesize, _Fonts ["maven_pro_regular"], x, inputtop); while (SwinGame.ReadingText()) { SwinGame.ProcessEvents(); DrawHighScores(); SwinGame.DrawText("Name: ", Color.White, fromleft - 5, inputtop); SwinGame.DrawText("Your name must be at least 3 characters!", Color.White, fromleft - 5, inputtop + 15); SwinGame.RefreshScreen(60); } s.Name = SwinGame.TextReadAsASCII(); if (s.Name.Length == 3) { s.Name = s.Name + new string (Convert.ToChar(" "), 3 - s.Name.Length); _Scores.RemoveAt(_Scores.Count - 1); _Scores.Add(s); _Scores.Sort(); SaveScores(); } } } } } else { DrawHighScores(); GameController.GameState = GameState.EndingRanking; } }