Exemplo n.º 1
0
        public virtual void Set(MinoType type)
        {
            var mino         = resolver.Get(type);
            var minoRenderer = mino.GetComponent <SpriteRenderer>();

            container.sprite = minoRenderer.sprite;
        }
Exemplo n.º 2
0
    public void BestMove(MinoType block)
    {
        double score = -1000;
        double scoreToCheck;
        int    height;
        int    completeLines;
        int    holes;
        int    bumpiness;

        for (int j = 0; j < 4; j++)
        {
            for (int i = GetRange(rotationList[j], block).x; i <= GetRange(rotationList[j], block).y; i++)
            {
                height        = GetAggregateHeight(i, rotationList[j]);
                completeLines = GetCompleteLines(i, rotationList[j]);
                holes         = GetHoles(i, rotationList[j]);
                bumpiness     = GetBumpiness(i, rotationList[j]);

                scoreToCheck = GetScore(height, completeLines, holes, bumpiness);

                if (scoreToCheck > score && scoreToCheck != 0)
                {
                    score    = scoreToCheck;
                    x_pos    = i;
                    rotation = rotationList[j];
                }
            }
        }
    }
Exemplo n.º 3
0
    public MinoType Change(MinoType newMinoType)
    {
        MinoType ret = minoType;

        minoType = newMinoType;
        spriteRenderer.sprite = PreliminalManager.Sprites[(int)newMinoType];
        return(ret);
    }
Exemplo n.º 4
0
 private void DrawMino()
 {
     //	if(row==-1 || col == -1) { throw new System.NotImplementedException();}
     GetComponent <SpriteRenderer>().sortingOrder = 1; // sets the order to the max
     minoType       = GetMinoType(row, col);
     minoSpriteName = "Minos_" + ((int)tetroMinoType * 15 + (int)minoType);
     //  Debug.Log("mino sprite" + minoSpriteName);
     GetComponent <SpriteRenderer>().sprite = GameResources.instance.GetSpriteByName(minoSpriteName); //changes the sprite combining the color and the type
 }
Exemplo n.º 5
0
    public MinoType Get()
    {
        MinoType ret = nextTypes[0];

        nextTypes[0]            = nextTypes[1];
        nextTypes[1]            = nextTypes[2];
        nextTypes[2]            = RandomMino();
        nextRenderers[0].sprite = nextRenderers[1].sprite;
        nextRenderers[1].sprite = nextRenderers[2].sprite;
        nextRenderers[2].sprite = PreliminalManager.GetSprite(nextTypes[2]);

        return(ret);
    }
Exemplo n.º 6
0
        private void setType(MinoType type)
        {
            currentType = type;
            controlable = true;

            var position = perspective.Field.Ceiling.transform.position;
            var obj      = spawner.Spawn(type, position);

            obj.AddComponent <Rigidbody2D>().CopyOf(minoRigidbody);
            var controller = obj.AddComponent <MinoController>().Initialize(sfxManager, controlSettings, fallSpeed);

            controller.Hit += onHitMino;

            minos.Add(obj);
        }
Exemplo n.º 7
0
 public Point GetRange(Rotation blockRotation, MinoType blockType)
 {
     if (blockRotation == Rotation.None)
     {
         return(blockRange[blockType]);
     }
     else if (blockRotation == Rotation.Left)
     {
         if (blockType == Tetromino.I)
         {
             return(new Point(0, 9));
         }
         else
         {
             return(new Point(1, 9));
         }
     }
     else if (blockRotation == Rotation.Right)
     {
         if (blockType == Tetromino.I)
         {
             return(new Point(0, 9));
         }
         else
         {
             return(new Point(0, 8));
         }
     }
     else
     {
         if (blockType == Tetromino.I)
         {
             return(new Point(2, 8));
         }
         else if (blockType == Tetromino.O)
         {
             return(new Point(1, 9));
         }
         else
         {
             return(blockRange[blockType]);
         }
     }
 }
Exemplo n.º 8
0
    private void SetWidth(MinoType t)
    {
        if (t == MinoType.Empty)
        {
            Vector3 scale = this.transform.localScale;
            scale.z = 0.01f;

            Vector3 pos = this.transform.localPosition;
            pos.z = 0.5f;
            this.transform.localScale    = scale;
            this.transform.localPosition = pos;
        }
        else
        {
            this.transform.localScale = Vector3.one;
            Vector3 pos = this.transform.localPosition;
            pos.z = 0.0f;
            this.transform.localPosition = pos;
        }
    }
Exemplo n.º 9
0
        public E this[MinoType type] {
            get {
                switch (type)
                {
                case MinoType.I: return(I);

                case MinoType.O: return(O);

                case MinoType.T: return(T);

                case MinoType.L: return(L);

                case MinoType.J: return(J);

                case MinoType.S: return(S);

                case MinoType.Z: return(Z);
                }
                throw new ArgumentOutOfRangeException("Invalid type was specified.");
            }
        }
