public void Dice(Piece currPlayer, UnityPieceImage currPlayerUnity) //probably an int later when taking care of front end { System.Random rnd = new System.Random((int)DateTime.Now.Ticks); d1 = rnd.Next(1, 7); d2 = rnd.Next(1, 7); diceTotal = d1 + d2; if (d1 == d2) { currPlayer.doubcount = currPlayer.doubcount + 1; if (currPlayer.doubcount == 3) { lastLoc = currPlayer.location; currPlayer.location = 10; currPlayerUnity.MoveTo(currPlayer.location, currPlayer.player.ID); currPlayer.isJailed = true; currPlayer.doubcount = 0; currPlayer.player.money = currPlayer.player.money - 50; //bail immediate for the time being } else { if (currPlayer.location + diceTotal > 39) { currPlayer.player.money = currPlayer.player.money + 200; } lastLoc = currPlayer.location; currPlayer.location = (currPlayer.location + diceTotal) % 40; currPlayerUnity.MoveTo(currPlayer.location, currPlayer.player.ID); } } else { if (currPlayer.location + diceTotal > 39) { currPlayer.player.money = currPlayer.player.money + 200; } lastLoc = currPlayer.location; currPlayer.location = (currPlayer.location + diceTotal) % 40; currPlayerUnity.MoveTo(currPlayer.location, currPlayer.player.ID); currPlayer.doubcount = 0; } }
void Start() { Debug.Log("Game Start"); GameBoard = new Board(); unityBuildings = new BuildingHandler[40, 5] { { null, null, null, null, null }, { house1_1, house1_2, house1_3, house1_4, hotel1 }, { null, null, null, null, null }, { house3_1, house3_2, house3_3, house3_4, hotel3 }, { null, null, null, null, null }, { null, null, null, null, null }, { house6_1, house6_2, house6_3, house6_4, hotel6 }, { null, null, null, null, null }, { house8_1, house8_2, house8_3, house8_4, hotel8 }, { house9_1, house9_2, house9_3, house9_4, hotel9 }, { null, null, null, null, null }, { house11_1, house11_2, house11_3, house11_4, hotel11 }, { null, null, null, null, null }, { house13_1, house13_2, house13_3, house13_4, hotel13 }, { house14_1, house14_2, house14_3, house14_4, hotel14 }, { null, null, null, null, null }, { house16_1, house16_2, house16_3, house16_4, hotel16 }, { null, null, null, null, null }, { house18_1, house18_2, house18_3, house18_4, hotel18 }, { house19_1, house19_2, house19_3, house19_4, hotel19 }, { null, null, null, null, null }, { house21_1, house21_2, house21_3, house21_4, hotel21 }, { null, null, null, null, null }, { house23_1, house23_2, house23_3, house23_4, hotel23 }, { house24_1, house24_2, house24_3, house24_4, hotel24 }, { null, null, null, null, null }, { house26_1, house26_2, house26_3, house26_4, hotel26 }, { house27_1, house27_2, house27_3, house27_4, hotel27 }, { null, null, null, null, null }, { house29_1, house29_2, house29_3, house29_4, hotel29 }, { null, null, null, null, null }, { house31_1, house31_2, house31_3, house31_4, hotel31 }, { house32_1, house32_2, house32_3, house32_4, hotel32 }, { null, null, null, null, null }, { house34_1, house34_2, house34_3, house34_4, hotel34 }, { null, null, null, null, null }, { null, null, null, null, null }, { house37_1, house37_2, house37_3, house37_4, hotel37 }, { null, null, null, null, null }, { house39_1, house39_2, house39_3, house39_4, hotel39 } }; greyBoxes = new BuildingHandler[40] { Box0, Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9, Box10, Box11, Box12, Box13, Box14, Box15, Box16, Box17, Box18, Box19, Box20, Box21, Box22, Box23, Box24, Box25, Box26, Box27, Box28, Box29, Box30, Box31, Box32, Box33, Box34, Box35, Box36, Box37, Box38, Box39 }; int j = 0; foreach (BuildingHandler i in unityBuildings) { if (j < 40) { greyBoxes[j].MoveDown(); j++; } if (i != null) { i.MoveDown(); } } //start the game turncounter = 0; unityPieces.Add(PurplePiece); unityPieces.Add(OrangePiece); allOff(); OVRPlayerController.enabled = false; BalancesBoard.GetComponent <MeshRenderer>().enabled = false; ball.GetComponent <MeshRenderer>().enabled = true; GameBoard.state = 0; PurplePiece.MoveTo(0, 0); OrangePiece.MoveTo(0, 1); }
//probably an int later when taking care of front end public void Dice(Piece currPlayer, UnityPieceImage currPlayerUnity) { System.Random rnd = new System.Random ((int)DateTime.Now.Ticks); d1 = rnd.Next (1, 7); d2 = rnd.Next (1, 7); diceTotal = d1 + d2; if (d1 == d2) { currPlayer.doubcount = currPlayer.doubcount + 1; if (currPlayer.doubcount == 3) { lastLoc = currPlayer.location; currPlayer.location = 10; BluetoothWrite(currPlayer); currPlayerUnity.MoveTo (currPlayer.location, currPlayer.player.ID); currPlayer.isJailed = true; currPlayer.doubcount = 0; currPlayer.player.money = currPlayer.player.money - 50; //bail immediate for the time being } else { if (currPlayer.location + diceTotal > 39) { currPlayer.player.money = currPlayer.player.money + 200; } lastLoc = currPlayer.location; currPlayer.location = (currPlayer.location + diceTotal) % 40; BluetoothWrite(currPlayer); currPlayerUnity.MoveTo (currPlayer.location, currPlayer.player.ID); } } else { if (currPlayer.location + diceTotal > 39) { currPlayer.player.money = currPlayer.player.money + 200; } lastLoc = currPlayer.location; currPlayer.location = (currPlayer.location + diceTotal) % 40; BluetoothWrite(currPlayer); currPlayerUnity.MoveTo (currPlayer.location, currPlayer.player.ID); currPlayer.doubcount = 0; } }
void Update() { if (Input.GetKeyDown(KeyCode.LeftShift)) { BirdsEyeCam.enabled = !BirdsEyeCam.enabled; OVRPlayerController.enabled = !OVRPlayerController.enabled; if (BirdsEyeCam.enabled) { BalancesBoard.GetComponent <MeshRenderer>().enabled = false; ball.GetComponent <MeshRenderer>().enabled = true; } else { BalancesBoard.GetComponent <MeshRenderer>().enabled = true; ball.GetComponent <MeshRenderer>().enabled = false; } } updatePrints(); if (!gameOver) { int playerID = (turncounter % 2); Piece currPlayer = ((Piece)GameBoard.pieces[playerID]); UnityPieceImage currPlayerUnity = ((UnityPieceImage)this.unityPieces[playerID]); if (playerID == 0) { //if player's turn if (currPlayer.player.hasMonopoly && GameBoard.state != 6 && GameBoard.state != 7) { turnOn(BuyBuilding); if ((Input.GetKeyDown(KeyCode.B))) { GameBoard.backupState = GameBoard.state; GameBoard.state = 6; } } if (GameBoard.state == 8) { Debug.Log("State8"); if (currPlayerUnity.isFinished()) { if (d1 == d2) { GameBoard.state = 0; } else { GameBoard.state = 5; } } else { allOff(); goto end; } } if (GameBoard.state == 6) { turnOn(Cancel); turnOff(BuyBuilding); if ((Input.GetKeyDown(KeyCode.RightControl))) { GameBoard.state = GameBoard.backupState; } Actions.text = ResolveTextSize("Select a highlighted tile to buy a building on it. \n\n Press the right ctrl key to return to game.", 30); int j = 0; foreach (Tile t in GameBoard.tiles) { if (t.isProperty) { if (t.property.buildings > 0 && t.property.buildings < 6) { if ((t.property.player != null) && (t.property.player.ID == currPlayer.player.ID)) { } else if (!greyBoxes[j].isUp) { greyBoxes[j].MoveUp(); } } else if (!greyBoxes[j].isUp) { greyBoxes[j].MoveUp(); } } else if (!greyBoxes[j].isUp) { greyBoxes[j].MoveUp(); } j++; } if ((Input.GetMouseButtonDown(0))) { for (int i = 0; i < 40; i++) { if (((ball.transform.position.z + .2 >= GameBoard.ballCoords[i, 0]) && (ball.transform.position.z - .2 <= GameBoard.ballCoords[i, 0])) && ((ball.transform.position.x - .2 <= GameBoard.ballCoords[i, 1]) && ((ball.transform.position.x + .2 >= GameBoard.ballCoords[i, 1])))) { if (!greyBoxes[i].isUp) { GameBoard.toAddBuilding = i; GameBoard.state = 7; break; } } } } } else if (GameBoard.state != 7) { turnOff(Cancel); for (int i = 0; i < 40; i++) { if (greyBoxes[i].isUp) { greyBoxes[i].MoveDown(); } } } if (GameBoard.state == 7) { int buildingCost = (((GameBoard.toAddBuilding / 10) + 1) * 50); if (currPlayer.player.money > buildingCost) { ((Tile)GameBoard.tiles[GameBoard.toAddBuilding]).property.addBuilding(); currPlayer.player.money = currPlayer.player.money - buildingCost; enableBuildings(GameBoard.toAddBuilding, ((Tile)GameBoard.tiles[GameBoard.toAddBuilding])); } GameBoard.state = 6; } if (GameBoard.state == 0) { Actions.text = ResolveTextSize("It's your turn! Roll the dice! \n\n Press K to roll.", 30); turnOff(RentOkButton); turnOn(Roll); turnOff(PropertyYes); turnOff(PropertyNo); if ((Input.GetKeyDown(KeyCode.K))) { GameBoard.state = 1; } goto end; } //reset everything to false else if (GameBoard.state == 1) { Dice(currPlayer, currPlayerUnity); //roll and move GameBoard.state = 8; goto end; } Tile thisTile = (Tile)GameBoard.tiles[currPlayer.location]; if (thisTile.isProperty) { //is property if (thisTile.property.player != null) { //owned if (thisTile.property.player.ID != currPlayer.player.ID) { if (GameBoard.state == 5) { Actions.text = ResolveTextSize("You owe CPU " + thisTile.property.player.ID + " $" + thisTile.rents[thisTile.property.buildings] + " for rent on " + thisTile.title + ". \n\n Press I to accept.", 30); turnOn(RentOkButton); turnOff(Roll); turnOff(PropertyYes); turnOff(PropertyNo); if ((Input.GetKeyDown(KeyCode.I))) { GameBoard.state = 2; } goto end; } if (GameBoard.state == 2) { payRent(currPlayer.player, thisTile.property); GameBoard.state = 0; } } else { //else owned by you if (GameBoard.state != 6 && GameBoard.state != 7) { GameBoard.state = 0; } } } else { //unowned if (!(GameBoard.state == 4)) { GameBoard.state = 3; } if (GameBoard.state == 3) { Actions.text = ResolveTextSize("Would you like to purchase " + thisTile.title + " for $" + thisTile.property.value + "? This would leave you with $" + (currPlayer.player.money - thisTile.property.value) + ".\n\n Press J for yes or L for no.", 30); turnOff(Roll); turnOff(RentOkButton); turnOn(PropertyYes); turnOn(PropertyNo); if ((Input.GetKeyDown(KeyCode.L))) { unbought = true; GameBoard.state = 4; } if ((Input.GetKeyDown(KeyCode.J))) { unbought = false; GameBoard.state = 4; } goto end; } if (GameBoard.state == 4) { if (!unbought) { purchase(currPlayer.player, thisTile.property); //buy tile //now check for color set bool colorset = true; //for each tile, if owner is different (or null) && colorgroup is the same, colorset false if (!(String.Compare(thisTile.property.colorGroup, "UTIL") == 0)) { foreach (Tile T in GameBoard.tiles) { if (T.isProperty) { if (String.Compare(T.property.colorGroup, thisTile.property.colorGroup) == 0) { if (T.property.player == null || T.property.player.ID != currPlayer.player.ID) { colorset = false; break; } } } } } else { colorset = false; } if (colorset) { currPlayer.player.hasMonopoly = true; foreach (Tile V in GameBoard.tiles) { if (V.isProperty) { if (V.property.colorGroup == thisTile.property.colorGroup) { V.property.addBuilding(); } } } } } unbought = false; GameBoard.state = 0; } } } else { //not property if (GameBoard.state != 6 && GameBoard.state != 7) { GameBoard.state = 0; } if (thisTile.rents[0] != 0 && currPlayer.location != 0) { //assuming action tile, only true if go or tax currPlayer.player.money = currPlayer.player.money - thisTile.rents[0]; } else if (currPlayer.location == 30) { //go to jail lastLoc = currPlayer.location; currPlayer.location = 10; currPlayerUnity.MoveTo(currPlayer.location, currPlayer.player.ID); currPlayer.isJailed = true; } } } else { //else not player's turn allOff(); if (currPlayerUnity.isFinished()) { //run above things Dice(currPlayer, currPlayerUnity); //roll and move Tile thisTile = (Tile)GameBoard.tiles[currPlayer.location]; if (thisTile.isProperty) { //is property if (thisTile.property.player != null) { //owned if (thisTile.property.player.ID != currPlayer.player.ID) { payRent(currPlayer.player, thisTile.property); } else if (thisTile.property.buildings > 0) { //if has color set, color set is buildings = 1 int buildingCost = (((currPlayer.location / 10) + 1) * 50); if (currPlayer.player.money > buildingCost && thisTile.property.buildings < 6) { thisTile.property.addBuilding(); currPlayer.player.money = currPlayer.player.money - buildingCost; enableBuildings(currPlayer.location, thisTile); } } } else { //unowned purchase(currPlayer.player, thisTile.property); //buy tile //now check for color set bool colorset = true; //for each tile, if owner is different (or null) && colorgroup is the same, colorset false if (!(String.Compare(thisTile.property.colorGroup, "UTIL") == 0)) { foreach (Tile T in GameBoard.tiles) { if (T.isProperty) { if (String.Compare(T.property.colorGroup, thisTile.property.colorGroup) == 0) { if (T.property.player == null || T.property.player.ID != currPlayer.player.ID) { colorset = false; break; } } } } } else { colorset = false; } if (colorset) { currPlayer.player.hasMonopoly = true; foreach (Tile V in GameBoard.tiles) { if (V.isProperty) { if (V.property.colorGroup == thisTile.property.colorGroup) { V.property.addBuilding(); } } } } } } else { //not property if (thisTile.rents[0] != 0 && currPlayer.location != 0) { //assuming action tile, only true if go or tax currPlayer.player.money = currPlayer.player.money - thisTile.rents[0]; } else if (currPlayer.location == 30) { //go to jail lastLoc = currPlayer.location; currPlayer.location = 10; currPlayerUnity.MoveTo(currPlayer.location, currPlayer.player.ID); currPlayer.isJailed = true; } } } } //update printouts updatePrints(); if (currPlayer.doubcount == 0 && GameBoard.state == 0) { //end of turn, not in jail turncounter++; } if (currPlayer.player.money < 0) { //game end condition gameOver = true; if (!currPlayer.player.isHuman) { Actions.text = ResolveTextSize("Game over; CPU " + currPlayer.player.ID + " has $" + currPlayer.player.money, 30); } else { Actions.text = ResolveTextSize("Game over; You have $" + currPlayer.player.money, 30); } } end :; } }