Esempio n. 1
0
 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;
     }
 }
Esempio n. 2
0
    //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;
        }
    }
Esempio n. 3
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 :;
     }
 }