-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.cs
More file actions
80 lines (69 loc) · 2.16 KB
/
Board.cs
File metadata and controls
80 lines (69 loc) · 2.16 KB
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
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HangMan
{
class Board
{
Puzzle puzzle;
public bool stopGame;
public Board()
{
puzzle = new Puzzle();
stopGame = false;
}
public void validateInput(string input)
{
input = input.Trim().ToLower();
if(input.Length > 1)
{
//Need additional validation -> contains only letters
if (puzzle.checkForSolve(input))
{
Console.WriteLine(Environment.NewLine + "Congratulations! You win!");
startNewGame();
} else
{
Console.WriteLine(Environment.NewLine + "Incorrect! Game over.");
startNewGame();
}
}
else if (input.Length == 1)
{
char letter = Convert.ToChar(input);
puzzle.checkGuessedLetter(letter);
} else
{
Console.WriteLine("Your input was invalid. Please try again.");
}
}
public void showPuzzle()
{
Console.WriteLine(puzzle);
}
public void timeToGuess()
{
Console.WriteLine(Environment.NewLine + "Guess a letter, or type in a word to solve the puzzle.");
}
void resetGame()
{
Console.WriteLine(Environment.NewLine + "Great! Here is your new puzzle." + Environment.NewLine);
puzzle = new Puzzle();
}
public void startNewGame()
{
Console.WriteLine(Environment.NewLine + "Would you like to play again? Y/N?");
string input = Console.ReadLine();
if (input.Equals("y"))
{
resetGame();
} else
{
Console.WriteLine(Environment.NewLine + "Game has ended. Press CRTL + C to close the window." + Environment.NewLine);
stopGame = true;
}
}
}
}