Esempio n. 1
0
 private void Step(Direction dir)
 {
     if (!IsStarted)
     {
         return;
     }
     if (_isShooting)
     {
         if (!_gameLogic.ShootArrow(dir))
         {
             //some error happend
         }
         ActArrow       = _gameLogic.PlayerArrows;
         _isShooting    = false;
         ArrowShootText = "Change!";
     }
     else if (!_gameLogic.Step(dir))
     {
         //some error, try to catch.. (game is not running or things like this)
     }
 }
Esempio n. 2
0
        private static void Game()
        {
            System.Console.WriteLine("Mit cselekszel?\n");
            System.Console.WriteLine("1_ - Lépés szomszédos mezőre\n" +
                                     "\t11 - Fel\n" +
                                     "\t12 - Le\n" +
                                     "\t13 - Jobbra\n" +
                                     "\t14 - Balra\n" +
                                     "2_ - Nyíl kilövése\n" +
                                     "\t21 - Fel\n" +
                                     "\t22 - Le\n" +
                                     "\t23 - Jobbra\n" +
                                     "\t24 - Balra\n" +
                                     "3 - Arany felvétele\n" +
                                     //"4 - Mentés\n" +
                                     //"5 - Betöltés\n" +
                                     "0 - Kilépés");
            int dirInt;

            ReadSafeInput(out dirInt);
            switch (dirInt)
            {
            case 11:
            case 12:
            case 13:
            case 14:
                var dirStep = GetDirection(dirInt - 10);
                if (dirStep == null)
                {
                    return;
                }
                if (!_game.Step((Direction)dirStep))
                {
                    //some error, try to catch.. (game is not running or things like this)
                }
                break;

            case 21:
            case 22:
            case 23:
            case 24:
                var dirArrow = GetDirection(dirInt - 20);
                if (dirArrow == null)
                {
                    return;
                }
                _lastArrow = true;
                if (!_game.ShootArrow((Direction)dirArrow))
                {
                    //some error, try to catch.. (game is not running or things like this)
                }

                break;

            case 3:
                if (!_game.GrabGold())
                {
                    //no gold in actual field
                    System.Console.WriteLine("Nincs itt az arany. Nem csillog semmi!");
                    Game();
                }
                break;

            case 4:
                //save
                if (!_game.IsStarted)
                {
                    return;
                }
                System.Console.WriteLine("\nAdd meg a fájl nevét: ");
                var fileName = System.Console.ReadLine();
                if (!String.IsNullOrWhiteSpace(fileName))
                {
                    try
                    {
                        fileName = "./" + fileName;
                        _game.Save(fileName);
                        System.Console.WriteLine("Sikeres mentés! \n");
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine("Sikertelen mentés: " + e.Message);
                    }
                }
                Game();
                break;

            case 5:
                //load
                System.Console.WriteLine("\nAdd meg a fájl nevét: ");
                var loadFileName = System.Console.ReadLine();
                if (!String.IsNullOrWhiteSpace(loadFileName) && File.Exists(loadFileName))
                {
                    try
                    {
                        var loadGame = _dataAccess.LoadGame(loadFileName);
                        System.Console.WriteLine("Sikeres betöltés!\n");
                        SetGame(loadGame);
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine("Sikertelen betöltés: " + e.Message);
                        Game();
                    }
                }
                else
                {
                    Game();
                }
                break;

            //case 5:
            //    //load
            //    System.Console.WriteLine("\nAdd meg a fájl nevét: ");
            //    var loadFileName = System.Console.ReadLine();
            //    if (!String.IsNullOrWhiteSpace(loadFileName) && File.Exists(loadFileName))
            //    {
            //        try
            //        {
            //            SetGame(_dataAccess.LoadGame(loadFileName));
            //        }
            //        catch (Exception e)
            //        {
            //            System.Console.WriteLine("Sikertelen mentés: " + e.Message);
            //            Game();
            //        }
            //    }
            //    else
            //    {
            //        Game();
            //    }
            //    break;



            case 0:
                return;

                break;

            default:
                Game();
                break;
            }
            System.Console.WriteLine("");
        }