示例#1
0
 /// <summary>
 /// The constructor for tablesprite takes a PsGame, PirateSpades.GameLogic.Game and a rectangle
 /// </summary>
 /// <param name="game">The PsGame currently running</param>
 /// <param name="playingGame">The current game being played</param>
 /// <param name="rect">The rectangle used to specify the size of the texture tablesprite draws</param>
 public TableSprite(PsGame game, Game playingGame, Rectangle rect)
 {
     Contract.Requires(game != null && playingGame != null);
     this.game = game;
     this.playingGame = playingGame;
     this.rect = rect;
     this.SetUp();
 }
示例#2
0
 /// <summary>
 /// Make a new round with this game, number and dealer
 /// </summary>
 /// <param name="game">The game</param>
 /// <param name="number">The roundnumber</param>
 /// <param name="dealer">The dealer</param>
 public Round(Game game, int number, int dealer)
 {
     Contract.Requires(game != null && dealer >= 0 && dealer < game.Players.Count);
     this.Game = game;
     this.Dealer = dealer;
     this.Number = number;
     this.CurrentPlayer = dealer;
     this.BoardCards = new Trick();
     this.PlayerTricks = new Dictionary<Player, List<Trick>>();
     this.PlayerBets = new Dictionary<Player, int>();
     this.Started = false;
     this.TricksDone = 0;
     this.Cards = 0;
 }
示例#3
0
        private static void GameFinished(Game game)
        {
            var sb = new StringBuilder();

            sb.AppendLine("Testing GetRoundScore");
            for(var i = 1; i <= game.RoundsPossible; i++) {
                var s = game.GetRoundScore(i);
                var t = game.GetRoundScoreTotal(i);
                sb.AppendLine("Round #" + i);
                foreach(var kvp in s) {
                    sb.AppendLine("\t" + kvp.Key.Name + ": " + kvp.Value);
                }
                sb.AppendLine("\tTotals:");
                foreach(var kvp in t) {
                    sb.AppendLine("\t\t" + kvp.Key.Name + ": " + kvp.Value);
                }
            }
            sb.AppendLine();
            sb.AppendLine();

            sb.AppendLine("Testing GetTotalScores");
            var st = game.GetTotalScores();
            foreach(var kvp in st) {
                sb.AppendLine(kvp.Key.Name + ": " + kvp.Value);
            }
            sb.AppendLine();
            sb.AppendLine();

            sb.AppendLine("Testing GetScoreTable");
            var sct = game.GetScoreTable();
            sb.Append("Round");
            foreach(var p in sct[1].Keys) {
                sb.Append("\t" + p.Name);
            }
            sb.AppendLine();
            foreach(var kvp in sct) {
                sb.Append(kvp.Key.ToString());
                foreach(var score in kvp.Value.Values) {
                    sb.Append("\t" + score);
                }
                sb.AppendLine();
            }

            var fs = new FileStream("score test.txt", FileMode.OpenOrCreate, FileAccess.Write);
            var buffer = Encoding.Default.GetBytes(sb.ToString());
            fs.Write(buffer, 0, buffer.Length);
            fs.Close();
        }
示例#4
0
 /// <summary>
 /// Round started.
 /// </summary>
 /// <param name="game">The game.</param>
 private void RoundStarted(Game game)
 {
     PirateHostCommands.NewRound(this);
 }
示例#5
0
 /// <summary>
 /// New pile has been created.
 /// </summary>
 /// <param name="game">The game.</param>
 private void RoundNewPile(Game game)
 {
     PirateHostCommands.NewPile(this);
 }
示例#6
0
 /// <summary>
 /// Round finished.
 /// </summary>
 /// <param name="game">The game.</param>
 private void RoundFinished(Game game)
 {
     PirateHostCommands.RoundFinished(this);
 }
示例#7
0
 /// <summary>
 /// Round begun.
 /// </summary>
 /// <param name="game">The game.</param>
 private void RoundBegun(Game game)
 {
     PirateHostCommands.RequestCard(this, Clients[game.Round.CurrentPlayer]);
 }
