-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
113 lines (83 loc) · 2.9 KB
/
Game.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using DeckOfCards;
using BridgePlayer;
using BridgeBid;
using BridgeTricks;
using BridgeScoring;
using BridgeRound;
namespace BridgeGame
{
public class BGame
{
int nummaOfPlayers;
int dealerIndex;
Player[] players;
Deck deck;
Hand currentHand;
ScorePad scorepad;
const int book = 6;
// CONSIDER A HAND/ROUND CLASS
public BGame()
{
// DEFAULT NUMBER OF PLAYERS
this.nummaOfPlayers = 4;
this.dealerIndex = 0;
this.deck = new Deck();
this.currentHand = new Hand(this.dealerIndex);
this.players = new Player[nummaOfPlayers];
for(int i = 0; i < nummaOfPlayers; i++)
{
this.players[i] = new Player( (i), this.partnerAcrossTable(i) );
}
this.scorepad = new ScorePad(this.dealerIndex, this.players);
while(!this.scorepad.RubberOver())
{
// ONE HAND
this.scorepad.UpdateScores(this.currentHand.NewHand(this.players), this.currentHand.FinalContract(), this.players[this.currentHand.FinalContractPlayer()]);
if(this.currentHand.FinalContract().Suit() != biddableSuits.PASS)
{
//this.currentHand.PrintHand();
this.currentHand.PrintNumberOfBiddersTricks();
}
this.printAllPlayersScores();
this.dealerIndex = (this.dealerIndex + 1) % this.nummaOfPlayers;
Console.WriteLine("----NEW HAND----");
}
/** /
this.nummaOfTricks = this.deck.CardCount() / this.nummaOfPlayers;
/** /this.deck.PrintDeck();/** /
this.DealAllCards(this.dealerIndex);
//this.Auction();
if(this.PlayableContract())
{
this.allTricks = new Trick[this.nummaOfTricks];
this.PlayTricks();
}
/**/
this.scorepad.AwardRubberPoints();
this.printAllPlayersScores();
}
public void printAllPlayers()
{
for(int i = 0; i < nummaOfPlayers; i++)
{
Console.WriteLine("Player " + (i+1) + ":");
this.players[i].PrintHand();
}
}
public void printAllPlayersScores()
{
this.scorepad.PrintScoreCard();
for(int i = 0; i < nummaOfPlayers; i++)
{
Console.WriteLine("Player " + (i+1) + ": " + this.players[i].Score() + " points");
}
}
//only works with even number of players
private int partnerAcrossTable(int indexOfMe)
{
return (indexOfMe + nummaOfPlayers/2) % nummaOfPlayers;
}
}
}