mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-27 21:23:30 -08:00
Reinstated Tester project. The Visual Studio test runner still doesn't display any test results but this is common to all solutions. It's a VS issue, not an issue with this Program.
First cut at a working program.
This commit is contained in:
@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.31112.23
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "War", "War\War.csproj", "{C13BE0FA-D8F7-4CA7-A95D-DA03A9DE8950}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WarTester", "WarTester\WarTester.csproj", "{B539F618-EE83-486C-9A6D-404E998BED2D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{C13BE0FA-D8F7-4CA7-A95D-DA03A9DE8950}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C13BE0FA-D8F7-4CA7-A95D-DA03A9DE8950}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C13BE0FA-D8F7-4CA7-A95D-DA03A9DE8950}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B539F618-EE83-486C-9A6D-404E998BED2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B539F618-EE83-486C-9A6D-404E998BED2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B539F618-EE83-486C-9A6D-404E998BED2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B539F618-EE83-486C-9A6D-404E998BED2D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -2,11 +2,99 @@
|
||||
|
||||
namespace War
|
||||
{
|
||||
public class Intro
|
||||
{
|
||||
public void WriteIntro()
|
||||
{
|
||||
Console.WriteLine(" WAR");
|
||||
Console.WriteLine(" CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("THIS IS THE CARD GAME OF WAR. EACH CARD IS GIVEN BY SUIT-#");
|
||||
Console.WriteLine("AS S-7 FOR SPADE 7. ");
|
||||
|
||||
if (AskQuestion("DO YOU WANT DIRECTIONS? "))
|
||||
{
|
||||
Console.WriteLine("THE COMPUTER GIVES YOU AND IT A 'CARD'. THE HIGHER CARD");
|
||||
Console.WriteLine("(NUMERICALLY) WINS. THE GAME ENDS WHEN YOU CHOOSE NOT TO");
|
||||
Console.WriteLine("CONTINUE OR WHEN YOU HAVE FINISHED THE PACK.");
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
public bool AskQuestion(string question)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.Write(question);
|
||||
string result = Console.ReadLine();
|
||||
|
||||
if (result.ToLower()[0] == 'y')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else /*if (result.ToLower() == "no")*/
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Console.WriteLine("YES OR NO, PLEASE.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
var intro = new Intro();
|
||||
intro.WriteIntro();
|
||||
|
||||
var deck = new Deck();
|
||||
deck.Shuffle();
|
||||
|
||||
int yourScore = 0;
|
||||
int computersScore = 0;
|
||||
bool usedAllCards = true;
|
||||
|
||||
for (int i = 0; i < Deck.deckSize; i += 2)
|
||||
{
|
||||
var yourCard = deck.GetCard(i);
|
||||
var computersCard = deck.GetCard(i + 1);
|
||||
|
||||
Console.WriteLine($"YOU: {yourCard} COMPUTER: {computersCard}");
|
||||
if (yourCard < computersCard)
|
||||
{
|
||||
computersScore++;
|
||||
Console.WriteLine($"THE COMPUTER WINS!!! YOU HAVE {yourScore} AND THE COMPUTER HAS {computersScore}");
|
||||
}
|
||||
else if (yourCard > computersCard)
|
||||
{
|
||||
yourScore++;
|
||||
Console.WriteLine($"YOU WIN. YOU HAVE {yourScore} AND THE COMPUTER HAS {computersScore}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("TIE. NO SCORE CHANGE");
|
||||
}
|
||||
|
||||
if (!intro.AskQuestion("DO YOU WANT TO CONTINUE? "))
|
||||
{
|
||||
usedAllCards = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (usedAllCards)
|
||||
{
|
||||
Console.WriteLine("WE HAVE RUN OUT OF CARDS.");
|
||||
}
|
||||
Console.WriteLine($"FINAL SCORE: YOU: {yourScore} THE COMPUTER: {computersScore}");
|
||||
Console.WriteLine("THANKS FOR PLAYING. IT WAS FUN.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user