コード例 #1
0
ファイル: GameManager.cs プロジェクト: Auron-tliar/MAI-CI
    // restart the simulation
    public void RestartSimulation()
    {
        EndText.gameObject.SetActive(false);
        RestartButton.SetActive(false);
        ReGenerateStatisticsButton.SetActive(false);

        for (int i = 0; i < _guardControllers.Count; i++)
        {
            _guardControllers[i].ResetGuard();
        }

        _timeLeft       = TurnTime;
        _turnsLeft      = TurnLimit;
        TimerField.text = _timeLeft.ToString("F4");
        TurnsLeft.text  = _turnsLeft.ToString();

        Destroy(_ninjaObject);

        if (_randomNinjaMode)
        {
            GenerateRandomNinjas();
            GameStage = GameStages.Simulation;
        }
        else
        {
            MapGrid.SetStartingNodes(true);

            GameStage = GameStages.PositionSelection;
            SelectCellText.SetActive(true);
        }
    }
コード例 #2
0
ファイル: GameStagesForm.cs プロジェクト: erbuka/andrea
        public GameStagesForm()
        {
            InitializeComponent();

            this.gameStages = GameStages.Load();
            this.UpdateList();
        }
コード例 #3
0
ファイル: GameManager.cs プロジェクト: Auron-tliar/MAI-CI
    // start the simulation
    public void StartSimulation()
    {
        GameStage = GameStages.PositionSelection;

        RouteCanvas.gameObject.SetActive(false);
        SimulationCanvas.gameObject.SetActive(true);
        MapGrid.SetDetections(NumberOfGuards);

        _timeLeft       = TurnTime;
        _turnsLeft      = TurnLimit;
        TimerField.text = _timeLeft.ToString("F4");
        TurnsLeft.text  = _turnsLeft.ToString();
        MapGrid.SetGoal();

        MapGrid.ClearRoutes();

        for (int i = 0; i < _guardControllers.Count; i++)
        {
            _guardControllers[i].ResetGuard();
        }

        if (_randomNinjaMode)
        {
            GenerateRandomNinjas();
            GameStage = GameStages.Simulation;
        }
        else
        {
            MapGrid.SetStartingNodes(true);

            SelectCellText.SetActive(true);
        }
    }
コード例 #4
0
        protected override void LoadContent()
        {
            this.IsMouseVisible = true;
            stages = GameStages.Game_Stage;
            // Create a new SpriteBatch, which can be used to draw textures.
            this.spriteBatch = new SpriteBatch(this.GraphicsDevice);

            GfxHandler.Load(this.Content);

            GoldCoin coin = new GoldCoin(new Vector2(300, 300), "TestObjects/coin");

            // testEnemyTex = Content.Load<Texture2D>(@"TestObjects/cockSprite");
            Vector2 enemyPos = new Vector2(550, 350);
            Vector2 pos      = new Vector2(
                GlobalVariables.WindowWidth / 2 - 140,
                GlobalVariables.WindowHeight / 2);

            this.sampleEnemy = new Enemy(enemyPos, @"TestObjects/cockSprite", 100, 100, 1, this.testLevel);
            this.testPlayer  = new TestChar(pos, @"Player/p1Rotation", 100, 100, 2, this.testLevel);

            this.testLevel = new Level(@"..\..\..\Content\Maps\testMap2.txt", this.testPlayer);

            this.testLevel.Assets.Add(coin);

            this.sampleEnemy.Level = this.testLevel;
            this.testPlayer.Level  = this.testLevel;
            this.testLevel.Enemies.Add(this.sampleEnemy);

            // TODO: Get Width and Heignt based on the level size?
            this.graphics.PreferredBackBufferWidth  = GlobalVariables.WindowWidth;  // set this value to the desired width of your window
            this.graphics.PreferredBackBufferHeight = GlobalVariables.WindowHeight; // set this value to the desired height of your window
            this.graphics.ApplyChanges();
        }
コード例 #5
0
ファイル: GameManager.cs プロジェクト: Auron-tliar/MAI-CI
 // to stop the simulation and change the game stage
 public void EndGame(string endMessage)
 {
     GameStage = GameStages.End;
     RestartButton.SetActive(true);
     ReGenerateStatisticsButton.SetActive(true);
     EndText.gameObject.SetActive(true);
     EndText.text = endMessage;
 }
