Beispiel #1
0
        /// /////////////////////////////////////////////////////////////////////////////////////////

        public piece placeapiece(int x, int y, piecetype type)
        {
            //find cloest 2 points
            Point nodeid = Findnode(x, y);

            //if not return false
            if (nodeid == no_match)
            {
                return(null);
            }
            //if have check piece placed
            if (pieces[nodeid.X, nodeid.Y] != null)
            {
                return(null);
            }
            //make a piece by type
            Point formpos = convert(nodeid);

            if (type == piecetype.BLACK)
            {
                pieces[nodeid.X, nodeid.Y] = new black(formpos.X, formpos.Y);
            }
            else if (type == piecetype.WHITE)
            {
                pieces[nodeid.X, nodeid.Y] = new white(formpos.X, formpos.Y);
            }

            //final postion placed peice
            lastone = nodeid;
            return(pieces[nodeid.X, nodeid.Y]);
        }
Beispiel #2
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        private void checkwin()
        {
            int centerX = board.lastplace.X;
            int centerY = board.lastplace.Y;

            for (int xdir = -1; xdir <= 1; xdir++)
            {
                for (int ydir = -1; ydir <= 1; ydir++)
                {
                    int count2 = 1;
                    while (count2 < 5)
                    {
                        int targetx = centerX - count2 * xdir;
                        int targety = centerY - count2 * ydir;

                        if (targetx < 0 || targetx >= board.count ||
                            targety < 0 || targety >= board.count ||
                            board.gettype(targetx, targety) != current)
                        {
                            break;
                        }
                        count2++;
                        // without center x+0,y+0 if x+0 and y+0 skip
                        if (xdir == 0 && ydir == 0)
                        {
                            continue;
                        }
                        int count = 1;
                        ///////////store how many pieces right now
                        while (count < 5)
                        {
                            int x = count * xdir;
                            int y = count * ydir;
                            targetx = centerX + x;
                            targety = centerY + y;
                            // check is color the same
                            if (targetx < 0 || targetx >= board.count ||
                                targety < 0 || targety >= board.count ||
                                board.gettype(targetx, targety) != current)
                            {
                                break;
                            }
                            count++;
                        }
                        //check
                        if (count == 5)
                        {
                            winner = current;
                        }
                        if (count + count2 > 5)
                        {
                            winner = current;
                            reset  = current;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /////////////////////////////////////////////////////////////////////////////////

        public piece placeapiece(int x, int y)
        {
            piece piece = board.placeapiece(x, y, current);

            if (piece != null)
            {
                //check have winner rightnow?
                checkwin();
                //switch player
                if (current == piecetype.BLACK)
                {
                    current = piecetype.WHITE;
                }
                else if (current == piecetype.WHITE)
                {
                    current = piecetype.BLACK;
                }
                return(piece);
            }
            return(null);
        }