public void ButtonClick() { GameObject scripts = GameObject.Find("/Scripts"); GameController gameController = scripts.GetComponent <GameController> (); if (gameController.GetPlayerTurn() == false) { return; } Player player = GameObject.Find("/Player").GetComponent <Player> (); CursorController cursorController = scripts.GetComponent <CursorController> (); CursorStatus cursorStatus = cursorController.GetCursorStatus(); // The playerRole is a GridSpaceStatus to easily check if the clicked GridSpace can be moved by the player. if (cursorStatus == CursorStatus.EMPTY && player.playerRole == this.gridSpaceStatus) { // Pick up current piece cursorController.SetCursorStatus(CursorStatus.OCCUPIED); cursorController.setPreviousLocation(this.gridSpaceNumber); this.SetGridSpaceStatus(GridSpaceStatus.EMPTY); // Color the tiles where a player can put the piece. switch (player.playerRole) { case GridSpaceStatus.WOLF: if (PieceOnLeftEdge(gridSpaceNumber) == true) { gameController.SetGridSpaceAvailableColor(gridSpaceNumber); gameController.SetGridSpaceAvailableColor(gridSpaceNumber - 7); gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 9); } else if (PieceOnRightEdge(gridSpaceNumber) == true) { gameController.SetGridSpaceAvailableColor(gridSpaceNumber); gameController.SetGridSpaceAvailableColor(gridSpaceNumber - 9); gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 7); } else { gameController.SetGridSpaceAvailableColor(gridSpaceNumber); gameController.SetGridSpaceAvailableColor(gridSpaceNumber - 7); gameController.SetGridSpaceAvailableColor(gridSpaceNumber - 9); gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 7); gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 9); } break; case GridSpaceStatus.SHEEP: if (PieceOnLeftEdge(gridSpaceNumber) == true) { gameController.SetGridSpaceAvailableColor(gridSpaceNumber); gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 9); } else if (PieceOnRightEdge(gridSpaceNumber) == true) { gameController.SetGridSpaceAvailableColor(gridSpaceNumber); gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 7); } else { gameController.SetGridSpaceAvailableColor(gridSpaceNumber); gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 7); gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 9); } break; default: Debug.LogError("PlayerRole set to UNKNOWN. Check Player.cs and MainMenu.cs"); break; } } if (cursorStatus == CursorStatus.OCCUPIED) { switch (player.playerRole) { case GridSpaceStatus.WOLF: if (PieceOnLeftEdge(cursorController.getPreviousLocation())) { if ( this.gridSpaceNumber == cursorController.getPreviousLocation() || this.gridSpaceNumber == (cursorController.getPreviousLocation() - 7) || this.gridSpaceNumber == (cursorController.getPreviousLocation() + 9) ) { if (this.gridSpaceStatus != GridSpaceStatus.SHEEP) { PlacePiece(cursorController, gameController, player); gameController.SetWolfPosition(this.gridSpaceNumber); } } } else if (PieceOnRightEdge(cursorController.getPreviousLocation())) { if ( this.gridSpaceNumber == cursorController.getPreviousLocation() || this.gridSpaceNumber == (cursorController.getPreviousLocation() - 9) || this.gridSpaceNumber == (cursorController.getPreviousLocation() + 7) ) { if (this.gridSpaceStatus != GridSpaceStatus.SHEEP) { PlacePiece(cursorController, gameController, player); gameController.SetWolfPosition(this.gridSpaceNumber); } } } else { if ( this.gridSpaceNumber == cursorController.getPreviousLocation() || this.gridSpaceNumber == (cursorController.getPreviousLocation() - 7) || this.gridSpaceNumber == (cursorController.getPreviousLocation() - 9) || this.gridSpaceNumber == (cursorController.getPreviousLocation() + 7) || this.gridSpaceNumber == (cursorController.getPreviousLocation() + 9) ) { if (this.gridSpaceStatus != GridSpaceStatus.SHEEP) { PlacePiece(cursorController, gameController, player); gameController.SetWolfPosition(this.gridSpaceNumber); } } } break; case GridSpaceStatus.SHEEP: if (this.gridSpaceStatus != GridSpaceStatus.WOLF) { if (PieceOnLeftEdge(cursorController.getPreviousLocation())) { if ( this.gridSpaceNumber == cursorController.getPreviousLocation() || this.gridSpaceNumber == (cursorController.getPreviousLocation() + 9) ) { PlacePiece(cursorController, gameController, player); } } else if (PieceOnRightEdge(cursorController.getPreviousLocation())) { if ( this.gridSpaceNumber == cursorController.getPreviousLocation() || this.gridSpaceNumber == (cursorController.getPreviousLocation() + 7) ) { PlacePiece(cursorController, gameController, player); } } else { if ( this.gridSpaceNumber == cursorController.getPreviousLocation() || this.gridSpaceNumber == (cursorController.getPreviousLocation() + 7) || this.gridSpaceNumber == (cursorController.getPreviousLocation() + 9) ) { PlacePiece(cursorController, gameController, player); } } } break; default: Debug.LogError("PlayerRole set to UNKNOWN. Check Player.cs and MainMenu.cs"); break; } } }
public void ButtonClick() { GameObject scripts = GameObject.Find("/Scripts"); Player player = GameObject.Find("/Player").GetComponent <Player> (); CursorController cursorController = scripts.GetComponent <CursorController> (); clearSignalAlowedGspace = false; CursorStatus cursorStatus = cursorController.GetCursorStatus(); // The playerRole is a GridSpaceStatus to easily check if the clicked GridSpace can be moved by the player. if (cursorStatus == CursorStatus.EMPTY && player.playerRole == this.gridSpaceStatus && !AITurn) { // Pick up current piece //print("---"+ GetGridSpaceStatus()); cursorController.SetCursorStatus(CursorStatus.OCCUPIED); this.SetGridSpaceStatus(GridSpaceStatus.EMPTY); lastpickedUp = this.gridSpaceNumber; print("picked up"); if (signalDroped == true) { signalDroped = false; // signalpicked = true; } } //print sheep positions /*print("sheep1Position: " + sheep1Position); * print("sheep2Position: " + sheep2Position); * print("sheep3Position: " + sheep3Position); * print("sheep4Position: " + sheep4Position);*/ /*print(alowedGridSpaceses.Count); * print("0--0");*/ for (int i = 0; i < alowedGridSpaceses.Count; i++) { // print("alowedGridSpaceses[" + i + "]: " + alowedGridSpaceses[i]); } for (int i = 0; i < alowedGridSpacesSheep.Count; i++) { // print("alowedGridSpacesSheep[" + i + "]: " + alowedGridSpacesSheep[i]); } for (int i = 0; i < mmAlowedGridSpacesSheep.Count; i++) { // print("mmAlowedGridSpacesSheep[" + i + "]: " + mmAlowedGridSpacesSheep[i]); } for (int i = 0; i < alowedGridSpaceses.Count; i++) { if (cursorStatus == CursorStatus.OCCUPIED) { if (this.gridSpaceStatus == GridSpaceStatus.EMPTY && alowedGridSpaceses[i] == foxPosition && player.playerRole == GridSpaceStatus.WOLF ) { // Drop Piece if allowed // print("Count = " + i); // print("FoxPOsition = " + foxPosition); // print(this.GetGridSpaceNumber()); cursorController.SetCursorStatus(CursorStatus.EMPTY); this.SetGridSpaceStatus(player.playerRole); if (player.playerRole == GridSpaceStatus.WOLF) { AITurn = true; } print("Case 0"); } } } for (int i = 0; i < currentAlowedGridSpacesSheep.Count; i++) { //print(alowedGridSpacesSheep[i]); if (cursorStatus == CursorStatus.OCCUPIED) { //sheep1 if (this.gridSpaceStatus == GridSpaceStatus.EMPTY && sheep1 == true) { if (sheep1OldPos != GridSpaceStatus.SHEEP) { if (currentAlowedGridSpacesSheep[i] == this.gridSpaceNumber) { cursorController.SetCursorStatus(CursorStatus.EMPTY); this.SetGridSpaceStatus(player.playerRole); if (player.playerRole == GridSpaceStatus.SHEEP) { AITurn = true; } clearSignalAlowedGspace = true; signalDroped = true; sheep1Position = this.gridSpaceNumber; // print("SHEEEEEEP POSSS1 !" + sheep1Position); // print("SHEEEEEEP POSSS2 !" + sheep2Position); // print("SHEEEEEEP POSSS3 !" + sheep3Position); // print("SHEEEEEEP POSSS4 !" + sheep4Position); } } } // sheep 2 if (this.gridSpaceStatus == GridSpaceStatus.EMPTY && sheep2 == true) { if (sheep2OldPos != GridSpaceStatus.SHEEP) { if (currentAlowedGridSpacesSheep[i] == this.gridSpaceNumber) { cursorController.SetCursorStatus(CursorStatus.EMPTY); this.SetGridSpaceStatus(player.playerRole); if (player.playerRole == GridSpaceStatus.SHEEP) { AITurn = true; } clearSignalAlowedGspace = true; signalDroped = true; sheep2Position = this.gridSpaceNumber; // print("SHEEEEEEP POSSS1 !" + sheep1Position); // print("SHEEEEEEP POSSS2 !" + sheep2Position); // print("SHEEEEEEP POSSS3 !" + sheep3Position); // print("SHEEEEEEP POSSS4 !" + sheep4Position); } } } //sheep 3 if (this.gridSpaceStatus == GridSpaceStatus.EMPTY && sheep3 == true) { if (sheep3OldPos != GridSpaceStatus.SHEEP) { if (currentAlowedGridSpacesSheep[i] == this.gridSpaceNumber) { cursorController.SetCursorStatus(CursorStatus.EMPTY); this.SetGridSpaceStatus(player.playerRole); if (player.playerRole == GridSpaceStatus.SHEEP) { AITurn = true; } clearSignalAlowedGspace = true; signalDroped = true; sheep3Position = this.gridSpaceNumber; // print("SHEEEEEEP POSSS1 !" + sheep1Position); // print("SHEEEEEEP POSSS2 !" + sheep2Position); // print("SHEEEEEEP POSSS3 !" + sheep3Position); // print("SHEEEEEEP POSSS4 !" + sheep4Position); } } } //sheep4 if (this.gridSpaceStatus == GridSpaceStatus.EMPTY && sheep4 == true) { if (sheep4OldPos != GridSpaceStatus.SHEEP) { if (currentAlowedGridSpacesSheep[i] == this.gridSpaceNumber) { cursorController.SetCursorStatus(CursorStatus.EMPTY); this.SetGridSpaceStatus(player.playerRole); if (player.playerRole == GridSpaceStatus.SHEEP) { AITurn = true; } clearSignalAlowedGspace = true; signalDroped = true; sheep4Position = this.gridSpaceNumber; // print("SHEEEEEEP POSSS1 !" + sheep1Position); // print("SHEEEEEEP POSSS2 !" + sheep2Position); // print("SHEEEEEEP POSSS3 !" + sheep3Position); // print("SHEEEEEEP POSSS4 !" + sheep4Position); } } } } } }