コード例 #6
0
        public void Update(KeyboardState keyboardState)
        {
            //zakonczenie gry
            if (!EndGame)
            {
                CheckEndGame();
            }
            if (EndGame)
            {
                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    _currentStage = GameStages.MENU;
                }
            }
            // opcja dla pauzy oraz powrotu do dalszej gry
            else
            {
                if (keyboardState.IsKeyDown(Keys.Escape))
                {
                    if (_currentStage == GameStages.PLAYING)
                    {
                        _currentStage = GameStages.PAUSE;
                        pauseMenuView = new PauseMenuView(songResources);
                        MediaPlayer.Pause();
                    }
                    else
                    {
                        _currentStage = GameStages.PLAYING;
                        MediaPlayer.Resume();
                    }
                }
                if (pauseMenuView != null)
                {
                    if (pauseMenuView.Exit == true)
                    {
                        if (pauseMenuView.pauseStages == PauseStages.RETURN)
                        {
                            _currentStage = GameStages.PLAYING;
                            MediaPlayer.Resume();
                        }
                        else
                        {
                            _currentStage = GameStages.MENU;
                        }
                    }
                    else
                    {
                        pauseMenuView.Update(keyboardState);
                    }
                }

                if (_currentStage == GameStages.PLAYING)
                {
                    actualSongType.Update(keyboardState);
                }
            }
        }
コード例 #7
0
ファイル: GameManager.cs プロジェクト: Auron-tliar/MAI-CI
    // start with the selected settings
    public void RunSettings()
    {
        if (ReadFromFileField.isOn && !File.Exists(MapFilePathField.text))
        {
            ColorBlock cb = MapFilePathField.colors;
            cb.normalColor          = new Color(1f, 0.7f, 0.7f);
            MapFilePathField.colors = cb;
            return;
        }

        ReadMapFromFile          = ReadFromFileField.isOn;
        MapFilePath              = MapFilePathField.text;
        MapWidth                 = int.Parse(MapWidthField.text);
        MapHeight                = int.Parse(MapHeightField.text);
        NumberOfGuards           = int.Parse(NumberOfGuardsField.text);
        RouteGenotypeLength      = int.Parse(GenotypeLengthField.text);
        CrossoverPerStage        = int.Parse(CrossoverNumberField.text);
        DetectionRadius          = int.Parse(DetectionRadiusField.text);
        DetectionDecayTime       = int.Parse(DetectionDecayField.text);
        FitnessFunction          = (FitnessFunctions)(FitnessFunctionField.value);
        NumberOfSchemes          = int.Parse(NumberOfSchemesField.text);
        SimpleCrossover          = SimpleCrossoverField.isOn;
        UseMinFunction           = UseMinFunctionField.isOn;
        MutationProbability      = float.Parse(MutationProbabilityField.text);
        RouteMutationProbability = float.Parse(RouteMutationProbabilityField.text);
        NumberOfIterations       = int.Parse(NumberOfIterationsField.text);
        FitnessBinsX             = int.Parse(FitnessBinsXField.text);
        FitnessBinsY             = int.Parse(FitnessBinsYField.text);
        RandomSeed               = int.Parse(RandomSeedField.text);

        TurnTime  = float.Parse(TurnTimeField.text);
        TurnLimit = int.Parse(TurnLimitField.text);
        EnvironmentalNoiseProbability = float.Parse(EnvNoiseProbabilityField.text);
        EnvironmentalNoiseDegree      = int.Parse(EnvNoiseDegreeField.text);
        CrawlNoise        = float.Parse(CrawlNoiseField.text);
        WalkNoise         = float.Parse(WalkNoiseField.text);
        RunNoise          = float.Parse(RunNoiseField.text);
        NoiseRandomRange  = float.Parse(NoiseRadiusField.text);
        MinOutputToCheck  = float.Parse(MinOutputCheckField.text);
        MinOutputForAlarm = float.Parse(MinOutputAlarmField.text);
        RandomNinjaNumber = int.Parse(RandomNinjaNumberField.text);


        SettingsCanvas.gameObject.SetActive(false);
        RouteCanvas.gameObject.SetActive(true);

        if (RandomSeed != -1)
        {
            Random.InitState(RandomSeed);
        }
        if (!GenerateMap())
        {
            return;
        }
        SetGuards();
        GameStage = GameStages.RouteGeneration;
    }
