예제 #1
0
        public void UpdateSweep(Sweep sweep)
        {
            JsonObject obj = BuildGameMessageJson(GameMessageType.SweepUpdated, msg =>
            {
                var bounds = sweep.Bounds;
                msg.start = new JsonObject();
                msg.start.x = bounds.Item1.X;
                msg.start.y = bounds.Item1.Y;
                msg.end = new JsonObject();
                msg.end.x = bounds.Item2.X;
                msg.end.y = bounds.Item2.Y;
            });

            Messages.Add(obj);
        }
예제 #2
0
 public Game(int x, int y)
 {
     Players = new List <Player>();
     Board   = new Board(x, y);
     sweep   = new Sweep(Board, new PiecesInARowClearingRule(this, 4));
 }
예제 #3
0
 public Game(int x, int y)
 {
     Players = new List<Player>();
     Board = new Board(x, y);
     sweep = new Sweep(Board, new PiecesInARowClearingRule(this, 4));
 }
예제 #4
0
        public void Apply(Sweep sweep, IMessageLog log)
        {
            List <Slot> slotsToClear = new List <Slot>();

            Tuple <Slot, Slot> bounds = sweep.Bounds;

            IEnumerable <Slot> searchSet = null;

            if (bounds.Item1.X == bounds.Item2.X)
            {
                searchSet = game.Board.Column(bounds.Item1.X);
            }
            else
            {
                searchSet = game.Board.Row(bounds.Item1.Y);
            }

            List <Slot> currentRun = new List <Slot>();

            foreach (var slot in searchSet)
            {
                if (slot.Piece == null)
                {
                    if (currentRun.Count >= Target)
                    {
                        slotsToClear.AddRange(currentRun);
                    }

                    currentRun.Clear();
                }
                else
                {
                    if (currentRun.Count > 0 && currentRun.First().Piece.Owner != slot.Piece.Owner)
                    {
                        if (currentRun.Count >= Target)
                        {
                            slotsToClear.AddRange(currentRun);
                        }

                        currentRun.Clear();
                    }

                    currentRun.Add(slot);
                }
            }

            if (currentRun.Count >= Target)
            {
                slotsToClear.AddRange(currentRun);
            }

            foreach (var slot in slotsToClear)
            {
                log.RemovePiece(slot);
                slot.Piece.Owner.Score++;
                slot.Piece = null;
            }

            if (slotsToClear.Count > 0)
            {
                log.UpdateScores(game);
            }
        }
예제 #5
0
        public void Apply(Sweep sweep, IMessageLog log)
        {
            List<Slot> slotsToClear = new List<Slot>();

            Tuple<Slot, Slot> bounds = sweep.Bounds;

            IEnumerable<Slot> searchSet = null;
            if (bounds.Item1.X == bounds.Item2.X)
                searchSet = game.Board.Column(bounds.Item1.X);
            else
                searchSet = game.Board.Row(bounds.Item1.Y);

            List<Slot> currentRun = new List<Slot>();

            foreach (var slot in searchSet)
            {
                if (slot.Piece == null)
                {
                    if (currentRun.Count >= Target)
                        slotsToClear.AddRange(currentRun);

                    currentRun.Clear();
                }
                else
                {
                    if (currentRun.Count > 0 && currentRun.First().Piece.Owner != slot.Piece.Owner)
                    {
                        if (currentRun.Count >= Target)
                            slotsToClear.AddRange(currentRun);

                        currentRun.Clear();
                    }

                    currentRun.Add(slot);
                }
            }

            if (currentRun.Count >= Target)
                slotsToClear.AddRange(currentRun);

            foreach (var slot in slotsToClear)
            {
                log.RemovePiece(slot);
                slot.Piece.Owner.Score++;
                slot.Piece = null;
            }

            if(slotsToClear.Count > 0)
                log.UpdateScores(game);
        }