public Player(bool isPieceOut, LudoHelper.color colorChoise, bool isHuman, int playerNr) { this.isPieceOut = isPieceOut; this.colorChoise = colorChoise; this.isHuman = isHuman; this.playerNr = playerNr; }
//Funktion der udfører slag for at få brikker ud på brættet hvor du har 3 forsøg hvis du ikke har nogen ude public void moveOut(LudoHelper.color next, PlayPiece[] pieces) { Control ctrl = new Control(); Dice ludoDice = new Dice(6); int diceTal = 0; LudoHelper.color plColor = next; int tal = Convert.ToInt32(plColor); userMessage = ""; userMessage = "Spiller nr " + player[tal].playerNr + " der spiller " + player[tal].colorChoise.ToString() + " har først 3 forsøg på at få en brik ud "; for (int i = 1; i <= 3; i++) { if (diceTal == 6) { userMessage = "Du har fået en ud "; player[tal].isPieceOut = true; changeToMove(pieces, tal); moveNormal(tal, pieces); break; } } }
public PlayPiece(LudoHelper.color color, int locationBoard, LudoHelper.state state, bool inGoal, string brikNr) { this.color = color; this.locationBoard = locationBoard; this.state = state; this.inGoal = false; this.brikNr = brikNr; }
//Den funktion der opretter spillere og tildeler dem en farve og hvem der er først public string startgame(int antalSP) { Random rand = new Random(); Control ctrl = new Control(); LudoBoardField[] ludoBoard = new LudoBoardField[52]; PlayPiece[] pieces = new PlayPiece[16]; player = new Player[antalSP]; ludoBoard = this.ludoBoard.makeBoard(); userMessage = ""; pieces = this.ludoBoard.createLudoPieces(); LudoHelper.color[] ludoHelp = new LudoHelper.color[4]; ludoHelp[0] = LudoHelper.color.red; ludoHelp[1] = LudoHelper.color.yellow; ludoHelp[2] = LudoHelper.color.blue; ludoHelp[3] = LudoHelper.color.green; Dice ludoDice = new Dice(6); int[] rNumber = ludoDice.getRandomNR(0, antalSP); ludoHelp = ctrl.unsortArray(ludoHelp); int tal = 0; for (int i = 0; i <= antalSP - 1; i++) { tal = rNumber[i]; player[i] = new Player(false, ludoHelp[tal], true, tal + 1); } player = ctrl.sortArray(player); for (int i = 0; i < player.Length; i++) { userMessage += "Spiller nr " + player[i].playerNr + " har fået farve " + player[i].colorChoise.ToString() + " \r\n"; } if (antalSP < 3) { tal = rand.Next(0, 1); userMessage += "Det er spiller nr " + (tal + 1) + " der starter med " + player[tal].colorChoise.ToString() + " farve"; } else { tal = rand.Next(0, 4); userMessage += "Det er spiller nr " + (tal + 1) + " der starter med " + player[tal].colorChoise.ToString() + " farve"; } //moveControl(player[tal].colorChoise, pieces); return(userMessage); }
public LudoHelper.color[] unsortArray(LudoHelper.color[] uArray) { Random rand = new Random(); // Shuffle the array for (int i = 0; i < uArray.Length; ++i) { int index = rand.Next(uArray.Length); LudoHelper.color temp = uArray[index]; uArray[index] = uArray[i]; uArray[i] = temp; } return(uArray); }
public void startgame(int antalSP) { Random rand = new Random(); Control ctrl = new Control(); LudoBoardField[] ludoBoard = new LudoBoardField[52]; PlayPiece[] pieces = new PlayPiece[16]; player = new Player[antalSP]; ludoBoard = this.ludoBoard.makeBoard(); pieces = this.ludoBoard.createLudoPieces(); LudoHelper.color[] ludoHelp = new LudoHelper.color[4]; ludoHelp[0] = LudoHelper.color.red; ludoHelp[1] = LudoHelper.color.yellow; ludoHelp[2] = LudoHelper.color.blue; ludoHelp[3] = LudoHelper.color.green; Dice ludoDice = new Dice(6); int[] rNumber = ludoDice.getRandomNR(0, antalSP); ludoHelp = ctrl.unsortArray(ludoHelp); int tal = 0; for (int i = 0; i <= antalSP - 1; i++) { tal = rNumber[i]; player[i] = new Player(false, ludoHelp[tal], true, tal + 1); } player = ctrl.sortArray(player); for (int i = 0; i < player.Length; i++) { Console.WriteLine("Spiller nr {0:D} har fået farve {1:D}", player[i].playerNr, player[i].colorChoise.ToString()); } tal = rand.Next(0, 4); //Console.WriteLine("Det er spiller nr {0:D} der starter med {1:D} farve", tal+1, player[tal].colorChoise.ToString()); moveOutNOn(player[tal].colorChoise, pieces); }
public LudoHelper.color playerNext(LudoHelper.color color) { switch (color) { case LudoHelper.color.green: return(LudoHelper.color.blue); case LudoHelper.color.blue: return(LudoHelper.color.yellow); case LudoHelper.color.yellow: return(LudoHelper.color.red); case LudoHelper.color.red: return(LudoHelper.color.green); default: return(LudoHelper.color.green); } }
//Funktion der samler move funktioner og udfører dem udfra om man har brikker ude eller ej public void moveControl(LudoHelper.color next, PlayPiece[] pieces) { LudoHelper.color plColor = next; int tal = Convert.ToInt32(plColor); while (true) { if (!player[tal].isPieceOut) { moveOut(player[tal].colorChoise, pieces); } else { moveNormal(tal, pieces); } plColor = playerNext(plColor); tal = Convert.ToInt32(plColor); Console.WriteLine("Så er det spillernr {0:D} tur", player[tal].playerNr); } }
//Funktion der flytter dem ud til start steder udfra farve public int moveToMove(LudoHelper.color color) { int moveNr = 0; switch (color) { case LudoHelper.color.green: moveNr = 1; break; case LudoHelper.color.blue: moveNr = 14; break; case LudoHelper.color.yellow: moveNr = 25; break; case LudoHelper.color.red: moveNr = 40; break; } return(moveNr); }
public void moveOutNOn(LudoHelper.color next, PlayPiece[] pieces) { Control ctrl = new Control(); Dice ludoDice = new Dice(6); int diceTal = 0; int cntr = 0; string brikNr = ""; LudoHelper.color plColor = next; int tal = Convert.ToInt32(plColor); while (true) { if (!player[tal].isPieceOut) { if (cntr == 0) { Console.WriteLine(""); Console.WriteLine("Spiller nr {0:D} der spiller {1:D} har først 3 forsøg på at få en brik ud ", player[tal].playerNr, player[tal].colorChoise.ToString()); cntr++; } else { Console.WriteLine(""); Console.WriteLine("Spiller nr {0:D} der spiller {1:D} har først 3 forsøg på at få en brik ud ", player[tal].playerNr, player[tal].colorChoise.ToString()); } for (int i = 1; i <= 3; i++) { Console.Write("Rul en terning ved at trykke d: "); if (Console.ReadLine().ToLower() == "d") { Console.WriteLine("Du har rullet {0:D}", diceTal = ludoDice.roll_D6Dice()); } else { Console.WriteLine("Du har rullet 1", diceTal = 1); } if (diceTal == 6) { Console.WriteLine("Du har fået en ud "); player[tal].isPieceOut = true; for (int j = 0; j < pieces.Length; j++) { if (pieces[j].color == player[tal].colorChoise) { if (pieces[j].state == LudoHelper.state.ude) { pieces[j].state = LudoHelper.state.move; break; } else { pieces[j + 1].state = LudoHelper.state.move; break; } } } moveNormal(tal, diceTal, pieces); break; } } } else { Console.WriteLine("Så er det spillernr {0:D} tur", player[tal].playerNr); moveNormal(tal, diceTal, pieces); } plColor = playerNext(plColor); tal = Convert.ToInt32(plColor); //Console.WriteLine("Så er det spillernr {0:D} tur", player[tal].playerNr); } }