-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
70 lines (58 loc) · 2.31 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
namespace QuadaxExcercise
{
class Program
{
static void Main(string[] args)
{
var mastermind = new Mastermind();
Console.WriteLine("Welcome to Quadax's Programming Excerice!");
Console.WriteLine("Would you like to play Mastermind? (y or n)");
char yOrN = Console.ReadLine()[0];
while (yOrN != 'n' && yOrN != 'N')
{
if (yOrN == 'y' || yOrN == 'Y')
{
PlayMastermind(mastermind);
}
else
{
Console.WriteLine("I'm sorry Please type 'y' for Yes or 'n' for No:");
}
Console.WriteLine("Would you like to play Mastermind? (y or n)");
yOrN = Console.ReadLine()[0];
}
Console.WriteLine("Thank you for playing!");
}
public static void PlayMastermind(Mastermind m)
{
m.NewGame();
var guessesPerRound = m.GetNumberOfPieces();
var numberOfColors = m.GetNumberOfColors();
Console.Clear();
Console.WriteLine("Enter {0} seperate integers from 1-{1} representing your guesses:", guessesPerRound, numberOfColors);
for (var i = 1; m.validGame(); i++)
{
var guesses = new List<int>();
Console.WriteLine("Round {0}:", i);
for (var j = 1; j <= guessesPerRound; j++)
{
Console.Write("Guess {0}:", j);
var input = Console.ReadLine();
int.TryParse(input, out int result);
if (result < 1 || result > numberOfColors)
{
j--;
Console.WriteLine("I'm sorry that is an invalid guess, must be an int from 1-{0}", numberOfColors);
}
else{
guesses.Add(result);
}
}
Console.WriteLine("Round {0} Result:{1}",i, m.Guess(guesses));
Console.WriteLine("-------------------------------------------");
}
}
}
}