示例#8
0
 /// <summary>
 /// New game.
 /// </summary>
 private void NewGame()
 {
     if (Game != null) {
         Game.RoundStarted -= RoundStarted;
         Game.RoundBegun -= RoundBegun;
         Game.RoundFinished -= RoundFinished;
         Game.GameFinished -= GameFinished;
         Game.RoundNewPile -= this.RoundNewPile;
     }
     Game = new Game();
     Game.RoundStarted += RoundStarted;
     Game.RoundBegun += RoundBegun;
     Game.RoundFinished += RoundFinished;
     Game.GameFinished += GameFinished;
     Game.RoundNewPile += this.RoundNewPile;
 }
示例#9
0
 /// <summary>
 /// Game finished.
 /// </summary>
 /// <param name="game">The game.</param>
 private void GameFinished(Game game)
 {
     PirateHostCommands.GameFinished(this);
 }
示例#10
0
 /// <summary>
 /// Handler method for event RoundFinished and RoundNewPile when the round is finished
 /// </summary>
 /// <param name="g">The game</param>
 private void OnRoundFinished(Game g)
 {
     Contract.Ensures(cardsOnTable.Count == 0);
     cardsOnTable.Clear();
     winner = g.Round.LastTrick.Winner;
     roundOver = DateTime.Now;
 }
示例#11
0
        private static void Player()
        {
            Console.Write("IP to use (empty to scan): ");
            var strIp = Console.ReadLine();
            IPAddress ip = null;
            if(!string.IsNullOrEmpty(strIp)) {
                if(!IPAddress.TryParse(strIp, out ip)) {
                    Console.WriteLine("Invalid IP specified!");
                    Player();
                    return;
                }

                if(!PirateScanner.CheckIp(ip, 4939, 5000)) {
                    Console.WriteLine("No game is hosted at the specified ip!");
                    Player();
                    return;
                }
            }else {
                Console.WriteLine("Scanning for IPs...");
                /*var d = DateTime.Now;
                ip = new PirateScanner().ScanForIp(4939);
                Console.WriteLine("Scan took " + (DateTime.Now - d).TotalMilliseconds + " milliseconds");
                if (ip == null) {
                    Console.WriteLine("No IP found... Make sure there's a host!");
                    return;
                }
                Console.WriteLine("IP Found: " + ip);*/

                var games = new PirateScanner().ScanForGames(4939, 10000);
                if(games.Count > 0) {
                    for(var i = 0; i < games.Count; i++) {
                        Console.WriteLine("\t[" + i + "] " + games[i].Ip + " \"" + games[i].GameName + "\" (" + games[i].Players + "/" + games[i].MaxPlayers + ")");
                    }
                    Console.Write("Select IP (index): ");
                    var ipIndex = Console.ReadLine();
                    if(ipIndex == null || !Regex.IsMatch(ipIndex, "^[0-9]+$")) {
                        Console.WriteLine("Invalid index specified...");
                        Player();
                        return;
                    } else {
                        int index = int.Parse(ipIndex);
                        if (index >= games.Count) {
                            Console.WriteLine("Invalid index specified...");
                            Player();
                            return;
                        }
                        ip = games[index].Ip;
                    }
                }else {
                    Console.WriteLine("No IP found... Make sure there's a host!");
                    Player();
                    return;
                }
            }
            Console.WriteLine();

            var game = new Game();
            var pc = new PirateClient("", ip, 4939);
            pc.SetGame(game);
            pc.NameRequested += OnNameRequest;
            pc.Disconnected += OnDisconnect;
            pc.BetRequested += OnBetRequest;
            pc.CardRequested += OnCardRequest;
            Console.WriteLine("Initiating...");
            pc.InitConnection();

            while(pc.Socket.Connected) {
                Thread.Sleep(10);
            }
            return;
        }