public static bool Turn(Player player, Player[] players, Grid grid, MurderScenario murderScenario)
        {
            Console.Write(player.name + "'s turn. ");
            if (grid.roomID[player.x, player.y] > 0)
            {
                Console.WriteLine("You are currently in the " + murderScenario.roomList[grid.roomID[player.x, player.y] - 1] + ".");
                Console.WriteLine("Would you like to make a suggestion? Enter 0 for no, 1 for yes");
                ConsoleKeyInfo cki    = Console.ReadKey();
                int            choice = Convert.ToInt32(cki.Key.ToString());
                if (choice == 1)
                {
                    Suggest(player, players, grid.roomID[player.x, player.y], murderScenario);
                    return(false);
                }
                else
                {
                }
            }
            Console.WriteLine("Would you like to make an accusation? WARNING: Accusing incorrectly will kick you out of the game, so you should only do this when you're certaion of whodunnit!");
            Console.WriteLine("Enter 0 for no, 1 for yes.");
            int willAccuse = 0;

            willAccuse = Convert.ToInt32(Console.ReadLine());
            if (willAccuse == 1)
            {
                return(Accuse(player, murderScenario));
            }
            else
            {
                Console.WriteLine("Press any key to roll your dice!");

                Console.ReadKey();
                int diceRollOne = 0; int diceRollTwo = 0;
                player.rollDice(ref diceRollOne, ref diceRollTwo);
                Console.WriteLine("You rolled {0} + {1} = {2}! Choose a space to move to", diceRollOne, diceRollTwo, (diceRollOne + diceRollTwo));
                bool movementValid = false;
                int  x             = 0;
                int  y             = 0;
                while (!movementValid)
                {
                    Console.Write("\nEnter coordinates taking the form of letter then number, i.e. e15 or B4: ");
                    string coords = Console.ReadLine();
                    x = 0;
                    y = 0;
                    if (InterpretCoords(coords, ref x, ref y))
                    {
                        movementValid = player.movePlayer(grid, x, y, diceRollOne + diceRollTwo);
                    }
                }
                if (grid.roomID[x, y] > 0)
                {
                    Suggest(player, players, grid.roomID[x, y], murderScenario);
                }
            }
            return(false);
        }
        private static void Suggest(Player player, Player[] players, int roomID, MurderScenario murderScenario)
        {
            bool suggestionReady = false;
            int  weaponChoice    = 0;
            int  personChoice    = 0;

            while (!suggestionReady)
            {
                Console.Write("\nSuggest a weapon from the weapon list: ");
                foreach (string weapon in murderScenario.weaponList)
                {
                    Console.Write(weapon + ", ");
                }
                Console.WriteLine();
                weaponChoice = Convert.ToInt32(Console.ReadLine());
                Console.Write("\nSuggest a person from the person list: ");
                foreach (string person in murderScenario.personList)
                {
                    Console.Write(person + ", ");
                }
                Console.WriteLine();
                personChoice = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("You suggest that " + murderScenario.personList[personChoice - 1] + " comitted murder in the " + murderScenario.roomList[roomID - 1] + " with the " + murderScenario.weaponList[weaponChoice - 1]);
                Console.WriteLine("Are you happy with this suggestion? 1 for yes 0 for no");
                int choice = Convert.ToInt32(Console.ReadLine());
                if (choice == 1)
                {
                    suggestionReady = true;
                }
            }
            Player nearestPlayerWithCards = CheckPlayersForCards(player.id, players, murderScenario.personList[personChoice - 1], murderScenario.roomList[roomID - 1], murderScenario.weaponList[weaponChoice - 1]);

            if (nearestPlayerWithCards == null)
            {
                Console.WriteLine("The cards you suggested are not held by any of your fellow detectives...");
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine(nearestPlayerWithCards.name + " holds one or more of the cards you suggested. They will now decide which card to reveal.");
                string cardToShow = ChooseCardToShow(nearestPlayerWithCards, player, murderScenario.personList[personChoice - 1], murderScenario.roomList[roomID - 1], murderScenario.weaponList[weaponChoice - 1]);
                Console.WriteLine(nearestPlayerWithCards.name + " shows you " + cardToShow + ". Press any key to continue."); //this needs to be sent in a DM to the player
                Console.ReadKey();
            }
        }
        private static bool Accuse(Player player, MurderScenario murderScenario)
        //currently there's no way to escape an accusation after initiating one
        {
            bool accusationReady = false;
            int  weaponChoice    = 0;
            int  roomChoice      = 0;
            int  personChoice    = 0;

            while (!accusationReady)
            {
                Console.Write("\nChoose a weapon from the weapon list: ");
                foreach (string weapon in murderScenario.weaponList)
                {
                    Console.Write(weapon + ", ");
                }
                Console.WriteLine();
                weaponChoice = Convert.ToInt32(Console.ReadLine());
                Console.Write("\nChoose a room from the room list: ");
                foreach (string room in murderScenario.roomList)
                {
                    Console.Write(room + ", ");
                }
                Console.WriteLine();
                roomChoice = Convert.ToInt32(Console.ReadLine());
                Console.Write("\nChoose a person from the person list: ");
                foreach (string person in murderScenario.personList)
                {
                    Console.Write(person + ", ");
                }
                Console.WriteLine();
                personChoice = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("You accuse " + murderScenario.personList[personChoice - 1] + " of comitting murder in the " + murderScenario.roomList[roomChoice - 1] + " with the " + murderScenario.weaponList[weaponChoice - 1]);
                Console.WriteLine("Are you happy with this accusation? 1 for yes 0 for no");
                int choice = Convert.ToInt32(Console.ReadLine());
                if (choice == 1)
                {
                    accusationReady = true;
                }
            }
            int correctCards = 0;

            foreach (string murderCard in murderScenario.murderList)
            {
                if (murderCard.Equals(murderScenario.personList[personChoice - 1]) || murderCard.Equals(murderScenario.roomList[roomChoice - 1]) || murderCard.Equals(murderScenario.weaponList[weaponChoice - 1]))
                {
                    correctCards++;
                }
            }
            if (correctCards == 3)
            {
                player.gameStatus = 1;
                Console.WriteLine("CONGRATULATIONS! You have cracked the case! " + murderScenario.personList[personChoice - 1] + " goes behind bars and you win the game! Press any key to continue.");
                Console.ReadKey();
                return(true);
            }
            else
            {
                player.gameStatus = -1;
                Console.WriteLine("False accusations never solve anything. You got " + correctCards + " out of 3 cards correct, and are forced to retire from the case. Press any key to continue.");
                Console.ReadKey();
                return(false);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Grid myGrid = new Grid(25, 24); // 25 x 24 is the original size, rotated
                                            // rotated so that the y is 24 - due to discord character limits we may
                                            // need to draw a grid using multiple messages. we can only do this by sending
                                            // as rows rather than columns, and 24 has more versatile factors than 25
                                            // which should give us more options when attempting this
                                            // (1, 2, 3, 4, 6, 8, 12, 24 as opposed to 1, 5, 25)
            int    currentPlayer = 0;
            bool   gameRunning   = true;
            Player playerOne     = new Player(1, "Tom", 7, 0);     //one bug I didnt get around to fixing: two players can't have
            Player playerTwo     = new Player(2, "Max", 24, 9);    //the same name. I know why this happens and it's pretty much
            Player playerThree   = new Player(3, "Brian", 24, 14); //better in every way to fix by preventing people from sharing names

            Player[] players = new Player[6];
            players[0] = playerOne;
            players[1] = playerTwo;
            players[2] = playerThree;
            myGrid.initializeGrid(players);
            myGrid.AssignStandardWalls();
            MurderScenario murderScenario = new MurderScenario(players);

            //the above line of code does all the card stuff haygarth implemented, i.e. setting
            //up the murder and dealing out cards to players

            //DEBUG BLOCK (displays the three murder cards, and then each player's hand
            foreach (string card in murderScenario.murderList)
            {
                Console.Write(card + ", ");
            }
            Console.WriteLine();
            foreach (Player player in players)
            {
                if (player != null)
                {
                    Console.Write(player.name + "'s cards: ");
                    foreach (string card in player.cards)
                    {
                        Console.Write(card + ", ");
                    }
                    Console.Write('\n');
                }
            }
            //DEBUG BLOCK END


            myGrid.drawGrid();
            while (gameRunning)
            {
                string winner = "";
                switch (GameManager.GameStatus(players)) //checks if game has ended
                {
                case 1:                                  //if ended due to a player winning
                    for (int i = 0; i < players.Length; i++)
                    {
                        if (players[i] != null)
                        {
                            if (players[i].gameStatus == 1)     //find the winner
                            {
                                winner = players[i].name;
                            }
                        }
                    }
                    Console.WriteLine("GAME WON BY " + winner + " VIA ACCUSATION");
                    gameRunning = false;
                    break;

                case -1:     //if ended due to all but one players losing
                    for (int i = 0; i < players.Length; i++)
                    {
                        if (players[i] != null)
                        {
                            if (players[i].gameStatus != -1)     //the winner is the one that isn't a loser
                            {
                                winner = players[i].name;
                            }
                        }
                    }
                    Console.WriteLine("GAME WON BY " + winner + " BY LAST MAN STANDING");
                    gameRunning = false;
                    break;

                default:     //if the game hasn't ended, do the following
                    if (players[currentPlayer] != null && players[currentPlayer].gameStatus != -1)
                    // the != null check comes into play if there are less than 6 players
                    // gameStatus != -1 checks if the player hasn't lost and can no longer have turns
                    {
                        if (GameManager.Turn(players[currentPlayer], players, myGrid, murderScenario))
                        //runs the current players turn. if they win, return true. if they don't, return false
                        {
                            gameRunning = false;
                        }
                        else
                        {
                            myGrid.drawGrid();
                        }
                    }
                    currentPlayer++;        //cycle to the next player
                    if (currentPlayer >= 6) //if you go out of the array bounds
                    {
                        currentPlayer = 0;  //the next player cycles back around to 0
                    }
                    break;
                }
            }
            Console.ReadKey();
        }