private void glBoard_MouseDown(object sender, MouseEventArgs e) { if (!GameClient.MyTurn) { return; } if (_boardRect.Contains((int)_mouseLocation.X, (int)_mouseLocation.Y)) { var piece = GetBoardPieceAt(_mouseLocation); if (piece == null) { return; } _mouseGrabOffset = new PointF(piece.X - _mouseLocation.X, piece.Y - _mouseLocation.Y); _selectedGamePiece = piece.Type; GameClient.DestroyPiece(piece.Id); } else { var pieceOver = GetGutterPieceAt(_mouseLocation); if (pieceOver == null) { return; } _mouseGrabOffset = new PointF(pieceOver.Bounds.X + pieceOver.Bounds.Width / 2 - _mouseLocation.X, pieceOver.Bounds.Y + pieceOver.Bounds.Height / 2 - _mouseLocation.Y); _selectedGamePiece = pieceOver.Piece; } }
public GamePiece(Guid id, GamePieceType type, float x, float y) { Id = id; Type = type; X = x; Y = y; }
public CPacketNewPiece(GamePieceType type, Guid id, float x, float y) { Type = type; Id = id; X = x; Y = y; }
public void fillBoard() { UnityEngine.Random.seed = (int)System.DateTime.Now.Ticks; for (int row = 0; row < Constants.Instance().nRows; row++) { for (int col = 0; col < Constants.Instance().nCols; col++) { // skip over positions that already have triangles if (triangles [row, col] != null) { continue; } // don't make triangles in empty positions if (isEmptyPosition(row, col)) { continue; } // initialize incenters incenters [row, col] = getIncenter(row, col); // instantiate a game object that will not cause a match GamePieceType type_choice = getRandomType(); while (potentialMatchGroup(row, col, type_choice).Count >= 3) // pick at random until no match is made { type_choice = getRandomType(); } triangles [row, col] = GameObject.Instantiate(piecePrefabs [(int)type_choice]); triangles [row, col].GetComponent <TriangleHandler> ().type = type_choice; // make this board the parent of the game piece triangles [row, col].transform.SetParent(transform); triangles [row, col].GetComponent <TriangleHandler> ().Row = row; triangles [row, col].GetComponent <TriangleHandler> ().Col = col; // default is no rune triangles [row, col].GetComponent <TriangleHandler> ().Rune = God.None; // setup name to indicate where the piece is and what it is triangles [row, col].GetComponent <TriangleHandler> ().rename(); // move incenter to correct location triangles [row, col].transform.localPosition = incenters [row, col]; // rotate based on position triangles [row, col].GetComponent <TriangleHandler>().reorient(getDirection(row, col)); } } }
public GutterPiece(Point position, SizeF size, GamePieceType piece) { Position = position; Size = size; Piece = piece; Bounds = new RectangleF(new PointF(Position.X - Size.Width / 2f, Position.Y - Size.Height / 2f), Size); }
private void GameClientOnFloatingPiece(object sender, SPacketFloatingPiece e) { _selectedGamePiece = e.Type; _mouseGrabOffset = PointF.Empty; _mouseLocation = new PointF(e.X, e.Y); glBoard.Invalidate(); }
public static void CreatePiece(GamePieceType pieceType, float x, float y) { var piece = new GamePiece(Guid.NewGuid(), pieceType, x, y); Room.Board.Add(piece); Client.SendMessage(Client.CreateStructMessage(new CPacketNewPiece(piece.Type, piece.Id, piece.X, piece.Y)), NetDeliveryMethod.ReliableUnordered); Client.FlushSendQueue(); }
// returns the list of positions that would match if this piece were the given type List <Vector2> potentialMatchGroup(int row, int col, GamePieceType pieceType, bool recording = false) { if (isEmptyPosition(row, col)) { return(new List <Vector2> ()); } // Determine whether putting the given piece at the given position would cause a match // Do a BFS from the given position and record all pieces with the same piece type List <Vector2> closedList = new List <Vector2> (); Stack <Vector2> openList = new Stack <Vector2> (); openList.Push(new Vector2(row, col)); Vector2 current; List <Vector2> neighbors; while (openList.Count > 0) { current = openList.Pop(); if (isEmptyPosition((int)current.x, (int)current.y)) { continue; } // record that current has been grouped into a match group if (recording && !isEmptyPosition((int)current.x, (int)current.y)) { inMatchGroup [(int)current.x, (int)current.y] = true; } neighbors = getNeighbors((int)current.x, (int)current.y); foreach (Vector2 nbr in neighbors) { // if nothing was put there yet, skip checking if (triangles [(int)nbr.x, (int)nbr.y] == null || isEmptyPosition((int)nbr.x, (int)nbr.y)) { continue; } // if piece was already seen in search, skip checking it again if (closedList.Contains(nbr)) { continue; } if (getType((int)nbr.x, (int)nbr.y).Equals(pieceType)) { //include it in the result of the search openList.Push(nbr); } } closedList.Add(current); } // matches are 3 or more items. return(closedList); }
public GamePiece PlacePiece(GamePieceType piece, bool red) { var b = (red) ? redBank : bank; GamePiece ret = null; if (b[piece].Count > 0) { ret = b[piece][0]; b[piece].RemoveAt(0); } return ret; }
private void glBoard_MouseUp(object sender, MouseEventArgs e) { if (!GameClient.MyTurn) { return; } if (_selectedGamePiece != 0 && _boardRect.Contains((int)_mouseLocation.X, (int)_mouseLocation.Y)) { GameClient.CreatePiece(_selectedGamePiece, e.X + _mouseGrabOffset.X, e.Y + _mouseGrabOffset.Y); } _selectedGamePiece = 0; GameClient.UpdateFloatingPiece(0, 0, 0); }
private SizeF GetPieceSize(GamePieceType piece) { if (piece.HasFlag(GamePieceType.QuestionMark)) { return(_questionSize); } if (piece.HasFlag(GamePieceType.Exclamation)) { return(_exclamationSize); } if (piece.HasFlag(GamePieceType.Cube)) { return(_cubeSize); } return(_bulbSize); }
void doubleCheckMatchGroups() { List <Vector2>[,] matchGroupLists = getAllMatches(); foreach (var matchGrp in matchGroupLists) { if (matchGrp == null || matchGrp.Count == 0) { continue; } GamePieceType groupType = getType((int)matchGrp [0].x, (int)matchGrp [0].y); foreach (var gamePiece in matchGrp) { if (getType((int)gamePiece.x, (int)gamePiece.y) != groupType) { print("BADDIE AT " + gamePiece.ToString()); } } } }
private void GetSelectedGamePieceType() { List <int> selectedTypes = new List <int>(); for (int i = 0; i < System.Enum.GetValues(typeof(GamePieceType)).Length; i++) { int layer = 1 << i; if (((int)Type & layer) != 0) { selectedTypes.Add(i); } } if (selectedTypes.Count == 0 || selectedTypes.Count > 1) { throw new UnassignedReferenceException("You must select a single, valid Game Piece Type for each Game Piece object."); } this.Type = (GamePieceType)selectedTypes[0]; }
public override void PlayerAttacked(BasePlayer player, Point from, Point to, GamePieceType piece, AttackResult result) { EstimatedState[from.x, from.y] = null; if (result == AttackResult.Win) { if (player != this) { EstimatedState[to.x, to.y] = GamePieceFactory.Create(piece, !this.IsRed); } } else if (result == AttackResult.Tie) { EstimatedState[to.x, to.y] = null; } else if (result == AttackResult.Lose) { if (player == this) { EstimatedState[to.x, to.y] = GamePieceFactory.Create(piece, !this.IsRed); } } }
private void DrawPiece(GamePieceType piece, float x, float y) { var tint = Color.White; if (piece.HasFlag(GamePieceType.Blue)) { tint = Color.DeepSkyBlue; } else if (piece.HasFlag(GamePieceType.Green)) { tint = Color.LawnGreen; } else if (piece.HasFlag(GamePieceType.Red)) { tint = Color.OrangeRed; } else if (piece.HasFlag(GamePieceType.Yellow)) { tint = Color.Yellow; } if (piece.HasFlag(GamePieceType.QuestionMark)) { DrawQuestion(x, y, tint); } else if (piece.HasFlag(GamePieceType.Exclamation)) { DrawExclamation(x, y, tint); } else if (piece.HasFlag(GamePieceType.Cube)) { DrawCube(x, y, tint); } else if (piece.HasFlag(GamePieceType.LightBulb)) { DrawBulb(x, y, tint); } }
public static GamePiece Create(GamePieceType gamePieceType, bool IsRed) { if (gamePieceType == GamePieceType.Bomb) { return new BombGamePiece(IsRed); } if (gamePieceType == GamePieceType.Spy) { return new SpyGamePiece(IsRed); } if (gamePieceType == GamePieceType.Flag) { return new FlagGamePiece(IsRed); } if (gamePieceType == GamePieceType.Eight) { return new EightGamePiece(IsRed); } return new GamePiece(gamePieceType, IsRed); }
public bool PlacePiece(GamePieceType pieceType, bool red, Point p) { if (state.Turn == PlayerTurn.Setup) { if (red) { if (p.y < 6) { return false; } } else { if (p.y > 3) { return false; } } if(state.Board[p.x, p.y] == null) { var piece = bank.PlacePiece(pieceType, red); if (piece != null) { state.Board[p.x, p.y] = piece; return true; } } } return false; }
private void DrawBankItem(GamePieceType piece, int x, int y) { DrawPiece(x, y, piece, playerIsRed); string text = stratego.GetAvailablePieces(piece, playerIsRed).ToString(); var size = Font.MeasureString(text); spriteBatch.DrawString(Font, text, new Vector2(x + 72 - size.X / 2, y + (GRID_SIZE - size.Y) / 2), Color.White); }
private void RenderPiece(int grid_size, GamePieceType piece, bool isRed) { if (piece > 0) { Rectangle rect = new Rectangle(1, 1, grid_size - 1, grid_size - 1); spriteBatch.Draw(pixel, rect, piece.IsBlock() ? Color.Black : isRed ? Color.Red : Color.Blue); if (!piece.IsBlock() && !piece.IsHidden()) { var text = Text[piece.GetPieceType()]; var size = Font.MeasureString(text); GraphicsDevice.Clear(Color.Transparent); spriteBatch.DrawString(Font, text, new Vector2((grid_size - size.X) / 2, (grid_size - size.Y) / 2), Color.White); } } }
public int GetAvailablePieces(GamePieceType piece, bool red) { return bank.PieceCount(piece, red); }
public abstract void PlayerAttacked(BasePlayer player, Point from, Point to, GamePieceType piece, AttackResult result);
public CPacketFloatingPiece(GamePieceType type, float x, float y) { Type = type; X = x; Y = y; }
private Texture2D RenderPieceTexture(int width, int height, GamePieceType gamePiece, bool isRed) { Texture2D texture = new Texture2D(GraphicsDevice, width, height); var renderTarget = new RenderTarget2D(GraphicsDevice, width, height); GraphicsDevice.SetRenderTarget(renderTarget); spriteBatch.Begin(); RenderPiece(width, gamePiece, isRed); spriteBatch.End(); GraphicsDevice.SetRenderTarget(null); Color[] c = new Color[width * height]; renderTarget.GetData<Color>(c); texture.SetData<Color>(c); return texture; }
public int PieceCount(GamePieceType piece, bool red) { var b = (red) ? redBank : bank; return b[piece].Count; }
public IEnumerator handleMatches(bool playerTurn = true) { // wait until other stuff finishes while (BattleInfo.gameState != GameState.HandlingMatches) { ; } List <Vector2>[,] matchGroupLists = getAllMatches(); Dictionary <GamePieceType, int> matchedPieces = new Dictionary <GamePieceType, int>(); // start with 0 pieces of each type matched foreach (GamePieceType gptype in Enum.GetValues(typeof(GamePieceType))) { matchedPieces.Add(gptype, 0); } bool matchedFervor = false; bool extraTurn = false; foreach (List <Vector2> matchGrp in matchGroupLists) { if (matchGrp.Count >= 3) { // record pieces matched so they can have their match effect GamePieceType matchType = triangles [(int)matchGrp [0].x, (int)matchGrp [0].y].GetComponent <TriangleHandler> ().type; matchedPieces [matchType] += matchGrp.Count; if (matchType == GamePieceType.Fervor) { matchedFervor = true; } // if you match enough pieces, you get an extra turn! if (matchGrp.Count >= 4) { Vector2 positionOfFirstPiece = RectTransformUtility.WorldToScreenPoint( Camera.main, incenters [(int)matchGrp [0].x, (int)matchGrp [0].y]); extraTurn = true; UIHandler.Instance().spawnRisingText(positionOfFirstPiece, "Extra Turn!", Color.red, floatingDistance: 15, lifespan: 1.5f, fontSize: 18, fontStyle: FontStyle.Normal); } yield return(explodePieces(matchGrp)); yield return(applyMatchedPieces(matchType, matchedPieces[matchType])); } } // if you got an extra turn, let that register briefly before giving next turn. // TODO: probably remove this when game pieces slide into place instead of appearing instantly if (!matchedFervor) { if (BattleInfo.playerWentLast) { BattleInfo.doPlayerFervorDecay(); } else { BattleInfo.currentEnemy.doFervorDecay(); } } fillBoard(); // if the board is left with no matches, reset it. while (getLegalSwaps().Count == 0) { reset(); } if (extraTurn) { yield return(new WaitForSeconds(1.5f)); } // TODO: instead of always switching turns after handling matches, wait for falling pieces // to finish falling, handle their matches, and only switch turns once this process yields // no more matches // if the game should be over now (someone's health is 0), do end-game popup if (BattleInfo.playerHealth == 0) { UIHandler.Instance().youLostDialog(); yield break; } else if (BattleInfo.currentEnemy.health == 0) { UIHandler.Instance().youWonDialog(); yield break; } // Display "Your turn" or "enemy's turn" for some amount of time first, float timeToShowTurnSwitch = 1.5f; if (!extraTurn) // only show if it's the beginning of the turn, not an extra turn { if (BattleInfo.playerWentLast) { Vector2 middleScreen = RectTransformUtility.WorldToScreenPoint(Camera.main, Camera.main.transform.position); UIHandler.Instance().spawnRisingText(middleScreen, "Enemy Turn", Color.red, floatingDistance: 0, lifespan: timeToShowTurnSwitch, fontSize: 70, fontStyle: FontStyle.Normal); } else //if ((BattleInfo.playerWentLast && extraTurn) || (!BattleInfo.playerWentLast && !extraTurn)) { Vector2 middleScreen = RectTransformUtility.WorldToScreenPoint(Camera.main, Camera.main.transform.position); UIHandler.Instance().spawnRisingText(middleScreen, "Your Turn", Color.cyan, floatingDistance: 0, lifespan: timeToShowTurnSwitch, fontSize: 70, fontStyle: FontStyle.Normal); } } yield return(new WaitForSeconds(timeToShowTurnSwitch)); // then actually change turns if ((BattleInfo.playerWentLast && !extraTurn) || (!BattleInfo.playerWentLast && extraTurn)) { // wait a little longer, to feel like the enemy is "thinking"... yield return(new WaitForSeconds(timeToShowTurnSwitch)); BattleInfo.gameState = GameState.EnemyTurn; } else // if ((BattleInfo.playerWentLast && extraTurn) || (!BattleInfo.playerWentLast && !extraTurn)) { BattleInfo.gameState = GameState.PlayerTurn; } yield return(null); }
public IEnumerator applyMatchedPieces(GamePieceType type, int numPieces) { // prep floating text stuff GameObject playerSprite = GameObject.Find("Player Sprite"); Vector2 spritePos = RectTransformUtility.WorldToScreenPoint(Camera.main, playerSprite.transform.position); if (BattleInfo.playerWentLast) { switch (type) { case GamePieceType.Damage: // player deals damage float damageDealt = (1 + BattleInfo.playerFervorMultiplier * BattleInfo.playerFervor) * numPieces; if (damageDealt > 0) { BattleInfo.currentEnemy.takeDamage(damageDealt); } break; case GamePieceType.Healing: float prevHealth = BattleInfo.playerHealth; BattleInfo.playerHealth += numPieces; BattleInfo.playerHealth = Mathf.Min(BattleInfo.playerMaxHealth, BattleInfo.playerHealth); // floating healing text! float roundedHealing = BattleInfo.playerHealth - prevHealth; if (roundedHealing > 0) { UIHandler.Instance().spawnRisingText(spritePos, "+" + roundedHealing.ToString(), Constants.Instance().healingColor, floatingDistance: 90, lifespan: 2.5f); } break; case GamePieceType.Coin: float prevCoins = BattleInfo.Coins; BattleInfo.Coins += numPieces; // floating money text! float roundedCoins = BattleInfo.Coins - prevCoins; if (roundedCoins > 0) { UIHandler.Instance().spawnRisingText(spritePos, "+" + roundedCoins.ToString(), Constants.Instance().coinColor, floatingDistance: 90, lifespan: 2.5f); } break; case GamePieceType.Fervor: float prevFervor = BattleInfo.playerFervor; BattleInfo.playerFervor += numPieces; BattleInfo.playerFervor = Mathf.Min(BattleInfo.playerFervor, BattleInfo.playerMaxFervor); // floating fervor text! float roundedFervor = BattleInfo.playerFervor - prevFervor; if (roundedFervor > 0) { UIHandler.Instance().spawnRisingText(spritePos, "+" + roundedFervor.ToString(), Constants.Instance().fervorColor, floatingDistance: 90, lifespan: 2.5f); } break; case GamePieceType.Summoning: float prevSummoning = BattleInfo.playerSummoning; BattleInfo.playerSummoning += numPieces; BattleInfo.playerSummoning = Mathf.Round(Mathf.Min(BattleInfo.playerSummoning, BattleInfo.playerMaxSummoning)); // floating summoning-gain text! float roundedSummoning = BattleInfo.playerSummoning - prevSummoning; if (roundedSummoning > 0) { UIHandler.Instance().spawnRisingText(spritePos, "+" + roundedSummoning.ToString(), Constants.Instance().summoningColor, floatingDistance: 90, lifespan: 2.5f); } break; default: yield return(null); break; } } else // player didn't go last { switch (type) { case GamePieceType.Damage: // enemy deals damage float prevValue = BattleInfo.playerHealth; BattleInfo.playerHealth -= (1 + BattleInfo.currentEnemy.fervorMultiplier * BattleInfo.currentEnemy.fervor) * numPieces; BattleInfo.playerHealth = Mathf.Round(Mathf.Max(0, BattleInfo.playerHealth)); float damageDealt = prevValue - BattleInfo.playerHealth; // floating damage text! if (damageDealt > 0) { UIHandler.Instance().spawnRisingText(spritePos, "-" + damageDealt.ToString(), Constants.Instance().damageColor, floatingDistance: -90, lifespan: 2.5f); } break; case GamePieceType.Healing: BattleInfo.currentEnemy.healDamage(numPieces); break; case GamePieceType.Coin: // nobody's gettin' that gold! // maybe some special enemies will collect gold and do something with it, or give more gold // when you defeat them. break; case GamePieceType.Fervor: BattleInfo.currentEnemy.addFervor(numPieces); break; case GamePieceType.Summoning: BattleInfo.currentEnemy.addSummoning(numPieces); break; default: yield return(null); break; } } }
// returns a dictionary of swaps (key) and the match type they create (value) public Dictionary <Vector4, GamePieceType> getLegalSwaps() { // TODO: TODO: TODO: // this usually gives correct moves, but sometimes gives wrong swaps in the sense that: // - makes a swap that does not result in a match.... List <Vector2>[,] matchGroupLists = getAllMatches(); Dictionary <Vector4, GamePieceType> legalSwaps = new Dictionary <Vector4, GamePieceType> (); GamePieceType groupType; // first do simple swaps (not including swaps that connect three entirely isolated pieces foreach (List <Vector2> matchGrp in matchGroupLists) { // DEBUGGING: I'm pretty sure matchGroupLists is correct. if (matchGrp.Count < 2) { continue; } groupType = getType((int)matchGrp [0].x, (int)matchGrp [0].y); // DEBUGGING: I'm pretty sure getType is correct. // if any one-step neighbors (outside the group) have a one-step neighbor same as the matchgroup, // report a swap there. // gather the neighbors of the match group List <Vector2> neighbors = new List <Vector2> (); foreach (Vector2 gamePiece in matchGrp) { List <Vector2> gamePieceNeighbors = getNeighbors((int)gamePiece.x, (int)gamePiece.y); foreach (Vector2 nbr in gamePieceNeighbors) { if (!neighbors.Contains(nbr) && !matchGrp.Contains(nbr)) { neighbors.Add(nbr); } else if (matchGrp.Contains(nbr)) { } } } foreach (Vector2 nbr in neighbors) { // test swapping that neighbor with one of its neighbors. // if it yields a match (same type as group type), record it List <Vector2> two_away_nbrs = getNeighbors((int)nbr.x, (int)nbr.y); foreach (Vector2 two_away_nbr in two_away_nbrs) { // don't use two_away_nbrs in the match group itself if (matchGrp.Contains(two_away_nbr)) { continue; } if (getType((int)two_away_nbr.x, (int)two_away_nbr.y).Equals(groupType)) { Vector4 theSwap = new Vector4(nbr.x, nbr.y, two_away_nbr.x, two_away_nbr.y); if (!legalSwaps.ContainsKey(theSwap)) { legalSwaps.Add(theSwap, groupType); } } } } } // add "triangle swaps"; game pieces with all neighbors the same color. any of these neighbors // can be swapped with the central one to make a match // TODO: finish this for (int row = 0; row < Constants.Instance().nRows; row++) // top and bottom row can't be the center { for (int col = 0; col < Constants.Instance().nCols; col++) { // if a piece has 3 neighbors and all are the same color, return all 3 swaps List <Vector2> neighbors = getNeighbors(row, col); if (neighbors.Count < 3) { continue; } GamePieceType firstNeighborType = getType((int)neighbors [0].x, (int)neighbors [0].y); bool allSame = true; foreach (Vector2 nbr in neighbors) { if (isEmptyPosition((int)nbr.x, (int)nbr.y) || getType((int)nbr.x, (int)nbr.y) != firstNeighborType) { allSame = false; } } if (allSame) { // add swaps with each neighbor foreach (Vector2 nbr in neighbors) { Vector4 theSwap = new Vector4(nbr.x, nbr.y, row, col); if (!legalSwaps.ContainsKey(theSwap)) { legalSwaps.Add(theSwap, firstNeighborType); } } } } } return(legalSwaps); }
private void AddPieces(GamePieceType gamePieceType,int count) { List<GamePiece> pieces = new List<GamePiece>(); List<GamePiece> redPieces = new List<GamePiece>(); for (int i = 0; i < count; i++) { pieces.Add(GamePieceFactory.Create(gamePieceType, false)); redPieces.Add(GamePieceFactory.Create(gamePieceType, true)); } bank.Add(gamePieceType, pieces); redBank.Add(gamePieceType, redPieces); }
public GamePiece(GamePieceType gamePieceType, bool IsRed) { Type = gamePieceType; this.IsRed = IsRed; }
public static void UpdateFloatingPiece(GamePieceType pieceType, float x, float y) { Client.SendMessage(Client.CreateStructMessage(new CPacketFloatingPiece(pieceType, x, y)), NetDeliveryMethod.UnreliableSequenced); Client.FlushSendQueue(); }
private void DrawPiece(int x, int y, GamePieceType piece, bool isRed, bool hideOtherColor = true) { if (piece != null) { Texture2D texture = null; if (!piece.IsBlock() && hideOtherColor) { if (isRed != playerIsRed) { piece = GamePieceType.Hidden; } } if (texture == null) { texture = ((isRed)?RedPieceTextures:BluePieceTextures)[piece]; } spriteBatch.Draw(texture, new Vector2(x, y), Color.White); } }