public ViewLevel(Controller.Game game, Model.ModelLevel levelModel) { InitializeComponent(); //Set the gameController controller gameController = game; //Set the right model this.levelModel = levelModel; //Create the right amount of rows and columns setGrid(); //Set the view to the right hight and width this.Width = levelModel.IWidth; this.Height = levelModel.IHeight; //Add a mousedown event to the grid mainGrid.MouseDown += new MouseButtonEventHandler(mainGrid_MouseDown); //Draw all the fields drawFields(); //Draw the decoration images on the grid drawImages(); }
public ViewMessage(Model.ModelLevel levelModel, Controller.Player[] aPlayers) { InitializeComponent(); this.levelModel = levelModel; this.aPlayers = aPlayers; viewMap = new String[levelModel.IMapHeight, levelModel.IMapWidth]; }
//Create a new board according to the type of board selected by the user input public void newBoard(int iHumanPlayers, String sBoardType, int playerTurn) { this.playerTurn = playerTurn; //Show the "hoofdmenu" button, allowing the user to return the the main menu main.label_mainmenu.Visibility = Visibility.Visible; main.label_save.Visibility = Visibility.Visible; if (sBoardType.Equals("normaal")) { createPlayers(iHumanPlayers, 5); levelModel = new Model.ModelLevelSlow(); level = new View.ViewLevel(this, levelModel); } else { createPlayers(iHumanPlayers, 4); levelModel = new Model.ModelLevelFast(); level = new View.ViewLevel(this, levelModel); } main.mainGrid.Children.Add(level); level.Visibility = Visibility.Visible; dice = new View.Dice(playerTurn); dice.HorizontalAlignment = HorizontalAlignment.Right; dice.Margin = new Thickness(0,0,10,0); main.mainGrid.Children.Add(dice); skip = new View.Skip(this); skip.HorizontalAlignment = HorizontalAlignment.Right; skip.Margin = new Thickness(0, 160, 10, 0); main.mainGrid.Children.Add(skip); winner = new View.WinnerMessage(); winner.Visibility = Visibility.Collapsed; winner.HorizontalAlignment = HorizontalAlignment.Center; winner.VerticalAlignment = VerticalAlignment.Center; main.mainGrid.Children.Add(winner); }
//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."); }