Пример #1
0
            public override bool CheckEye(int index, int count, ref IEnumerable <WinFlag> winFlags)
            {
                if (count == 2 && __isCheck)
                {
                    IEnumerator enumerator = __enumerator == null ? null : __enumerator.Clone();
                    if (enumerator != null)
                    {
                        for (int i = 0; i <= index; ++i)
                        {
                            if (!enumerator.MoveNext())
                            {
                                return(false);
                            }
                        }

                        Mahjong.Tile tile = Mahjong.Tile.Get(enumerator.Current);
                        if (tile.number != 1 && tile.number != 4 && tile.number != 7)
                        {
                            return(false);
                        }
                    }

                    __isCheck = false;
                }

                return(base.CheckEye(index, count, ref winFlags));
            }
Пример #2
0
 public bool CanMove(Tile tile)
 {
     bool up = CanMoveUp(tile);
     bool ul = up && CanMoveLeft(tile);
     bool ur = up && CanMoveRight(tile);
     return ul || ur;
 }
Пример #3
0
    private void RpcThrow(byte index, byte group, Mahjong.Tile instance)
    {
        NetworkWriter writer = RpcStart();

        writer.Write(index);
        writer.Write(group);
        writer.Write(instance);
        RpcEnd((short)MahjongNetworkRPCHandle.Throw);
    }
Пример #4
0
            public new bool Discard(int index)
            {
                Mahjong.Tile tile = Mahjong.Tile.Get(GetHandTileIndex(index));
                if (base.Discard(index))
                {
                    if (instance != null)
                    {
                        instance.Throw((byte)index, 255, tile);
                    }

                    return(true);
                }

                return(false);
            }
Пример #5
0
    public void As(MahjongAsset asset, Mahjong.Tile tile)
    {
        if (textures == null)
        {
            return;
        }

        byte code = tile;

        if (textures.Length <= code)
        {
            return;
        }

        Material material = asset == null || asset.renderer == null ? null : asset.renderer.material;

        if (material != null)
        {
            material.mainTexture = textures[code];
        }
    }
Пример #6
0
 private bool CanMoveRight(Tile tile)
 {
     return CanMove(tile, 1, 0, 0);
 }
Пример #7
0
 private bool CanMoveUp(Tile tile)
 {
     return CanMove(tile, 0, 0, 1);
 }
Пример #8
0
        private bool CanMove(Tile tile, int xd, int yd, int zd)
        {
            Point[] points = GetTestPoints(tile.X, tile.Y);

            int z = tile.Z + zd;
            for (int i = 0; i < points.Length; i++)
            {
                int x = points[i].X + xd;
                int y = points[i].Y + yd;

                Tile found = FindTile(x, y, z);
                if (found != null && tile != found)
                    return false;
            }

            return true;
        }
Пример #9
0
 private bool CanMoveLeft(Tile tile)
 {
     return CanMove(tile, -1, 0, 0);
 }
Пример #10
0
 public void Remove(Tile tile)
 {
     int index = CalcTileIndex(tile.X, tile.Y, tile.Z);
     if (tile != _tiles[index])
         throw new Exception("Uh-oh, tile reference mismatch!");
     _tiles.Remove(index);
 }
Пример #11
0
 private static int TileDrawingOrder(Tile tile1, Tile tile2)
 {
     if (tile1.Z == tile2.Z)
     {
         if (tile1.Y == tile2.Y)
         {
             return tile1.X - tile2.X;
         }
         else return tile1.Y - tile2.Y;
     }
     else return tile1.Z - tile2.Z;
 }
Пример #12
0
        private void LoadStructure(Field field, TileType type, string path)
        {
            string[] lines = File.ReadAllLines(path);

            if (lines.Length % 2 != 0)
                throw new Exception("Invalid odd tile count!");

            foreach (string line in lines)
            {
                string[] splitted = line.Split(' ');
                if (splitted.Length != 3) continue;
                Tile tile = new Tile(int.Parse(splitted[0]), int.Parse(splitted[1]), int.Parse(splitted[2]), type);
                field.Add(tile);
            }
        }
Пример #13
0
 private RectangleF TileRectangle(Tile t)
 {
     return new RectangleF(t.X * CELLWIDTH, t.Y * CELLHEIGHT,
         Tile.WIDTH * CELLWIDTH, Tile.HEIGHT * CELLHEIGHT);
 }
Пример #14
0
 public void Throw(byte index, byte group, Mahjong.Tile instance)
 {
     RpcThrow(index, group, instance);
 }
