private void ComputerClick(List <int[]> moveToClick) //metoda imitująca kliknięcie na podstawie najlepszego znalezionego ruchu { GameObject[] pawnsArray = app.controller.board.PawnsArray; GameObject[] emptyArray = app.controller.board.EmptyArray; for (int i = 0; i < pawnsArray.Length; i++) { PawnScript tmpPawnScript = pawnsArray [i].GetComponent <PawnScript> (); if (tmpPawnScript.matrix_x == moveToClick [0] [0] && tmpPawnScript.matrix_y == moveToClick [0] [1]) { app.controller.board.Click(tmpPawnScript); //wywołanie kliknięcia pionka } } for (int i = 1; i < moveToClick.Count; i++) { for (int j = 0; j < emptyArray.Length; j++) { PawnScript tmpPawnScript = emptyArray [j].GetComponent <PawnScript> (); if (tmpPawnScript.matrix_x == moveToClick [i] [0] && tmpPawnScript.matrix_y == moveToClick [i] [1]) { app.controller.board.Click(tmpPawnScript); //wywołanie kliknięcia pustej pozycji } } } }
private void PrepareClick(int x, int y) { GameObject[] pawnsArray = app.controller.board.PawnsArray; bool isPawn = false; for (int j = 0; j < pawnsArray.Length; j++) { PawnScript ps = pawnsArray[j].GetComponent <PawnScript>(); if (ps.matrix_x == x && ps.matrix_y == y) { app.controller.board.Click(ps); isPawn = true; break; } } if (!isPawn) { GameObject[] empty = app.controller.board.EmptyArray; for (int j = 0; j < empty.Length; j++) { PawnScript ps = empty[j].GetComponent <PawnScript>(); if (ps.matrix_x == x && ps.matrix_y == y) { app.controller.board.Click(ps); break; } } } }
public bool AssignedPawn(PawnScript mypawn) { foreach (PawnScript go in pawns) { if (go.Equals(mypawn)) { return(true); } } return(false); }
public void StartGame() { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { GameObject pawn = PhotonNetwork.Instantiate(playerPawn.name, playerPawn.transform.position, playerPawn.transform.rotation, 0); PawnScript pawnScript = pawn.GetComponent <PawnScript>(); pawnScript.SetColor((PlayerColorsEnum)i); pawnScript.SetOrder(j); } } }
public void MovePawn(PawnScript pawn, MoveDirection direction) { if (pawn != null) { pawn.Move(direction); } if (CheckEndGame()) { EndGame(); } else { NextTurn(); } }
public void Select(PawnScript pawn, bool left, bool top, bool right, bool bottom) { if (pawn != null) { leftS.SetActive(left); topS.SetActive(top); rightS.SetActive(right); bottomS.SetActive(bottom); transform.position = pawn.transform.position; informationPanel.SetActive(true); informationPanel.transform.Find("InformationText").GetComponent <Text>().text = pawn.GetInformation(); } gameObject.SetActive(pawn != null); informationPanel.SetActive(pawn != null); }
void FindBestTurn() { PawnScript selectPawn = null; MoveDirection direction = MoveDirection.Left; float deltaScore = -100; foreach (PawnScript go in pawns) { float newScore = 0; Vector2 position = go.transform.position; float score = GetScorePosition(position); Vector2 newPosition = Vector2.left; MoveDirection newDirection = MoveDirection.Left; for (var i = 0; i < 4; i++) { Vector2 pos = position + newPosition; if (cgs.notPawnInPosition(pos) && pos.x >= 0 && pos.y >= 0 && pos.x <= 7 && pos.y <= 7) { newScore = GetScorePosition(pos); if (newScore - score > deltaScore) { deltaScore = newScore - score; selectPawn = go; direction = newDirection; } } switch (i) { case 0: newDirection = MoveDirection.Top; newPosition = Vector2.up; break; case 1: newDirection = MoveDirection.Right; newPosition = Vector2.right; break; case 2: newDirection = MoveDirection.Bottom; newPosition = Vector2.down; break; } } } cgs.MovePawn(selectPawn, direction); }
public void Glowing(PawnScript pS, List <int[]> moves_list) { List <int[]> moves; moves = new List <int[]> (); for (int i = 0; i < moves_list.Count; i++) { moves.Add(moves_list [i]); } int iter = 0; for (int i = 0; i < board.Length; i++) { for (int j = 0; j < board [i].Length; j++) { if (board [i] [j] == -1) { continue; } if (pS.matrix_x == i && pS.matrix_y == j) { glowsArray [iter].GetComponent <SpriteRenderer> ().color = BLUE; glowsArray [iter].transform.localScale = new Vector3(1f, 1f, 1f); iter++; continue; } for (int k = 0; k < moves.Count; k++) { if (moves [k] [0] == i && moves [k] [1] == j) { glowsArray [iter].GetComponent <SpriteRenderer> ().color = GREEN; glowsArray [iter].transform.localScale = new Vector3(0.75f, 0.75f, 1f); moves.RemoveAt(k); break; } } iter++; } } }
public void NextTurn() { int nowIndex = players.IndexOf(activePlayer); if (nowIndex == players.Count - 1) { activePlayer = players[0]; } else { activePlayer = players[nowIndex + 1]; } selectPawn = null; selectObject.Select(null, false, false, false, false); OnVisionTurn(); if (activePlayer is AIScript) { (activePlayer as AIScript).AITurn(); } }
void Update() { if (isInit) { if (gameMode.mode == GameModeController.Mode.multiplayer_bluetooth_server && app.controller.turns.Turn != 1) { return; } if (gameMode.mode == GameModeController.Mode.multiplayer_bluetooth_client && app.controller.turns.Turn != 2) { return; } if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePos.z = 0; RaycastHit2D hit = Physics2D.Raycast(mousePos, Vector2.zero); if (hit.collider != null) { PawnScript pS = hit.collider.GetComponent <PawnScript>(); Debug.Log("Mouse"); board.Click(pS); } } else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); mousePos.z = 0; RaycastHit2D hit = Physics2D.Raycast(mousePos, Vector2.zero); if (hit.collider != null) { PawnScript pS = hit.collider.GetComponent <PawnScript> (); Debug.Log("Touch"); board.Click(pS); } } } }
void Select(Vector3 position) { selectPawn = null; foreach (PLayerScript ps in players) { selectPawn = ps.GetPawnOnPosition(position); if (selectPawn != null) { Vector2 posPawn = selectPawn.transform.position; Vector2 newPos = posPawn + Vector2.left; bool left = notPawnInPosition(newPos) && newPos.x >= 0; newPos = posPawn + Vector2.right; bool right = notPawnInPosition(newPos) && newPos.x < 8; newPos = posPawn + Vector2.up; bool top = notPawnInPosition(newPos) && newPos.y < 8; newPos = posPawn + Vector2.down; bool bottom = notPawnInPosition(newPos) && newPos.y >= 0; selectObject.Select(selectPawn, left, top, right, bottom); return; } } selectObject.Select(null, false, false, false, false); }
public void Init() { app = App.Instance; board = new int[3][]; boardTransform = app.view.board; emptyTransform = app.view.empty; glowTransform = app.view.glow; glowController = app.controller.glow; glow = app.model.glows; pawn1 = app.model.pawn1; pawn2 = app.model.pawn2; empty = app.model.empty; points = app.view.points; string boardString = ""; pointArray = new Transform[points.childCount]; pawnsArray = new GameObject[points.childCount - 1]; emptyArray = new GameObject[points.childCount]; glowsArray = new GameObject[points.childCount]; for (int i = 0; i < points.childCount; i++) { pointArray [i] = points.GetChild(i); } int iterPawn = 0; int iterPos = 0; for (int i = 0; i < board.Length; i++) { board [i] = new int[7]; for (int j = 0; j < board [i].Length; j++) { if (i % 2 == 0 && j == 3) { } else { GameObject empty_position = Instantiate(empty); empty_position.name = "Empty " + iterPos; empty_position.transform.SetParent(emptyTransform); empty_position.transform.localPosition = new Vector3(pointArray[iterPos].localPosition.x, pointArray[iterPos].localPosition.y, 1); empty_position.AddComponent <CircleCollider2D>(); empty_position.GetComponent <CircleCollider2D>().radius = 1.25f; emptyArray[iterPos] = empty_position; PawnScript emptyScript = emptyArray[iterPos].GetComponent <PawnScript>(); emptyScript.id = iterPos; emptyScript.team = 0; emptyScript.matrix_x = i; emptyScript.matrix_y = j; ps_chosen = null; moves_list = new List <int[]>(); GameObject glowPosition = Instantiate(glow); glowPosition.name = "Glow " + iterPos; glowPosition.transform.SetParent(glowTransform); glowPosition.transform.localPosition = new Vector3(pointArray[iterPos].localPosition.x, pointArray[iterPos].localPosition.y, 0f); glowsArray[iterPos] = glowPosition; SpriteRenderer renderer = glowsArray[iterPos].GetComponent <SpriteRenderer>(); renderer.color = new Color(0f, 1f, 0f, 0f); } if (i == 1 && j == 3) { board [i] [j] = 0; boardString += board [i] [j]; iterPos++; } else if (i % 2 == 0 && j == 3) { board [i] [j] = -1; boardString += board [i] [j]; } else { if (j <= 2) { board [i] [j] = 1; boardString += board [i] [j]; GameObject pawn = Instantiate(pawn1); pawn.name = "Pawn " + iterPawn; pawn.transform.SetParent(boardTransform); pawn.transform.localPosition = new Vector3(pointArray [iterPos].localPosition.x, pointArray [iterPos].localPosition.y, 0f); pawn.AddComponent <CircleCollider2D> (); pawnsArray [iterPawn] = pawn; PawnScript pawnScript = pawnsArray [iterPawn].GetComponent <PawnScript> (); pawnScript.id = iterPawn; pawnScript.team = 1; pawnScript.matrix_x = i; pawnScript.matrix_y = j; iterPawn++; iterPos++; } else { board [i] [j] = 2; boardString += board [i] [j]; GameObject pawn = Instantiate(pawn2); pawn.name = "Pawn " + iterPawn; pawn.transform.SetParent(boardTransform); pawn.transform.localPosition = new Vector3(pointArray [iterPos].localPosition.x, pointArray [iterPos].localPosition.y, 0f); pawn.AddComponent <CircleCollider2D> (); pawnsArray [iterPawn] = pawn; PawnScript pawnScript = pawnsArray [iterPawn].GetComponent <PawnScript> (); pawnScript.id = iterPawn; pawnScript.team = 2; pawnScript.matrix_x = i; pawnScript.matrix_y = j; iterPawn++; iterPos++; } } boardString += " "; } boardString += "\n"; } print(boardString); }
public void Click(PawnScript pawnScript) { Debug.Log("Clicked - team: " + pawnScript.team + " x: " + pawnScript.matrix_x + " y: " + pawnScript.matrix_y); if (ps_chosen == null && pawnScript.team == app.controller.turns.Turn) { if (app.controller.turns.CaptureAvailable != pawnScript.canCapture) { Debug.Log("CaptureAvailable!"); return; } ps_chosen = pawnScript; Debug.Log("Chosen pawn: " + ps_chosen.id); moves_list = app.controller.logic.checking(pawnScript.team, pawnScript.matrix_x, pawnScript.matrix_y, board); for (int i = 0; i < moves_list.Count; i++) { Debug.Log("Logic = x: " + moves_list[i][0] + " y: " + moves_list[i][1]); } glowController.Glowing(ps_chosen, moves_list); if ((app.controller.gameMode.mode == GameModeController.Mode.multiplayer_bluetooth_client && app.controller.turns.Turn == 2) || (app.controller.gameMode.mode == GameModeController.Mode.multiplayer_bluetooth_server && app.controller.turns.Turn == 1)) { //app.controller.bluetooth.SendMove(pawnScript.matrix_x, pawnScript.matrix_y); FindObjectOfType <LostPolygon.AndroidBluetoothMultiplayer.Examples.ActorController>().SendMove(pawnScript.matrix_x, pawnScript.matrix_y); } } else if (ps_chosen == pawnScript) { Debug.Log("Unchosen pawn: " + pawnScript.id); ps_chosen = null; app.controller.logic.capture = false; moves_list.Clear(); glowController.DisableGlows(); if ((app.controller.gameMode.mode == GameModeController.Mode.multiplayer_bluetooth_client && app.controller.turns.Turn == 2) || (app.controller.gameMode.mode == GameModeController.Mode.multiplayer_bluetooth_server && app.controller.turns.Turn == 1)) { //app.controller.bluetooth.SendMove(pawnScript.matrix_x, pawnScript.matrix_y); FindObjectOfType <LostPolygon.AndroidBluetoothMultiplayer.Examples.ActorController>().SendMove(pawnScript.matrix_x, pawnScript.matrix_y); } } else if (pawnScript.team == 0 && ps_chosen != null) { for (int i = 0; i < moves_list.Count; i++) { if (pawnScript.matrix_x == moves_list[i][0] && pawnScript.matrix_y == moves_list[i][1]) { if (app.controller.logic.capture) { int captured_x; if (ps_chosen.matrix_x == 1) { captured_x = pawnScript.matrix_x; } else if (pawnScript.matrix_x == 1) { captured_x = ps_chosen.matrix_x; } else { captured_x = ps_chosen.matrix_x + (pawnScript.matrix_x - ps_chosen.matrix_x) / 2; } int captured_y = ps_chosen.matrix_y + (pawnScript.matrix_y - ps_chosen.matrix_y) / 2; for (int j = 0; j < pawnsArray.Length; j++) { PawnScript ps_captured = pawnsArray[j].GetComponent <PawnScript>(); if (ps_captured.matrix_x == captured_x && ps_captured.matrix_y == captured_y) { ps_captured.matrix_x = -1; ps_captured.matrix_y = -1; ps_captured.Disable(); board[captured_x][captured_y] = 0; break; } } moves_list = app.controller.logic.checking(ps_chosen.team, pawnScript.matrix_x, pawnScript.matrix_y, board); } board[ps_chosen.matrix_x][ps_chosen.matrix_y] = 0; ps_chosen.matrix_x = pawnScript.matrix_x; ps_chosen.matrix_y = pawnScript.matrix_y; ps_chosen.MoveTo(pawnScript.transform.localPosition.x, pawnScript.transform.localPosition.y); board[pawnScript.matrix_x][pawnScript.matrix_y] = ps_chosen.team; glowController.DisableGlows(); if ((app.controller.gameMode.mode == GameModeController.Mode.multiplayer_bluetooth_client && app.controller.turns.Turn == 2) || (app.controller.gameMode.mode == GameModeController.Mode.multiplayer_bluetooth_server && app.controller.turns.Turn == 1)) { //app.controller.bluetooth.SendMove(pawnScript.matrix_x, pawnScript.matrix_y); FindObjectOfType <LostPolygon.AndroidBluetoothMultiplayer.Examples.ActorController>().SendMove(pawnScript.matrix_x, pawnScript.matrix_y); } if (!app.controller.logic.capture) { moves_list.Clear(); ps_chosen = null; app.controller.turns.ChangeTurn(); } else { glowController.Glowing(ps_chosen, moves_list); } break; } } } }
public float GetScorePawn(PawnScript go) { return(GetScorePosition(go.transform.position)); }
public bool CheckTruePositionPawn(PawnScript pawn) { return(CheckTruePosition(pawn.transform.position)); }