private void Win_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.GetPosition(this).X >= 715 && e.GetPosition(this).X <= 795 && e.GetPosition(this).Y >= 5 && e.GetPosition(this).Y <= 35)
            {
                this.dispatcherTimer.Stop();
                this.enemyMover.Stop();
                this.enemybulletMove.Stop();
                foreach (var item in this.model.PlayerBullets.ToList())
                {
                    item.Timer.Stop();
                    this.model.PlayerBullets.Remove(item);
                }

                foreach (var item in this.model.EnemyBullets.ToList())
                {
                    item.Timer.Stop();
                    this.model.EnemyBullets.Remove(item);
                }

                this.saveLogic = new SaveLogic(new SaveInstance(), this.model);
                this.saveLogic.SaveInstance();
                Window win = Window.GetWindow(this);
                win.Close();
                MainMenuWindow mainMenuWindow = new MainMenuWindow();
                mainMenuWindow.Show();
            }
        }
    void Start()
    {
        groundCount = 0;

        WorldData data = SaveLogic.LoadWorld();

        saveExists = data.savedGame;

        mouseRotatorScript.enabled = false;

        GroundBuild();
        HighwayBuild();
    }
        private void GameOver()
        {
            if (this.model.Player.Life == 0)
            {
                this.dispatcherTimer.Stop();
                this.enemyMover.Stop();
                this.enemybulletMove.Stop();

                // MessageBox.Show("Game Over!\n\nHighscore: " + this.model.Score, "GameOver", MessageBoxButton.OK, MessageBoxImage.Hand);
                NameAsk nameAsk = new NameAsk();
                nameAsk.ShowDialog();
                HighScoreRepository highScore = new HighScoreRepository();
                this.saveLogic = new SaveLogic(highScore, this.model);
                this.saveLogic.HighscoreInstance(PlayerName);
                Window win = Window.GetWindow(this);
                win.Close();
                MainMenuWindow mainMenuWindow = new MainMenuWindow();
                mainMenuWindow.Show();
            }
        }
        private void GameControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.dispatcherTimer = new DispatcherTimer();
            this.bulletMover     = new DispatcherTimer();
            this.enemyMover      = new DispatcherTimer();
            this.enemybulletMove = new DispatcherTimer();
            this.wait            = new DispatcherTimer();
            this.saveLogic       = new SaveLogic(new SaveInstance(), this.model);
            if (this.saveLogic.LoadGame() == null)
            {
                this.logic = new GameLogic(this.model);
                this.model = this.logic.InitModel();
            }
            else
            {
                this.model = this.saveLogic.LoadGame();
                this.logic = new GameLogic(this.model);
                this.saveLogic.DeleteSave();
            }

            this.renderer = new GameRenderer(this.model);
            Window win = Window.GetWindow(this);

            if (win != null)
            {
                win.KeyDown             += this.Win_KeyDown;
                win.MouseLeftButtonDown += this.Win_MouseLeftButtonDown;
            }

            this.dispatcherTimer.Interval = TimeSpan.FromMilliseconds(50);
            this.dispatcherTimer.Tick    += this.DispatcherTimer_Tick;
            this.enemyMover.Interval      = TimeSpan.FromMilliseconds(2000);
            this.enemyMover.Tick         += this.EnemyMover_Tick;
            this.enemybulletMove.Interval = TimeSpan.FromMilliseconds(4000);
            this.enemybulletMove.Tick    += this.EnemybulletMove_Tick;
            this.enemybulletMove.Start();
            this.enemyMover.Start();
            this.dispatcherTimer.Start();

            this.InvalidateVisual();
        }
    public void LoadWorld()
    {
        WorldData data = SaveLogic.LoadWorld();

        worldScript.objects    = data.objects;
        worldScript.Xpositions = data.Xpositions;
        worldScript.Ypositions = data.Ypositions;
        worldScript.Zpositions = data.Zpositions;

        goldScript.gold                    = data.gold;
        populationScript.population        = data.population;
        populationScript.residentHappiness = data.residenthappiness;

        placementScript.houses = data.houses;

        worldScript.residents = data.residents;

        existingHouses = GameObject.FindGameObjectsWithTag("Build");

        for (int i = 0; i < existingHouses.Length; i++)
        {
            Destroy(existingHouses[i]);
        }
        existingRoads = GameObject.FindGameObjectsWithTag("Road");

        for (int i = 0; i < existingRoads.Length; i++)
        {
            Destroy(existingRoads[i]);
        }
        existingTerrain = GameObject.FindGameObjectsWithTag("Terrain");

        for (int i = 0; i < existingHouses.Length; i++)
        {
            Destroy(existingTerrain[i]);
        }

        for (int i = 0; i < worldScript.objects.Length; i++)
        {
            if (data.objects[i] == "House1")
            {
                prefab        = House1;
                houseCapacity = 5;
            }
            else if (data.objects[i] == "House2")
            {
                prefab        = House2;
                houseCapacity = 8;
            }
            else if (data.objects[i] == "tree")
            {
                prefab = tree;
            }
            else if (data.objects[i] == "tree1")
            {
                prefab = tree1;
            }
            else if (data.objects[i] == "tree2")
            {
                prefab = tree2;
            }
            else if (data.objects[i] == "road")
            {
                prefab = road;
            }
            else if (data.objects[i] == "cornerRoad")
            {
                prefab = cornerRoad;
            }
            else if (data.objects[i] == "cornerRoadLeftBottom")
            {
                prefab = cornerRoadLeftBottom;
            }
            else if (data.objects[i] == "cornerRoadRightTop")
            {
                prefab = cornerRoadRightTop;
            }
            else if (data.objects[i] == "cornerRoadRightBottom")
            {
                prefab = cornerRoadRightBottom;
            }
            else if (data.objects[i] == "3wayRoad")
            {
                prefab = threeWayRoad;
            }
            else if (data.objects[i] == "3wayRoadLeft")
            {
                prefab = threeWayRoadLeft;
            }
            else if (data.objects[i] == "3wayRoadUpwards")
            {
                prefab = threeWayRoadUpwards;
            }
            else if (data.objects[i] == "3wayRoadDown")
            {
                prefab = threeWayRoadDown;
            }
            else if (data.objects[i] == "4cornerRoad")
            {
                prefab = fourCornerRoad;
            }
            else if (data.objects[i] == "roadVertical")
            {
                prefab = roadVertical;
            }
            else
            {
                prefab = null;
            }

            if (prefab != null)
            {
                currentObject = Instantiate(prefab);
                currentObject.transform.SetPositionAndRotation(new Vector3(data.Xpositions[i], data.Ypositions[i], data.Zpositions[i]), currentObject.transform.rotation);
                if (prefab == House1 || prefab == House2)
                {
                    HouseLogic houseScript = currentObject.GetComponent <HouseLogic>();
                    houseScript.capacity    = houseCapacity;
                    houseScript.houseNumber = i;
                }
                if (prefab.tag == "Road")
                {
                    currentObject.name = "Road" + i;
                }
                if (currentObject.tag == "Terrain")
                {
                    currentObject.name = "Tree" + i;
                }
            }
        }
    }
 public void SaveWorld()
 {
     SaveLogic.SaveWorld(worldScript);
 }
