-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanPlayer.cs
More file actions
34 lines (27 loc) · 751 Bytes
/
HumanPlayer.cs
File metadata and controls
34 lines (27 loc) · 751 Bytes
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace GoFish {
public class HumanPlayer : Player {
public HumanPlayer() {
this.Hand = new Hand();
}
public override List<Card> HandleGuess(Card guess) {
return this.Hand.HandleGuess(guess);
}
public override Card GetGuess() {
Console.Write("Your guess: ");
string input = Console.ReadLine();
if (!Card.CardNames.Contains(input)) {
Console.Error.WriteLine("Invalid card name.");
return this.GetGuess();
}
int index = this.Hand.Cards.FindIndex((card) => card.Name == input);
if (index == -1) {
Console.Error.WriteLine("You don't have this card!");
return this.GetGuess();
}
return this.Hand.Cards[index];
}
}
}