File tree Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change 3
3
using DesignPatternsInCSharp . Memento ;
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Threading ;
6
7
7
8
namespace HangmanGameApp
8
9
{
@@ -56,14 +57,27 @@ static void Main(string[] args)
56
57
}
57
58
}
58
59
#endif
59
- game . Guess ( entry ) ;
60
+ try
61
+ {
62
+ game . Guess ( entry ) ;
60
63
#if SupportUndo
61
- gameHistory . Push ( game . CreateSetPoint ( ) ) ;
64
+ gameHistory . Push ( game . CreateSetPoint ( ) ) ;
62
65
#endif
63
- Console . WriteLine ( ) ;
66
+ Console . WriteLine ( ) ;
67
+ }
68
+ catch ( DuplicateGuessException )
69
+ {
70
+ OutputError ( "You already guessed that." ) ;
71
+ continue ;
72
+ }
73
+ catch ( InvalidGuessException )
74
+ {
75
+ OutputError ( "Sorry, invalid guess." ) ;
76
+ continue ;
77
+ }
64
78
}
65
79
66
- if ( game . Result == GameResult . Won )
80
+ if ( game . Result == GameResult . Won )
67
81
{
68
82
Console . WriteLine ( "CONGRATS! YOU WON!" ) ;
69
83
}
@@ -73,5 +87,14 @@ static void Main(string[] args)
73
87
Console . WriteLine ( "SORRY, You lost this time. Try again!" ) ;
74
88
}
75
89
}
90
+
91
+ private static void OutputError ( string message )
92
+ {
93
+ Console . WriteLine ( ) ;
94
+ Console . ForegroundColor = ConsoleColor . Red ;
95
+ Console . WriteLine ( message ) ;
96
+ Console . ResetColor ( ) ;
97
+ Thread . Sleep ( 3000 ) ;
98
+ }
76
99
}
77
100
}
You can’t perform that action at this time.
0 commit comments