public async Task <AccelerationGameModel> LoadAsync(String path)
        {
            try
            {
                using (StreamReader reader = new StreamReader(path))
                {
                    String panel = await reader.ReadLineAsync();

                    String[] panelCoords      = panel.Split(' ');
                    Pair     panelCoordinates = new Pair(Int32.Parse(panelCoords[0]), Int32.Parse(panelCoords[1]));
                    String   line             = await reader.ReadLineAsync();

                    String[] numbers            = line.Split(' ');
                    Int32    coordinate_x       = Int32.Parse(numbers[0]);
                    Int32    coordinate_y       = Int32.Parse(numbers[1]);
                    Pair     coordinates        = new Pair(coordinate_x, coordinate_y);
                    Int32    dimension_x        = Int32.Parse(numbers[2]);
                    Int32    dimension_y        = Int32.Parse(numbers[3]);
                    Pair     dimensions         = new Pair(dimension_x, dimension_y);
                    AccelerationGameModel model = new AccelerationGameModel(panelCoordinates, coordinates, dimensions);
                    model.m_motorCycle = new MotorCycleObject(coordinates, dimensions);
                    model.m_motorCycle.m_consumption    = Int32.Parse(numbers[4]);
                    model.m_motorCycle.m_petrolQuantity = Int32.Parse(numbers[5]);
                    //model.m_motorCycle.m_coordinates.m_x = Int32.Parse(numbers[0]);
                    //model.m_motorCycle.m_coordinates.m_y = Int32.Parse(numbers[1]);
                    String numOfPetrols = await reader.ReadLineAsync();

                    for (Int32 i = 0; i < Int32.Parse(numOfPetrols); i++)
                    {
                        String line3 = await reader.ReadLineAsync();

                        String[]     numbers2       = line3.Split(' ');
                        Int32        p_coordinate_x = Int32.Parse(numbers2[0]);
                        Int32        p_coordinate_y = Int32.Parse(numbers2[1]);
                        Pair         p_coordinates  = new Pair(p_coordinate_x, p_coordinate_y);
                        Int32        p_dimension_x  = Int32.Parse(numbers2[2]);
                        Int32        p_dimension_y  = Int32.Parse(numbers2[3]);
                        Pair         p_dimensions   = new Pair(p_dimension_x, p_dimension_y);
                        PetrolObject petrol         = new PetrolObject(p_coordinates, p_dimensions);
                        petrol.m_id = Int32.Parse(numbers2[4]);
                        model.m_petrolsList.Add(petrol);
                    }
                    String time = await reader.ReadLineAsync();

                    model.m_time = Int32.Parse(time);
                    String speed = await reader.ReadLineAsync();

                    model.m_speed = Int32.Parse(speed);
                    String counter = await reader.ReadLineAsync();

                    model.m_counter = Int32.Parse(counter);
                    return(model);
                }
            }

            catch
            {
                throw new AccelerationException();
            }
        }
Beispiel #2
0
        private void App_Startup(object sender, StartupEventArgs e)
        {
            // modell létrehozása

            Pair panelSize       = new Pair(650, 500);
            Pair motorDimension  = new Pair(50, 50);
            Pair petrolDimension = new Pair(50, 50);

            m_model = new AccelerationGameModel(new AccelerationFileDataAccess(), panelSize, motorDimension, petrolDimension);

            m_model.GameOver += On_GameOver;

            // nézemodell létrehozása
            m_viewModel            = new AccelerationViewModel(m_model);
            m_viewModel.NewGame   += ViewModel_NewGame;
            m_viewModel.ExitGame  += ViewModel_ExitGame;
            m_viewModel.LoadGame  += ViewModel_LoadGame;
            m_viewModel.SaveGame  += new EventHandler(ViewModel_SaveGame);
            m_viewModel.MoveLeft  += ViewModel_MoveLeft;
            m_viewModel.MoveRight += ViewModel_MoveRight;

            // nézet létrehozása
            m_view             = new MainWindow();
            m_view.DataContext = m_viewModel;
            m_view.Closing    += new System.ComponentModel.CancelEventHandler(View_Closing);
            m_view.Show();
        }