コード例 #8
0
 void ResumeStage(GameStages stage)
 {
     currentStage = stage;
     if (wasTimerRunning)
     {
         adjustmentTimer.Start();
         wasTimerRunning = false;
     }
 }
コード例 #9
0
    private void PlayStage()
    {
        player.EnableGravity();
        player.EnableMove();
        player.MoveBirdUp();

        infoText.enabled = false;

        gameStage = GameStages.PLAY;
    }
コード例 #10
0
ファイル: GameManager.cs プロジェクト: Auron-tliar/MAI-CI
    // for the map tiles to call when they are clicked
    public void SelectStartCell(MapTileController selection)
    {
        SelectCellText.SetActive(false);
        MapGrid.SetStartingNodes(false);

        _ninjaObject = Instantiate(NinjaPrefab, selection.transform.position, new Quaternion());
        _ninjaNoise  = new Noise(new Vector2(_ninjaObject.transform.position.x, _ninjaObject.transform.position.y), 0f);

        GameStage = GameStages.Simulation;
    }
コード例 #11
0
        public GameStageController(SongResources proporties, bool isGameEnable)
        {
            songResources = proporties;
            _currentStage = GameStages.PLAYING;
            if (isGameEnable)
                actualSongType = new SongController(proporties);
            else
                actualSongType = new Editor(proporties);

        }
コード例 #12
0
ファイル: KwikEngine.cs プロジェクト: WildGenie/PuckControl
 void _game_GameStageChange(object sender, GameStages e)
 {
     if (e == GameStages.Playing || e == GameStages.Countdown)
     {
         this.StartTracking();
     }
     else
     {
         this.StopTracking();
     }
 }
コード例 #13
0
    public void GameOverStage()
    {
        player.DisableMove();

        infoText.text    = GAME_OVER_INFO_TEXT + points.ToString();
        infoText.enabled = true;
        retryBtn.enabled = true;

        animator.SetBool("isBirdBroken", true);

        gameStage = GameStages.GAME_OVER;
    }
コード例 #14
0
 public GameStageController(SongResources proporties, bool isGameEnable)
 {
     songResources = proporties;
     _currentStage = GameStages.PLAYING;
     if (isGameEnable)
     {
         actualSongType = new SongController(proporties);
     }
     else
     {
         actualSongType = new Editor(proporties);
     }
 }
コード例 #15
0
    private void OnBeat()
    {
        StartCoroutine(FadeOutFX((float)BeatSynchronizer.Instance.AudioSyncBeatIntervalSeconds - 2.0f / 60.0f));
        if (Animator)
        {
            Animator.SetTrigger("Beat");
        }
        GameStages gameStages = FindObjectOfType <GameStages>();

        if (gameStages)
        {
            gameStages.TriggerAnimations("FirstBirdHouse", GameStage);
        }
    }
コード例 #16
0
    public void DemoStage()
    {
        ResetPoint();
        player.ResetPlayer();
        player.DisableGravity();

        infoText.text    = INFO_TXT;
        infoText.enabled = true;
        retryBtn.enabled = false;

        animator.SetBool("isBirdBroken", false);

        ObsticleManager.DeleteAllObsticles();

        gameStage = GameStages.DEMO;
    }
コード例 #17
0
        public void Update(KeyboardState keyboardState)
        {
            //zakonczenie gry 
            if (!EndGame)
                CheckEndGame();
            if (EndGame)
            {
                if (keyboardState.IsKeyDown(Keys.Enter))
                    _currentStage = GameStages.MENU;
            }
            // opcja dla pauzy oraz powrotu do dalszej gry
            else
            {
                if (keyboardState.IsKeyDown(Keys.Escape))
                {
                    if (_currentStage == GameStages.PLAYING)
                    {
                        _currentStage = GameStages.PAUSE;
                        pauseMenuView = new PauseMenuView(songResources);
                        MediaPlayer.Pause();
                    }
                    else
                    {
                        _currentStage = GameStages.PLAYING;
                        MediaPlayer.Resume();
                    }
                }
                if (pauseMenuView != null)
                    if (pauseMenuView.Exit == true)
                    {
                        if (pauseMenuView.pauseStages == PauseStages.RETURN)
                        {
                            _currentStage = GameStages.PLAYING;
                            MediaPlayer.Resume();
                        }
                        else
                            _currentStage = GameStages.MENU;
                    }
                    else
                    {
                        pauseMenuView.Update(keyboardState);
                    }

                if (_currentStage == GameStages.PLAYING)
                    actualSongType.Update(keyboardState);
            }
        }
