ITP Code Backup
This commit is contained in:
25
RockPaperScissors/RockPaperScissors.sln
Normal file
25
RockPaperScissors/RockPaperScissors.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32210.238
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RockPaperScissors", "RockPaperScissors\RockPaperScissors.csproj", "{5CF3AD0B-48EF-46AB-A5AC-B387C8951830}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5CF3AD0B-48EF-46AB-A5AC-B387C8951830}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5CF3AD0B-48EF-46AB-A5AC-B387C8951830}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5CF3AD0B-48EF-46AB-A5AC-B387C8951830}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5CF3AD0B-48EF-46AB-A5AC-B387C8951830}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F76444DC-6901-46E5-B8A7-002D69B3C598}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
144
RockPaperScissors/RockPaperScissors/RockPaperScissors.cs
Normal file
144
RockPaperScissors/RockPaperScissors/RockPaperScissors.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
Random rand = new Random();
|
||||
|
||||
int playerPoints = 0;
|
||||
int computerPoints = 0;
|
||||
|
||||
PlayRound();
|
||||
Console.WriteLine($"Current score is PC: {computerPoints} to Player: {playerPoints}");
|
||||
Console.WriteLine();
|
||||
PlayRound();
|
||||
Console.WriteLine($"Current score is PC: {computerPoints} to Player: {playerPoints}");
|
||||
Console.WriteLine();
|
||||
PlayRound();
|
||||
DetermineWinner();
|
||||
|
||||
|
||||
//computerPick
|
||||
string GetRandomPick()
|
||||
{
|
||||
int roll = rand.Next(3);
|
||||
string computerPick = String.Empty;
|
||||
if (roll == 0)
|
||||
{
|
||||
computerPick = "rock";
|
||||
}
|
||||
else if (roll == 1)
|
||||
{
|
||||
computerPick = "paper";
|
||||
}
|
||||
else if (roll == 2)
|
||||
{
|
||||
computerPick = "scissors";
|
||||
}
|
||||
return computerPick;
|
||||
|
||||
}
|
||||
|
||||
//Player input validation
|
||||
bool ValidatePick(string playerPick)
|
||||
{
|
||||
if (playerPick == "rock" || playerPick == "paper" || playerPick == "scissors")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//playerPick
|
||||
string GetPlayerPick()
|
||||
{
|
||||
Console.Write("Pick rock, paper, or scissors: ");
|
||||
string userInput = Console.ReadLine();
|
||||
string playerPick = userInput.ToLower();
|
||||
if (ValidatePick(playerPick) == false)
|
||||
{
|
||||
Console.WriteLine("Exiting. Please restart and type, \"rock\", \"paper\", or, \"scissors\".");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
return playerPick;
|
||||
}
|
||||
|
||||
//Display each pick
|
||||
void DisplayPicks(string playerChoice, string computerChoice)
|
||||
{
|
||||
Console.WriteLine($"Player chose {playerChoice}.");
|
||||
Console.WriteLine($"PC chose {computerChoice}.");
|
||||
}
|
||||
|
||||
//Scoring system 3
|
||||
void UpdateScore(string playerChoice, string computerChoice)
|
||||
{
|
||||
computerChoice = computerChoice.ToLower();
|
||||
playerChoice = playerChoice.ToLower();
|
||||
|
||||
|
||||
if (computerChoice == playerChoice)
|
||||
{
|
||||
Console.WriteLine("Tie. No points awarded.");
|
||||
}
|
||||
else if ((computerChoice != playerChoice) && (computerChoice == "paper" && playerChoice == "rock"))
|
||||
{
|
||||
Console.WriteLine("Paper covers rock. Point for PC.");
|
||||
computerPoints++;
|
||||
}
|
||||
else if ((computerChoice != playerChoice) && (computerChoice == "scissors" && playerChoice == "rock"))
|
||||
{
|
||||
Console.WriteLine("Rock smashes scissors. Point for player.");
|
||||
playerPoints++;
|
||||
}
|
||||
else if ((computerChoice != playerChoice) && (computerChoice == "scissors" && playerChoice == "paper"))
|
||||
{
|
||||
Console.WriteLine("Scissors cut paper. Point for PC.");
|
||||
computerPoints++;
|
||||
}
|
||||
else if ((computerChoice != playerChoice) && (computerChoice == "rock" && playerChoice == "paper"))
|
||||
{
|
||||
Console.WriteLine("Paper covers rock. Point for player.");
|
||||
playerPoints++;
|
||||
}
|
||||
else if ((computerChoice != playerChoice) && (computerChoice == "paper" && playerChoice == "scissors"))
|
||||
{
|
||||
Console.WriteLine("Scissors cut paper. Point for player.");
|
||||
playerPoints++;
|
||||
}
|
||||
else if ((computerChoice != playerChoice) && (computerChoice == "rock" && playerChoice == "scissors"))
|
||||
{
|
||||
Console.WriteLine("Rock smashes scissors. Point for PC.");
|
||||
computerPoints++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PlayRound()
|
||||
{
|
||||
string computerChoice = GetRandomPick();
|
||||
string playerChoice = GetPlayerPick();
|
||||
Console.WriteLine();
|
||||
DisplayPicks(playerChoice, computerChoice);
|
||||
UpdateScore(playerChoice, computerChoice);
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
void DetermineWinner()
|
||||
{
|
||||
Console.WriteLine("FINAL SCORE");
|
||||
Console.WriteLine($"Player Points: {playerPoints}");
|
||||
Console.WriteLine($"Computer Points: {computerPoints}");
|
||||
|
||||
if (playerPoints > computerPoints)
|
||||
{
|
||||
Console.WriteLine("PLAYER WINS!");
|
||||
}
|
||||
else if (playerPoints < computerPoints)
|
||||
{
|
||||
Console.WriteLine("PC WINS!");
|
||||
}
|
||||
else if (playerPoints == computerPoints)
|
||||
{
|
||||
Console.WriteLine("PLAYER AND PC HAVE TIED.");
|
||||
}
|
||||
}
|
10
RockPaperScissors/RockPaperScissors/RockPaperScissors.csproj
Normal file
10
RockPaperScissors/RockPaperScissors/RockPaperScissors.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user