コード例 #1
0
        public void GiveUp()
        {
            // add all cards on the game player's hand to the stitch of one opponent player
            Player opponentPlayer = null;

            foreach (var p in Players)
            {
                if (p != GamePlayer && opponentPlayer == null)
                {
                    opponentPlayer = p;
                    p.Stitches.AddRange(GamePlayer.Cards);
                    p.Stitches.AddRange(GamePlayer.Stitches);
                    p.Stitches.AddRange(p.Cards);
                    p.Stitches.AddRange(Skat);
                    p.Stitches.AddRange(Stitch);
                    p.Cards.Clear();
                    GamePlayer.Cards.Clear();
                    GamePlayer.Stitches.Clear();
                    Skat.Clear();
                    Stitch.Clear();
                }
                else if (p != GamePlayer && opponentPlayer != null)
                {
                    opponentPlayer.Stitches.AddRange(p.Cards);
                    p.Cards.Clear();
                }
            }
            var game = GamePlayer.Game;

            GameValue         = game.GetGameValue(MatadorsJackStraight, GamePlayer.Stitches, Skat, CurrentBidValue, true);
            GamePlayer.Score += GameValue.Score;
        }
コード例 #2
0
        public void StartNewRound()
        {
            GameCounter += 1;
            foreach (var p in Players)
            {
                p.Stitches.Clear();
                p.Cards.Clear();
                p.Game = new Game(GameType.Grand);
                switch (p.Position)
                {
                case PlayerPosition.Middlehand:
                    p.Position  = PlayerPosition.Forehand;
                    p.BidStatus = BidStatus.Accept;
                    break;

                case PlayerPosition.Rearhand:
                    p.Position  = PlayerPosition.Middlehand;
                    p.BidStatus = BidStatus.Bid;
                    break;

                case PlayerPosition.Forehand:
                    p.Position  = PlayerPosition.Rearhand;
                    p.BidStatus = BidStatus.Wait;
                    break;

                default:
                    break;
                }
            }
            MatadorsJackStraight = null;
            GameStarted          = false;
            GamePlayer           = null;
            GameValue            = null;
            SkatTaken            = false;
            CurrentPlayer        = null;
            Stitch.Clear();
            Skat.Clear();
            LastStitch.Clear();
            using (var rng = new RNGCryptoServiceProvider())
            {
                var deck = Card.GenerateDeck();
                foreach (var player in Players)
                {
                    player.Cards.AddRange(Card.Draw(rng, deck, 10));
                }
                Skat.AddRange(Card.Draw(rng, deck, 2));
            }
            BidSaid       = false;
            BidValueIndex = -1;
            BidExceeded   = false;
        }
コード例 #3
0
        public void PerformPlayerAction(Player player, ActionType actionType)
        {
            switch (actionType)
            {
            case ActionType.TakeSkat:
                SkatTaken = true;
                break;

            case ActionType.PlayHand:
                SetGameOption(player, player.Game.Option | GameOption.Hand);
                break;

            case ActionType.StartGame:
                StartGame(player);
                break;

            case ActionType.DoNotPlayHand:
                var gameOption = player.Game.Option & ~GameOption.Hand;
                if (player.Game.Type != GameType.Null)
                {
                    gameOption &= ~GameOption.Ouvert;
                }
                SetGameOption(player, gameOption);
                break;

            case ActionType.Bid:
                BidSaid = true;
                MoveNextBidValue();
                break;

            case ActionType.PassBid:
                player.BidStatus = BidStatus.Pass;
                foreach (var p in Players)
                {
                    if (p.Position == PlayerPosition.Rearhand && p.BidStatus != BidStatus.Pass)
                    {
                        p.BidStatus = BidStatus.Bid;
                        break;
                    }
                }
                BidSaid = false;
                break;

            case ActionType.HoldBid:
                BidSaid = false;
                break;

            case ActionType.PassHold:
                BidSaid          = false;
                player.BidStatus = BidStatus.Pass;
                foreach (var p in Players)
                {
                    if (p.Position == PlayerPosition.Rearhand && p.BidStatus != BidStatus.Pass)     // weitersagen
                    {
                        p.BidStatus = BidStatus.Bid;
                    }
                    else if (p.Position == PlayerPosition.Middlehand && p.BidStatus != BidStatus.Pass)     // hoeren
                    {
                        p.BidStatus = BidStatus.Accept;
                    }
                }
                break;

            default:
                break;
            }
            if (actionType == ActionType.PassBid ||
                actionType == ActionType.PassHold ||
                actionType == ActionType.Bid)
            {
                // find if all player have given up
                Player gamePlayer = null;
                var    cntPassen  = 0;
                foreach (var p in Players)
                {
                    if (p.BidStatus != BidStatus.Pass)
                    {
                        gamePlayer = p;
                        continue;
                    }
                    cntPassen++;
                }
                // all gave up
                if (cntPassen == 3)
                {
                    GamePlayer = Players[0];
                    GameValue  = new GameValue {
                        Score = 0
                    };
                    GameStarted = true;
                    foreach (var p in Players)
                    {
                        p.Cards.Clear();
                        p.Stitches.Clear();
                    }
                    Skat.Clear();
                    Stitch.Clear();
                    CurrentHistory.GamePlayerScore = 0;
                    CurrentHistory.GameValue       = 0;
                    SkatResult.History.Add(CurrentHistory);
                    SkatResult.EndedUtc = DateTime.UtcNow;
                }
                // two player gave up, remaing playing is the game player
                else if (gamePlayer != null && cntPassen == 2)
                {
                    if (gamePlayer.Position == PlayerPosition.Forehand && CurrentBidValue == 0)
                    {
                        gamePlayer.BidStatus = BidStatus.Bid;
                    }
                    else
                    {
                        GamePlayer  = gamePlayer;
                        GameStarted = false;
                        SkatTaken   = false;
                    }
                }
            }
        }
