//////////////////////////////////////////////////////////////////////////////////////////////// private async Task Suggest(Player player, Player[] players, int roomID, MurderScenario murderScenario) { int personChoice = -1; int weaponChoice = -1; for (int i = 0; i < murderScenario.weaponList.Count; i++) { if (suggestedWeapon == murderScenario.weaponList[i]) { weaponChoice = i; } } for (int i = 0; i < murderScenario.personList.Count; i++) { if (suggestedPerson == murderScenario.personList[i]) { personChoice = i; } } if (personChoice == -1 || weaponChoice == -1) { await Context.Channel.SendMessageAsync("Invalid suggestion. Check ?list to see which cards are available!"); suggestionInProgress = false; return; } await Context.Channel.SendMessageAsync(players[playerTurn].usernameNoID + " suggested that " + suggestedPerson + " committed the murder with the " + suggestedWeapon + " in the " + murderScenario.roomList[roomID] + "."); Player nearestPlayerWithCards = CheckPlayersForCards(player.playerNumber, players, murderScenario.personList[personChoice], murderScenario.roomList[roomID], murderScenario.weaponList[weaponChoice]); //removed -1 from all indexes if (nearestPlayerWithCards == null) { await Context.User.SendMessageAsync("The cards you suggested are not held by any of your fellow detectives..."); return; } else { //await Context.Channel.SendMessageAsync(nearestPlayerWithCards.userID + " 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], murderScenario.roomList[roomID], murderScenario.weaponList[weaponChoice]); //removed -1 from all indexes shownCardsBuffer = (nearestPlayerWithCards.usernameNoID + " shows you " + cardToShow + "."); return; } }
//////////////////////////////////////////////////////////////////////////////////////////////// void SendListToBuffer(ref string buffer, MurderScenario murderScenario) { buffer = "Weapons: "; foreach (string weapon in murderScenario.weaponList) { buffer += weapon + ", "; } buffer += ".\nPlayers: "; foreach (string person in murderScenario.personList) { buffer += person + ", "; } buffer += ".\nRooms: "; foreach (string person in murderScenario.roomList) { buffer += person + ", "; } }
public async Task StartGame() { if (gamePlaying == true) { return; } currentPlayers = 0; foreach (Player playerNum in player) { if (playerNum != null) { currentPlayers++; } } if (currentPlayers < 2) { await Context.Channel.SendMessageAsync("There are not enough players to start the game."); return; } //grid.initializeGrid(player); await PrintGrid(); MurderScenario murderScenario = new MurderScenario(player); listOfEverything = ""; SendListToBuffer(ref listOfEverything, murderScenario); //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 player) { if (player != null) { Console.Write("Player " + (player.playerNumber + 1) + "'s cards: "); foreach (string card in player.cards) { Console.Write(card + ", "); } Console.Write('\n'); } } //DEBUG BLOCK END for (int i = 0; i < currentPlayers; i++) { } await Context.Channel.SendMessageAsync("The game has begun!"); gamePlaying = true; playerTurn = 0; gameState = "Roll"; while (gamePlaying) { string winner = ""; switch (GameStatus(player)) //checks if game has ended { case 1: //if ended due to a player winning for (int i = 0; i < player.Length; i++) { if (player[i] != null) { if (player[i].gameStatus == 1) //find the winner { winner = player[i].usernameNoID; } } } await Context.Channel.SendMessageAsync("GAME WON BY " + winner + " VIA ACCUSATION"); gameState = "Won"; gamePlaying = false; await CloseGame(); break; case -1: //if ended due to all but one players losing for (int i = 0; i < player.Length; i++) { if (player[i] != null) { if (player[i].gameStatus != -1) //the winner is the one that isn't a loser { winner = player[i].usernameNoID; } } } await Context.Channel.SendMessageAsync("GAME WON BY " + winner + " BY LAST MAN STANDING"); gameState = "Won"; gamePlaying = false; await CloseGame(); break; default: //if the game hasn't ended, do the following if (player[playerTurn] != null && player[playerTurn].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 { await Turn(player[playerTurn], player, grid, murderScenario); if (gameState == "Won") //runs the current players turn. if they win, return true. if they don't, return false { gamePlaying = false; } else { await PrintGrid(); gameState = "Roll"; } } playerTurn++; //cycle to the next player if (playerTurn >= currentPlayers) //if you go out of the array bounds { playerTurn = 0; //the next player cycles back around to 0 } ResetVars(); break; } } }
//////////////////////////////////////////////////////////////////////////////////////////////// private /*static bool */ async Task Accuse(Player player, MurderScenario murderScenario) { int weaponChoice = -1; int roomChoice = -1; int personChoice = -1; for (int i = 0; i < murderScenario.weaponList.Count; i++) { if (suggestedWeapon == murderScenario.weaponList[i]) { weaponChoice = i; } } for (int i = 0; i < murderScenario.personList.Count; i++) { if (suggestedPerson == murderScenario.personList[i]) { personChoice = i; } } for (int i = 0; i < murderScenario.roomList.Count; i++) { if (suggestedRoom == murderScenario.roomList[i]) { roomChoice = i; } } if (personChoice == -1 || weaponChoice == -1 || roomChoice == -1) { await Context.Channel.SendMessageAsync("Invalid accusation. Check ?list to see which cards are available!"); accusationInProgress = false; return; } int correctCards = 0; foreach (string murderCard in murderScenario.murderList) { if (murderCard.Equals(murderScenario.personList[personChoice]) || murderCard.Equals(murderScenario.roomList[roomChoice]) || murderCard.Equals(murderScenario.weaponList[weaponChoice])) { correctCards++; } } if (correctCards == 3) { player.gameStatus = 1; await Context.Channel.SendMessageAsync("CONGRATULATIONS! You have cracked the case! " + murderScenario.personList[personChoice] + " goes behind bars and you win the game!"); gameState = "Won"; return /*true*/; } else { player.gameStatus = -1; await Context.Channel.SendMessageAsync("False accusations never solve anything. You got " + correctCards + " out of 3 cards correct, and are forced to retire from the case."); return /*false*/; } }
//////////////////////////////////////////////////////////////////////////////////////////////// public async Task Turn(Player player, Player[] players, Grid grid, MurderScenario murderScenario) { if (grid.roomID[player.x, player.y] > 0) { await Context.Channel.SendMessageAsync("Player " + (playerTurn + 1) + "'s turn. You are currently in the " + murderScenario.roomList[grid.roomID[player.x, player.y]] + ". " + "Make a ?suggestion, ?accuse someone, or ?roll the dice."); gameState = "RollSuggest"; SpinWait.SpinUntil(() => suggestionInProgress || roll > 0 || accusationInProgress); if (suggestionInProgress) { await Suggest(player, players, grid.roomID[player.x, player.y], murderScenario); return /*false*/; } if (accusationInProgress) { await Accuse(player, murderScenario); return /*false*/; } } if (roll == 0) { await Context.Channel.SendMessageAsync("Player " + (playerTurn + 1) + "'s turn. ?Roll the dice or ?accuse someone of murder!"); gameState = "Roll"; } SpinWait.SpinUntil(() => roll > 0 || accusationInProgress); if (accusationInProgress) { await Accuse(player, murderScenario); return /*false*/; } if (roll > 0) { gameState = "Move"; bool movementValid = false; int x = 0; int y = 0; while (!movementValid) { x = 0; y = 0; userCoords = ""; SpinWait.SpinUntil(() => userCoords != ""); if (InterpretCoords(userCoords, ref x, ref y)) { movementValid = player.MovePlayer(grid, x, y, roll); } if (movementError != "") { await Context.Channel.SendMessageAsync(movementError); movementError = ""; } } if (grid.roomID[x, y] > 0) { await Context.Channel.SendMessageAsync("You can now ?suggest a case. (?Suggest [person] [weapon])"); gameState = "Suggest"; while (!suggestionInProgress) { SpinWait.SpinUntil(() => suggestionInProgress); await Suggest(player, players, grid.roomID[player.x, player.y], murderScenario); //return /*false*/; } suggestionInProgress = false; } } ResetVars(); return /* false*/; }