void OnGUI() { if (!Knight.knightAtk) { if (Piece.attacking) { if (GUI.Button(new Rect(10, 10, 150, 100), "End Turn")) { MovePiece.EndTurn(); } } else if (MovePiece.selectedPiece != null) { if (MovePiece.selectedPiece.tag == "Knight") { if (GUI.Button(new Rect(10, 150, 150, 100), "Attack With " + MovePiece.selectedPiece.tag)) { MovePiece.selectedPiece.GetComponent <Knight>().atk = true; Knight.knightAtk = true; } Piece.attacking = true; } } } }
public void UpdateGrid(MovePiece tetris) { for (int y = 0; y < gridHeight; y++) { for (int x = 0; x < gridWidth; x++) { if (grid[x, y] != null) { if (grid[x, y].parent == tetris.transform) { grid[x, y] = null; } } } } foreach (Transform piece in tetris.transform) { Vector3 pos = Round(piece.position); if (pos.y < gridHeight) { grid[(int)pos.x, (int)pos.y] = piece; } } }
public void CanDoMovePieceTest3() { commandMove = new MovePiece(0, 0, 0, 2); Assert.IsTrue(commandMove.CanDo(g) == false); commandMove = new MovePiece(0, 2, 0, 1); Assert.IsTrue(commandMove.CanDo(g) == false); }
public IActionResult MovePiece(int selectedPiece, int currentPlayerId, int gameId, string nameOfCurrentPlayer) { MovePiece movePiece = new MovePiece { playerId = currentPlayerId, pieceId = selectedPiece, numberOfFields = _diceValue }; var request = new RestRequest($"api/ludo/{gameId}", Method.PUT); request.RequestFormat = DataFormat.Json; request.AddJsonBody(movePiece); IRestResponse backendResponse = _client.Put(request); var gameModel = GetTotalGameInfo(gameId); // Try get winner name and assign it to gameModel so it can be accessed in Index.cshtml. request = new RestRequest($"api/ludo/{gameId}/winner", Method.GET); backendResponse = _client.Get(request); string winner = JsonConvert.DeserializeObject <string>(backendResponse.Content); gameModel.winner = winner == "N/A" ? null : winner; Log.Information("Player: {nameOfCurrentPlayer} moved {_diceValue} steps with pieceId: {selectedPiece}", nameOfCurrentPlayer, _diceValue, selectedPiece); return(View("~/Views/Ludo/Index.cshtml", gameModel)); }
public void InitMovePieceTests() { BoardStrategy strat = BoardStrategy.Standard; g = new GameBuilder().SetBoard(3, strat).SetPlayer0("Clément", "vert").SetPlayer1("Pierre", "orange").Build(); commandMove = new MovePiece(0, 0, 1, 0); }
public override void Move(Vector3 target) { if (CanMove(gameObject.transform.position, target)) { base.Move(target); MovePiece.EndTurn(); } }
public virtual void Attack(GameObject target) { if (target.GetComponent <Piece>().hp <= 0) { target.GetComponent <Piece>().Kill(); } target.GetComponent <Piece>().RefreshDisplay(); MovePiece.EndTurn(); }
public static async Task <bool> MovePiece(IRestClient client, MovePiece piece, int gameId) { var response = new RestRequest($"api/ludo/{gameId}", Method.PUT); response.AddJsonBody(piece); var restResponse = await client.ExecuteTaskAsync(response); return(true); }
private void Awake() { movableComponent = GetComponent <MovePiece>(); colorComponent = GetComponent <ColorPeice>(); clearableComponent = GetComponent <ClearablePiece>(); champComponent = GetComponent <ChampPiece>(); bombaComponent = GetComponent <Bomba>(); targetComponent = GetComponent <TargetPiece>(); }
//Deactivate Piece's sockets and stop movement void deactivateGameObject(Transform object1, Transform object2, MovePiece script1, MovePiece script2) { object1.gameObject.SetActive(false); object2.gameObject.SetActive(false); script1.pieceStatus = "idle"; script1.leanSelect.enabled = false; script1.leanDrag.enabled = false; script1.joinStatus = true; script2.joinStatus = true; }
public void MovePieceTest1() { g.Update(new MovePiece(0, 0, 1, 0)); MovePiece cmd = (MovePiece)g.CommandHistory.Pop().GetCommand(); Assert.IsTrue(cmd.NextX == 1); Assert.IsTrue(cmd.NextY == 0); Assert.IsTrue(cmd.PrevX == 0); Assert.IsTrue(cmd.PrevY == 0); Assert.IsTrue(g.UndoHistory.Count == 0); }
/// <summary> /// ハッシュ値を計算します。 /// </summary> public override int GetHashCode() { return( BWType.GetHashCode() ^ (DstSquare != null ? DstSquare.GetHashCode() : 0) ^ (SrcSquare != null ? SrcSquare.GetHashCode() : 0) ^ (MovePiece != null ? MovePiece.GetHashCode() : 0) ^ DropPieceType.GetHashCode() ^ IsPromote.GetHashCode() ^ SpecialMoveType.GetHashCode()); }
public override void Attack(GameObject target) { if (/*gameObject.tag == "Queen" &&*/ CanMove(initPos, target.transform.position) && Distance(gameObject.transform.position, target.transform.position) == 1) { target.GetComponent <Piece>().hp -= attack; base.Attack(target); } else { MovePiece.DeselectPiece(); } }
public override void Attack(GameObject target) { Debug.Log(Distance(initPos, target.transform.position)); if (CanMove(initPos, gameObject.transform.position) && Distance(initPos, target.transform.position) <= speed) { target.GetComponent <Piece>().hp -= attack; base.Attack(target); } else { MovePiece.DeselectPiece(); } }
public Board CreateMoveBoard(Piece piece, List <Move> moves) { Board board = new Board(); Piece moveBoardPiece = piece.Copy(); board.PlacePiece(moveBoardPiece, piece.xPostion, piece.yPostion); foreach (var item in moves) { var movePiece = new MovePiece(piece.isWhite); board.PlacePiece(movePiece, item.xMove, item.yMove); } return(board); }
void traverseChildren(Transform root, string status) { foreach (Transform child in root) { // Do something with child, then recurse. script1 = child.gameObject.GetComponent <MovePiece>(); if (script1 != null) { script1.pieceStatus = status; traverseChildren(child, status); } } }
// Detect to collision with another collider to either attach or not void OnTriggerEnter2D(Collider2D collider) { string string1 = null; string string2 = null; script1 = collider.transform.parent.gameObject.GetComponent <MovePiece>(); script2 = this.transform.parent.gameObject.GetComponent <MovePiece>(); if (collider is CircleCollider2D && collider.gameObject.name == gameObject.name) { string1 = collider.transform.parent.name; string2 = gameObject.transform.parent.name; //float angle1 = collider.transform.parent.transform.localEulerAngles.z; //float angle2 = this.transform.parent.transform.localEulerAngles.z; parent_angle1 = searchParent(collider.transform.parent); parent_angle2 = searchParent(this.transform.parent); angle1 = parent_angle1.localEulerAngles.z; angle2 = parent_angle2.localEulerAngles.z; //print(this.transform.parent.name + " angle " + angle2); //print(collider.transform.parent.name + " angle " + angle1); float angle = Mathf.Round(angle1); print(Mathf.Abs((angle1 - angle2))); if (Mathf.Abs(angle1 - angle2) < 20) { if (script2.pieceStatus == "pickedup") { child = collider.transform.parent; parent = this.gameObject.transform.parent; alignPieces(parent, child, string1, string2, angle); transformParent(parent, child); deactivateGameObject(collider.transform, this.transform, script2, script1); } else if (script1.pieceStatus == "pickedup") { child = this.transform.parent; parent = collider.transform.parent; alignPieces(parent, child, string1, string2, angle); transformParent(parent, child); deactivateGameObject(collider.transform, this.transform, script1, script2); } } } }
public bool CheckIsAboveGrid(MovePiece tetris) { for (int x = 0; x < gridWidth; ++x) { foreach (Transform piece in tetris.transform) { Vector3 pos = Round(piece.position); if (pos.y > gridHeight - 1) { return(true); } } } return(false); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && atk) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction); if (hit.transform.parent.CompareTag("White") || hit.transform.parent.CompareTag("Black")) { Attack(hit.transform.gameObject); if (hp <= 0) { knightAtk = false; atk = false; MovePiece.EndTurn(); Debug.Log(knightAtk + " " + atk + " " + Board.whiteTurn); Kill(); } } else if (hit.transform.CompareTag("Empty")) { //MovePiece.EndTurn(); int currX = (int)gameObject.transform.position.x; int currY = (int)gameObject.transform.position.y; if ((Math.Abs(currX - hit.transform.position.x) == 2 && Math.Abs(currY - hit.transform.position.y) == 1) || (Math.Abs(currX - hit.transform.position.x) == 1 && Math.Abs(currY - hit.transform.position.y) == 2)) { MoveTo(hit.transform.position); hasMoved = false; atk = false; knightAtk = false; MovePiece.EndTurn(); } else { knightAtk = false; atk = false; MovePiece.DeselectPiece(); } } else { atk = false; knightAtk = false; attacking = false; } } }
private IResponse TryMovePiece(MovePiece move) { var player = move.Player; var piece = move.Piece; if (GameState.Value != EGameState.PlayTurn) { return(Failed(move, $"Currently in {GameState}, {player} cannot move {piece}.")); } if (move.Coord == piece.Coord.Value) { return(Failed(move, $"Can't move to same square")); } if (piece.MovedThisTurn) { return(Failed(move, $"{piece} can only move once per turn.")); } if (CurrentPlayer.Value != player) { return(Failed(move, $"Not {player}'s turn.")); } if (player.Mana.Value < 1) { return(Failed(move, "Requires 1 mana to move a piece.")); } if (GetEntry(move.Player).MovedPiece) { return(Failed(move, $"{player} has already moved a piece this turn.")); } var resp = Board.TryMovePiece(move); if (resp.Success) { piece.MovedThisTurn = true; player.ChangeMana(-1); } return(resp); }
// Use this for initialization void Start() { Debug.Log(" ~~~~~~~~~~~~~~~~ GameController"); players = new GameObject[5]; players [1] = P1; players [2] = P2; players [3] = P3; players [4] = P4; money = new float[5]; diceval = new int[5]; playerorder = new GameObject[5]; playerindex = new int[5]; //playerindex used for input for what player is doing what...essentially an int mps = new MovePiece[5]; for (int i = 0; i < 5; ++i) { money [i] = initialMoney; diceval[i] = 0; playerindex[0] = 0; } propertyOwner = new int[32]; for (int i = 0; i < 32; ++i) { propertyOwner[i] = 0; } playerorder [1] = P1; playerorder [2] = P2; playerorder [3] = P3; playerorder [4] = P4; P1mp = P1.GetComponent <MovePiece> (); P2mp = P2.GetComponent <MovePiece> (); P3mp = P3.GetComponent <MovePiece> (); P4mp = P4.GetComponent <MovePiece> (); mps [1] = P1mp; mps [2] = P2mp; mps [3] = P3mp; mps [4] = P4mp; initializeChancePile(); }
public override void Attack(GameObject target) { int currX = (int)gameObject.transform.position.x; int currY = (int)gameObject.transform.position.y; // Debug.Log() if ((Math.Abs(currX - target.transform.position.x) == 2 && Math.Abs(currY - target.transform.position.y) == 1) || (Math.Abs(currX - target.transform.position.x) == 1 && Math.Abs(currY - target.transform.position.y) == 2)) { MoveTo(target.transform.position); GameObject[] g = GameObject.FindGameObjectsWithTag("MoveOption"); for (int i = 0; i < g.Length; ++i) { Destroy(g[i]); } GameObject.FindGameObjectWithTag("MainCamera").GetComponent <MovePiece>().ShowMoves(); hasMoved = true; target.GetComponent <Piece>().hp -= attack; if (target.transform.parent.tag != gameObject.transform.parent.tag) { hp--; RefreshDisplay(); } if (target.GetComponent <Piece>().hp <= 0) { target.GetComponent <Piece>().Kill(); } else { target.GetComponent <Piece>().RefreshDisplay(); } } else if (target != gameObject) { knightAtk = false; atk = false; MovePiece.DeselectPiece(); } }
public uint Serialize() { uint bits = 0; // 2bit bits |= (uint)BWType; // 1bit bits |= ((uint)(IsPromote ? 1 : 0) << 2); // 7bit bits |= ((uint)SerializeSquare(DstSquare) << 3); // 7bit bits |= (ActionType == ActionType.Drop ? ((uint)(DropPieceType + 100) << 10) : ((uint)SerializeSquare(SrcSquare) << 10)); // 1bit bits |= ((uint)(HasSameSquareAsPrev ? 1 : 0) << 17); // 5bit if (MovePiece != null) { bits |= ((uint)MovePiece.Serialize() << 18); } // 5bit if (TookPiece != null) { bits |= ((uint)TookPiece.Serialize() << 23); } // 4bit if (SpecialMoveType != SpecialMoveType.None) { bits |= ((uint)SpecialMoveType << 28); } return(bits); }
public IResponse TryMovePiece(MovePiece move) { Assert.IsNotNull(move); Assert.IsNotNull(move.Coord); Assert.IsNotNull(move.Piece); var coord = move.Coord; var piece = move.Piece; Verbose(5, $"Attempt to move {piece} @{piece.Coord.Value} to {coord}"); var dest = At(coord); if (dest != null) { return(dest != piece?Failed(move, $"Cannot move {piece} onto {dest}") : Response.Ok); } var coords = GetMovements(piece).Coords; return(coords.All(c => c != coord) ? Failed(move, $"Cannot move {move.Piece} move to {move.Coord}") : MovePieceTo(coord, piece)); }
public IResponse TryMovePiece(MovePiece move) { Assert.IsNotNull(move); Assert.IsNotNull(move.Coord); Assert.IsNotNull(move.Piece); var coord = move.Coord; var piece = move.Piece; var dest = At(coord); if (dest != null) { return(dest != piece?Failed(move, $"Cannot move {piece} onto {dest}") : Response.Ok); } var movements = GetMovements(piece); if (!movements.Coords.Any()) { return(Failed(move, $"Cannot move {move.Piece} move to {move.Coord}")); } return(MovePieceTo(coord, piece)); }
public void PutGame(int gameId, [FromBody] MovePiece value) { var player = ludoGames[gameId].GetPlayers().First(p => p.PlayerId == value.PlayerId); ludoGames[gameId].MovePiece(player, value.PieceId, value.NumberOfFields); }
private void Awake() { movableComponent = GetComponent <MovePiece>(); colorComponent = GetComponent <ColorPeice>(); clearableComponent = GetComponent <ClearablePiece>(); }
public override void PlayOneAction(Game g) { if (g.CurrentPlayer == 1) { int prevX = 1, prevY = -1, nextX = -1, nextY = -1; bool isActionValid = false; //Convert MutliDim Enum Array to 1-Dim Int Array int[] intArray = GetIntArray(g.Board.Tiles); int nbTiles = g.Board.Tiles.Length; while (!isActionValid) { int randomNumber = random.Next(0, 100); switch (randomNumber) { case int x when x <= 40: // MovePiece if (g.MovePieceCount < 2) { IntPtr actionMovePiecePtr = Algo_MovePieceNoobStrategy(intArray, nbTiles); prevX = (int)Marshal.ReadIntPtr(actionMovePiecePtr); prevY = (int)Marshal.ReadIntPtr(actionMovePiecePtr + 4); nextX = (int)Marshal.ReadIntPtr(actionMovePiecePtr + 8); nextY = (int)Marshal.ReadIntPtr(actionMovePiecePtr + 12); Console.Write("IA NoobStrategy moves a piece from (" + prevX + "," + prevY + ") to (" + nextX + "," + nextY + ")\n"); MovePiece mp = new MovePiece(prevX, prevY, nextX, nextY); g.Update(mp); isActionValid = true; } break; case int x when x <= 80: // MoveBall if (g.MoveBallCount == 0) { IntPtr actionMoveBallPtr = Algo_MoveBallNoobStrategy(intArray, nbTiles); prevX = (int)Marshal.ReadIntPtr(actionMoveBallPtr); prevY = (int)Marshal.ReadIntPtr(actionMoveBallPtr + 4); nextX = (int)Marshal.ReadIntPtr(actionMoveBallPtr + 8); nextY = (int)Marshal.ReadIntPtr(actionMoveBallPtr + 12); if (nextX != -1 && nextY != -1) { Console.Write("IA NoobStrategy moves his ball from (" + prevX + "," + prevY + ") to (" + nextX + "," + nextY + ")\n"); MoveBall mb = new MoveBall(prevX, prevY, nextX, nextY); g.Update(mb); isActionValid = true; } } break; default: // EndTurn Command endTurnCmd = new EndTurn(); //Console.Write("IA NoobStrategy EndTurn\n"); g.Update(endTurnCmd); break; } } } else { throw new InvalidOperationException("L'IA n'est plus le joueur courant !"); } }
private void Awake() { instance = this; }
public void DoMovePieceTest3() { commandMove = new MovePiece(-1, -1, g.Board.BoardSize - 1, 0); commandMove.Do(g); Assert.IsTrue(g.Board.Tiles[g.Board.BoardSize - 1, 0] == TileTypes.PiecePlayer1); }