I am relatively new to coding on c# and just wondering why I get a red underline on my "Else" line. can anyone help me??
class Program
{
static void Main()
{
string temp;
int number;
char computer = ' ', answer;
Random rand = new Random();
Console.WriteLine("Press p for paper, s for scissor or r for rock");
temp = Console.ReadLine();
answer = Convert.ToChar(temp);
number = rand.Next(3);
switch (number)
{
case 1:
computer = 'p';
Console.WriteLine("CPU chose paper");
break;
case 2:
computer = 's';
Console.WriteLine("CPU chose scissors");
break;
case 3:
computer = 'r';
Console.WriteLine("CPU chose rock");
break;
}
if (answer == computer)
{
Console.WriteLine("Draw");
}
else if (((answer == 'r')&&(computer == 's'))
||((answer == 's')&&(computer == 'p'))
||((answer == 'p')&&(computer == 'r')))
{
Console.WriteLine("You have won");
}
else (((answer == 's')&&(computer == 'r'))
||((answer == 'p')&&(computer == 's'))
||((answer == 'r')&&(computer == 'p')))
{
Console.WriteLine("You have lost");
}
Console.ReadLine();
}
}
You cant have conditions in else. I have converted your else with else if. below is corrected code
class Program
{
static void Main()
{
string temp;
int number;
char computer = ' ', answer;
Random rand = new Random();
Console.WriteLine("Press p for paper, s for scissor or r for rock");
temp = Console.ReadLine();
answer = Convert.ToChar(temp);
number = rand.Next(3);
switch (number)
{
case 1:
computer = 'p';
Console.WriteLine("CPU chose paper");
break;
case 2:
computer = 's';
Console.WriteLine("CPU chose scissors");
break;
case 3:
computer = 'r';
Console.WriteLine("CPU chose rock");
break;
}
if (answer == computer)
{
Console.WriteLine("Draw");
}
else if (((answer == 'r') && (computer == 's')) || ((answer == 's') && (computer == 'p')) || ((answer == 'p') && (computer == 'r')))
{
Console.WriteLine("You have won");
}
else if
(((answer == 's') && (computer == 'r')) || ((answer == 'p') && (computer == 's')) || ((answer == 'r') && (computer == 'p')))
{
Console.WriteLine("You have lost");
}
else
{
Console.WriteLine("In conclusive");
}
Console.ReadLine();
}
}
The else alone can't take a condition. To check a condition you need another if clause in the else branch:
if (condition) {
...
}
else if (other condition)
{
...
}
Related
I'm a beginner programer that have started programming a week ago. As part of the learning to consolidate knowledge, I try to recreate my Toothbrush program. I want to dependent the program on two keys PowerButton and OptionButton.
Here's the code:
Console.WriteLine("Hello!");
int powerButtonCount = 0;
int optionButtonCount = 0;
if (Console.ReadKey().KeyChar == 'p')
{
powerButtonCount++;
while (powerButtonCount >= 1)
{
if (Console.ReadKey().KeyChar == 'o')
{
optionButtonCount++;
switch (optionButtonCount)
{
case 1:
Console.WriteLine("Sensitive");
while (powerButtonCount == 2 && optionButtonCount == 1)
{
Console.WriteLine("Brushing in Sensitive mode!");
}
break;
case 2:
Console.WriteLine("Gum Care");
while (powerButtonCount == 2 && optionButtonCount == 2)
{
Console.WriteLine("Brushing in Gum Care mode!");
}
break;
case 3:
Console.WriteLine("Intense");
while (powerButtonCount == 2 && optionButtonCount == 3)
{
Console.WriteLine("Brushing in Intense mode!");
}
break;
case 4:
Console.WriteLine("Daily Clean");
while (powerButtonCount == 2 && optionButtonCount == 4)
{
Console.WriteLine("Brushing in Daily Clean mode!");
}
break;
case 5:
Console.WriteLine("Whiten");
while (powerButtonCount == 2 && optionButtonCount == 5)
{
Console.WriteLine("Brushing in Whiten mode!");
}
break;
}
}
else if (powerButtonCount == 3)
{
powerButtonCount = 0;
Console.WriteLine("Good Bye!");
}
}
}
What I came across is problem that I can't read input from user in realtime. After my testing, seems like I'm able to jump between switches, but when I want to initialize "Brushing thing" C# doesn't read 'p'.
I'm coding a rock paper scissors game and some reason the counter is incrementing weird. Could anyone explain to me why when I win it increments by 1, when I lose it increments by 2, and when I tie, it increments by 3? I just want it to add by 1. I appreciate all answers.
class RPSLS
{
public enum GameMode
{
Unknown,
Single_Player,
Two_Player,
}
public GameMode GameType {get; set;}
public enum Hand { Rock = 1, Paper, Scissors, Lizard, Spock, Report, Exit };
public enum Outcome { Win, Lose, Tie };
public Hand ComputerHand { get; set; }
public Hand PlayerHand { get; set; }
public char UserSelection { get; set; }
int win = 0;
int lose = 0;
int tie = 0;
public Hand getUserHand()
{
while (!validateSelection())
{
Console.Clear();
Console.WriteLine("Invalid Input");
UserSelection = Convert.ToChar(Console.ReadLine());
}
switch (Char.ToUpper(UserSelection))
{
case 'R':
PlayerHand = Hand.Rock;
break;
case 'P':
PlayerHand = Hand.Paper;
break;
case 'S':
PlayerHand = Hand.Scissors;
break;
case 'L':
PlayerHand = Hand.Lizard;
break;
case 'K':
PlayerHand = Hand.Spock;
break;
case 'Q':
PlayerHand = Hand.Exit;
break;
case 'T':
PlayerHand = Hand.Report;
break;
default:
throw new Exception("Unexpected Error");
}
return PlayerHand;
}
public Outcome DetermineWinner()
{
if (PlayerHand == Hand.Scissors && ComputerHand == Hand.Paper)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Scissors && ComputerHand == Hand.Lizard)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Rock && ComputerHand == Hand.Scissors)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Rock && ComputerHand == Hand.Scissors)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Paper && ComputerHand == Hand.Rock)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Paper && ComputerHand == Hand.Spock)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Lizard && ComputerHand == Hand.Paper)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Lizard && ComputerHand == Hand.Spock)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Spock && ComputerHand == Hand.Scissors)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Spock && ComputerHand == Hand.Rock)
{
win++;
return Outcome.Win;
}
else if (PlayerHand == Hand.Scissors && ComputerHand == Hand.Rock)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Scissors && ComputerHand == Hand.Spock)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Rock && ComputerHand == Hand.Paper)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Rock && ComputerHand == Hand.Spock)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Paper && ComputerHand == Hand.Scissors)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Paper && ComputerHand == Hand.Lizard)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Lizard && ComputerHand == Hand.Rock)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Lizard && ComputerHand == Hand.Scissors)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Spock && ComputerHand == Hand.Lizard)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Spock && ComputerHand == Hand.Paper)
{
lose++;
return Outcome.Lose;
}
else if (PlayerHand == Hand.Exit)
{
Environment.Exit(0);
}
else if (PlayerHand == Hand.Report)
{
Report();
}
tie++;
return Outcome.Tie;
}
private void Report()
{
Console.WriteLine("Your Score is (W:L:T:) : {0}:{1}:{2}", win, lose, tie);
}
private void PlayGame()
{
bool gameOver = false;
var rand = new Random();
char response;
while (!gameOver)
{
Screen();
UserSelection = Convert.ToChar(Console.ReadLine());
getUserHand();
ComputerHand = (Hand)rand.Next(1, 6);
Console.Clear();
Console.WriteLine("Computer's Hand: {0}", ComputerHand);
Console.WriteLine("Player's Hand: {0}", PlayerHand);
if (DetermineWinner() == Outcome.Win)
Console.WriteLine("Win");
else if (DetermineWinner() == Outcome.Lose)
Console.WriteLine("Lose");
else if (DetermineWinner() == Outcome.Tie)
Console.WriteLine("Tie");
Console.WriteLine("Would you Like to play another game? (y/n)");
response = Convert.ToChar(Console.ReadLine());
while(validateResponse(response) == false)
{
Console.WriteLine("Invalid Input, Please re-enter your selection: ");
response = Convert.ToChar(Console.ReadLine());
}
if (response == 'N' || response == 'n')
gameOver = true;
Console.Clear();
}
}
public bool validateResponse (char response)
{
if (Char.ToUpper(response) != 'Y' && Char.ToUpper(response) != 'N')
return false;
return true;
}
private bool validateSelection()
{
char value = Char.ToUpper(UserSelection);
if (value != 'R' && value != 'P' && value != 'S' && value != 'L' && value != 'K' && value != 'T' && value != 'Q')
return false;
return true;
}
private void Screen()
{
Console.WriteLine("(R)ock | (P)aper | (S)cissors | (L)izard | Spoc(k) | (Q)uit | Repor(t)");
}
public GameMode getGameType()
{
bool flag = true;
string buffer;
GameMode GameType = GameMode.Unknown;
GameType = GameMode.Unknown;
Console.WriteLine("Available options are: (S)ingle Player | (T)wo Player");
Console.Write("What would you like to play?: ");
while (flag)
{
buffer = Console.ReadLine();
try
{
switch (buffer.ToUpper())
{
case "S":
case "SINGLE PLAYER":
GameType = GameMode.Single_Player;
break;
case "T":
case "TWO PLAYER":
GameType = GameMode.Two_Player;
break;
default:
Console.WriteLine("Action not understood.");
break;
}
if (GameType != GameMode.Unknown)
{
PerformWork(GameType);
}
}
catch (ArgumentException)
{
Console.WriteLine("'{0}' is not understood.", buffer);
}
}
return GameType;
}
private void PerformWork(GameMode cmd)
{
if (cmd == GameMode.Single_Player)
{
Console.Clear();
SinglePlayer(cmd);
}
else if (cmd == GameMode.Two_Player)
{
Console.WriteLine("Two Player Mode");
}
else
{
Console.WriteLine("Action not understood.");
}
}
private void SinglePlayer(GameMode cmd)
{
Console.WriteLine("Hello. You are now playing Single Player Mode");
Console.Write("Please Enter Your Name: ");
String nameInput = Console.ReadLine();
Console.Write("Please Enter A Name For Computer: ");
string computerNameInput = Console.ReadLine();
Console.Clear();
Console.WriteLine(nameInput + " vs " + computerNameInput);
PlayGame();
}
}
}
The side effects from this block of code will increment your class level variables.
if (DetermineWinner() == Outcome.Win)
Console.WriteLine("Win");
else if (DetermineWinner() == Outcome.Lose)
Console.WriteLine("Lose");
else if (DetermineWinner() == Outcome.Tie)
Console.WriteLine("Tie");
Each time DetermineWinner() is called the fields are touched.
You're incrementing when you call DetermineWinner() which you do 3 times for a tie, twice for a loss, and once for a win.
eg assuming the result is a tie, you're calling DetermineWinner() to check if it's a win which meets the tie condition in the function and increments the value. The evaluation fails, so it runs the else and calls DetermineWinner() again, whcih increments again.
Fix would be to call DetermineWinner() once and assign the result to a variable then you can evaluate that without reincrementing.
I'm a beginner with programming so any hints would be greatly appreciated!
I'm trying to create a program where the user guesses whether a 'coin toss' will produce heads (0) or tails (1) using a random number generator and a loop as the 'coin'. The program must output the percent of correct guesses out of the total games played.
I've tried many different ways and it's far from right! It's v discouraging.
Thanks in advance for any tips!!
-C
This is basically the closest I've come:
for (numPlays = 0; ; numPlays++)
{
Console.Write("\nWrite H/h to guess Heads, T/t to guess Tails, or Q/q to quit => ");
userChoice = Convert.ToChar(Console.ReadLine());
if (userChoice == 'H' || userChoice == 'h')
{
if (compChoice == 0)
{
Console.WriteLine("\nYOU WON");
numWins++;
}
else
Console.WriteLine("\nYOU LOSE");
if (userChoice == 'Q' || userChoice == 'q')
if (compChoice == 1)
{
Console.WriteLine("\nYOU WON");
numWins++;
}
else
Console.WriteLine("\nYOU LOSE");
if (userChoice == 'q' || userChoice == 'Q')
{
percentWin = (double)(numWins / numPlays);
Console.WriteLine("\nYou won {0} out of {1} game(s) or {2:P} of the games played.", numWins, numPlays, percentWin);
}
}
}
Console.ReadKey();
}
}
I optimized your code a little bit,I hope this helps:
int numPlays = 0, numWins = 0;
int compChoice = 0;
char userChoice;
double percentWin;
Random rnd = new Random();
while (true)
{
Console.Write("\nWrite H/h to guess Heads, T/t to guess Tails, or Q/q to quit => ");
userChoice = Console.ReadKey().KeyChar;
compChoice = rnd.Next(0, 2);
if (char.ToLowerInvariant(userChoice) != 'q')
{
if (char.ToLowerInvariant(userChoice) == 'h' && compChoice == 0)
{
Console.WriteLine("\nYOU WON");
numWins++;
}
else if (char.ToLowerInvariant(userChoice) == 't' && compChoice == 1)
{
Console.WriteLine("\nYOU WON");
numWins++;
}
else
{
Console.WriteLine("\nYOU LOSE");
}
numPlays++;
}
else
{
percentWin = (double) numWins/numPlays;
Console.WriteLine("\nYou won {0} out of {1} game(s) or {2:P} of the games played.", numWins, numPlays, percentWin);
break;
}
}
I think you don't need an explanation, all of the code is self-explanatory.But you have an obvious mistake when you calculating the percentage:
percentWin = (double)(numWins / numPlays);
Here you are performing an integer division,then casting that result to double,it's pointless because you already lose your decimal points.Instead you should cast one of the operands to double so it will perform a double division and you will get the correct result.
Just invoke this method and play your game!
public static void SomeMethod()
{
Console.Write("\nWrite H/h to guess Heads, T/t to guess Tails, or Q/q to quit => ");
char userChoice;
int numWins = 0;
int numPlays = 0;
double percentWin = 0d;
while ((userChoice = Convert.ToChar(Console.ReadLine())).ToString().ToLower() != "q")
{
numPlays++;
int compChoice = new Random().Next(2);
if (userChoice == 'H' || userChoice == 'h')
{
if (compChoice == 0)
{
Console.WriteLine("\nYOU WON");
numWins++;
}
else
{
Console.WriteLine("\nYOU LOSE");
}
continue;
}
if (userChoice == 'T' || userChoice == 't')
{
if (compChoice == 1)
{
Console.WriteLine("\nYOU WON");
numWins++;
}
else
{
Console.WriteLine("\nYOU LOSE");
}
continue;
}
}
if (numPlays != 0)
{
percentWin = (double)numWins / numPlays;
}
Console.WriteLine("\nYou won {0} out of {1} game(s) or {2:P} of the games played.", numWins, numPlays, percentWin);
Console.ReadKey();
}
This should not be any difficult, you just need to make a clear algorithm
Let me suggest one
Char playOrExit= 'y'
Int32 gameCount = 0;
Int32 Wins = 0;
While (playOrExit.ToUpper.Equals('Y'))
{
Console.Write("Press Y to continue playing and N to exit");
playOrExit = Convert.ToChar(Console.ReadLine());
//Computer choice will be math.random from 0 and 1
//now take user choice
//compare and show if he won or lost
}
if(gameCount >0)
{
Console.WriteLine("\nYou played {0} times, out of which {1} game(s) were won.", gameCount,Wins);
}
Is there a better way to present the following method which prints out different messages depending on the parameters. Find it too wordy and lengthy and yet unable to simply it cos the messages differ at each line. Do advice if I could shorten it. Thank you.
private void message(int choice, string result)
{
if (choice == 1 && result == "Draw")
{
MessageBox.Show("It is a draw. Both chose Rock");
}
else if (choice == 2 && result == "Draw")
{
MessageBox.Show("It is a draw. Both chose Paper");
}
else if (choice == 3 && result == "Draw")
{
MessageBox.Show("It is a draw. Both chose Scissor");
}
else if (choice == 1 && result == "Win")
{
MessageBox.Show("Congratulations! Rock beats Scissor");
}
else if (choice == 2 && result == "Win")
{
MessageBox.Show("Congratulations! Paper beats Rock");
}
else if (choice == 3 && result == "Win")
{
MessageBox.Show("Congratulations! Scissor beats Paper");
}
else if (choice == 1 && result == "Lose")
{
MessageBox.Show("You lose. Paper beats rock");
}
else if (choice == 2 && result == "Lose")
{
MessageBox.Show("You lose. Scissor beats Paper");
}
else if (choice == 3 && result == "Lose")
{
MessageBox.Show("You lose. Rock beats Scissor");
}
}
Setup an enum to represent the possible choices:
public enum Choice
{
Rock = 1,
Paper = 2,
Scissor = 3
}
Then just use string.Format():
var selectedChoice = Enum.GetName(typeof(Choice), choice);
var beatsChoice = selectedChoice == Choice.Rock ? Choice.Scissor
: (selectedChoice == Choice.Paper ? Choice.Rock : Choice.Paper);
if (result == "Draw")
MessageBox.Show(string.Concat("It is a draw. Both chose ", selectedChoice);
else if (result == "Win")
MessageBox.Show(string.Concat("Congratulations! ", selectedChoice, " beats ", beatsChoice);
else if (result == "Lose")
MessageBox.Show(string.Concat("You lose. ", selectedChoice, " beats ", beatsChoice);
Dont know if this is a good idea but you can do like this:
private void message(int choice, string result)
{
if(result == "Draw")
{
switch (choice)
case 1: MessageBox.Show("It is a draw. Both chose Rock");
break;
case 2: MessageBox.Show("It is a draw. Both chose Paper");
break;
case 3: MessageBox.Show("It is a draw. Both chose Scissor");
break;
}
//similarly do for the rest.
}
Not sure I like your design, but given what you have this is (slightly) nicer to maintain ...
private void message(int choice, string result)
{
string self;
switch(choice)
{
case 1: self = "Rock"; break;
case 2: self = "Paper"; break;
case 3: self = "Scissor"; break;
}
switch(result)
{
case "Draw":
MessageBox.Show(String.Format("It is a draw. Both chose {0}", self));
break;
case "Win":
string beats;
switch(choice)
{
case 1: beats = "Scissor"; break;
case 2: beats = "Rock"; break;
case 3: beats = "Paper"; break;
}
MessageBox.Show(String.Format("Congratulations! {0} beats {1}", self, beats));
break;
case "Lose":
string loses;
switch(choice)
{
case 1: loses = "Paper"; break;
case 2: loses = "Scissor"; break;
case 3: loses = "Rock"; break;
}
MessageBox.Show(String.Format("You lose. {1} beats {0}", self, loses));
break;
break;
}
}
That said, this solution is still horribly ugly. A better way would to be passing around objects which encapsulate rock/paper/scissor states rather than "choice" ints. These would have methods to get what they beat. Printing would then be much simpler.
Another thing is that you could make the integer and string as Enum's this would allow you to print out the wording of the in very few lines of code.
Use enums to increase readability. I would also use two parameters since it's not clear who won:
public enum RockPaperScissors
{
Rock,
Paper,
Scissor
}
public enum GameResult
{
PlayerOneWin,
PlayerTwoWin,
Draw
}
Then the method can be shortened to:
private void message(GameResult result, RockPaperScissors choice1, RockPaperScissors choice2)
{
if (result == GameResult.Draw)
{
MessageBox.Show("It is a draw. Both chose " + choice1.ToString());
}
else
{
string message = string.Format("Congratulations, {0} beats {1}!"
, result == GameResult.PlayerOneWin ? choice1 : choice2
, result == GameResult.PlayerOneWin ? choice2 : choice1);
MessageBox.Show(message);
}
}
I wrote a small Shotgun app, however, the section of code that needs to stop the game when either the AI (called Genius), the user, or both, are shot, I can't get to work. What am I doing wrong? I feel like I over-complicated my code a ton by adding lots of returns with different booleans, in which some are being passed and others aren't.
In testing it right now, the loop ends no matter what if the user move (called string move) equals "f". In any other scenario, I can not get the loop to end.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public static void Main(string[] args)
{
Start("r");
}
public static string Start(string move)
{
Console.Write("Welcome to the Shotgun App\nEnter s for single player and m for multiplayer: ");
string gameType = Console.ReadLine();
if (gameType == "s")
{
Console.Write("Single Player Controls:\n r = reload\n s = shield\n f = fire\nYou start with 1 ammo\nReady to play?");
Console.ReadLine();
int ammo = 1;
int geniusAmmo = 1;
string geniusMove = "";
bool done = false;
while (!done)
{
Console.Write("\nEnter your move: ");
move = Console.ReadLine();
switch (move)
{
case "r":
Console.Write("\nYou have reloaded, press enter for Genius\n");
ammo++;
Console.Write("Your ammo is " + ammo);
Console.ReadLine();
Genius(geniusMove, move, geniusAmmo, done);
break;
case "s":
Console.Write("\nYou have shielded, press enter for Genius\n");
Console.Write("Your ammo is " + ammo);
Console.ReadLine();
Genius(geniusMove, move, geniusAmmo, done);
break;
case "f":
if (ammo != 0)
{
Console.Write("\nYou have fired, press enter for Genius\n");
ammo--;
Console.Write("Your ammo is " + ammo);
Console.ReadLine();
Genius(geniusMove, move, geniusAmmo, done);
}
else
{
Console.Write("You don't have enough ammo, try again");
done = false;
}
break;
default:
Console.Write("\nInvalid move, try again\n");
done = false;
break;
}
done = EndLoop(move, geniusMove, done);
Console.ReadLine();
}
return move;
}
else
{
return move;
}
}
public static string Genius(string geniusMove, string move, int geniusAmmo, bool done)
{
Random RandomNumber = new Random();
int x = RandomNumber.Next(0,3);
if (x == 0)
{
geniusMove = "f";
geniusAmmo--;
Console.Write("Genius had decided to fire.\nGenius ammo is " + geniusAmmo + "\n");
TestMoves(move, geniusMove);
}
else if (x == 1)
{
geniusMove = "r";
geniusAmmo++;
Console.Write("Genius had decided to reload.\nGenius ammo is " + geniusAmmo + "\n");
TestMoves(move, geniusMove);
}
else if (x == 2)
{
geniusMove = "s";
Console.Write("Genius had decided to shield.\nGenius ammo is " + geniusAmmo + "\n");
TestMoves(move, geniusMove);
}
return geniusMove;
}
public static void TestMoves(string move, string geniusMove)
{
bool done = false;
if (move == "s" && geniusMove == "f")
{
Console.Write("Nice shield, no one has died yet");
}
else if (move == "f" && geniusMove == "f")
{
Console.Write("You both died! Good game!");
}
else if (move == "r" && geniusMove == "f")
{
Console.Write("No shield!? You died! Good game!");
}
else if (move == "f" && geniusMove == "s")
{
Console.Write("Genius is too good, no one has died yet");
}
else if (move == "f" && geniusMove != "s")
{
Console.Write("Genius let his guard down! Good game!");
}
else if (move != "f" && geniusMove != "f")
{
Console.Write("Keep playing it safe.");
}
else
{
}
}
static bool EndLoop(string move, string geniusMove, bool done)
{
done = false;
if (move == "s" && geniusMove == "f")
{
return false;
}
else if (move == "f" && geniusMove == "f")
{
return true;
}
else if (move != "s" && geniusMove == "f")
{
return true;
}
else if (move == "f" && geniusMove == "s")
{
return false;
}
else if (move == "f" && geniusMove != "s")
{
return true;
}
else if (move != "f" && geniusMove != "f")
{
return false;
}
else
{
return done;
}
}
}
}
You are setting done in a few different places, both in some execution branches in the switch cases, and when calling EndLoop. The assignment from EndLoop will overwrite any previous assignment, so make that The One Place You Set done.
Setting done with EndLoop in TestMoves does not have any effect since you immediately return a hard-coded value right after you call EndLoop.
I suggest you follow through EndLoop in a debugger. If it makes it easier for you to visualize what's happening, you might consider instead printing to the console the input parameters for EndLoop, and which if condition you end up selecting.
geniusMove will always be an empty string since you are not storing the result of the call to the Genius method.
Either store the result in the geniusMove variable or pass it in by reference
public static string Genius(ref string geniusMove, string move, int geniusAmmo, bool done)
or
geniusMove = Genius(geniusMove, move, geniusAmmo, done);