public GameOver(string nameOfPlayer, DTOClass data) { this.transferObject = data; InitializeComponent(nameOfPlayer); //Stop the timer and save the time transferObject.stopTimer(); }
/// <param name="width">Board width</param> /// <param name="height">Board height</param> /// <param name="side">Hexagon side length</param> /// <param name="xOffset">X coordinate offset</param> /// <param name="yOffset">Y coordinate offset</param> public Board(int width, int height, int side, int xOffset, int yOffset, BoardState boardState, List <Player> players, HexagonalTest.DTOClass dataTransfer) { this.width = width; this.height = height; this.nonWaterFields = width * height; this.side = side; this.transferObject = dataTransfer; this.xOffset = xOffset; this.yOffset = yOffset; this.boardState = boardState; this.players = players; hexes = new Hex[height, width]; //opposite of what we'd expect textPosX = new int[height, width]; // MaHa textPosY = new int[height, width]; // MaHa float h = Hexagonal.Math.CalculateH(side); // short side float r = Hexagonal.Math.CalculateR(side); // long side //Initalize, fill and shuffle field helper to give each player the same amount of fields on the start this.fieldHelper = new List <int>(width * height); int f = 0; while (f < fieldHelper.Capacity) { for (int p = players.Count - 1; p >= 0 && f < fieldHelper.Capacity; p--) { fieldHelper.Add(p); f++; } } Math.Shuffle <int>(fieldHelper); //Preload some dice results RandomGenerator.getInstance().initialize(); // // Calculate pixel info..remove? // because of staggering, need to add an extra r/h float hexWidth = 0; float hexHeight = 0; hexWidth = side + h; hexHeight = r + r; this.pixelWidth = (width * hexWidth) + h; this.pixelHeight = (height * hexHeight) + r; bool inTopRow = false; bool inBottomRow = false; bool inLeftColumn = false; bool inRightColumn = false; bool isTopLeft = false; bool isTopRight = false; bool isBotomLeft = false; bool isBottomRight = false; // f = field number in 2D plane f = 0; // i = y coordinate (rows), j = x coordinate (columns) of the hex tiles 2D plane for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Player player = getPlayerByID(fieldHelper[f]); bool isBorderWater = i == 0 || j == 0 || i == height - 1 || j == width - 1; isBorderWater &= RandomGenerator.getInstance().rollTheDice(1) < 3; bool isInnerWater = i > 1 && j > 1 && i < height - 2 && j < width - 2; isInnerWater &= RandomGenerator.getInstance().rollTheDice(1) == 1; bool isWater = isBorderWater || isInnerWater; Hex current = new Hex(side, isWater ? Hex.WaterColor : player.Color, j, i, isWater ? 0 : 1, isWater); if (isWater) { nonWaterFields--; } else { player.addField(); } f++; // Set position booleans #region Position Booleans if (i == 0) { inTopRow = true; } else { inTopRow = false; } if (i == height - 1) { inBottomRow = true; } else { inBottomRow = false; } if (j == 0) { inLeftColumn = true; } else { inLeftColumn = false; } if (j == width - 1) { inRightColumn = true; } else { inRightColumn = false; } if (inTopRow && inLeftColumn) { isTopLeft = true; } else { isTopLeft = false; } if (inTopRow && inRightColumn) { isTopRight = true; } else { isTopRight = false; } if (inBottomRow && inLeftColumn) { isBotomLeft = true; } else { isBotomLeft = false; } if (inBottomRow && inRightColumn) { isBottomRight = true; } else { isBottomRight = false; } #endregion // // Calculate Hex positions // if (isTopLeft) { //First hex current.Initialize(0 + h + xOffset, 0 + yOffset); hexes[0, 0] = current; } else { if (inLeftColumn) { // Calculate from hex above current.Initialize(hexes[i - 1, j].Points[(int)Hexagonal.FlatVertice.BottomLeft]); hexes[i, j] = current; } else { // Calculate from Hex to the left and need to stagger the columns if (j % 2 == 0) { // Calculate from Hex to left's Upper Right Vertice plus h and R offset float x = hexes[i, j - 1].Points[(int)Hexagonal.FlatVertice.UpperRight].X; float y = hexes[i, j - 1].Points[(int)Hexagonal.FlatVertice.UpperRight].Y; x += h; y -= r; current.Initialize(x, y); hexes[i, j] = current; } else { // Calculate from Hex to left's Middle Right Vertice current.Initialize(hexes[i, j - 1].Points[(int)Hexagonal.FlatVertice.MiddleRight]); hexes[i, j] = current; } } } } } this._playersByColor = players.ToDictionary(x => x.Color); //Give players extra dices at the start. //Each player gets total number of fields minus his largest patch plus MAX_DICE foreach (Player player in players) { int largestPatch = FindLargesPatchForPlayer(player); this.distributeDices(player, (int)((nonWaterFields) * 0.2 - largestPatch + MAX_DICE)); player.Reward = largestPatch; } }
public BoardBuilder withDataTransfer(HexagonalTest.DTOClass data) { this.dataTransfer = data; return(this); }
public WinnerName(HexagonalTest.DTOClass data) { this.dataTransferObject = data; InitializeComponent(); }