コード例 #18
0
 private void CheckEndGame()
 {
     if (actualSongType.End)
     {
         if (actualSongType is SongController)
         {
             _currentStage  = GameStages.SCOREBOARD;
             scoreBoardView = new ScoreBoardView(songResources);
             DrawResults();
         }
         else
         {
             _currentStage = GameStages.MENU;
         }
         MediaPlayer.Stop();
         EndGame = true;
     }
 }
コード例 #19
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }
            if (this.stages == GameStages.Game_Stage && this.testLevel.Character.CurrentHealth <= 0)
            {
                stages = GameStages.Death_Stage;
            }
            //if(stages == GameStages.Start_Stage)
            //{
            //    this.staRtScreen.Update(gameTime);
            //}

            if (stages == GameStages.Game_Stage)
            {
                timeSinceLastUpdate += gameTime.ElapsedGameTime.Milliseconds;
                if (timeSinceLastUpdate >= oneSec)
                {
                    timeSinceLastUpdate = 0;
                    this.testLevel.Character.CooldownTimer += 1;
                }
                this.testPlayer.Move();
                GfxHandler.GetSprite(this.testPlayer).Update(gameTime, this.testPlayer);

                foreach (Character enemy in this.testLevel.Enemies.ToList())
                {
                    enemy.Move();
                    GfxHandler.GetSprite(enemy).Update(gameTime, enemy);
                }

                foreach (Projectile projectile in this.testLevel.Projectiles.ToList())
                {
                    projectile.Move();
                    GfxHandler.GetSprite(projectile).Update(gameTime);
                }
            }
            else
            {
            }

            base.Update(gameTime);
        }
コード例 #20
0
ファイル: GameManager.cs プロジェクト: Auron-tliar/MAI-CI
    // Use this for initialization
    private void Awake()
    {
        // set the stage to the setting menu
        GameStage = GameStages.Settings;

        // get the main camera
        _mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();

        // open the log file for the fuzzy system
        sw = new StreamWriter("Fuzzy Log.txt", true);

        // if we don't want the setting screens (using within unity setting instead)
        if (!ShowGameSettingsMenu)
        {
            // then change the canvas and go strait to the GA
            SettingsCanvas.gameObject.SetActive(false);
            RouteCanvas.gameObject.SetActive(true);

            GameStage = GameStages.RouteGeneration;

            if (RandomSeed != -1)
            {
                Random.InitState(RandomSeed);
            }
            GenerateMap();
            SetGuards();
        }
        else
        {
            // otherwise wait for the user to select settings
            SettingsCanvas.gameObject.SetActive(true);
            RouteCanvas.gameObject.SetActive(false);

            if (PlayerPrefs.HasKey("SavedSettings"))
            {
                LoadSettingsButton.interactable = true;
                LoadSettingsButtonClick();
            }
            else
            {
                LoadSettingsButton.interactable = false;
            }
        }
    }
コード例 #21
0
ファイル: GameEngine.cs プロジェクト: Rattatak/LeGame
        protected override void LoadContent()
        {
            this.IsMouseVisible = true;

            this.graphics.PreferredBackBufferWidth = GlobalVariables.WindowWidthDefault; // set this value to the desired width of your window
            this.graphics.PreferredBackBufferHeight = GlobalVariables.WindowHeightDefault;   // set this value to the desired height of your window
            this.graphics.ApplyChanges();

            this.statPanel = new StatPanel();
            this.startScreen = new StartScreen();
            this.deathScreen = new DeathScreen();

            this.stage = GameStages.Start_Stage;

            // Create a new SpriteBatch, which can be used to draw textures.
            this.spriteBatch = new SpriteBatch(this.GraphicsDevice);

            GfxHandler.Load(this.Content);

            this.startScreen.Load(this.Content);
            this.deathScreen.Load(this.Content);
            this.statPanel.Load(this.Content);
        }
