Example #1
0
 public Game(int maxx, int maxy, System.Windows.Forms.Timer t)
 {
     gameState = new PreGameState(this);
     resetGame(maxx,maxy);
     sound = new Sounds();
     timer = t;
 }
Example #2
0
 //Run to start/reset the game
 public static void Start()
 {
     PlayerBoard = new Board(new Rectangle((screenWidth - (boardWidth * gridSize)) / 2,
             (screenHeight - (boardHeight * gridSize)) / 2, boardWidth * gridSize, boardHeight * gridSize));
     GameBoards.Add(PlayerBoard);
     gameState = GameState.Play;
     PlayerBoard.fillUpcomingPieces();
     PlayerBoard.changeCurrentPiece();
     Highscore.ReadFromFile();
 }
Example #3
0
 private void gameOver()
 {
     timer.Stop();
     gameState = new GameOverState(this);
     PlayerNameForm pn=new PlayerNameForm();
     if (DialogResult.OK == pn.ShowDialog())
     {
         player.Name = pn.Ime;
         player.Date = DateTime.Now;
         BestPlayersForm bp = new BestPlayersForm(player);
         bp.Show();
     }
 }
Example #4
0
 public void newGame()
 {
     resetGame(MAXX,MAXY);
     activeForm = getRandomForm();
     tetrisForms.Add(activeForm);
     nextForm = getRandomForm();
     HasNewPoints = true;
     gameState = new ActiveState(this);
     timer.Start();
 }
Example #5
0
 public void Pause()
 {
     if (gameState as ActiveState != null)
     {
         gameState = new PausedState(this);
         timer.Stop();
     }
     else if (gameState as PausedState!=null)
     {
         timer.Start();
         gameState = new ActiveState(this);
     }
 }
Example #6
0
 static void ToMenu()
 {
     //Go to the main menu
     currentGameState = GameState.Menu;
     //Save the stats and achievements
     SaveStats();
 }
Example #7
0
        static void UpdateGame()
        {
            //Update world
            foreach (World w in gameWorld)
            {
                w.Update();
                //For singleplayer: if player is dead, game over
                if (currentGameMode == GameMode.Singleplayer)
                    if (!w.IsAlive)
                    {
                        SaveStats();
                        currentGameState = GameState.GameOver;
                    }
                //For multiplayer: go to the MPLost or MPWon game over screen, depending on if the player or the AI died
                if (currentGameMode == GameMode.Multiplayer)
                {
                    if (w.CurrentControlMode == ControlMode.Player && !w.IsAlive)
                        currentGameState = GameState.MPLost;
                    if (w.CurrentControlMode == ControlMode.AI && !w.IsAlive)
                        currentGameState = GameState.MPWon;
                }
            }

            //Update achievements
            foreach (Achievement a in achievementList)
                a.Update();

            //Pause game if esc is pressed
            if (InputState.isKeyPressed(pauseKey))
                currentGameState = GameState.Paused;
        }
Example #8
0
 static void ToAchievements()
 {
     //Set the gamestate to Achievements
     currentGameState = GameState.Achievements;
 }
Example #9
0
        static void StartSP()
        {
            gameWorld = new List<World>();

            //Set gamemode
            currentGameMode = GameMode.Singleplayer;
            //Load world
            GameWorld.Add(new World(new Rectangle(50, 70, 216, 360), 0, ControlMode.Player, false));
            //Change gamestate
            currentGameState = GameState.Playing;
        }
Example #10
0
        static void StartMP()
        {
            gameWorld = new List<World>();

            //Set gamemode
            currentGameMode = GameMode.Multiplayer;
            //Load worlds
            GameWorld.Add(new World(new Rectangle(50, 70, 240, 400), 0, ControlMode.Player, false));
            AIWorld = new World(new Rectangle(510, 70, 240, 400), 0, ControlMode.AI);
            GameWorld.Add(AIWorld);
            //Change gamestate
            currentGameState = GameState.Playing;
        }
Example #11
0
 static void Continue()
 {
     //Continue the game
     currentGameState = GameState.Playing;
 }
Example #12
0
        public static void Update(GameTime newGameTime)
        {
            //Update input
            InputState.update();
            //Update gametime
            gameTime = newGameTime;

            switch (currentGameState)
            {
                case GameState.Playing:
                    UpdateGame();
                    if (currentGameMode == GameMode.Singleplayer)
                    {
                        //Add time
                        if (prevTime != newGameTime.TotalGameTime.Seconds)
                        {
                            secondsPlayed++;
                            prevTime = newGameTime.TotalGameTime.Seconds;
                        }
                        //Get achievement
                        if (secondsPlayed == 600)
                            love.GetAchievement();
                        //Set level
                        if (secondsPlayed % levelTime == 0 && level <= maxLevel && lastLevelUp != secondsPlayed)
                        {
                            lastLevelUp = secondsPlayed;
                            level++;
                            if (level == maxLevel)
                                maxLevelReached.GetAchievement();
                        }
                    }
                    break;
                case GameState.Menu:
                    menuEmitter.Update();
                    mainMenu.Update();
                    break;
                case GameState.Paused:
                    //Unpause game if esc is pressed
                    if (InputState.isKeyPressed(pauseKey))
                        currentGameState = GameState.Playing;
                    pausedMenu.Update();
                    break;
                case GameState.StartScreen:
                    currentGameState = GameState.Menu;
                    break;
                case GameState.GameOver:
                    foreach (World w in gameWorld)
                        w.Update();
                    gameOverMenu.Update();
                    break;
                case GameState.MPWon:
                    //Get the mpWon achievement
                    mpWon.GetAchievement();
                    //Update achievements
                    foreach (Achievement a in achievementList)
                        a.Update();
                    //Update particles
                    menuEmitter.Update();
                    //Update the menu
                    mpGameOverMenu.Update();
                    break;
                case GameState.MPLost:
                    //Update the menu
                    mpGameOverMenu.Update();
                    break;
                case GameState.Achievements:
                    gotAchievements = 0;
                    //Check each achievement
                    for (int n = 0; n < achievementList.Count(); n++)
                    {
                        Achievement a = achievementList.ElementAt(n);
                        //If the achievement is achieved
                        if (a.Achieved)
                            //Add 1 to got achievements
                            gotAchievements++;
                    }
                    //Calculate locked achievements
                    lockedAchievements = achievementList.Count() - gotAchievements;
                    //If locked achievements = 1, get the last achievement
                    if (lockedAchievements == 1)
                        achievementWh0re.GetAchievement();
                    //Update achievements
                    foreach (Achievement a in achievementList)
                        a.Update();
                    //Update the menu
                    achievementsMenu.Update();
                    break;
            }
        }