public PlayerAbstract[] loadPlayers() { //Create an array of players //Read the player info from XML and create two new playerobjects with the data PlayerAbstract[] players = new PlayerAbstract[2]; List <XElement> tempList = new List <XElement>(); foreach (XElement e in xdoc.Descendants("Player")) { tempList.Add(e); } for (int i = 0; i < 2; i++) { XElement tempElement = tempList[i]; if (bool.Parse(tempElement.Attribute("isAI").Value)) { players[i] = new AI(tempElement.Attribute("Name").Value.ToString(), tempElement.Attribute("Color").Value); players[i]._tilesRemaining = int.Parse(tempElement.Attribute("TilesRemaining").Value); } else { players[i] = new Human(tempElement.Attribute("Name").Value.ToString(), tempElement.Attribute("Color").Value); players[i]._tilesRemaining = int.Parse(tempElement.Attribute("TilesRemaining").Value); } } return(players); }
private void startingCurrentPlayer(PlayerAbstract startingPlayer) { currentPlayer = startingPlayer; rulesEngine._board.allowMovesAgain += allowMovesAgain; Action <String> onPlayerChange = playerChange; if (onPlayerChange != null) { onPlayerChange(currentPlayer._name + " spelar nu och har " + currentPlayer._tilesRemaining + " brickor kvar"); } currentPlayer.doThings(this); }
public void setStartingColor(String colorStr, String playerStr) { PlayerAbstract tempPlayer = null; rulesEngine.linq.initBoard(); if (playerStr.Equals("AI")) { player1 = new AI("Dator", "Black"); player2 = new AI("Dumburk", "White"); rulesEngine.linq.createPlayers(player1, player2); tempPlayer = player1; } else if (playerStr.Equals("Human")) { if (colorStr.Equals("light")) { player1 = new Human("Människa", "White"); player2 = new Human("En annan människa", "Black"); tempPlayer = player2; } else if (colorStr.Equals("dark")) { player1 = new Human("Människa", "Black"); player2 = new Human("En annan människa", "White"); tempPlayer = player1; } } else { if (colorStr.Equals("light")) { player1 = new Human("Människa", "White"); player2 = new AI("Dumburk", "Black"); tempPlayer = player2; } else if (colorStr.Equals("dark")) { player1 = new Human("Människa", "Black"); player2 = new AI("Dumburk", "White"); tempPlayer = player1; } } rulesEngine.linq.createPlayers(player1, player2); rulesEngine._board.loadBoard(rulesEngine.linq.loadGame()); gameEnded = false; startingCurrentPlayer(tempPlayer); }
public void updateTilesRemaining(PlayerAbstract currentPlayer) { //Updates the number of tiles remaining in the playerobject //Reads the current number of tiles remaining in the XML and rewrites it -1 currentPlayer.updateTiles(); IEnumerable <XElement> piece = from pieces in xdoc.Descendants("Player") where pieces.Attribute("Color").Value.Equals(currentPlayer._color) select pieces; foreach (XElement itemElement in piece) { itemElement.SetAttributeValue("TilesRemaining", currentPlayer._tilesRemaining); } xdoc.Save(@Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\board.xml"); }
public void createPlayers(PlayerAbstract player1, PlayerAbstract player2) { //Adds the new players to the XML-file xdoc = XDocument.Load(@Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\board.xml"); if (!(xdoc.Root.Element("Players").HasElements)) { xdoc.Root.Element("Players").Add(new XElement("Player", new XAttribute("isAI", player1._isAI), new XAttribute("Color", player1._color), new XAttribute("Name", player1._name), new XAttribute("TilesRemaining", player1._tilesRemaining))); xdoc.Root.Element("Players").Add(new XElement("Player", new XAttribute("isAI", player2._isAI), new XAttribute("Color", player2._color), new XAttribute("Name", player2._name), new XAttribute("TilesRemaining", player2._tilesRemaining))); } xdoc.Save(@Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\board.xml"); }
public void loadGame() { PlayerAbstract[] loadedPlayers = rulesEngine.linq.loadPlayers(); player1 = loadedPlayers[0]; player2 = loadedPlayers[1]; if (player1._tilesRemaining > player2._tilesRemaining) { currentPlayer = player2; } else { currentPlayer = player1; } rulesEngine._board.loadBoard(rulesEngine.linq.loadGame()); rulesEngine.roundsLeft = rulesEngine.linq.loadTurnsRemaining(); Action<String> onPlayerChange = playerChange; if (onPlayerChange != null) { onPlayerChange(currentPlayer._name + " spelar nu och har " + currentPlayer._tilesRemaining + " brickor kvar"); } currentPlayer.doThings(this); }
public void changeCurrentPlayer() { if (gameEnded == false) { if (currentPlayer == player1) { currentPlayer = player2; } else { currentPlayer = player1; } Action<String> onPlayerChange = playerChange; if (onPlayerChange != null) { onPlayerChange(currentPlayer._name + " spelar nu och har " + currentPlayer._tilesRemaining + " brickor kvar"); } currentPlayer.doThings(this); } }
public void changeCurrentPlayer() { if (gameEnded == false) { if (currentPlayer == player1) { currentPlayer = player2; } else { currentPlayer = player1; } Action <String> onPlayerChange = playerChange; if (onPlayerChange != null) { onPlayerChange(currentPlayer._name + " spelar nu och har " + currentPlayer._tilesRemaining + " brickor kvar"); } currentPlayer.doThings(this); } }
public void playMade(int row, int column, PlayerAbstract currentPlayer) { //Checks if the suggested move if allowed //If allowed the it updates the tiles remaining for the player making the move, both in XML and in the playerobject //It then calls the method makeMove and pushes an event to the LINQ class telling it to save the new board positions to XML //If not allowed it pushes an event to the UI telling the player that the move is impossible String playerColor = currentPlayer._color; if (isMoveLegal(row, column, playerColor)) { linq.playerNotDoingThings = false; linq.updateTilesRemaining(currentPlayer); makeMove(row, column, playerColor); Action <String[, ]> onBoardChangedLINQ = onBoardChanged; if (onBoardChangedLINQ != null) { onBoardChanged(_board._boardArray); } linq.playerNotDoingThings = true; } else { Action <String> localOnChange = onMoveFeedback; if (localOnChange != null) { localOnChange("You can't make that move"); } } Action localOnFinished = onMoveFinished; if (localOnFinished != null) { localOnFinished(); } }
public void loadGame() { PlayerAbstract[] loadedPlayers = rulesEngine.linq.loadPlayers(); player1 = loadedPlayers[0]; player2 = loadedPlayers[1]; if (player1._tilesRemaining > player2._tilesRemaining) { currentPlayer = player2; } else { currentPlayer = player1; } rulesEngine._board.loadBoard(rulesEngine.linq.loadGame()); rulesEngine.roundsLeft = rulesEngine.linq.loadTurnsRemaining(); Action <String> onPlayerChange = playerChange; if (onPlayerChange != null) { onPlayerChange(currentPlayer._name + " spelar nu och har " + currentPlayer._tilesRemaining + " brickor kvar"); } currentPlayer.doThings(this); }
public void playMade(int row, int column, PlayerAbstract currentPlayer) { //Checks if the suggested move if allowed //If allowed the it updates the tiles remaining for the player making the move, both in XML and in the playerobject //It then calls the method makeMove and pushes an event to the LINQ class telling it to save the new board positions to XML //If not allowed it pushes an event to the UI telling the player that the move is impossible String playerColor = currentPlayer._color; if (isMoveLegal(row, column, playerColor)) { linq.playerNotDoingThings = false; linq.updateTilesRemaining(currentPlayer); makeMove(row, column, playerColor); Action<String[,]> onBoardChangedLINQ = onBoardChanged; if (onBoardChangedLINQ != null) { onBoardChanged(_board._boardArray); } linq.playerNotDoingThings = true; } else { Action<String> localOnChange = onMoveFeedback; if (localOnChange != null) { localOnChange("You can't make that move"); } } Action localOnFinished = onMoveFinished; if (localOnFinished != null) { localOnFinished(); } }
public void updateTilesRemaining(PlayerAbstract currentPlayer) { //Updates the number of tiles remaining in the playerobject //Reads the current number of tiles remaining in the XML and rewrites it -1 currentPlayer.updateTiles(); IEnumerable<XElement> piece = from pieces in xdoc.Descendants("Player") where pieces.Attribute("Color").Value.Equals(currentPlayer._color) select pieces; foreach (XElement itemElement in piece) { itemElement.SetAttributeValue("TilesRemaining", currentPlayer._tilesRemaining); } xdoc.Save(@Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\board.xml"); }
public PlayerAbstract[] loadPlayers() { //Create an array of players //Read the player info from XML and create two new playerobjects with the data PlayerAbstract[] players = new PlayerAbstract[2]; List<XElement> tempList = new List<XElement>(); foreach (XElement e in xdoc.Descendants("Player")) tempList.Add(e); for (int i = 0; i < 2; i++) { XElement tempElement = tempList[i]; if (bool.Parse(tempElement.Attribute("isAI").Value)) { players[i] = new AI(tempElement.Attribute("Name").Value.ToString(), tempElement.Attribute("Color").Value); players[i]._tilesRemaining = int.Parse(tempElement.Attribute("TilesRemaining").Value); } else { players[i] = new Human(tempElement.Attribute("Name").Value.ToString(), tempElement.Attribute("Color").Value); players[i]._tilesRemaining = int.Parse(tempElement.Attribute("TilesRemaining").Value); } } return players; }
private void startingCurrentPlayer(PlayerAbstract startingPlayer) { currentPlayer = startingPlayer; rulesEngine._board.allowMovesAgain += allowMovesAgain; Action<String> onPlayerChange = playerChange; if (onPlayerChange != null) { onPlayerChange(currentPlayer._name + " spelar nu och har " + currentPlayer._tilesRemaining + " brickor kvar"); } currentPlayer.doThings(this); }