Beispiel #1
0
    protected void EnsureTicketDisplayValid()
    {
        for (int i = 0; i < TicketDisplay.Length; i++)
        {
            if (TicketDisplay[i] == null && TicketDeck.CanDraw())
            {
                TicketDisplay[i] = TicketDeck.Draw();
            }
        }

        var isDeckBigEnough = TicketDeck.CanDraw(TicketDisplay.Length - RuleSet.TicketAnyShownMaximum,
                                                 c => c.Color != Color.Any);

        if (isDeckBigEnough)
        {
            while (TicketDisplay.Count(c => c.Color == Color.Any) >= RuleSet.TicketAnyShownMaximum)
            {
                TicketDeck.Discard.AddRange(TicketDisplay);
                var index = 0;
                foreach (var item in TicketDeck.Draw(TicketDisplay.Length))
                {
                    TicketDisplay[index++] = item;
                }
            }
        }
    }
Beispiel #2
0
    public MainHub(MainGame tempGame) : base("Sprites/MainHub.png", 32, 24, "Sprites/MainHub.png", 32, 24, "colors.png", 1, 1, tempGame)
    {
        FileName = @"Screens/MainHub/MainHub.tmx";

        Map _levelData = MapParser.ReadMap(FileName);

        SpawnCollisionTiles(_levelData);
        SpawnBackgroundTiles(_levelData, true);
        SpawnObjects(_levelData);
        SpawnOverlapTiles(_levelData);

        _game       = tempGame;
        _displayTut = _game.DisplayTutorial;

        _tickets = new TicketDisplay(_game);
        AddChild(_tickets);

        _clock = new Clock();
        AddChild(_clock);

        if (_displayTut)
        {
            _c = new ConversationBox("Text/Tutorial.txt", this);
            AddChild(_c);
        }

        FirstInstance = false;

        _shopKeeper = new ShopKeeper();
        AddChild(_shopKeeper);
    }
    public BarHub(MainGame tempGame) : base("Sprites/Bar.png", 32, 24, "Sprites/Bar.png", 32, 24, "colors.png", 1, 1, tempGame)
    {
        FileName = @"Screens/BarHub/BarHub.tmx";

        Map _levelData = MapParser.ReadMap(FileName);

        SpawnCollisionTiles(_levelData);
        SpawnBackgroundTiles(_levelData, false);
        SpawnObjects(_levelData);
        SpawnOverlapTiles(_levelData);

        FirstInstance = false;

        _game = tempGame;

        _tickets = new TicketDisplay(_game);
        AddChild(_tickets);

        _clock = new Clock();
        AddChild(_clock);

        _dj = new DJ();
        LateAddChild(_dj);

        _barMan = new BarMan();
        LateAddChild(_barMan);

        _devil = new DevilNPC();
        LateAddChild(_devil);

        _cat = new CatManNPC();
        LateAddChild(_cat);
    }
Beispiel #4
0
    public bool Claim(TrainCard pick, Player player, int claimsLeft)
    {
        if (pick == null)
        {
            if (!TicketDeck.CanDraw())
            {
                throw new ArgumentException("There is nothing left to draw");
            }

            player.Tickets.Add(TicketDeck.Draw());
            return(claimsLeft > 0);
        }

        player.Tickets.Add(pick);

        TicketDisplay[TicketDisplay.FindIndex(pick)] = null;

        EnsureTicketDisplayValid();

        return(pick.Color != Color.Any && TicketDisplay.Any(c => c?.Color != Color.Any) && claimsLeft > 0);
    }
Beispiel #5
0
    /// <summary>
    /// Really feel weird about this
    /// </summary>
    /// <returns></returns>
    public IOrderedEnumerable <Player> Play()
    {
        var gameActive = true;

        foreach (var player in Players.Cycle())
        {
            ScopeChoices(() =>
            {
                var move           = player.Destinations.Any() ? player.DecideAction(this) : PlayerAction.DrawDestination;
                var movePublicInfo = "";

                switch (move)
                {
                case PlayerAction.ClaimRoute:
                    var route = player.NextClaim(this);
                    Claim(route, player);
                    if (player.Trains < RuleSet.PlayerTrainMinimum)
                    {
                        gameActive = false;
                    }
                    break;

                case PlayerAction.DrawDestination:
                    var choices = DestinationDeck.DrawOptions();
                    ScopeChoices(() =>
                    {
                        var picks = player.DecideDestinations(choices, this);
                        Claim(picks, player);
                        DestinationDeck.ReturnOptions(choices.Except(picks));
                        movePublicInfo = "Picked " + picks.Count();
                    });

                    break;

                case PlayerAction.DrawTicket:
                    TrainCard pick;
                    if (TicketDisplay.All(c => c == null))
                    {
                        throw new ArgumentException("Nothing left to draw from");
                    }
                    ScopeChoices(() =>
                    {
                        var left = RuleSet.TicketDrawMaximum;
                        do
                        {
                            pick            = player.DecideTicket(TicketDisplay, this);
                            movePublicInfo += (movePublicInfo.Any() ? " " : "Picked ") + pick.Color;
                        } while (Claim(pick, player, --left));
                    });
                    break;
                }
                ;
                Log.Add(new Turn(player, move, movePublicInfo));
            });

            if (!gameActive)
            {
                break;
            }
        }

        return(ScoreDestinations());
    }