Beispiel #7
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            EnableControls(false);
            SetTitle("Running...");

            if (rbLoadJSON.Checked)
            {
                Task.Factory.StartNew(() => // creates a new task to prevent locking UI
                {
                    int index           = 0;
                    List <string> items = GetSelection();
                    string[] itemsArray = items.ToArray();
                    SaveLogic sl        = new SaveLogic();

                    Parallel.For           // for spreading the small load into multiple threads
                    (
                        0,                 // start index
                        itemsArray.Length, // end index
                        i =>               // index variable
                    {
                        sl.SaveMatchData(items[i]);
                        SetTitle("Running... - " + (++index) + " of " + itemsArray.Length);     // possibly thread-unsafe index incrementing
                    }                                                                           // but makes little difference in the end
                    );

                    OperationFinished();
                });
            }
            else if (rbRunQueries.Checked)
            {
                Task.Factory.StartNew(() => // creates a new task to prevent locking UI
                {
                    SaveLogic sl        = new SaveLogic();
                    LoadLogic ll        = new LoadLogic();
                    List <string> items = GetSelection();
                    Parallel.ForEach // for spreading the small load into multiple threads
                    (
                        items, lvi =>
                    {
                        switch (lvi)
                        {
                        case "SaveChampData":
                            {
                                sl.SaveChampData();
                                break;
                            }

                        case "SaveItemData":
                            {
                                sl.SaveItemData();
                                break;
                            }

                        case "SaveSumSpellData":
                            {
                                sl.SaveSumSpellData();
                                break;
                            }

                        case "LoadTimeGraph":
                            {
                                ll.LoadTimeGraph();
                                break;
                            }

                        case "LoadChampInfo":
                            {
                                ll.LoadChampInfo();
                                break;
                            }
                        }
                    }
                    );
                    OperationFinished();
                });
            }
        }