コード例 #4
0
        public void StartNewRound()
        {
            GameCounter += 1;
            if (InactivePlayer == null)
            {
                foreach (var p in Players)
                {
                    p.Stitches.Clear();
                    p.Cards.Clear();
                    p.Game = new Game(GameType.Grand);
                    switch (p.Position)
                    {
                    case PlayerPosition.Middlehand:
                        p.Position  = PlayerPosition.Forehand;
                        p.BidStatus = BidStatus.Accept;
                        break;

                    case PlayerPosition.Rearhand:
                        p.Position  = PlayerPosition.Middlehand;
                        p.BidStatus = BidStatus.Bid;
                        break;

                    case PlayerPosition.Forehand:
                        p.Position  = PlayerPosition.Rearhand;
                        p.BidStatus = BidStatus.Wait;
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            {
                var nextPlayers = new Player[3];
                var newPlayer   = InactivePlayer;
                newPlayer.Position  = PlayerPosition.Rearhand;
                newPlayer.BidStatus = BidStatus.Wait;
                newPlayer.Stitches.Clear();
                newPlayer.Cards.Clear();
                newPlayer.Game = new Game(GameType.Grand);
                nextPlayers[2] = newPlayer;
                foreach (var p in Players)
                {
                    p.Stitches.Clear();
                    p.Cards.Clear();
                    p.Game = new Game(GameType.Grand);
                    if (p.Position == PlayerPosition.Forehand)
                    {
                        InactivePlayer = p;
                        p.Position     = PlayerPosition.Inactive;
                        p.BidStatus    = BidStatus.Wait;
                    }
                    else if (p.Position == PlayerPosition.Middlehand)
                    {
                        p.Position     = PlayerPosition.Forehand;
                        p.BidStatus    = BidStatus.Accept;
                        nextPlayers[0] = p;
                    }
                    else if (p.Position == PlayerPosition.Rearhand)
                    {
                        p.Position     = PlayerPosition.Middlehand;
                        p.BidStatus    = BidStatus.Bid;
                        nextPlayers[1] = p;
                    }
                }
                Players.Clear();
                Players.AddRange(nextPlayers);
            }
            MatadorsJackStraight = null;
            GameStarted          = false;
            GamePlayer           = null;
            GameValue            = null;
            IsSpeedUp            = false;
            SkatTaken            = false;
            CurrentPlayer        = null;
            Stitch.Clear();
            Skat.Clear();
            LastStitch.Clear();
            CurrentHistory = new GameHistory();
            var deck = Card.GenerateDeck();

            foreach (var player in Players)
            {
                player.Cards.AddRange(Card.Draw(deck, 10));
                player.SortCards();
                CurrentHistory.PlayerCards.Add((player.Name, new List <Card>(player.Cards)));
            }
            Skat.AddRange(Card.Draw(deck, 2));
            CurrentHistory.Skat.AddRange(Skat);
            BidSaid       = false;
            BidValueIndex = -1;
        }