Beispiel #3
0
        public void Initialize()
        {
            m_mock = new Mock <IAccelerationDataAccess>();
            m_mock.Setup(mock => mock.LoadAsync(It.IsAny <String>()))
            .Returns(() => Task.FromResult(m_model));

            m_model = new AccelerationGameModel(coordinates, panelSize, sizes);
            m_model.RefreshMotorPosition += new EventHandler <AccelerationEventArgs>(Model_Slot_RefreshMotorPosition);
            m_model.AppearNewPetrols     += new EventHandler <AppearNewPetrolsArgs>(Model_Slot_NewPetrolsAppearOnScreen);

            /*
             * m_model.RefreshPetrolsMoving += Slot_RefreshMovingPetrols;
             * m_model.RefreshTimeAndPetrol += Slot_RefreshTimeAndPetrol;
             * m_model.RemovePetrolObject += Slot_RemovePetrolFromScreen;
             * m_model.GameOver += Slot_GameOver;
             */
        }
Beispiel #4
0
        public void Initialize()
        {
            m_mockedModel = new AccelerationGameModel(new AccelerationFileDataAccess(), panelSize, sizes, sizes);
            m_mockedModel.NewPetrol(sizes, 532);
            m_mockedModel.m_petrolsList[0].m_coordinates.m_x = 50;
            m_mockedModel.m_petrolsList[0].m_coordinates.m_y = 50;
            m_mockedModel.NewPetrol(sizes, 532);
            m_mockedModel.m_petrolsList[0].m_coordinates.m_x = 150;
            m_mockedModel.m_petrolsList[0].m_coordinates.m_y = 150;
            m_mockedModel.NewPetrol(sizes, 532);
            m_mockedModel.m_petrolsList[0].m_coordinates.m_x = 400;
            m_mockedModel.m_petrolsList[0].m_coordinates.m_y = 350;
            m_mock = new Mock <IAccelerationDataAccess>();
            m_mock.Setup(mock => mock.LoadAsync(It.IsAny <String>()))
            .Returns(() => Task.FromResult(m_mockedModel));


            m_model = new AccelerationGameModel(m_mock.Object, panelSize, sizes, sizes);
        }
Beispiel #5
0
 public GameForm()
 {
     InitializeComponent();
     m_panelSize.m_x               = panel1.Height - statusStrip2.Height;
     m_panelSize.m_y               = panel1.Width;
     m_model                       = new AccelerationGameModel(m_panelSize, m_motorDimension, m_petrolDimension);
     _newGameStrip.Click          += new System.EventHandler(NewGameStrip_Click);
     _pauseOrResumeStrip.Click    += new System.EventHandler(PauseOrResumeStrip_Click);
     _saveStrip.Click             += new System.EventHandler(SaveStrip_Click);
     _loadStrip.Click             += new System.EventHandler(LoadStrip_Click);
     _exit.Click                  += new System.EventHandler(MenuFileExit_Click);
     m_model.RefreshMotorPosition += Slot_RefreshMotorPosition;
     m_model.AppearNewPetrols     += Slot_NewPetrolsAppearOnScreen;
     m_model.RefreshPetrolsMoving += Slot_RefreshMovingPetrols;
     m_model.RefreshTimeAndPetrol += Slot_RefreshTimeAndPetrol;
     m_model.RemovePetrolObject   += Slot_RemovePetrolFromScreen;
     m_model.GameOver             += Slot_GameOver;
     picOfMotor                    = new PictureBox();
     m_petrolsPicture              = new List <MyPictureBox>();
     _pauseOrResumeStrip.Enabled   = false;
     _saveStrip.Enabled            = false;
     _loadStrip.Enabled            = false;
 }
Beispiel #6
0
        public AccelerationViewModel(AccelerationGameModel model)
        {
            m_model = model;

            m_model.RefreshMotorPosition += On_RefreshMotorPosition;
            m_model.AppearNewPetrols     += On_AppearNewPetrols;
            m_model.RefreshTimeAndPetrol += On_RefreshTimeAndPetrol;
            m_model.RefreshPetrolsMoving += On_RefreshPetrolsMoving;
            m_model.RemovePetrolObject   += On_RemovePetrolObject;

            NewGameCommand       = new DelegateCommand(param => OnNewGame());
            LoadGameCommand      = new DelegateCommand(param => OnLoadGame());
            SaveGameCommand      = new DelegateCommand(param => OnSaveGame());
            PauseOrResumeCommand = new DelegateCommand(param => OnPauseOrResume());
            ExitCommand          = new DelegateCommand(param => OnExitGame());
            MoveLeftCommand      = new DelegateCommand(param => OnMoveLeft());
            MoveRightCommand     = new DelegateCommand(param => OnMoveRight());

            SaveIsEnable            = "False";
            LoadIsEnable            = "False";
            PauseOrResumeButtonText = "Szüneteltetés";
            PauseOrResumeEnable     = "False";
            ViewScreenObjects       = new ObservableCollection <ViewScreenObject>();
        }