Пример #15
0
        private void DoAction(string action)
        {
            if (action.StartsWith("moveable"))
                _showMoveable = !_showMoveable;
            else if (action.StartsWith("hint"))
                _showHint = !_showHint;
            else if (action.StartsWith("select"))
            {
                string[] splitted = action.Split(new char[]{'|'},
                    StringSplitOptions.RemoveEmptyEntries);
                if (splitted.Length != 3)
                    return;

                int x, y;
                if (int.TryParse(splitted[1], out x) && int.TryParse(splitted[2], out y))
                {
                    Tile tile = _field.GetTileFromCoord(x, y);
                    if (tile == null)
                        return;
                    else if (_selected == null || _selected == tile)
                        _selected = tile;
                    else
                    {
                        if (_field.Play(_selected, tile) == PlayResult.NoFurtherMoves)
                            _field.Scramble();
                        _selected = null;
                    }
                }
            }
        }
Пример #16
0
        private void ClickEdit(MouseEventArgs e)
        {
            int xp = (int)(e.X / CELLWIDTH);
            int yp = (int)(e.Y / CELLHEIGHT);

            if (e.Button == MouseButtons.Right)
            {
                Tile tile = _field.GetTileFromCoord(xp, yp);
                if (tile != null)
                    _field.Remove(tile);
            }
            else
            {
                int zp = _field.FindNewTileZ(xp, yp);
                Tile tile = new Tile(xp, yp, zp, null);
                _field.Add(tile);
            }
        }
Пример #17
0
        private void ClickPlay(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Middle)
            {
                _showMoveable = !_showMoveable;
                return;
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                _showHint = !_showHint;
                return;
            }

            int xp = (int)(e.X / CELLWIDTH);
            int yp = (int)(e.Y / CELLHEIGHT);

            Tile clicked = _field.GetTileFromCoord(xp, yp);
            if (clicked == null)
                return;

            if (!_field.CanMove(clicked))
                return;

            if (_selected == null || clicked == _selected)
                _selected = clicked;
            else
            {
                PlayResult result = _field.Play(_selected, clicked);
                if (result == PlayResult.Won)
                {
                    MessageBox.Show("You won the game in " + Math.Ceiling(_field.GameTime.TotalSeconds) + " seconds !", "You won!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if ((result & PlayResult.NoFurtherMoves) != 0)
                {
                    DialogResult boxResult = MessageBox.Show("No further moves possible :( Scramble?", "Dead end",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (boxResult == DialogResult.Yes)
                        _field.Scramble();
                }
                _selected = null;
            }
        }
Пример #18
0
        private void DrawTile(Graphics g, Tile tile)
        {
            int id = tile.Type != null ? tile.Type.Id : -1;
            if (!_images.ContainsKey(id))
            {
                Bitmap copy;
                using (Image img = Image.FromFile("tiles/" + tile.Type.Name + ".png"))
                {
                    copy = new Bitmap(_tileImage);
                    Graphics.FromImage(copy).DrawImage(img, new Rectangle(0, 0, DRAWWIDTH, DRAWHEIGHT));
                    _images.Add(id, copy);
                }
            }

            Image texture = _images[id];
            RectangleF rect = TileRectangle(tile);
            rect.X -= 5;
            rect.Y -= 5 + 5 * tile.Z;
            rect.Width = DRAWWIDTH;
            rect.Height = DRAWHEIGHT;
            g.DrawImage(texture, rect);

            if (_showMoveable && !_field.CanMove(tile))
                g.DrawImage(_disImage, rect);

            if (_showHint && (tile == _hint1 || tile == _hint2))
                g.DrawImage(_hintImage, rect);

            if (tile == _selected)
                g.DrawImage(_selImage, rect);
        }
Пример #19
0
 public void Add(Tile tile)
 {
     int index = CalcTileIndex(tile.X, tile.Y, tile.Z);
     _tiles.Add(index, tile);
 }
Пример #20
0
        public PlayResult Play(Tile tile1, Tile tile2)
        {
            if (!_started)
            {
                _startTime = DateTime.Now;
                _started = true;
            }

            if (tile1 == tile2)
                return PlayResult.InvalidMove;

            if (tile1.Type != tile2.Type)
                return PlayResult.DifferentTypes;

            if (!CanMove(tile1) || !CanMove(tile2))
                return PlayResult.CanNotMoveTile;

            Remove(tile1);
            Remove(tile2);

            if (_tiles.Count == 0)
            {
                _gameTime = DateTime.Now - _startTime;
                return PlayResult.Won;
            }

            PlayResult result = PlayResult.ValidMove;
            if (!NextMovePossible())
                result |= PlayResult.NoFurtherMoves;
            return result;
        }
Пример #21
0
 public TilePair(Tile tile1, Tile tile2)
 {
     Tile1 = tile1;
     Tile2 = tile2;
 }
Пример #22
0
 private void FindHints()
 {
     TilePair hint = _field.GetHint();
     if (hint != null)
     {
         _hint1 = hint.Tile1;
         _hint2 = hint.Tile2;
     }
 }