-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cs
More file actions
95 lines (74 loc) · 2.52 KB
/
Game.cs
File metadata and controls
95 lines (74 loc) · 2.52 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
namespace GoFish {
public class Game {
static void Main(string[] args) {
Random rand = new Random();
Player human = new HumanPlayer();
Player ai = new AIPlayer(rand);
Player[] players = {human, ai};
Deck deck = new Deck(rand);
bool cont = true;
bool playersSwapped = true;
while (cont) {
deck.Shuffle();
int curPlayer = rand.Next(0, 1);
int lastPlayer = curPlayer == 0 ? 1 : 0;
for (int i = 0; i < 14; i++) {
players[i % 2].DrawCard(deck);
}
while (players.All(player => player.HasMoreCards())) {
Player pl = players[curPlayer];
Player other = players[curPlayer == 0 ? 1 : 0];
string youOrI = curPlayer == 0 ? "You" : "I";
string otherYouOrI = curPlayer == 0 ? "I" : "You";
if (!playersSwapped) {
Console.WriteLine($"{youOrI} get another guess!");
}
List<Card> previousBooks = pl.Hand.Books.ToList();
Console.WriteLine($"Your hand: {human.Hand}");
Card guess = pl.GetGuess();
if (curPlayer == 1) {
Console.WriteLine($"My guess: {guess.Name}");
}
List<Card> cards = other.HandleGuess(guess);
if (cards.Count == 0) {
Console.WriteLine($"{otherYouOrI} say GO FISH!!!");
Card drawn = pl.DrawCard(deck);
if (curPlayer == 0) {
Console.WriteLine($"You drew: {drawn.Name}");
}
if (!drawn.Equals(guess)) {
curPlayer = curPlayer == 0 ? 1 : 0;
playersSwapped = true;
} else {
Console.WriteLine($"{youOrI} drew the guess!");
playersSwapped = false;
}
} else {
Console.WriteLine($"{otherYouOrI} have {cards.Count} {guess.Name}(s).");
pl.ReceiveCards(cards);
playersSwapped = false;
}
List<Card> newBooks = pl.Hand.Books.Except(previousBooks).ToList();
if (newBooks.Count > 0) {
Console.WriteLine($"{youOrI} made a book of {newBooks[0]}s!");
}
}
Console.WriteLine($"Your books: {human.Hand.Books.Count}");
Console.WriteLine($"My books: {ai.Hand.Books.Count}");
if (human.Hand.Books.Count > ai.Hand.Books.Count) {
Console.WriteLine("You win!");
} else if (ai.Hand.Books.Count > human.Hand.Books.Count) {
Console.WriteLine("I win!");
} else {
Console.WriteLine("Tie game!");
}
Console.Write("Would you like to play again? [Y/n]: ");
string input = Console.ReadLine();
cont = input != null && input.Equals("y", StringComparison.InvariantCultureIgnoreCase);
}
}
}
}