using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { Random random = new Random(); bool playAgain = true; String player; String computer; String answer; while (playAgain) { player = ""; computer = ""; answer = ""; while (player != "ROCK" && player != "PAPER" && player != "SCISSORS") { Console.Write("Enter ROCK, PAPER, or SCISSORS: "); player = Console.ReadLine(); player = player.ToUpper(); }
switch (random.Next(1, 4)) { case 1: computer = "ROCK"; break; case 2: computer = "PAPER"; break; case 3: computer = "SCISSORS"; break; } Console.WriteLine("Player: " + player); Console.WriteLine("Computer: " + computer); switch (player) { case "ROCK": if (computer == "ROCK") { Console.WriteLine("It's a draw!"); } else if (computer == "PAPER") { Console.WriteLine("You lose!"); } else { Console.WriteLine("You win!"); } break; case "PAPER": if (computer == "ROCK") { Console.WriteLine("You win!"); } else if (computer == "PAPER") { Console.WriteLine("It's a draw!"); } else { Console.WriteLine("You lose!"); } break; case "SCISSORS": if (computer == "ROCK") { Console.WriteLine("You lose!"); } else if (computer == "PAPER") { Console.WriteLine("You win!"); } else { Console.WriteLine("It's a draw!"); } break; } Console.Write("Would you like to play again (Y/N): "); answer = Console.ReadLine(); answer = answer.ToUpper(); if (answer == "Y") { playAgain = true; } else { playAgain = false; }
} Console.WriteLine("Thanks for playing!"); Console.ReadKey(); } } }
A shorter version of this code - namespace ConsoleTesting { internal class Program { static void Main(string[] args) { var random = new Random(); var playAgain = true; while (playAgain) { Console.Write("Enter ROCK, PAPER, or SCISSORS: "); var player = Console.ReadLine().ToUpper(); while (player != "ROCK" && player != "PAPER" && player != "SCISSORS") { Console.Write("Invalid input, enter ROCK, PAPER, or SCISSORS: "); player = Console.ReadLine().ToUpper(); } var computer = random.Next(1, 4) switch { 1 => "ROCK", 2 => "PAPER", _ => "SCISSORS" }; Console.WriteLine("Player: " + player); Console.WriteLine("Computer: " + computer); var result = player switch { "ROCK" when computer == "ROCK" => "It's a draw!", "ROCK" when computer == "PAPER" => "You lose!", "ROCK" => "You win!", "PAPER" when computer == "ROCK" => "You win!", "PAPER" when computer == "PAPER" => "It's a draw!", "PAPER" => "You lose!", "SCISSORS" when computer == "ROCK" => "You lose!", "SCISSORS" when computer == "PAPER" => "You win!", _ => "It's a draw!" }; Console.WriteLine(result); Console.Write("Would you like to play again (Y/N): "); playAgain = Console.ReadLine().ToUpper() == "Y"; } Console.WriteLine("Thanks for playing!"); Console.ReadKey(); } } }
is my code ok? using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace rock_paper_scissors_game { internal class Program { static void Main(string[] args) { Random random = new Random(); String game = "ROCK, PAPER, SCISSORS: "; Console.Write(game); String user_input = Console.ReadLine().ToLower(); int random_char = random.Next(0, 3); while (true) { while (user_input != "paper" || user_input != "rock" || user_input != "scissors") { Console.WriteLine("please, write either paper or rock or scissors");
I think your computer was tricking you in this game. I've been following your playlist for weeks, and I've been learning a lot with you. Thanks for making this video.
I took the final result and added a score system of first to 3. Whichever wins (player or computer) it displays they won and the score after each win. using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { Random random = new Random(); bool playAgain = true; String player; String computer; String answer; int playerWins = 0; int computerWins = 0; while (playAgain) { player = ""; computer = ""; answer = "";
while (player != "ROCK" && player != "PAPER" && player != "SCISSORS") { Console.WriteLine("Enter ROCK, PAPER, or SCISSORS: "); player = Console.ReadLine(); player = player.ToUpper(); } switch (random.Next(1, 4)) { case 1: computer = "ROCK"; break; case 2: computer = "PAPER"; break; case 3: computer = "SCISSORS"; break; } Console.WriteLine("Player: " + player); Console.WriteLine("Computer: " + computer); switch (player) { case "ROCK": if (computer == "ROCK") { Console.WriteLine("It's a draw!"); } else if (computer == "PAPER") { Console.WriteLine("You lose!"); computerWins++; } else { Console.WriteLine("You win!"); playerWins++; } break; case "PAPER": if (computer == "ROCK") { Console.WriteLine("You win!"); playerWins++; } else if (computer == "PAPER") { Console.WriteLine("It's a draw!"); } else { Console.WriteLine("You lose!"); computerWins++; } break; case "SCISSORS": if (computer == "ROCK") { Console.WriteLine("You lose"); computerWins++; } else if (computer == "PAPER") { Console.WriteLine("You win!"); playerWins++; } else { Console.WriteLine("It's a draw!"); } break; } Console.WriteLine("Current score: " + playerWins + " - " + computerWins); if (playerWins == 3) { Console.WriteLine("Congratulations, you win the series!"); } else if (computerWins == 3) { Console.WriteLine("Damn bruh you suck lmaooo"); } if (playerWins == 3 || computerWins == 3) { playerWins = 0; computerWins = 0; } Console.Write("Would you like to play again? (Y/N): "); answer = Console.ReadLine(); answer = answer.ToUpper(); if (answer == "Y") { playAgain = true; } else { playAgain = false; } } Console.WriteLine("Thanks for playing!"); Console.ReadKey(); } } }
add some variables that go up for both the computer and player and add them into the if else statements ex: if(computer == player){ System.Console.WriteLine("DRAW"); playerScore++; computerScore++; }
Create video... If you guys want to test your skills a bit, try making it a best out of 3 game.. It's really not that hard and fun when you get it right (For reference i'm a newbie coder, so if I can do it so can you).
this is mine using System; public class HelloWorld { public static void Main(string[] args) { Console.WriteLine("Rock paper scissors"); Random random = new Random(); string playagain = ""; while (playagain == "") { Console.Write("choose rock paper or scissors "); string answer = Console.ReadLine(); answer = answer.ToUpper(); while (answer != "ROCK" && answer != "PAPER" && answer != "SCISSORS" ) { Console.Write("invalid choice choose ROCK PAPER or scissors "); answer = Console.ReadLine(); } Console.WriteLine("You chose: "+answer); int computer = random.Next(1,4); string ai = ""; switch (computer) { case 1: ai = "ROCK"; break; case 2: ai = "PAPER"; break; case 3: ai = "SCISSORS"; break; } Console.WriteLine("Computer chose: "+ai); if (answer == "ROCK" && ai == "SCISSORS") { Console.WriteLine("you win"); } else if (answer == "PAPER" && ai == "ROCK") { Console.WriteLine("you win"); } else if (answer == "SCISSORS" && ai == "PAPER") { Console.WriteLine("you win"); } else if (answer == "ROCK" && ai == "PAPER") { Console.WriteLine("you loose"); } else if (answer == "PAPER" && ai == "SCISSORS") { Console.WriteLine("you loose"); } else if (answer == "SCISSORS" && ai == "ROCK") { Console.WriteLine("you loose"); } else if (answer == "ROCK" && ai == "ROCK") { Console.WriteLine("it is a tie"); } else if (answer == "PAPER" && ai == "PAPER") { Console.WriteLine("it is a tie"); } else if (answer == "SCISSORS" && ai == "SCISSORS") { Console.WriteLine("it is a tie"); } else { Console.WriteLine("you loose"); } Console.Write("press enter to play again type no to stop"); playagain = Console.ReadLine(); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine(""); } Console.WriteLine("Thanks for playing this game"); } }
when I try to use the "while" loop for stopping the user to input another thing that is not "ROCK" , "Paper" , "Scissors" , it tells me that I cannot use the "&&" for string variables... help?
hey Bro,, is this considered a bad code? xD Thats how I've done before seeing your example: using System; using System.ComponentModel.Design; using System.Linq; using System.Threading.Channels; namespace projeto1 { internal class Program { static void Main(string[] args) {
bool PlayAgain = true; string cpuresponse = ""; while (PlayAgain == true) { Random cpunumber = new Random(); int cpunumber1 = cpunumber.Next(1, 3);
//#1= tesoura, #2= papel, #3 if (cpunumber1 == 1) { cpuresponse = "Tesoura"; } else if (cpunumber1 == 2) { cpuresponse = "Papel"; } else if (cpunumber1 == 3) { cpuresponse = "Pedra"; } Console.WriteLine("3...2...1... Pedra, papel ou tesooooura!?"); string response = Console.ReadLine(); Console.WriteLine(response + " VS " + cpuresponse); while (cpuresponse != response) { if (response == "Pedra" & cpuresponse == "Tesoura") { Console.WriteLine("Você venceu!"); break; } else if (response == "Pedra" && cpuresponse == "Papel") { Console.WriteLine("Você perdeu!"); break; } else if (response == "Tesoura" && cpuresponse == "Papel") { Console.WriteLine("Você ganhou!"); break; } else if (response == "Tesoura" && cpuresponse == "Papel") { Console.WriteLine("Você ganhou!"); break; } else if (response == "Tesoura" && cpuresponse == "Pedra") { Console.WriteLine("Você Perdeu!"); break; } else if (response == "Papel" && cpuresponse == "Pedra") { Console.WriteLine("Você ganhou!"); break; } else if(response == "Papel" && cpuresponse== "Tesoura") { Console.WriteLine("Você Perdeu!"); break; } } if (response == cpuresponse) { Console.WriteLine(cpuresponse + " é igual a " + response + ". Empate, tenta de novo..."); } Console.WriteLine("Quer jogar de novo? Y/N"); string PlayAgainresponse = Console.ReadLine(); if (PlayAgainresponse == "Y") { PlayAgain = true; } else { PlayAgain = false; } } Console.WriteLine("Obrigado por jogar!"); } } }
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();
bool playAgain = true;
String player;
String computer;
String answer;
while (playAgain)
{
player = "";
computer = "";
answer = "";
while (player != "ROCK" && player != "PAPER" && player != "SCISSORS") {
Console.Write("Enter ROCK, PAPER, or SCISSORS: ");
player = Console.ReadLine();
player = player.ToUpper();
}
switch (random.Next(1, 4))
{
case 1:
computer = "ROCK";
break;
case 2:
computer = "PAPER";
break;
case 3:
computer = "SCISSORS";
break;
}
Console.WriteLine("Player: " + player);
Console.WriteLine("Computer: " + computer);
switch (player)
{
case "ROCK":
if (computer == "ROCK")
{
Console.WriteLine("It's a draw!");
}
else if (computer == "PAPER")
{
Console.WriteLine("You lose!");
}
else
{
Console.WriteLine("You win!");
}
break;
case "PAPER":
if (computer == "ROCK")
{
Console.WriteLine("You win!");
}
else if (computer == "PAPER")
{
Console.WriteLine("It's a draw!");
}
else
{
Console.WriteLine("You lose!");
}
break;
case "SCISSORS":
if (computer == "ROCK")
{
Console.WriteLine("You lose!");
}
else if (computer == "PAPER")
{
Console.WriteLine("You win!");
}
else
{
Console.WriteLine("It's a draw!");
}
break;
}
Console.Write("Would you like to play again (Y/N): ");
answer = Console.ReadLine();
answer = answer.ToUpper();
if (answer == "Y")
{
playAgain = true;
}
else
{
playAgain = false;
}
}
Console.WriteLine("Thanks for playing!");
Console.ReadKey();
}
}
}
I decided to create a "best of 3" scenario (which is often what happens in real life) and before I'd watched the video had finally come up with the following code:
Random random = new Random();
String again = "y";
int computer_rand;
int computer_wins;
int player_wins;
while (again == "y")
{
Console.WriteLine("Welcome to Rock, Paper, Scissors!");
Console.WriteLine("Best of 3 rounds wins!");
Console.ReadLine();
computer_wins = 0;
player_wins = 0;
while (player_wins < 2 && computer_wins < 2)
{
String player = "";
String computer = "";
while (player != "rock" && player != "paper" && player != "scissors")
{
Console.WriteLine("Choose rock, paper or scissors: ");
player = Console.ReadLine();
player = player.ToLower();
}
computer_rand = random.Next(1, 4);
switch (computer_rand)
{
case 1:
computer = "rock";
break;
case 2:
computer = "paper";
break;
default:
computer = "scissors";
break;
}
Console.WriteLine("Computer is " + computer);
if (computer == player)
{
Console.WriteLine("TIE - REMATCH");
Console.ReadLine();
}
else if (computer == "rock")
{
switch (player)
{
case "paper":
Console.WriteLine("You win the round");
player_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
case "scissors":
Console.WriteLine("Computer wins the round");
computer_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
}
}
else if (computer == "paper")
{
switch (player)
{
case "scissors":
Console.WriteLine("You win the round");
player_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
case "rock":
Console.WriteLine("Computer wins the round");
computer_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
}
}
else if (computer == "scissors")
{
switch (player)
{
case "rock":
Console.WriteLine("You win the round");
player_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
case "paper":
Console.WriteLine("Computer wins the round");
computer_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
}
}
}
Console.WriteLine("Your wins: " + player_wins);
Console.WriteLine("Computer wins: " + computer_wins);
if (computer_wins > player_wins)
{
Console.WriteLine("Sorry, you lose. Computer wins the best of three");
}
else
{
Console.WriteLine("Congratulations! You won the best of three!");
}
Console.ReadLine();
Console.WriteLine("Play again? y/n?");
again = Console.ReadLine();
}
Console.WriteLine("Thanks for playing!");
Console.ReadKey();
A shorter version of this code -
namespace ConsoleTesting
{
internal class Program
{
static void Main(string[] args)
{
var random = new Random();
var playAgain = true;
while (playAgain)
{
Console.Write("Enter ROCK, PAPER, or SCISSORS: ");
var player = Console.ReadLine().ToUpper();
while (player != "ROCK" && player != "PAPER" && player != "SCISSORS")
{
Console.Write("Invalid input, enter ROCK, PAPER, or SCISSORS: ");
player = Console.ReadLine().ToUpper();
}
var computer = random.Next(1, 4) switch
{
1 => "ROCK",
2 => "PAPER",
_ => "SCISSORS"
};
Console.WriteLine("Player: " + player);
Console.WriteLine("Computer: " + computer);
var result = player switch
{
"ROCK" when computer == "ROCK" => "It's a draw!",
"ROCK" when computer == "PAPER" => "You lose!",
"ROCK" => "You win!",
"PAPER" when computer == "ROCK" => "You win!",
"PAPER" when computer == "PAPER" => "It's a draw!",
"PAPER" => "You lose!",
"SCISSORS" when computer == "ROCK" => "You lose!",
"SCISSORS" when computer == "PAPER" => "You win!",
_ => "It's a draw!"
};
Console.WriteLine(result);
Console.Write("Would you like to play again (Y/N): ");
playAgain = Console.ReadLine().ToUpper() == "Y";
}
Console.WriteLine("Thanks for playing!");
Console.ReadKey();
}
}
}
Thanks bro ☺
@@ChandranshuKumar its not good
is my code ok?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace rock_paper_scissors_game
{
internal class Program
{
static void Main(string[] args)
{
Random random = new Random();
String game = "ROCK, PAPER, SCISSORS: ";
Console.Write(game);
String user_input = Console.ReadLine().ToLower();
int random_char = random.Next(0, 3);
while (true)
{
while (user_input != "paper" || user_input != "rock" || user_input != "scissors")
{
Console.WriteLine("please, write either paper or rock or scissors");
Console.Write("ROCK, PAPER, SCISSORS: ");
user_input = Console.ReadLine();
random_char = random.Next(0, 3);
if (user_input == "paper" || user_input == "rock" || user_input == "scissors")
{
break;
}
}
if (random_char == 0 && user_input == "paper" || random_char == 1 && user_input == "rock" || random_char == 2 && user_input == "scissors")
{
if (random_char == 0)
{
Console.WriteLine("paper");
}
else if (random_char == 1)
{
Console.WriteLine("rock");
}
else if (random_char == 0)
{
Console.WriteLine("scissors");
}
Console.WriteLine("draw!");
}
else if (random_char == 0 && user_input == "rock" || random_char == 1 && user_input == "scissors" || random_char == 2 && user_input == "paper")
{
if (random_char == 0)
{
Console.WriteLine("paper");
}
else if (random_char == 1)
{
Console.WriteLine("rock");
}
else if (random_char == 0)
{
Console.WriteLine("scissors");
}
Console.WriteLine("VICTORYYY");
}
else if (random_char == 0 && user_input == "scissors" || random_char == 1 && user_input == "paper" || random_char == 2 && user_input == "rock")
{
if (random_char == 0)
{
Console.WriteLine("paper");
}
else if (random_char == 1)
{
Console.WriteLine("rock");
}
else if (random_char == 0)
{
Console.WriteLine("scissors");
}
Console.WriteLine("you lost :(");
}
Console.WriteLine("do you wanna continue?(y/n): ");
String continue_or_quit = Console.ReadLine();
if (continue_or_quit == "y")
{
Console.Write("ROCK, PAPER, SCISSORS: ");
user_input = Console.ReadLine();
random_char = random.Next(0, 3);
}
else if (continue_or_quit == "n")
{
Console.WriteLine("press any key to quit");
break;
}
}
}
}
}
Thank you! Great logic, and explanation!
I think your computer was tricking you in this game. I've been following your playlist for weeks, and I've been learning a lot with you. Thanks for making this video.
Bro, fantastic explanation of logic and clean coding and practice
Thank you so much. Very well explained.
Dude, Big thanks for explaining it! Now I understand it better.
Amazing explanation BRO. Thx again for your input.
Thank you so much! Finally some good explanation, comparing to my teachers)
Nice one bro!!! Thanks for sharing, learned a lot with this video!!
It's amazing bro 👌👌👌
Random comment = new Random();
That's kinda random
shortcut for random number:
int computer = new Random().Next(1,4);
all that code for such a simple little program.
what the hell did i get myself in to...
It's simple to understand so it's balanced I'd say
thanks for playing.
bro brought a gun to a rock paper scissors game
Thanks for the video Brother
tnks
Thanks man !
Thank you man!!
Rock!!
THANKS BRO!
Thanks bro
Thanks!
This is using the console application?
Thanks u r doing well
😊thnx
if (player == "rock" && cpu == "rock" || player == "paper" && cpu == "paper" || player == "scissors" && cpu == "scissors")
{
Console.WriteLine("Draw");
}
else if (player == "rock" && cpu == "scissors" || player == "scissors" && cpu == "paper" || player == "paper" && cpu == "rock")
{
Console.WriteLine("You Won!");
}
else
{
Console.WriteLine("Cpu won");
}
noice
thank you
I took the final result and added a score system of first to 3. Whichever wins (player or computer) it displays they won and the score after each win.
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();
bool playAgain = true;
String player;
String computer;
String answer;
int playerWins = 0;
int computerWins = 0;
while (playAgain)
{
player = "";
computer = "";
answer = "";
while (player != "ROCK" && player != "PAPER" && player != "SCISSORS")
{
Console.WriteLine("Enter ROCK, PAPER, or SCISSORS: ");
player = Console.ReadLine();
player = player.ToUpper();
}
switch (random.Next(1, 4))
{
case 1:
computer = "ROCK";
break;
case 2:
computer = "PAPER";
break;
case 3:
computer = "SCISSORS";
break;
}
Console.WriteLine("Player: " + player);
Console.WriteLine("Computer: " + computer);
switch (player)
{
case "ROCK":
if (computer == "ROCK")
{
Console.WriteLine("It's a draw!");
}
else if (computer == "PAPER")
{
Console.WriteLine("You lose!");
computerWins++;
}
else
{
Console.WriteLine("You win!");
playerWins++;
}
break;
case "PAPER":
if (computer == "ROCK")
{
Console.WriteLine("You win!");
playerWins++;
}
else if (computer == "PAPER")
{
Console.WriteLine("It's a draw!");
}
else
{
Console.WriteLine("You lose!");
computerWins++;
}
break;
case "SCISSORS":
if (computer == "ROCK")
{
Console.WriteLine("You lose");
computerWins++;
}
else if (computer == "PAPER")
{
Console.WriteLine("You win!");
playerWins++;
}
else
{
Console.WriteLine("It's a draw!");
}
break;
}
Console.WriteLine("Current score: " + playerWins + " - " + computerWins);
if (playerWins == 3)
{
Console.WriteLine("Congratulations, you win the series!");
}
else if (computerWins == 3)
{
Console.WriteLine("Damn bruh you suck lmaooo");
}
if (playerWins == 3 || computerWins == 3)
{
playerWins = 0;
computerWins = 0;
}
Console.Write("Would you like to play again? (Y/N): ");
answer = Console.ReadLine();
answer = answer.ToUpper();
if (answer == "Y")
{
playAgain = true;
}
else
{
playAgain = false;
}
}
Console.WriteLine("Thanks for playing!");
Console.ReadKey();
}
}
}
legend
Accumulation of score/wins throughout several runs? Suggestions?
add some variables that go up for both the computer and player and add them into the if else statements ex:
if(computer == player){
System.Console.WriteLine("DRAW");
playerScore++;
computerScore++;
}
Hi! I'm a beginer, why you use String? I'm use string and the program worcs.
String is basically text
I actually made a basic UWP version so you can run it on Xbox, too.
How do I put it to three rounds instead of 1 round, please help ASAP.
I created it as a "Best of 3 rounds" using the following code:
Random random = new Random();
String again = "y";
int computer_rand;
int computer_wins;
int player_wins;
while (again == "y")
{
Console.WriteLine("Welcome to Rock, Paper, Scissors!");
Console.WriteLine("Best of 3 rounds wins!");
Console.ReadLine();
computer_wins = 0;
player_wins = 0;
while (player_wins < 2 && computer_wins < 2)
{
String player = "";
String computer = "";
while (player != "rock" && player != "paper" && player != "scissors")
{
Console.WriteLine("Choose rock, paper or scissors: ");
player = Console.ReadLine();
player = player.ToLower();
}
computer_rand = random.Next(1, 4);
switch (computer_rand)
{
case 1:
computer = "rock";
break;
case 2:
computer = "paper";
break;
default:
computer = "scissors";
break;
}
Console.WriteLine("Computer is " + computer);
if (computer == player)
{
Console.WriteLine("TIE - REMATCH");
Console.ReadLine();
}
else if (computer == "rock")
{
switch (player)
{
case "paper":
Console.WriteLine("You win the round");
player_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
case "scissors":
Console.WriteLine("Computer wins the round");
computer_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
}
}
else if (computer == "paper")
{
switch (player)
{
case "scissors":
Console.WriteLine("You win the round");
player_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
case "rock":
Console.WriteLine("Computer wins the round");
computer_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
}
}
else if (computer == "scissors")
{
switch (player)
{
case "rock":
Console.WriteLine("You win the round");
player_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
case "paper":
Console.WriteLine("Computer wins the round");
computer_wins += 1;
Console.WriteLine("You: " + player_wins + " Computer: " + computer_wins);
Console.ReadLine();
break;
}
}
}
Console.WriteLine("Your wins: " + player_wins);
Console.WriteLine("Computer wins: " + computer_wins);
if (computer_wins > player_wins)
{
Console.WriteLine("Sorry, you lose. Computer wins the best of three");
}
else
{
Console.WriteLine("Congratulations! You won the best of three!");
}
Console.ReadLine();
Console.WriteLine("Play again? y/n?");
again = Console.ReadLine();
}
Console.WriteLine("Thanks for playing!");
Console.ReadKey();
Create video... If you guys want to test your skills a bit, try making it a best out of 3 game.. It's really not that hard and fun when you get it right (For reference i'm a newbie coder, so if I can do it so can you).
this is mine using System;
public class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine("Rock paper scissors");
Random random = new Random();
string playagain = "";
while (playagain == "")
{
Console.Write("choose rock paper or scissors ");
string answer = Console.ReadLine();
answer = answer.ToUpper();
while (answer != "ROCK" && answer != "PAPER" && answer != "SCISSORS" )
{
Console.Write("invalid choice choose ROCK PAPER or scissors ");
answer = Console.ReadLine();
}
Console.WriteLine("You chose: "+answer);
int computer = random.Next(1,4);
string ai = "";
switch (computer)
{
case 1:
ai = "ROCK";
break;
case 2:
ai = "PAPER";
break;
case 3:
ai = "SCISSORS";
break;
}
Console.WriteLine("Computer chose: "+ai);
if (answer == "ROCK" && ai == "SCISSORS")
{
Console.WriteLine("you win");
}
else if (answer == "PAPER" && ai == "ROCK")
{
Console.WriteLine("you win");
}
else if (answer == "SCISSORS" && ai == "PAPER")
{
Console.WriteLine("you win");
}
else if (answer == "ROCK" && ai == "PAPER")
{
Console.WriteLine("you loose");
}
else if (answer == "PAPER" && ai == "SCISSORS")
{
Console.WriteLine("you loose");
}
else if (answer == "SCISSORS" && ai == "ROCK")
{
Console.WriteLine("you loose");
}
else if (answer == "ROCK" && ai == "ROCK")
{
Console.WriteLine("it is a tie");
}
else if (answer == "PAPER" && ai == "PAPER")
{
Console.WriteLine("it is a tie");
}
else if (answer == "SCISSORS" && ai == "SCISSORS")
{
Console.WriteLine("it is a tie");
}
else
{
Console.WriteLine("you loose");
}
Console.Write("press enter to play again type no to stop");
playagain = Console.ReadLine();
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
}
Console.WriteLine("Thanks for playing this game");
}
}
string ifYouCantWin = "It's a dumb game" ;
for the aglorithm!
when I try to use the "while" loop for stopping the user to input another thing that is not "ROCK" , "Paper" , "Scissors" , it tells me that I cannot use the "&&" for string variables... help?
while (player != "ROCK" && player != "PAPER" && player != "SCISSORS")
lesson check😇
random comment
comment
hey Bro,, is this considered a bad code? xD
Thats how I've done before seeing your example:
using System;
using System.ComponentModel.Design;
using System.Linq;
using System.Threading.Channels;
namespace projeto1
{
internal class Program
{
static void Main(string[] args)
{
bool PlayAgain = true;
string cpuresponse = "";
while (PlayAgain == true)
{
Random cpunumber = new Random();
int cpunumber1 = cpunumber.Next(1, 3);
//#1= tesoura, #2= papel, #3
if (cpunumber1 == 1)
{ cpuresponse = "Tesoura"; }
else if (cpunumber1 == 2)
{ cpuresponse = "Papel"; }
else if (cpunumber1 == 3)
{ cpuresponse = "Pedra"; }
Console.WriteLine("3...2...1... Pedra, papel ou tesooooura!?");
string response = Console.ReadLine();
Console.WriteLine(response + " VS " + cpuresponse);
while (cpuresponse != response)
{
if (response == "Pedra" & cpuresponse == "Tesoura")
{
Console.WriteLine("Você venceu!");
break;
}
else if (response == "Pedra" && cpuresponse == "Papel")
{
Console.WriteLine("Você perdeu!");
break;
}
else if (response == "Tesoura" && cpuresponse == "Papel")
{
Console.WriteLine("Você ganhou!");
break;
}
else if (response == "Tesoura" && cpuresponse == "Papel")
{
Console.WriteLine("Você ganhou!");
break;
}
else if (response == "Tesoura" && cpuresponse == "Pedra")
{
Console.WriteLine("Você Perdeu!");
break;
}
else if (response == "Papel" && cpuresponse == "Pedra")
{
Console.WriteLine("Você ganhou!");
break;
}
else if(response == "Papel" && cpuresponse== "Tesoura")
{
Console.WriteLine("Você Perdeu!");
break;
}
}
if (response == cpuresponse)
{
Console.WriteLine(cpuresponse + " é igual a " + response + ". Empate, tenta de novo...");
}
Console.WriteLine("Quer jogar de novo? Y/N");
string PlayAgainresponse = Console.ReadLine();
if (PlayAgainresponse == "Y")
{
PlayAgain = true;
}
else { PlayAgain = false; }
}
Console.WriteLine("Obrigado por jogar!");
}
}
}
bool playAgain = true;
Random random = new Random();
while (playAgain)
{
int computerChoiceIdx = random.Next(1, 4);
String computerChoice = "";
if (computerChoiceIdx == 1)
{
computerChoice = "ROCK";
}
else if (computerChoiceIdx == 2)
{
computerChoice = "PAPER";
}
else
{
computerChoice = "SCISSORS";
}
Console.WriteLine(computerChoice);
Console.Write("What Is Your Choice? (Rock, Paper Or Scissors) - ");
String playerChoice = Console.ReadLine().ToUpper();
if (computerChoice == playerChoice)
{
Console.WriteLine("It Is A Tie!!");
}
else if (playerChoice == "ROCK")
{
if (computerChoice == "PAPER")
{
Console.WriteLine("You Lose!.");
}
else if (computerChoice == "SCISSORS")
{
Console.WriteLine("You Win!!");
}
}
else if (playerChoice == "PAPER")
{
if (computerChoice == "SCISSORS")
{
Console.WriteLine("You Lose!.");
}
else if (computerChoice == "ROCK")
{
Console.WriteLine("You Win!!");
}
}
else if (playerChoice == "SCISSORS")
{
if (computerChoice == "ROCK")
{
Console.WriteLine("You Lose!.");
}
else if (computerChoice == "PAPER")
{
Console.WriteLine("You Win!!");
}
}
Console.Write("Wanna Play Again? (Y/N) - ");
String wannaPlayAgain = Console.ReadLine().ToUpper();
if (wannaPlayAgain == "N")
{
playAgain = false;
Console.Clear();
Console.WriteLine("Byeeee!!!");
}
else
{
Console.Clear();
}
}
Console.WriteLine("Bro code zindabad" + "fan from 🇮🇳 ")