示例#1
0
        public void SaveMap()
        {
            var mapSaver = new MapSaver();
            var savePath = MapFilePath;

            // if (MapFilePath.IndexOf(Constants.EditedMapTag, StringComparison.InvariantCultureIgnoreCase) == -1)
            // {
            //  int extIdx = savePath.LastIndexOf('.');
            //  // savePath = savePath.Insert(extIdx, Constants.EditedMapTag);
            //
            //  SavedMapFileName = Path.GetFileName(savePath);
            // }

            Prefs.PreviousMapPath.Set(savePath);

            mapSaver.SaveMap(Map, MapFilePath);
        }
示例#2
0
        public void Update()
        {
            switch (State)
            {
            case GameState.GeneratingMap:
                if (!InvokeAction())
                {
                    Map.SetMap(MapGenerator.ConvertWriteableBitmapToBitmapImage(Map.GetWriteableBitmap()));
                    Map.Init();
                    SetState(GameState.ReadyToInitialize);
                }
                break;

            case GameState.ReadyToInitialize:
                Initialize();
                break;

            case GameState.Initializing_FindCountries:
                if (!InvokeAction())
                {
                    if (initX == Map.Width - 1 && initY == Map.Height - 1)
                    {
                        CreateWaters();
                        RemoveUnnecessaryBorders();
                        ActionQueue.AddRange(FindNeighboursQueue);
                        SetState(GameState.Initializing_FindNeighbours);
                    }
                    else
                    {
                        do
                        {
                            if (initX == Map.Width - 1)
                            {
                                initX = 0;
                                initY++;
                            }
                            else
                            {
                                initX++;
                            }
                        } while (!(initX == Map.Width - 1 && initY == Map.Height - 1) && Map.CompletedPoints[initX, initY]);
                        if (!(initX == Map.Width - 1 && initY == Map.Height - 1))
                        {
                            ActionQueue.Insert(0, () => FloodFill(true, initX, initY, MapPixelType.STARTVALUE));
                        }
                    }
                }
                break;

            case GameState.Initializing_FindNeighbours:
                if (!InvokeAction())
                {
                    DistanceToNearestBorderFinder finder = new DistanceToNearestBorderFinder(Map, ActionQueue);
                    ActionQueue.Add(() => finder.FindDistancesToNearestBorder(NearestBorderAlgorithm.BorderSpreadFourDirections));
                    FindNeighboursQueue.Clear();
                    SetState(GameState.Initializing_FindDistancesToNearestBorder);
                }
                break;

            case GameState.Initializing_FindDistancesToNearestBorder:
                if (!InvokeAction())
                {
                    SetSelectedBorders();
                    SetCenters();
                    ConnectIslands();
                    ConnectCloseCountriesOverWater(MaxWaterConnectionDistance);
                    Map.Name = "xxx";
                    MapSaver.SaveMap(Map, MapSelection.MAP_PATH);
                    SetState(GameState.ReadyToPlay);
                }
                break;

            case GameState.Playing_Initialize:
                if (!InvokeAction(int.Parse(RunSpeed.Text)))
                {
                    SetState(GameState.Playing_Idle);
                }
                break;

            case GameState.ReadyToPlay:
                InvokeAction(int.Parse(RunSpeed.Text));
                break;

            case GameState.Playing_Idle:
                if (!InvokeAction(int.Parse(RunSpeed.Text)) && AutoRun.IsChecked == true)
                {
                    NextTurn();
                }
                CheckGameOver();
                break;

            case GameState.Playing_DistrubutionPhase:
                if (!InvokeAction(int.Parse(RunSpeed.Text)))
                {
                    ActionQueue.Add(() => attackAgain = Players[currentPlayer].DoTurn(this));
                    SetState(GameState.Playing_AttackPhase);
                }
                break;

            case GameState.Playing_AttackPhase:
                if (!InvokeAction(int.Parse(RunSpeed.Text)))
                {
                    if (attackAgain)
                    {
                        ActionQueue.Add(() => attackAgain = Players[currentPlayer].DoTurn(this));
                    }
                    else
                    {
                        ActionQueue.Add(() => Players[currentPlayer].EndTurn(this));
                        SetState(GameState.Playing_MovePhase);
                    }
                }
                break;

            case GameState.Playing_MovePhase:
                if (!InvokeAction(int.Parse(RunSpeed.Text)))
                {
                    Player next;
                    do
                    {
                        currentPlayer = (currentPlayer + 1) % Players.Count;
                        next          = Players[currentPlayer];
                        UIManager.SetupPlayerOrderGrid(Players, currentPlayer);
                    } while (!next.Alive);
                    SetState(GameState.Playing_Idle);
                }
                break;
            }
        }
示例#3
0
    void SaveMap(string fileName)
    {
        MapSaver mapSaver = new MapSaver(mapSaveProperties);

        mapSaver.SaveMap(fileName);
    }