예제 #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
파일: Field.cs 프로젝트: cry-inc/mahjong
 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
파일: Field.cs 프로젝트: cry-inc/mahjong
 private bool CanMoveRight(Tile tile)
 {
     return CanMove(tile, 1, 0, 0);
 }
예제 #7
0
파일: Field.cs 프로젝트: cry-inc/mahjong
 private bool CanMoveUp(Tile tile)
 {
     return CanMove(tile, 0, 0, 1);
 }
예제 #8
0
파일: Field.cs 프로젝트: cry-inc/mahjong
        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
파일: Field.cs 프로젝트: cry-inc/mahjong
 private bool CanMoveLeft(Tile tile)
 {
     return CanMove(tile, -1, 0, 0);
 }
예제 #10
0
파일: Field.cs 프로젝트: cry-inc/mahjong
 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
파일: Field.cs 프로젝트: cry-inc/mahjong
 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
파일: HttpView.cs 프로젝트: cry-inc/mahjong
        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
파일: Field.cs 프로젝트: cry-inc/mahjong
 public void Add(Tile tile)
 {
     int index = CalcTileIndex(tile.X, tile.Y, tile.Z);
     _tiles.Add(index, tile);
 }
예제 #20
0
파일: Field.cs 프로젝트: cry-inc/mahjong
        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
파일: TilePair.cs 프로젝트: cry-inc/mahjong
 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;
     }
 }