예제 #1
0
        private void StartGame()
        {
            _setting = GetCurrSetting();
            //save current setting
            Levels.SetSettings(_setting, _diffIndex);

            _gameLogic = new WumpusGameLogic(_setting, _dataAccess);
            SetGameEventHandlers();
            try
            {
                if (_setting.Size > 50)
                {
                    throw new Exception();
                }
                SetExtraSettings();

                //start the game
                _gameLogic.StartGame();

                ActSize  = _setting.Size;
                ActArrow = _gameLogic.PlayerArrows;
                OnPropertyChanged("ActSize");

                UpdateField();
                Info       = "Mit cselekszel? Mozogni a nyíl gombokkal illetve a nyíl billentyűkkel is tudsz!";
                ActPosText = "Beléptél a barlangba, a bal alsó sarkában vagy.";
            }
            catch (Exception)
            {
                MessageBox.Show("Hibás játékparaméterek! Kérlek Figyelj, hogy értelmes adatokat adj meg!", "Hiba", MessageBoxButton.OK, MessageBoxImage.Error);
                _gameLogic = new WumpusGameLogic();
            }
        }
예제 #2
0
 public WumpusGameLogic(WumpusSetting setting, IWumpusDataAccess dataAccess)
 {
     _dataAccess    = dataAccess;
     Setting        = setting;
     IsStarted      = false;
     _isSaving      = false;
     ShowFieldEnd   = true;
     ShowFieldDebug = false;
 }
예제 #3
0
 public void Load(WumpusSetting setting, Pair playerCord, int playerArrow, int playerPoint, List <WumpusField> cave,
                  bool isStarted)
 {
     Setting      = setting;
     PlayerCord   = playerCord;
     PlayerArrows = playerArrow;
     PlayerPoints = playerPoint;
     if (_cave != null)
     {
         _cave.Clear();
     }
     _cave     = cave;
     IsStarted = isStarted;
     _isSaving = false;
 }
예제 #4
0
파일: Program.cs 프로젝트: jagofett/wumpus
        private static void SetGame(WumpusGameLogic game)
        {
            _game = game;

            _game.GameOverEvent    += WumpusGameOverEvent;
            _game.OutOfFieldEvent  += WumpusOutOfFieldEvent;
            _game.SucceccStepEvent += WumpusSucceccStepEvent;
            if (!_game.IsStarted)
            {
                _game.StartGame();
                System.Console.WriteLine("\n\nBeléptél a barlangba, a bal alsó sarkában vagy.\n" +
                                         "A barlang mérete: " + _game.Setting.Size + " x " + _game.Setting.Size);
                _lastSetting = _game.Setting;
            }
            //System.Console.WriteLine("Csapdák száma: " + game.Setting.TrapNumberMin + ".." + game.Setting.TrapNumberMax);
            WriteSenses();
            Game();
            //System.Console.ReadKey();
        }
예제 #5
0
        public WumpusGameLogic LoadGame(string fileName)
        {
            try
            {
                var reader = new StreamReader(fileName);
                var model  = new WumpusGameLogic(this);
                //setting
                var line    = reader.ReadLine().Split(' ');
                var setting = new WumpusSetting
                {
                    Size           = Int32.Parse(line[0]),
                    ArrowNumber    = Int32.Parse(line[1]),
                    SettingName    = line[2],
                    TrapNumberType = (TrapNumberType)Int32.Parse(line[3]),
                    TrapNumberMin  = Int32.Parse(line[4]),
                    TrapNumberMax  = Int32.Parse(line[5])
                };
                //player cord
                line = reader.ReadLine().Split(' ');
                var playerCord = new Tuple <int, int>(Int32.Parse(line[0]), Int32.Parse(line[1]));
                //arrow, points, started
                line = reader.ReadLine().Split(' ');
                var cArrow   = Int32.Parse(line[0]);
                var cPoint   = Int32.Parse(line[1]);
                var cStrated = Boolean.Parse(line[2]);

                //cave
                var cave = new List <WumpusField>();
                for (var i = 0; i < setting.Size; i++)
                {
                    for (int j = 0; j < setting.Size; j++)
                    {
                        line = reader.ReadLine().Split(' ');
                        var fieldType = (FieldType)int.Parse(line[0]);
                        var visible   = bool.Parse(line[1]);
                        var cord      = new Tuple <int, int>(Int32.Parse(line[2]), int.Parse(line[3]));

                        //sense
                        var sense = new List <SenseType>();
                        line = reader.ReadLine().Split(' ');
                        if (!line.Any(string.IsNullOrWhiteSpace))
                        {
                            sense = line.Select(x => (SenseType)int.Parse(x)).ToList();
                        }
                        cave.Add(new WumpusField
                        {
                            Coordinates = cord,
                            FieldType   = fieldType,
                            Visible     = visible,
                            SenseTypes  = sense
                        });
                    }
                }
                model.Load(setting, playerCord, cArrow, cPoint, cave, cStrated);


                return(model);
            }
            catch (Exception e)
            {
                //todo spec error
                throw;
            }
        }