Beispiel #1
0
 //Create the players.
 private void createPlayers(int iHumanPlayers, int amountPawns)
 {
     aPlayers[0] = new Player(iHumanPlayers >= 1, amountPawns, this);
     aPlayers[1] = new Player(iHumanPlayers >= 2, amountPawns, this);
     aPlayers[2] = new Player(iHumanPlayers >= 3, amountPawns, this);
     aPlayers[3] = new Player(iHumanPlayers >= 4, amountPawns, this);
 }
        //Save the current game to a new file.
        public void saveTheGame(int playerTurn, Model.ModelLevel levelModel, Player[] aPlayers)
        {
            this.levelModel = levelModel;
            this.aPlayers = aPlayers;

            iHumanPlayers = 0;

            foreach (Controller.Player player in aPlayers)
            {
                if (player.BIsHuman)
                {
                    iHumanPlayers++;
                }
            }

            createSaveFolder();
            createSaveMap();

            String date = DateTime.Now.ToString();
            date =  date.Replace(":", "-");
            String saveName = date + ".save";

            StreamWriter sw = new StreamWriter(path + "/" +  saveName);

            //Write amount of human players             LINE 1
            sw.WriteLine("humanplayers:" + iHumanPlayers);

            //Write who's turn it is                    LINE 2
            switch (playerTurn)
            {
                case 0:
                    sw.WriteLine("turn:red");
                    break;
                case 1:
                    sw.WriteLine("turn:green");
                    break;
                case 2:
                    sw.WriteLine("turn:yellow");
                    break;
                case 3:
                    sw.WriteLine("turn:blue");
                    break;
            }

            //Write what board we are playing           LINE 3
            if(levelModel.GetType() == typeof(Model.ModelLevelSlow))
            {
                sw.WriteLine("boardtype:normaal");
            }
            else
            {
                sw.WriteLine("boardtype:snel");
            }

            //Write the board itself
            for (int iRow = 0; iRow < levelModel.IMapHeight; iRow++)
            {
                String sRow = "";

                for (int iColumn = 0; iColumn < levelModel.IMapWidth; iColumn++)
                {
                    sRow += saveMap[iRow, iColumn] + " ";
                }

                sw.WriteLine(sRow);
            }

            //Close the stream
            sw.Close();

            MessageBox.Show("Het spel is opgeslagen.");
        }