public override void Initialize() { base.Initialize(); playerArea = GetComponentInParent <PlayerArea>(); targetObject = playerArea.targetFab; rigidbody = GetComponent <Rigidbody>(); }
private void Move() { if (Time.fixedTime >= nextActionTime) { randomizedSpeed = targetSpeed * UnityEngine.Random.Range(.5f, 1.5f); targetPosition = PlayerArea.ChooseRandomPosition(transform.parent.position, 0f, 5f, 0f, 5f); transform.rotation = Quaternion.Euler(0f, UnityEngine.Random.Range(0f, 360f), 0f); float timeToDest = Vector3.Distance(transform.position, targetPosition) / randomizedSpeed; nextActionTime = Time.fixedTime + timeToDest; } else { Vector3 moveVector = randomizedSpeed * transform.forward * Time.fixedDeltaTime; if (moveVector.magnitude <= Vector3.Distance(transform.position, targetPosition)) { transform.position += moveVector; } else { transform.position = targetPosition; nextActionTime = Time.fixedTime; } } }
public DrawACardCommand(PlayerArea playerArea, CardAsset cardAsset, int handPos, bool canSee) { this.playerArea = playerArea; this.cardAsset = cardAsset; this.handPos = handPos; this.canSee = canSee; }
public PlaySkillCardCommand(PlayerArea playerArea, CardAsset cardAsset, int handIndex, int monsterIndex) { this.playerArea = playerArea; this.cardAsset = cardAsset; this.handIndex = handIndex; this.monsterIndex = monsterIndex; }
public override void OnEndDrag() { GameObject target = DragTarget(); // turn off user monster highlights PlayerArea area = GameStateSync.Instance.opponentArea; area.monsterVisual.turnOffAllHighlights(); if (target != null) { MonsterManager monsterManager = target.GetComponent <MonsterManager>(); // set attack target GameStateSync.Instance.attackRequest.targets.Add(monsterManager.index); GameStateSync.Instance.attackRequest.damages.Add(0); // send attack request GameStateSync.Instance.MakeAttack(); } else { // highlight monster again GetComponentInParent <MonsterManager>().CardFaceGlowImage.enabled = true; } transform.localPosition = new Vector3(0f, 0f, 0.4f); sr.enabled = false; lr.enabled = false; triangleSR.enabled = false; }
/// <summary> /// Función que permite jugar una carta al jugador. /// </summary> public override void EmpezarEjecucionComanda() { //Eliminar la carta de la mano del jugador y elimina el gameobject HandVisual PlayerHand = Controlador.Instance.AreaJugador(p).manoVisual; //TODO se podria hacer que el id de la carta pase a ser el id de la criatura GameObject card = IDHolder.GetGameObjectWithID(cl.ID); PlayerHand.EliminarCarta(card); IDHolder.EliminarElemento(card.GetComponent <IDHolder>()); GameObject.Destroy(card); //Permite la previsualizacion de cartas //HoverPreview.PrevisualizacionesPermitidas = true; OpcionesObjeto.PrevisualizacionesPermitidas = true; // Añade la carta en el tablero PlayerArea areaJugador = Controlador.Instance.AreaJugador(p); if (ente.GetType() == typeof(Magica)) { areaJugador.tableVisual.AñadirMagica(cl.AssetCarta, ente.ID, tablePos); } else { if (((Criatura)ente).PosicionCriatura.Equals(PosicionCriatura.ATAQUE)) { areaJugador.tableVisual.AñadirCriaturaAtaque(cl.AssetCarta, ente.ID, tablePos); } else { areaJugador.tableVisual.AñadirCriaturaDefensa(cl.AssetCarta, ente.ID, tablePos); } } }
public AttackCommand(PlayerArea playerArea, PlayerArea otherPlayerArea, int attackerIndex, int defenderIndex) { this.playerArea = playerArea; this.otherPlayerArea = otherPlayerArea; this.attackerIndex = attackerIndex; this.defenderIndex = defenderIndex; }
public DrawArrowCommand(PlayerArea playerArea, PlayerArea targetArea, int user, int target) { this.playerArea = playerArea; this.targetArea = targetArea; this.user = user; this.target = target; }
/// <summary> /// Retorna o id da area dona da cenoura que voce pediu imbecil /// </summary> /// <param name="carrotId"></param> /// <returns></returns> private int AreaFromThisCarrot(int carrotId) { if (_showDebugMessages) { Debug.Log("Descobrindo a área que é dona dessa cenoura<" + carrotId + ">"); } Carrot carrotToFoundArea = GetCarrotById(carrotId); PlayerArea playerAreaFromThisCarrot = PlayerAreaList.Where(pl => pl.CarrotsList.Contains(carrotToFoundArea)).FirstOrDefault(); if (playerAreaFromThisCarrot == null) { if (_showDebugMessages) { Debug.Log("Cenoura está com algum jogador<Jogador Dono Atual:" + carrotToFoundArea.PlayerOwnerId + ">"); } return(0); } else { if (_showDebugMessages) { Debug.Log("Area dona encontrada: <" + playerAreaFromThisCarrot.Id + ">"); } return(playerAreaFromThisCarrot.Id); } }
public override void OnStartDrag() { savedHandSlot = whereIsCard.Slot; tempState = whereIsCard.VisualState; whereIsCard.VisualState = VisualStates.Dragging; whereIsCard.BringToFront(); PlayerArea area = GameStateSync.Instance.playerArea; if (GameStateSync.Instance.gameView.phase.Equals(GameStateSync.GUTS_PHASE)) { area.monsterVisual.HighlightMonster(area.highlightColor, 3, true); } else if (GameStateSync.Instance.gameView.phase.Equals(GameStateSync.ATTACK_PHASE) || GameStateSync.Instance.gameView.phase.Equals(GameStateSync.DEFEND_PHASE)) { foreach (PlayableCard playableCard in GameStateSync.Instance.playableCardView.playableCards) { if (playableCard.cardIndex == savedHandSlot) { for (int i = 0; i < playableCard.users.Count; i++) { // find targets area.monsterVisual.HighlightMonster(area.highlightColor, playableCard.users[i], true); GameStateSync.Instance.targets = playableCard.targets; } } } } }
/// <summary> /// Función que deshabilita para el jugador bot el visor de mana. /// </summary> public override void EmpezarEjecucionComanda() { PlayerArea areaJugador = Controlador.Instance.AreaJugador(p); areaJugador.ManaBar.gameObject.SetActive(false); comandas.CompletarEjecucionComanda(); }
// Draw or discard cards from hand public void SyncHand(PlayerArea area, ref List <string> playerHand, List <string> newPlayerHand, bool canSee) { for (int i = 0; i < newPlayerHand.Count; i++) { if (i > playerHand.Count - 1) { playerHand.Add(null); } if (!newPlayerHand[i].Equals(playerHand[i])) { // remove if current card is not null if (playerHand[i] != null && !"".Equals(playerHand[i])) { new RemoveACardCommand(area, i).AddToQueue(); } // draw if new card is not null if (newPlayerHand[i] != null && !"".Equals(newPlayerHand[i])) { new DrawACardCommand(area, FindCardAsset(newPlayerHand[i]), i, canSee).AddToQueue(); } // sync hand data to local playerHand[i] = newPlayerHand[i]; } } }
public RemoveACardCommand(PlayerArea playerArea, int monsterPos, int skillPos) { this.playerArea = playerArea; this.monsterPos = monsterPos; this.skillPos = skillPos; this.fromHand = false; }
/// <summary> /// Mira si el jugador tiene el turno, si no hay cartas pendientes por mostrar y si tiene el control activado. /// </summary> /// <returns><c>true</c>, if permite controlar el jugador was sed, <c>false</c> otherwise.</returns> /// <param name="jugador">Jugador.</param> public bool SePermiteControlarElJugador(JugadorPartida jugador) { PlayerArea areaJugador = AreaJugador(jugador); bool TurnoDelJugador = (_jugadorActual == jugador); bool NoCartasPendientesPorMostrar = !Comandas.Instance.ComandasDeDibujoCartaPendientes(); return(areaJugador.PermitirControlJugador && areaJugador.ControlActivado && TurnoDelJugador && NoCartasPendientesPorMostrar); }
/// <summary> /// Función que actualiza de forma visual el mana del jugador usuario. /// </summary> public override void EmpezarEjecucionComanda() { PlayerArea areaJugador = Controlador.Instance.AreaJugador(p); areaJugador.ManaBar.TotalCrystals = TotalMana; areaJugador.ManaBar.AvailableCrystals = AvailableMana; comandas.CompletarEjecucionComanda(); }
// Sync deck card count and size public void SyncDeck(PlayerArea area, ref int deckSize, int newDeckSize) { if (deckSize != newDeckSize) { new ChangeTextCommand(ref area.deckVisual.DeckSizeText, newDeckSize.ToString()).AddToQueue(); deckSize = newDeckSize; } }
// Sync guts amount public void SyncGuts(PlayerArea area, ref int gutsAmount, int newGutsAmount) { if (gutsAmount != newGutsAmount) { new ChangeTextCommand(ref area.monsterVisual.avatarManager.gutsText, newGutsAmount.ToString()).AddToQueue(); gutsAmount = newGutsAmount; } }
/// <summary> /// Determina si la carta se ha soltado en el sitio correcto y que no se encuentre lleno. /// </summary> /// <returns><c>true</c>, if successful was draged, <c>false</c> otherwise.</returns> protected override bool DragSuccessful() { bool TableNotFull = (playerOwner.NumEntesEnLaMesa() < 5); PlayerArea area = Controlador.Instance.AreaJugador(playerOwner); return(area.tableVisual.CursorSobreEstaMesa && TableNotFull); }
public Player(string username, QuestMatch match = null) { this.Converter.Json = new PlayerJsonConversion(); this.match = match; this.username = username; this.rank = new PlayerRank(this); this.hand = new Hand(this); this.battleArea = new PlayerArea(); }
// turn off all highlights public void turnOffAllHighlights(PlayerArea area) { for (int i = 0; i < slots.Children.Length; i++) { if (slots.Children[i].transform != null) { HighlightCard(new Color32(255, 255, 255, 255), i, false); } } }
//TODO inside public bool CheckSides(Pieces currElement, List <Pieces> existingPieces, PlayerArea Area) { //TODO //2. ReWrite for current instance bool result = true; // each existing piece if (currElement.hSpeed < 0) //check Left { //adjust speed and stay in play area for (int speed = -this.hSpeed; speed >= 0; speed--) { if (this.posCol - speed > 2) { this.hSpeed = -speed; break; } } foreach (Pieces piece in existingPieces) { if (piece.posRow == currElement.posRow) { if (piece.posCol + piece.stringLength > currElement.posCol + currElement.hSpeed) { result = false; } } } } else //Check Right { for (int speed = this.hSpeed; speed >= 0; speed--) { if (this.posCol + this.stringLength + speed < Area.Width - 2) { this.hSpeed = speed; break; } } foreach (Pieces piece in existingPieces) { if (piece.posRow == currElement.posRow) { if (piece.posCol < currElement.posCol + currElement.stringLength + currElement.hSpeed) { result = false; } } } } return(result); }
/// <summary> /// Inicializars los valores del jugador. /// </summary> /// <param name="jugador">Jugador.</param> public void InicializarValoresJugador(JugadorPartida jugador) { PlayerArea areaJugador = AreaJugador(jugador); jugador.ManaEnEsteTurno = 0; jugador.ManaRestante = 0; TransmitirInformacionVisualJugador(jugador); areaJugador.mazoVisual.CartasEnMazo = jugador.Jugador.NumCartasMazo(); // move both portraits to the center areaJugador.Personaje.transform.position = areaJugador.PosicionInicialPersonaje.position; }
// TODO: Play currently attack or defense cards from the server public void SyncTable(PlayerArea area, PlayerArea targetArea, ref AttackView attackView, AttackView newAttackView, ref DefendView defendView, DefendView newDefendView, ref GameView gameView, GameView newGameView) { if (newGameView.attackId != gameView.attackId && PLAYER2.Equals(newAttackView.player1)) { // play skill card to table for (int i = 0; i < newAttackView.cardsPlayed.Count; i++) { new RemoveACardCommand(area, newAttackView.handIndexes[i]).AddToQueue(); new PlaySkillCardCommand(area, FindCardAsset(newAttackView.cardsPlayed[i]), newAttackView.handIndexes[i], newAttackView.user).AddToQueue(); } // highlight attacking monster new HighlightCommand(area, newAttackView.user, true).AddToQueue(); // draw targeting arrows for (int i = 0; i < newAttackView.targets.Count; i++) { new DrawArrowCommand(area, targetArea, newAttackView.user, newAttackView.targets[i]).AddToQueue(); } // sync attack view to local gameView.attackId = newGameView.attackId; attackView = newAttackView; } if (newGameView.defendId != gameView.defendId && PLAYER2.Equals(newDefendView.player1)) { if (newDefendView == null) { defendView = newDefendView; return; } // play skill card to table for (int i = 0; i < newDefendView.cardAndTargets.Count; i++) { new RemoveACardCommand(area, newDefendView.cardAndTargets[i].handIndex).AddToQueue(); new PlaySkillCardCommand(area, FindCardAsset(newDefendView.cardAndTargets[i].card), newDefendView.cardAndTargets[i].handIndex, newDefendView.cardAndTargets[i].user).AddToQueue(); } // play attack animation RemoveCardsFromTable(); new AttackCommand(playerArea, opponentArea, attackRequest.user, attackRequest.targets[0]).AddToQueue(); // reset attack request attackRequest.cardsPlayed = new List <int>(); attackRequest.targets = new List <int>(); attackRequest.damages = new List <int>(); // sync defend view to local gameView.defendId = newGameView.defendId; defendView = newDefendView; } }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("PlayerArea")) { Debug.Log("Colliding with some player area: " + other.gameObject.name); _curPlayerArea = other.GetComponent <PlayerArea>(); _playerConfig.GameData.CanIBeTheOwner(_curPlayerArea.Id, _playerConfig.PlayerIdentity.PlayerId); CheckButtonToShow(); } }
public AIDecision(BattleField world, AIPlayer player) { this.world = world; this.player = player; this.area = player.Area; helper = new AIDecisionHelper(world); area.NewCity += PlayerArea_NewCity; area.LostCity += PlayerArea_RemoveCity; }
private void OnTriggerExit(Collider other) { if (other.CompareTag("PlayerArea")) { CheckButtonToShow(); if (_curPlayerArea != null) { _curPlayerArea = null; } } }
public void DrawArrow(PlayerArea targetArea, int user, int target) { GameObject targetArrow = GameObject.Instantiate(GameStateSync.Instance.ArrowTarget) as GameObject; Vector3 startVector = slots.Children[user].transform.position; Vector3 endVector = targetArea.monsterVisual.slots.Children[target].transform.position; LineRenderer lr = targetArrow.GetComponentInChildren <LineRenderer>(); lr.SetPositions(new Vector3[] { startVector, endVector }); lr.sortingLayerName = GameStateSync.ABOVE_EVERYTHING_LAYER; lr.enabled = true; arrows.Add(lr); }
public void InitializeFiguresForPlayer(Player player, PlayerArea area) { for (int x = 0; x < _game.GameFormat; x++) { for (int y = 0; y < _game.GameFormat; y++) { InstantiateAndSubscribeToFigure( area.Positions[x, y], player.PlayerColor, player); } } }
public void TransferCards() { // Transfer cards from player hand to battle area. KingArthur testCard = new KingArthur(ScenarioCreator.EmptyGame()); Hand playerHand = new Hand(null); PlayerArea battleArea = new PlayerArea(); playerHand.Add(testCard); playerHand.Transfer(battleArea, testCard); Assert.AreEqual(playerHand.Count, 0); Assert.AreEqual(battleArea.Count, 1); }
/// <summary> /// Retorna o id da área que o jogador é dono, -1 se ainda não tem área nenhuma /// </summary> /// <param name="playerId"></param> /// <returns></returns> public int GetAreaIdFromSomePlayer(int playerId) { PlayerArea areaFounded = PlayerAreaList.Where(pa => pa.PlayerOwnerId == playerId).FirstOrDefault(); if (areaFounded == null) { return(-1); } else { return(areaFounded.Id); } }
//TODO inside public bool CheckSides(Pieces currElement, List<Pieces> existingPieces, PlayerArea Area) { //TODO //2. ReWrite for current instance bool result = true; // each existing piece if (currElement.hSpeed < 0) //check Left { //adjust speed and stay in play area for (int speed = -this.hSpeed; speed >= 0; speed--) { if (this.posCol -speed >2) { this.hSpeed = -speed; break; } } foreach (Pieces piece in existingPieces) { if (piece.posRow == currElement.posRow) { if (piece.posCol + piece.stringLength > currElement.posCol + currElement.hSpeed) { result = false; } } } } else //Check Right { for (int speed = this.hSpeed; speed >= 0; speed--) { if ( this.posCol+this.stringLength+speed < Area.Width-2) { this.hSpeed = speed; break; } } foreach (Pieces piece in existingPieces) { if (piece.posRow == currElement.posRow) { if (piece.posCol < currElement.posCol + currElement.stringLength + currElement.hSpeed) { result = false; } } } } return result; }
//TODO - DONE public bool CheckRowBelow(List<Pieces> existingPieces, PlayerArea Area) { //working bool isFree = true; //check if out of bounds if (this.posRow + 1 > Area.Height) { isFree = false; } else //check for elements on the row below { foreach (Pieces piece in existingPieces) { Pieces longerString = piece.stringLength >= this.stringLength ? piece : this; Pieces shorterString = piece.stringLength < this.stringLength ? piece : this; //step1 check if they are on the same row if (piece.posRow == this.posRow + 1) { //step2 check if they intersect if (Enumerable.Range(longerString.posCol, longerString.stringLength ).Contains(shorterString.posCol) || Enumerable.Range(longerString.posCol, longerString.stringLength ).Contains(shorterString.posCol + shorterString.stringLength )) { Pieces higherCol; Pieces lowerCol; //broken if equal!!! if (piece.posCol > this.posCol) { higherCol = piece; lowerCol = this; } else if (piece.posCol == this.posCol) { higherCol = piece; lowerCol = this; } else { higherCol = this; lowerCol = piece; } int StartPosition = higherCol.posCol - lowerCol.posCol; //step 3 check each bit for (int col = 0; col < Math.Min(lowerCol.stringLength - StartPosition, shorterString.stringLength); col++) { if (higherCol.toPrint[col] == '1' && lowerCol.toPrint[higherCol.posCol - lowerCol.posCol + col] == '1') { isFree = false; } } } } } } return isFree; }
static void Main() { //settings Console.Clear(); PlayerArea playArea = new PlayerArea(); Console.BufferWidth = Console.WindowWidth = playArea.CanvasWidth; Console.BufferHeight = Console.WindowHeight = playArea.CanvasHeight; Console.Title = "B1tTris: The Game"; Console.BackgroundColor = ConsoleColor.Black; Console.CursorVisible = false; Console.Clear(); int difficultyMin = 1; int difficultyMax = 31; int appSpeed = 300; // lower is faster bool appIsRunning = true; Random mainRandomizer = new Random(); // end settings //variables List<Pieces> staticPieces = new List<Pieces>(); Player player1 = new Player(); //end variables while (appIsRunning) { //Create a new Shape player1.activePiece = new Pieces(mainRandomizer.Next(difficultyMin,difficultyMax)); //allign the new piece to the middle of the area player1.activePiece.posCol = (playArea.Width - player1.activePiece.stringLength) / 2; //MAIN while (player1.activePiece.isMoving) { //read player input while (Console.KeyAvailable) { player1.Input = Console.ReadKey(); switch (player1.Input.Key) { case ConsoleKey.LeftArrow: player1.activePiece.hSpeed += -1; if(player1.activePiece.hSpeed<-3) { player1.activePiece.hSpeed = -3; } player1.Input = new ConsoleKeyInfo(); break; case ConsoleKey.RightArrow: player1.activePiece.hSpeed += 1; if (player1.activePiece.hSpeed >3) { player1.activePiece.hSpeed = 3; } player1.Input = new ConsoleKeyInfo(); break; } } //check if position left or right is free if (player1.activePiece.CheckSides(player1.activePiece, staticPieces, playArea)) { player1.activePiece.posCol += player1.activePiece.hSpeed; //move the piece } player1.activePiece.hSpeed = 0; //rest hSpeed if (player1.activePiece.CheckRowBelow(staticPieces, playArea)) { player1.activePiece.posRow++; } else { player1.activePiece.isMoving = false; } if (!player1.activePiece.isMoving) { //score player1.Score += player1.activePiece.Score; //GAME OVER if(player1.activePiece.posRow==0) { appIsRunning = false; } staticPieces = player1.activePiece.CleanUp(staticPieces); staticPieces.Add(player1.activePiece); //full row player1.Score += player1.activePiece.FullRow(staticPieces); //remove hidden blocks for (int i = 0; i < staticPieces.Count; i++) { if (!staticPieces[i].isVisible) { staticPieces.Remove(staticPieces[i]); i--; } } } //INSERT PRINT FINCTION Console.Clear(); foreach (Pieces piece in staticPieces) { piece.PrintMe(); } player1.activePiece.PrintMe(); Thread.Sleep(appSpeed); } // Thread.Sleep(appSpeed); } Console.WriteLine("game over" + player1.Score); Console.ReadLine(); }