コード例 #22
0
        protected override void LoadContent()
        {
            this.IsMouseVisible = true;

            this.graphics.PreferredBackBufferWidth  = GlobalVariables.WindowWidthDefault;  // set this value to the desired width of your window
            this.graphics.PreferredBackBufferHeight = GlobalVariables.WindowHeightDefault; // set this value to the desired height of your window
            this.graphics.ApplyChanges();

            this.statPanel   = new StatPanel();
            this.startScreen = new StartScreen();
            this.deathScreen = new DeathScreen();

            this.stage = GameStages.Start_Stage;

            // Create a new SpriteBatch, which can be used to draw textures.
            this.spriteBatch = new SpriteBatch(this.GraphicsDevice);

            GfxHandler.Load(this.Content);

            this.startScreen.Load(this.Content);
            this.deathScreen.Load(this.Content);
            this.statPanel.Load(this.Content);
        }
コード例 #23
0
        protected override void Update(GameTime gameTime)
        {
            GlobalVariables.GlobalTimer += gameTime.ElapsedGameTime.Milliseconds;

            MouseState mouse = Mouse.GetState();

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (this.stage == GameStages.Start_Stage)
            {
                string characterClass = this.startScreen.IsClicked();

                if (characterClass != null)
                {
                    if (characterClass == "Redhead")
                    {
                        this.player = PlayerFacory.MakePlayer(PlayerChars.Redhead);
                    }
                    else if (characterClass == "Guy")
                    {
                        this.player = PlayerFacory.MakePlayer(PlayerChars.TheGuy);
                    }
                    else if (characterClass == "Blondie")
                    {
                        this.player = PlayerFacory.MakePlayer(PlayerChars.Blondy);
                    }

                    this.startScreen.UnloadButtons();
                    this.stage = GameStages.GameStage;

                    this.player.Level = LevelFactory.MakeLevel(this.player, Maps.HouseMap);
                }

                this.startScreen.Update(mouse);
            }

            if (this.stage == GameStages.DeathStage)
            {
                this.player.Level = null;
                string death = this.deathScreen.IsClicked();
                if (death != null)
                {
                    this.startScreen.UnloadButtons();
                    this.stage = GameStages.Start_Stage;
                }

                this.deathScreen.Update(mouse);
            }

            if (this.stage == GameStages.GameStage)
            {
                GfxHandler.UpdateLevel(gameTime, this.player.Level);

                if (this.player.CurrentHealth <= 0)
                {
                    this.stage        = GameStages.DeathStage;
                    this.player.Level = null;
                }
            }

            base.Update(gameTime);
        }
コード例 #24
0
 void ChangeStage(GameStages stage)
 {
     currentStage = stage;
     StartStage();
 }
コード例 #25
0
ファイル: GameManager.cs プロジェクト: Auron-tliar/MAI-CI
    // construct map from tiles based on the generated or loaded map
    private bool GenerateMap()
    {
        if (ReadMapFromFile)
        {
            try
            {
                MapGrid   = new Map(MapFilePath, FitnessFunction);
                MapWidth  = MapGrid.Width;
                MapHeight = MapGrid.Height;
            }
            catch (MapFileException ex)
            {
                ex.streamReader.Close();
                ColorBlock cbl = MapFilePathField.colors;
                cbl.normalColor         = new Color(1f, 0.7f, 0.7f);
                MapFilePathField.colors = cbl;

                GameStage = GameStages.Settings;
                SettingsCanvas.gameObject.SetActive(true);
                RouteCanvas.gameObject.SetActive(false);

                return(false);
            }
        }
        else
        {
            MapGrid = new Map(MapWidth, MapHeight, FitnessFunction);
        }

        GameObject        tempObject;
        Node              tempNode;
        MapTileController tempTile;

        for (int x = 0; x < MapWidth; x++)
        {
            for (int y = 0; y < MapHeight; y++)
            {
                tempObject    = Instantiate(MapTilePrefab, MapContainer);
                tempNode      = MapGrid.GetNode(x, y);
                tempNode.Tile = tempObject;
                tempTile      = tempObject.GetComponent <MapTileController>();
                for (int i = 0; i < 4; i++)
                {
                    tempTile.ModifyBorder((Node.Dir)(i), tempNode.Edges[(Node.Dir)(i)].IsPassable,
                                          tempNode.Edges[(Node.Dir)(i)].IsPerceptible);
                }
                tempObject.transform.position = new Vector3(x, y, 0f);
            }
        }


        _mainCamera.orthographicSize   = MapHeight / 2f + 1;
        _mainCamera.transform.position = new Vector3(MapWidth / 2f, MapHeight / 2f - 0.5f, _mainCamera.transform.position.z);

        CameraBoundaries cb = _mainCamera.GetComponent <CameraBoundaries>();

        cb.BottomBoundary = -1.5f;
        cb.LeftBoundary   = -1.5f;
        cb.TopBoundary    = MapHeight + 0.5f;
        cb.RightBoundary  = MapWidth + 0.5f;

        cb.Reinitialize();

        return(true);
    }
