private Transform createAt(string atGameObjName, RpsEnum objectType) { Transform obj = getPrefab(objectType); return Instantiate(obj, GameObject.Find(atGameObjName).transform.position, obj.rotation) as Transform; }
public OutcomeEnum GetGameOutcome(RpsEnum player, RpsEnum ai) { OutcomeEnum result; if (player == ai) result = (OutcomeEnum)((int)OutcomeSimple.Tie * 3 + player); else if (((int)player % 3) + 1 == (int)ai) result = (OutcomeEnum)((int)OutcomeSimple.Lose * 3 + player); else result = (OutcomeEnum)((int)OutcomeSimple.Win * 3 + player); return result; }
private Transform getPrefab(RpsEnum ofType) { switch (ofType) { case RpsEnum.Rock: return Rock; case RpsEnum.Paper: return Paper; case RpsEnum.Scissors: return Scissors; case RpsEnum.Undetermined: default: return null; } }
public async Task RockPaperScissorsAsync([Remainder] RpsEnum choice) { string[] emotesPlayer = { "🤜", "🖐️", "✌️" }; string[] emotesCPU = { "🤛", "🖐️", "✌️" }; var avatar = UserAccounts.GetAccount(Context.User); RpsEnum cpuChoice = (RpsEnum)((new Random()).Next(0, 1000) % 3); string result = ""; switch ((int)choice - (int)cpuChoice) { case 1: case -2: result = "You read me like an open book! You win!"; await ServerGames.UserWonRPS((SocketGuildUser)Context.User, (SocketTextChannel)Context.Channel); break; case 0: ServerGames.UserDidNotWinRPS((SocketGuildUser)Context.User); result = "I may not have the gift of Psynergy, but I can still match your strength!"; break; case -1: case 2: ServerGames.UserDidNotWinRPS((SocketGuildUser)Context.User); result = "Ahah! I may forever remember the day I beat an Adept in a fair game!"; break; } var embed = new EmbedBuilder(); embed.WithColor(Colors.Get("Iodem")); embed.WithDescription($"{emotesPlayer[(int)choice]} vs {emotesCPU[(int)cpuChoice]}"); embed.AddField("Result:", result); await Context.Channel.SendMessageAsync("", false, embed.Build()); }
private Rect createButton(RpsEnum choice) { float margin = 10; float left; float top = (Screen.height * 2) / 3 + margin; float width = Screen.width / 3 - (2 * margin); float height = Screen.height / 3 - (2 * margin); switch (choice) { case RpsEnum.Rock: left = 0 + margin; return new Rect(left, top, width, height); case RpsEnum.Paper: left = Screen.width / 3 + margin; return new Rect(left, top, width, height); case RpsEnum.Scissors: left = (Screen.width * 2) / 3 + margin; return new Rect(left, top, width, height); case RpsEnum.Undetermined: default: return button; } }
/// <summary> </summary> public void DropInChoice(RpsEnum player) { //cleanup last round removeGameObject(player3D); removeGameObject(ai3D); //calculate this round RpsEnum ai = aiObject.GetAiChoice(gameOutcomes); OutcomeEnum roundOutcome = referee.GetGameOutcome(player, ai); string gameHistoryUpdate; string outcomeText = referee.HandleOutcome(roundOutcome, ref gameOutcomes, out gameHistoryUpdate); //Update UI elements gameHistory = gameHistoryUpdate; gameConsole = "You chose " + player.ToString() + System.Environment.NewLine + "Computer chose " + ai.ToString() + outcomeText; //Drop in 3D objects player3D = createAt("PlayerDrop", player); ai3D = createAt("AiDrop", ai); }
public async Task RockPaperScissorsAsync([Remainder] RpsEnum choice) { string[] emotesPlayer = { "🤜", ":hand_splayed:", ":v:" }; string[] emotesCpu = { "🤛", ":hand_splayed:", ":v:" }; var cpuChoice = Enum.GetValues <RpsEnum>().Random(); var result = ""; switch ((int)choice - (int)cpuChoice) { case 1: case -2: result = "You read me like an open book! You win!"; _ = ServerGames.UserWonRps((SocketGuildUser)Context.User, (SocketTextChannel)Context.Channel); break; case 0: ServerGames.UserDidNotWinRps((SocketGuildUser)Context.User); result = "I may not have the gift of Psynergy, but I can still match your strength!"; break; case -1: case 2: ServerGames.UserDidNotWinRps((SocketGuildUser)Context.User); result = "Ahah! I may forever remember the day I beat an Adept in a fair game!"; break; } var embed = new EmbedBuilder(); embed.WithColor(Colors.Get("Iodem")); embed.WithDescription($"{emotesPlayer[(int)choice]} vs {emotesCpu[(int)cpuChoice]}"); embed.AddField("Result:", result); _ = Context.Channel.SendMessageAsync("", false, embed.Build()); await Task.CompletedTask; }
private void setChosen(bool? state, RpsEnum choice) { if (state.HasValue && state.Value == true) { switch (choice) { case RpsEnum.Rock: CheckedPaper = CheckedScissors = false; break; case RpsEnum.Paper: CheckedRock = CheckedScissors = false; break; case RpsEnum.Scissors: CheckedPaper = CheckedRock = false; break; case RpsEnum.Undetermined: default: break; } RpsChosen = choice; } //This assumes that all values are equal only when all values are false else if (CheckedRock == CheckedPaper && CheckedPaper == CheckedScissors) { RpsChosen = RpsEnum.Undetermined; } }