Exemplo n.º 10
0
    /// <summary>
    /// Creates a new Occupied array based on if a mino is dropped
    /// All params are optional, if any aren't used then the current mino/occupied is used
    /// </summary>
    /// <param name="position">Position to drop from, if null use current mino position</param>
    /// <param name="rotation">Rotation to drop from, if null use current mino rotation</param>
    /// <param name="type">Block to drop, if null use current mino block</param>
    /// <param name="occupied">Result from previous call, if null use board array</param>
    /// <returns></returns>
    public bool[,] TestDrop(Point position = null, Tetris.Rotation? rotation = null, MinoType type = null, bool[,] occupied = null)
    {
        if (position == null)
        {
            position = game.CurrentBlock.Position;
        }
        if (rotation == null)
        {
            rotation = game.CurrentBlock.Rotation;
        }
        if (type == null)
        {
            type = game.CurrentBlock.BlockType;
        }
        if (occupied == null)
        {
            occupied = Board.Occupied;
        }

        occupied = (bool[, ])occupied.Clone();

        while (IsValidPlacement(occupied, Mino.GetBlockLocations(type, position, (int)rotation)))
        {
            position.y++;
        }
        position.y--;
        if (IsValidPlacement(occupied, Mino.GetBlockLocations(type, position, (int)rotation)))
        {
            foreach (Point p in Mino.GetBlockLocations(type, position, (int)rotation))
            {
                if (p.y >= 0)
                {
                    occupied[p.y, p.x] = true;
                }
            }
        }
        return(occupied);
    }
Exemplo n.º 11
0
    public MinoColor colourStringToMino(string s)
    {
        int r = int.Parse(s.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);
        int g = int.Parse(s.Substring(3, 2), System.Globalization.NumberStyles.HexNumber);
        int b = int.Parse(s.Substring(5, 2), System.Globalization.NumberStyles.HexNumber);

        Color32  c = new Color32((byte)r, (byte)g, (byte)b, 255);
        MinoType t = MinoType.Color;
        float    hue;
        float    sat;
        float    lum;

        HSLConverter.RGB2HSL(r, g, b, out hue, out sat, out lum);
        if (sat < satGrey)
        {
            if (lum < EmptyLum)
            {
                t = MinoType.Empty;
            }
            else if (lum < SolidLum)
            {
                t = MinoType.Solid;
            }
            else if (lum < GarbageLum)
            {
                t = MinoType.Garbage;
            }
        }

        if (t == MinoType.Color)
        {
            sat = Mathf.Clamp01(sat * satAdjust);
            lum = Mathf.Clamp01(lum * lumAdjust);
            c   = HSLConverter.ToRGB(hue, sat, lum);
        }

        return(new MinoColor(c, t));
    }
Exemplo n.º 12
0
        public GameObject Spawn(MinoType type, Vector3 position)
        {
            var mino = resolver.Get(type);

            return(instantiator.Instantiate(mino.gameObject, position, Quaternion.identity));
        }
Exemplo n.º 13
0
 public Mino(MinoType type)
 {
     Type     = type;
     Position = new Vector2Int(4, type == MinoType.O ? 21 : 20);
     Rotate   = 0;
 }
Exemplo n.º 14
0
 public Mino(Mino source)
 {
     Type     = source.Type;
     Position = source.Position;
     Rotate   = source.Rotate;
 }
Exemplo n.º 15
0
 public void Set(MinoType type)
 {
     view.Set(type);
 }
Exemplo n.º 16
0
 public Sprite GetSprite(MinoType minoType)
 {
     return(Sprites[(int)minoType]);
 }
Exemplo n.º 17
0
 public void Set(MinoType type)
 {
     frame.Set(type);
 }
Exemplo n.º 18
0
 public MinoColor(Color c, MinoType t)
 {
     this.c    = c;
     this.type = t;
 }
Exemplo n.º 19
0
 public void ReDrawMino()
 {
     minoType       = GetMinoType(row, col);
     minoSpriteName = "Minos_" + ((int)tetroMinoType * 15 + (int)minoType);
     GetComponent <SpriteRenderer>().sprite = GameResources.instance.GetSpriteByName(minoSpriteName); //changes the sprite combining the color and the type
 }
Exemplo n.º 20
0
 public Mino Get(MinoType type) => minos[type];
Exemplo n.º 21
0
    // Update is called once per frame
    void Update()
    {
        Operate?operate  = GetOperate();
        int     freeFall = 0;
        Mino    dest;

        if (operate == Operate.Hold)
        {
            MinoType minoType = HoldManager.Change(mino.Type);
            if (minoType == MinoType.None)
            {
                mino = new Mino(NextManager.Get());
            }
            else
            {
                mino = new Mino(minoType);
            }
        }
        else if (operate != null)
        {
            dest = FieldMinos.Move(mino, operate.Value);
            if (dest != null)
            {
                mino = dest;
                if (operate == Operate.SoftDrop)
                {
                    ScoreManager.Add(1);
                }
            }
            if (operate == Operate.SoftDrop && dest == null || operate == Operate.HardDrop)
            {
                FieldMinos.Add(mino);
                mino = new Mino(NextManager.Get());
            }
        }

        if (operate == null || operate == Operate.MoveLeft || operate == Operate.MoveRight)
        {
            fallTime += Time.deltaTime;
            freeFall  = FreeFall();
            for (int i = 0; i < freeFall; ++i)
            {
                dest = FieldMinos.Move(mino, Operate.SoftDrop);
                if (dest != null)
                {
                    mino = dest;
                }
                else
                {
                    FieldMinos.Add(mino);
                    mino = new Mino(NextManager.Get());
                }
            }
        }
        else
        {
            fallTime = 0F;
        }

        SetSprites();
    }
Exemplo n.º 22
0
 public virtual void Set(MinoType type)
 {
     Type = type;
     Lock();
     view.Set(type);
 }
Exemplo n.º 23
0
 public override void Set(MinoType type)
 {
     base.Set(type);
     photonView.RPC("Set", PhotonTargets.Others, type);
 }
Exemplo n.º 24
0
 public ColorPair(MinoType t, float h)
 {
     this.t = t;
     hue    = h;
 }
Exemplo n.º 25
0
 public void Set(MinoType type)
 {
     frame.Set(type);
     sfxManager.Play(TetoSfxType.Hold);
     animator.Play(@"HoldAnimation", 0, 0.0f);
 }