コード例 #26
0
ファイル: GameEngine.cs プロジェクト: Rattatak/LeGame
        protected override void Update(GameTime gameTime)
        {
            GlobalVariables.GlobalTimer += gameTime.ElapsedGameTime.Milliseconds;

            MouseState mouse = Mouse.GetState();

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (this.stage == GameStages.Start_Stage)
            {
                string characterClass = this.startScreen.IsClicked();

                if (characterClass != null)
                {
                    if (characterClass == "Redhead")
                    {
                        this.player = PlayerFacory.MakePlayer(PlayerChars.Redhead);
                    }
                    else if (characterClass == "Guy")
                    {
                        this.player = PlayerFacory.MakePlayer(PlayerChars.TheGuy);
                    }
                    else if (characterClass == "Blondie")
                    {
                        this.player = PlayerFacory.MakePlayer(PlayerChars.Blondy);
                    }

                    this.startScreen.UnloadButtons();
                    this.stage = GameStages.GameStage;

                    this.player.Level = LevelFactory.MakeLevel(this.player);
                }

                this.startScreen.Update(mouse);
            }

            if (this.stage == GameStages.DeathStage)
            {
                this.player.Level = null;
                string death = this.deathScreen.IsClicked();
                if (death != null)
                {
                    this.startScreen.UnloadButtons();
                    this.stage = GameStages.Start_Stage;
                }

                this.deathScreen.Update(mouse);
            }

            if (this.stage == GameStages.GameStage)
            {
                GfxHandler.UpdateLevel(gameTime, this.player.Level);

                if (this.player.CurrentHealth <= 0)
                {
                    this.stage = GameStages.DeathStage;
                    this.player.Level = null;
                }
            }

            base.Update(gameTime);
        }
コード例 #27
0
 /// <summary>
 /// Validates the next step of the snake.
 /// </summary>
 /// <param name="newposition">The new position.</param>
 /// <param name="troncolor">The tron's color.</param>
 private static void ValidateNextStep(Position newposition, Tron.TronColors troncolor)
 {
     try
     {
         switch (map[newposition.X, newposition.Y])
         {
             case ' ':
                 foreach (Tron oneTron in trons)
                 {
                     if (oneTron.TronColor == troncolor)
                     {
                         // Draw the tron on the map and the display.
                         oneTron.Position = newposition;
                         RefreshChar(oneTron.Position, oneTron.Draw());
                         map[oneTron.Position.X, oneTron.Position.Y] = oneTron.Draw();
                     }
                 }
                 break;
             case 'x':
             case '+':
             case '#':
                 foreach (Tron oneTron in trons)
                 {
                     if (oneTron.TronColor == troncolor)
                     {
                         // Sets the tron's alive status to false.
                         oneTron.IsAlive = false;
                     }
                 }
                 gameStatus = GameStages.Menu;
                 break;
         }
     }
     catch
     { }
 }
