Esempio n. 1
0
        private void SendGuestsToTheCeller(ButtonCodes[] coveredSpaces)
        {
            int  numGuests;
            bool updateCellerLevel;

            if (coveredSpaces.Length != 3)
            {
                return;
            }


            for (int j = 0; j < coveredSpaces.Length; j++)
            {
                updateCellerLevel = false;

                for (int i = 0; i < players.Length; i++)
                {
                    numGuests = players[i].Query(coveredSpaces[j]);
                    for (int k = 0; k < numGuests; k++)
                    {
                        players[i].MoveGuestLocation(coveredSpaces[j], currentCellerLevel);
                        players[i].Score += cellerScore;
                        UpdateButton(currentCellerLevel);
                        UpdateButton(coveredSpaces[j]);
                        updateCellerLevel = true;
                    }
                }

                if (updateCellerLevel)
                {
                    currentCellerLevel = UpdateCellerLevel(currentCellerLevel);
                }
            }
        }
Esempio n. 2
0
        private bool MoveGuestDownHallway(ButtonCodes button)
        {
            ButtonCodes startingSpace;

            // hallway moves are valid
            // and a hallway choice must be within
            //  diceValue moves of a player
            if (diceValue > 0 && ButtonCodes.BHallway01 <= button && ButtonCodes.BHallway28 >= button)
            {
                startingSpace = PreviousLocation(button, diceValue);

                if (players[currentPlayer].Query(startingSpace) > 0)
                {
                    players[currentPlayer].MoveGuestLocation(startingSpace, button);

                    UpdateButton(startingSpace);
                    UpdateButton(button);

                    DisplayMessage(players[currentPlayer].PColor + " moves from " + startingSpace + " to " + button);

                    return(true);
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
 public void AddGuestLocation(ButtonCodes bc)
 {
     if (guestsPlaced < guestLocations.Length)
     {
         guestLocations[guestsPlaced] = bc;
         guestsPlaced++;
     }
 }
Esempio n. 4
0
        private void OccupyRoom(ButtonCodes oldSpace, ButtonCodes newSpace)
        {
            players[currentPlayer].MoveGuestLocation(oldSpace, newSpace);

            UpdateButton(oldSpace);
            UpdateButton(newSpace);

            DisplayMessage(players[currentPlayer].PColor + " moves from " + oldSpace + " into room " + newSpace);
        }
Esempio n. 5
0
        public static bool GetKeyUp(ButtonCodes key)
        {
            XRController controller = GetXRController(key);

            if (controller != null)
            {
                QuickButtonControl bControl = GetInputControlButton(controller, key);
                return(bControl != null && bControl.wasReleasedThisFrame);
            }

            return(false);
        }
Esempio n. 6
0
        public static bool GetKey(ButtonCodes key)
        {
            XRController controller = GetXRController(key);

            if (controller != null)
            {
                QuickButtonControl bControl = GetInputControlButton(controller, key);
                return(bControl != null && bControl.isPressed);
            }

            return(false);
        }
Esempio n. 7
0
 private ButtonCodes UpdateCellerLevel(ButtonCodes cl)
 {
     if (cl == ButtonCodes.Bcellerm02)
     {
         cellerScore = -2;
         return(ButtonCodes.Bcellerm02);
     }
     else
     {
         cellerScore += 1;
         return(cl + 1);
     }
 }
Esempio n. 8
0
 public void MoveGuestLocation(ButtonCodes currentPlace, ButtonCodes newPlace)
 {
     // find a guest that is on currentPlace and
     //  change it to newPlace
     for (int i = 0; i < guestsPlaced; i++)
     {
         if (currentPlace == guestLocations[i])
         {
             guestLocations[i] = newPlace;
             break;
         }
     }
 }
Esempio n. 9
0
        public ButtonContainer(MyForm mf, Rectangle rect, Color bcolor, ButtonCodes bc)
        {
            myForm     = mf;
            clickValue = bc;

            // create the button and link the click call back
            myButton = new Button();
            myButton.DialogResult = DialogResult.OK;
            myButton.Click       += new EventHandler(ButtonClick);
            myButton.Bounds       = rect;
            myButton.BackColor    = bcolor;
            myForm.Controls.Add(myButton);
        }
Esempio n. 10
0
        public int Query(ButtonCodes bc)
        {
            int found;

            found = 0;

            for (int i = 0; i < guestsPlaced; i++)
            {
                if (bc == guestLocations[i])
                {
                    found++;
                }
            }

            return(found);
        }
Esempio n. 11
0
        private void UpdateButton(ButtonCodes button)
        {
            int i;
            int numPlayers;
            int cnt;

            Bitmap[] playerImgs;

            // determine which players are on this
            //  button and put them on it

            buttons[(int)button].button.BackgroundImage = null;

            // iterate through all the players and find the
            // total
            numPlayers = 0;
            for (i = 0; i < players.Length; i++)
            {
                numPlayers += players[i].Query(button);
            }

            // check the ghost as well
            numPlayers += ghost.Query(button);

            playerImgs = new Bitmap[numPlayers];

            // now collect an array of images based on the players
            // occupying this button
            cnt = 0;
            for (i = 0; i < players.Length; i++)
            {
                numPlayers = players[i].Query(button);
                for (int j = 0; j < numPlayers; j++)
                {
                    playerImgs[cnt++] = (Bitmap)players[i].Icon;
                }
            }

            // check the ghost as well
            numPlayers = ghost.Query(button);
            for (int j = 0; j < numPlayers; j++)
            {
                playerImgs[cnt++] = (Bitmap)ghost.Icon;
            }

            buttons[(int)button].button.BackgroundImage = ImageResource.CombineImages(playerImgs);
        }
Esempio n. 12
0
        private bool RoomOccupied(ButtonCodes button)
        {
            bool occupied;

            occupied = false;

            if (ButtonCodes.BRoom01 <= button && ButtonCodes.BRoom11 >= button)
            {
                for (int i = 0; i < players.Length; i++)
                {
                    if (players[i].Query(button) > 0)
                    {
                        occupied = true;
                        break;
                    }
                }

                return(occupied);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 13
0
        public void HandleUserInput(ButtonCodes button)
        {
            int i;

            // custom button controls
            if (ButtonCodes.BDiceClicked == button &&
                (GameState.GamePlayNoGhost == globalGameState ||
                 GameState.GamePlayWithGhost == globalGameState))
            {
                // only advance the user if
                //  the diceValue == 0 or 6
                int gOdds;

                if (diceValue == 0 || diceValue == 6)
                {
                    // check the ghostOdds user input
                    try
                    {
                        gOdds = Convert.ToInt32(ghostOdds.Text);
                    }
                    catch (FormatException)
                    {
                        gOdds = 0;
                    }
                    catch (OverflowException)
                    {
                        gOdds = 0;
                    }

                    diceValue = rand.Next(6 + gOdds) + 1;

                    // make ghosts more frequent
                    if (diceValue >= 6 || diceValue == 3)
                    {
                        diceValue = 6;
                    }

                    buttons[(int)ButtonCodes.BDiceClicked].button.Text            = "";
                    buttons[(int)ButtonCodes.BDiceClicked].button.BackgroundImage = diceImgs[diceValue];

                    DisplayMessage(players[currentPlayer].PColor + ": " + diceValue + " rolled.");

                    if (6 == diceValue)
                    {
                        // advance the ghost X number of
                        // spaces.
                        //  If the ghost leaves the celler
                        //   then change the game state
                        //  Once out of the celler, send
                        //   people to the celler if eaten
                        switch (ghostLocation)
                        {
                        case ButtonCodes.Bcellerm10:
                            ghostLocation = ButtonCodes.Bcellerm07;
                            ghost.MoveGuestLocation(ButtonCodes.Bcellerm10, ButtonCodes.Bcellerm07);
                            UpdateButton(ButtonCodes.Bcellerm10);
                            UpdateButton(ButtonCodes.Bcellerm07);
                            break;

                        case ButtonCodes.Bcellerm07:
                            ghostLocation = ButtonCodes.Bcellerm04;
                            ghost.MoveGuestLocation(ButtonCodes.Bcellerm07, ButtonCodes.Bcellerm04);
                            UpdateButton(ButtonCodes.Bcellerm07);
                            UpdateButton(ButtonCodes.Bcellerm04);
                            break;

                        default:
                            // the ghost is out and will
                            //  send people to the dungen
                            ButtonCodes[] coveredSpaces = new ButtonCodes[3];

                            if (ButtonCodes.Bcellerm04 == ghostLocation)
                            {
                                coveredSpaces[0] = ButtonCodes.Bcellerm03;
                                coveredSpaces[1] = ButtonCodes.BHallway01;
                                coveredSpaces[2] = ButtonCodes.BHallway02;
                                // the ghost is out now
                                globalGameState = GameState.GamePlayWithGhost;
                            }
                            else if (ButtonCodes.BHallway28 == ghostLocation)
                            {
                                coveredSpaces[0] = ButtonCodes.BHallway01;
                                coveredSpaces[1] = ButtonCodes.BHallway02;
                                coveredSpaces[2] = ButtonCodes.BHallway03;
                            }
                            else if (ButtonCodes.BHallway27 == ghostLocation)
                            {
                                coveredSpaces[0] = ButtonCodes.BHallway28;
                                coveredSpaces[1] = ButtonCodes.BHallway01;
                                coveredSpaces[2] = ButtonCodes.BHallway02;
                            }
                            else if (ButtonCodes.BHallway26 == ghostLocation)
                            {
                                coveredSpaces[0] = ButtonCodes.BHallway27;
                                coveredSpaces[1] = ButtonCodes.BHallway28;
                                coveredSpaces[2] = ButtonCodes.BHallway01;
                            }
                            else
                            {
                                coveredSpaces[0] = ghostLocation + 1;
                                coveredSpaces[1] = ghostLocation + 2;
                                coveredSpaces[2] = ghostLocation + 3;
                            }

                            // eat the people on these spaces
                            SendGuestsToTheCeller(coveredSpaces);

                            // move the ghost
                            ghost.MoveGuestLocation(ghostLocation, coveredSpaces[2]);
                            UpdateButton(ghostLocation);
                            UpdateButton(coveredSpaces[2]);
                            ghostLocation = coveredSpaces[2];

                            break;
                        }
                    }

                    if (players[currentPlayer].Completed || 6 == diceValue)
                    {
                        SwitchUser();

                        // leave the Ghost up
                        if (6 == diceValue)
                        {
                            buttons[(int)ButtonCodes.BDiceClicked].button.Text            = "";
                            buttons[(int)ButtonCodes.BDiceClicked].button.BackgroundImage = diceImgs[diceValue];
                        }

                        diceValue = 0;
                    }
                }
            }
            else if (ButtonCodes.BNewGame == button ||
                     (ButtonCodes.BNewRound == button && null == players))
            {
                int    intPeople;
                Bitmap guestImg;

                // Todo: validate that a new game is legal
                //       check to see if the user should be
                //       be prompted for new game
                try
                {
                    intPeople = Convert.ToInt32(numPlayers.Text);
                    if (2 <= intPeople && 8 >= intPeople)
                    {
                        globalGameState = GameState.PlayerPlacement;

                        players       = new Player[intPeople];
                        startingGuest = rand.Next(players.Length);
                        diceValue     = 0;
                        currentRound  = 1;
                        msgBox.Text   = welcomeMsg;

                        switch (intPeople)
                        {
                        case 8:
                        case 7:
                        case 6:
                            numberOfGuests = 2;
                            break;

                        case 5:
                            numberOfGuests = 3;
                            break;

                        case 4:
                            numberOfGuests = 4;
                            break;

                        case 3:
                            numberOfGuests = 5;
                            break;

                        case 2:
                            numberOfGuests = 6;
                            break;
                        }

                        for (i = 0; i < players.Length; i++)
                        {
                            try
                            {
                                guestImg = new Bitmap("images\\Player" + i + ".bmp", false);
                            }
                            catch (ArgumentException)
                            {
                                guestImg = new Bitmap(35, 35);
                                Console.WriteLine("Could not find the image for player {0}", PColors[i]);
                            }
                            players[i] = new Player(numberOfGuests, guestImg, PColors[i]);
                        }

                        // clear all the buttons of people
                        for (i = 0; i < buttons.Length; i++)
                        {
                            if (null != buttons[i])
                            {
                                buttons[i].button.BackgroundImage = null;
                            }
                        }

                        try
                        {
                            guestImg = new Bitmap("images\\ghost.bmp", false);
                        }
                        catch (ArgumentException)
                        {
                            guestImg = new Bitmap(35, 35);
                            Console.WriteLine("Could not find the image for the Ghost");
                        }
                        ghost         = new Player(1, guestImg, Color.White);
                        ghostLocation = ButtonCodes.Bcellerm10;
                        ghost.AddGuestLocation(ghostLocation);
                        UpdateButton(ghostLocation);

                        currentCellerLevel = ButtonCodes.Bcellerm10;
                        cellerScore        = -10;

                        currentPlayer = startingGuest - 1;
                        SwitchUser();

                        startingGuest = (startingGuest + 1) % players.Length;

                        DisplayMessage("New game started.  Place your guests around the board.  " + players[currentPlayer].PColor + " is first");
                    }
                    else
                    {
                        // the text box did not contain a proper
                        // value
                        globalGameState = GameState.Idle;

                        DisplayMessage("Invalid number of players.  Must be >=2 and <=8");
                    }
                }
                catch (FormatException)
                {
                    // the text box did not contain a proper
                    // value
                    globalGameState = GameState.Idle;

                    DisplayMessage("Invalid number of players input.  Must be >=2 and <=8");
                }
            }
            else if (ButtonCodes.BNewRound == button)
            {
                // Todo: validate that a new game is legal
                //       check to see if the user should be
                //       be prompted for new game
                globalGameState = GameState.PlayerPlacement;

                for (i = 0; i < players.Length; i++)
                {
                    players[i].Reset(false);
                }

                currentPlayer = startingGuest - 1;
                SwitchUser();
                diceValue     = 0;
                startingGuest = (startingGuest + 1) % players.Length;
                currentRound++;

                // clear all the buttons of people
                for (i = 0; i < buttons.Length; i++)
                {
                    if (null != buttons[i])
                    {
                        buttons[i].button.BackgroundImage = null;
                    }
                }

                ghost.Reset(true);
                ghostLocation = ButtonCodes.Bcellerm10;
                ghost.AddGuestLocation(ghostLocation);
                UpdateButton(ghostLocation);

                currentCellerLevel = ButtonCodes.Bcellerm10;
                cellerScore        = -10;

                DisplayMessage("New round started.  Place your guests around the board.  " + players[currentPlayer].PColor + " is first");
            }
            else
            {
                bool legalMove;

                // state controls
                switch (globalGameState)
                {
                case GameState.Idle:
                    break;

                case GameState.PlayerPlacement:
                    int numFinishedPlayers;

                    // a placement is legal if:
                    //  1) the selection is between BHallway01
                    //     and BHallway28
                    //  2) the space has not already been selected
                    if (ButtonCodes.BHallway01 <= button && ButtonCodes.BHallway28 >= button)
                    {
                        legalMove = true;
                        for (i = 0; i < players.Length; i++)
                        {
                            if (players[i].Query(button) > 0)
                            {
                                legalMove = false;
                                break;
                            }
                        }

                        // if this is a legal move then place
                        //  the user on this space
                        if (legalMove)
                        {
                            players[currentPlayer].AddGuestLocation(button);

                            UpdateButton(button);

                            DisplayMessage(players[currentPlayer].PColor + " places a guest at " + button);

                            SwitchUser();

                            // if all the guests have been placed then move onto the
                            // next part of the game
                            numFinishedPlayers = 0;
                            for (i = 0; i < players.Length; i++)
                            {
                                if (numberOfGuests != players[i].GuestsPlaced)
                                {
                                    break;
                                }
                                numFinishedPlayers++;
                            }

                            if (numFinishedPlayers == players.Length)
                            {
                                globalGameState = GameState.GamePlayNoGhost;

                                DisplayMessage(players[currentPlayer].PColor + " roll the dice and move your guests.");
                            }
                        }
                        else
                        {
                            DisplayMessage("A user already occupies that space");
                        }
                    }
                    else
                    {
                        //DisplayMessage("Invalid move");
                    }

                    break;

                case GameState.GamePlayNoGhost:
                    // guest can only move within the hallways
                    if (MoveGuestDownHallway(button))
                    {
                        // this is a legal move so reset the diceValue
                        diceValue = 0;

                        SwitchUser();
                    }
                    else
                    {
                        //DisplayMessage("Invalid move");
                    }
                    break;

                case GameState.GamePlayWithGhost:
                    legalMove = false;
                    ButtonCodes startingSpace = 0;

                    // check if this is a hallway move
                    if (MoveGuestDownHallway(button))
                    {
                        legalMove = true;
                    }
                    else if (diceValue > 0 && ButtonCodes.BRoom01 <= button && ButtonCodes.BRoom11 >= button && !RoomOccupied(button))
                    {
                        // they must be moving for a room
                        // room 3 and 4 require exact
                        //  rolls to enter
                        if (ButtonCodes.BRoom03 == button || ButtonCodes.BRoom04 == button)
                        {
                            startingSpace = PreviousLocation(button, diceValue);
                            if (players[currentPlayer].Query(startingSpace) > 0)
                            {
                                // they made it into this room
                                OccupyRoom(startingSpace, button);
                                players[currentPlayer].Score += 3;
                                legalMove = true;
                            }
                        }
                        else
                        {
                            // to go into this room one of the previous
                            //  diceValue guests must exist
                            // ASSUMPTION: The farthest guest will go into
                            //   the room.  This is important if more than
                            //   1 guest could occupy the room
                            for (int dValue = diceValue; dValue > 0; dValue--)
                            {
                                startingSpace = PreviousLocation(button, dValue);

                                if (players[currentPlayer].Query(startingSpace) > 0)
                                {
                                    // they made it into this room
                                    OccupyRoom(startingSpace, button);
                                    legalMove = true;

                                    if (ButtonCodes.BRoom11 == button || ButtonCodes.BRoom09 == button)
                                    {
                                        players[currentPlayer].Score += -1;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        //DisplayMessage("Room is occupied");
                    }

                    if (legalMove)
                    {
                        // this is a legal move so reset the diceValue
                        diceValue = 0;

                        SwitchUser();
                    }

                    break;
                }
            }

            // check if the game is over
            if (GameState.GamePlayWithGhost == globalGameState)
            {
                int nPlayers = 0;
                for (i = 0; i < players.Length; i++)
                {
                    int numGuests = 0;
                    for (ButtonCodes space = ButtonCodes.BHallway01; space <= ButtonCodes.BHallway28; space++)
                    {
                        numGuests += players[i].Query(space);
                    }
                    players[i].Completed = (0 == numGuests);

                    if (players[i].Completed)
                    {
                        nPlayers++;
                    }
                }

                if (players.Length == nPlayers)
                {
                    long  lowestScore;
                    Color pWithLowestScore;
                    // print the scores
                    lowestScore      = long.MinValue;
                    pWithLowestScore = Color.White;
                    msgBox.Text      = "Overall Scores...\r\n\r\n";
                    for (i = 0; i < players.Length; i++)
                    {
                        msgBox.Text += players[i].PColor + ":\r\n\t" + players[i].Score + "\r\n";

                        if (players[i].Score > lowestScore)
                        {
                            pWithLowestScore = players[i].PColor;
                            lowestScore      = players[i].Score;
                        }
                    }

                    globalGameState = GameState.Idle;
                    if (3 == currentRound)
                    {
                        DisplayMessage("This game is over... " + pWithLowestScore + " is the winner!");
                        players = null;
                    }
                    else
                    {
                        DisplayMessage("Round " + currentRound + " is over... click new round for next round");
                    }
                }
            }
        }
Esempio n. 14
0
 protected override void SetInputDevice(ButtonCodes button)
 {
     _inputDevice = (button <= ButtonCodes.LeftGripTouch) ? XRController.leftHand : XRController.rightHand;
 }
Esempio n. 15
0
        private static QuickButtonControl GetInputControlButton(XRController controller, ButtonCodes button)
        {
            InputControl iControl = null;

            string[] values = _toButtonControl[button];
            for (int i = 0; iControl == null && i < values.Length; i++)
            {
                iControl = controller.TryGetChildControl(values[i]);
            }

            return(iControl == null ? null : new QuickButtonControl((AxisControl)iControl));
        }
Esempio n. 16
0
        protected override bool ImpGetButton(ButtonCodes button)
        {
            QuickButtonControl tmp = GetInputControlButton(_inputDevice, button);

            return(tmp != null ? tmp.isPressed : false);
        }
Esempio n. 17
0
 private static XRController GetXRController(ButtonCodes key)
 {
     return(key <= ButtonCodes.LeftGripTouch ? XRController.leftHand : XRController.rightHand);
 }
Esempio n. 18
0
        private ButtonCodes PreviousLocation(ButtonCodes button, int dvalue)
        {
            ButtonCodes startingSpace;

            // map the rooms to the closest hallway
            if (ButtonCodes.BRoom01 == button)
            {
                button = ButtonCodes.BHallway03;
                dvalue--;
            }
            else if (ButtonCodes.BRoom02 == button)
            {
                button = ButtonCodes.BHallway04;
                dvalue--;
            }
            else if (ButtonCodes.BRoom03 == button)
            {
                button = ButtonCodes.BHallway06;
                dvalue--;
            }
            else if (ButtonCodes.BRoom04 == button)
            {
                button = ButtonCodes.BHallway09;
                dvalue--;
            }
            else if (ButtonCodes.BRoom05 == button)
            {
                button = ButtonCodes.BHallway11;
                dvalue--;
            }
            else if (ButtonCodes.BRoom06 == button)
            {
                button = ButtonCodes.BHallway15;
                dvalue--;
            }
            else if (ButtonCodes.BRoom07 == button)
            {
                button = ButtonCodes.BHallway17;
                dvalue--;
            }
            else if (ButtonCodes.BRoom08 == button)
            {
                button = ButtonCodes.BHallway18;
                dvalue--;
            }
            else if (ButtonCodes.BRoom09 == button)
            {
                button = ButtonCodes.BHallway21;
                dvalue--;
            }
            else if (ButtonCodes.BRoom10 == button)
            {
                button = ButtonCodes.BHallway24;
                dvalue--;
            }
            else if (ButtonCodes.BRoom11 == button)
            {
                button = ButtonCodes.BHallway26;
                dvalue--;
            }

            // if the dvalue is 0 then the hallway must be itself
            if (0 == dvalue)
            {
                return(button);
            }

            // map the hallway to the previous hallway
            if ((button - dvalue) <= 0)
            {
                startingSpace = (button - dvalue) + ((int)ButtonCodes.BHallway28 - (int)ButtonCodes.BHallway01) + (int)ButtonCodes.BHallway01;
            }
            else if (((int)button - dvalue) == ((int)ButtonCodes.BHallway28 - (int)ButtonCodes.BHallway01))
            {
                startingSpace = (ButtonCodes)((int)ButtonCodes.BHallway28 - (int)ButtonCodes.BHallway01);
            }
            else
            {
                startingSpace = (ButtonCodes)(((int)button - dvalue) % ((int)ButtonCodes.BHallway28 - (int)ButtonCodes.BHallway01));
            }

            return(startingSpace);
        }