コード例 #28
0
        /// <summary>
        /// The main method of the Program.
        /// </summary>
        /// <param name="args">The input arguments.</param>
        static void Main(string[] args)
        {
            try
            {
                while (!gameFinished)
                {
                    #region Menu

                    // The menu stage.
                    if (gameStatus == GameStages.Menu)
                    {
                        #region RefreshDisplay

                        DisplayMenu();

                        #endregion RefreshDisplay

                        // Repeat the key read until a valid key is pushed.
                        while (gameStatus == GameStages.Menu)
                        {
                            #region HandleInput

                            // A key was pushed.
                            if (Console.KeyAvailable)
                            {
                                // Handle the key input.
                                switch (Console.ReadKey().Key)
                                {
                                    case ConsoleKey.D1:
                                    case ConsoleKey.NumPad1:
                                        gameStatus = GameStages.Game;
                                        break;
                                    case ConsoleKey.D2:
                                    case ConsoleKey.NumPad2:
                                        gameStatus = GameStages.Options;
                                        break;
                                    case ConsoleKey.D3:
                                    case ConsoleKey.NumPad3:
                                        gameStatus = GameStages.Exit;
                                        break;
                                }

                                // Delete the read key input.
                                DeleteKeyInput();
                            }

                            #endregion HandleInput
                        }
                    }

                    #endregion Menu

                    #region Game

                    // The game stage.
                    else if (gameStatus == GameStages.Game)
                    {
                        #region PreSet

                        // Refresh the tron.
                        trons.Clear();
                        trons.Add(new Tron(new Position(11, 14), Tron.TronColors.Red, Tron.Directions.Right, true));
                        trons.Add(new Tron(new Position(11, 63), Tron.TronColors.Blue, Tron.Directions.Left, true));

                        // Clears the map and repositions the trons.
                        for (int i = 1; i < mapHeight - 1; i++)
                        {
                            for (int j = 1; j < mapWidth - 1; j++)
                            {
                                map[i, j] = ' ';
                            }
                        }
                        
                        // Put the trons on the map.
                        map[trons[0].Position.X, trons[0].Position.Y] = trons[0].Draw();
                        map[trons[1].Position.X, trons[1].Position.Y] = trons[1].Draw();

                        // Set the game difficulty.
                        switch (gameDifficulty)
                        {
                            case GameDifficulties.Easy:
                                sleepTime = 65;
                                break;
                            case GameDifficulties.Normal:
                                sleepTime = 50;
                                break;
                            case GameDifficulties.Hard:
                                sleepTime = 40;
                                break;
                        }

                        #endregion PreSet

                        #region RefreshDisplay

                        DisplayMap();

                        #endregion RefreshDisplay

                        // Repeat while the game is active.
                        while (gameStatus == GameStages.Game)
                        {
                            #region HandleInput

                            // A key was pushed.
                            if (Console.KeyAvailable)
                            {
                                // Handle the key input.
                                switch (Console.ReadKey().Key)
                                {
                                    case ConsoleKey.W:
                                        if (trons[0].Direction != Tron.Directions.Down)
                                        {
                                            trons[0].Direction = Tron.Directions.Up;
                                        }
                                        break;
                                    case ConsoleKey.UpArrow:
                                        if (trons[1].Direction != Tron.Directions.Down)
                                        {
                                            trons[1].Direction = Tron.Directions.Up;
                                        }
                                        break;
                                    case ConsoleKey.A:
                                        if (trons[0].Direction != Tron.Directions.Right)
                                        {
                                            trons[0].Direction = Tron.Directions.Left;
                                        }
                                        break;
                                    case ConsoleKey.LeftArrow:
                                        if (trons[1].Direction != Tron.Directions.Right)
                                        {
                                            trons[1].Direction = Tron.Directions.Left;
                                        }
                                        break;
                                    case ConsoleKey.D:
                                        if (trons[0].Direction != Tron.Directions.Left)
                                        {
                                            trons[0].Direction = Tron.Directions.Right;
                                        }
                                        break;
                                    case ConsoleKey.RightArrow:
                                        if (trons[1].Direction != Tron.Directions.Left)
                                        {
                                            trons[1].Direction = Tron.Directions.Right;
                                        }
                                        break;
                                    case ConsoleKey.S:
                                        if (trons[0].Direction != Tron.Directions.Up)
                                        {
                                            trons[0].Direction = Tron.Directions.Down;
                                        }
                                        break;
                                    case ConsoleKey.DownArrow:
                                        if (trons[1].Direction != Tron.Directions.Up)
                                        {
                                            trons[1].Direction = Tron.Directions.Down;
                                        }
                                        break;
                                    case ConsoleKey.Escape:
                                        gameStatus = GameStages.Menu;
                                        break;
                                }

                                // Delete the read key input.
                                DeleteKeyInput();
                            }

                            #endregion HandleInput

                            #region HandleChanges

                            // Only handle the changes in the game stage.
                            if (gameStatus == GameStages.Game)
                            {
                                #region MoveTrons

                                // The trons move.
                                MoveTrons();

                                #endregion MoveTrons

                                #region CollisionDetection

                                if (trons[0].IsAlive == false && trons[1].IsAlive == false)
                                {
                                    Console.Write("Draw.");
                                    Thread.Sleep(2000);
                                }
                                else if (trons[0].IsAlive == true && trons[1].IsAlive == false)
                                {
                                    Console.Write("Red player wins.");
                                    Thread.Sleep(2000);
                                }
                                else if (trons[0].IsAlive == false && trons[1].IsAlive == true)
                                {
                                    Console.Write("Blue player wins.");
                                    Thread.Sleep(2000);
                                }

                                #endregion CollisionDetection
                            }

                            #endregion HandleChanges

                            Thread.Sleep(sleepTime);
                        }
                    }

                    #endregion Game

                    #region Options

                    // The options stage.
                    else if (gameStatus == GameStages.Options)
                    {
                        #region RefreshDisplay

                        DisplayOptions();
                        optionsPointer = 1;

                        #endregion RefreshDisplay

                        // Repeat the key read until the escape is pushed.
                        while (gameStatus == GameStages.Options)
                        {
                            #region HandleInput

                            // A key was pushed.
                            if (Console.KeyAvailable)
                            {
                                // Handle the key input.
                                switch (Console.ReadKey().Key)
                                {
                                    case ConsoleKey.Escape:
                                        gameStatus = GameStages.Menu;
                                        break;
                                    case ConsoleKey.LeftArrow:
                                        switch (optionsPointer)
                                        {
                                            case 1:
                                                if (coloredMap)
                                                {
                                                    coloredMap = false;
                                                    ChangeText(new Position(2, 7), "Off");
                                                }
                                                else
                                                {
                                                    coloredMap = true;
                                                    ChangeText(new Position(2, 7), "On ");
                                                }
                                                break;
                                            case 2:
                                                if (gameDifficulty == GameDifficulties.Hard)
                                                {
                                                    gameDifficulty = GameDifficulties.Normal;
                                                    ChangeText(new Position(4, 12), "Normal");
                                                }
                                                else if (gameDifficulty == GameDifficulties.Normal)
                                                {
                                                    gameDifficulty = GameDifficulties.Easy;
                                                    ChangeText(new Position(4, 12), " Easy ");
                                                }
                                                break;
                                        }
                                        break;
                                    case ConsoleKey.RightArrow:
                                        switch (optionsPointer)
                                        {
                                            case 1:
                                                if (coloredMap)
                                                {
                                                    coloredMap = false;
                                                    ChangeText(new Position(2, 7), "Off");
                                                }
                                                else
                                                {
                                                    coloredMap = true;
                                                    ChangeText(new Position(2, 7), "On ");
                                                }
                                                break;
                                            case 2:
                                                if (gameDifficulty == GameDifficulties.Easy)
                                                {
                                                    gameDifficulty = GameDifficulties.Normal;
                                                    ChangeText(new Position(4, 12), "Normal");
                                                }
                                                else if (gameDifficulty == GameDifficulties.Normal)
                                                {
                                                    gameDifficulty = GameDifficulties.Hard;
                                                    ChangeText(new Position(4, 12), " Hard ");
                                                }
                                                break;
                                        }
                                        break;
                                    case ConsoleKey.UpArrow:
                                        if (optionsPointer > 1)
                                        {
                                            optionsPointer--;
                                            ChangeOption(optionsPointer, optionsPointer + 1);
                                        }
                                        else
                                        {
                                            optionsPointer = optionsNumber;
                                            ChangeOption(optionsNumber, 1);
                                        }
                                        break;
                                    case ConsoleKey.DownArrow:
                                        if (optionsPointer < optionsNumber)
                                        {
                                            optionsPointer++;
                                            ChangeOption(optionsPointer, optionsPointer - 1);
                                        }
                                        else
                                        {
                                            optionsPointer = 1;
                                            ChangeOption(1, optionsNumber);
                                        }
                                        break;
                                }

                                // Delete the read key input.
                                DeleteKeyInput();
                            }

                            #endregion HandleInput
                        }
                    }

                    #endregion Options

                    #region Exit

                    // The exit stage.
                    else if (gameStatus == GameStages.Exit)
                    {
                        // End the program.
                        gameFinished = true;
                    }

                    #endregion Exit
                }
            }
            catch
            { }
        }
コード例 #29
0
        private void CheckEndGame()
        {
            if (actualSongType.End)
            {
                if (actualSongType is SongController)
                {
                    _currentStage = GameStages.SCOREBOARD;
                    scoreBoardView = new ScoreBoardView(songResources);
                    DrawResults();
                }
                else
                    _currentStage = GameStages.MENU;
                MediaPlayer.Stop();
                EndGame = true;
            }

        }