Example #1
0
        private GameLogic()
        {
            GameTable = new Cell[SIZE, SIZE];
            Score = 0;
            MovingDir = Direction.UP;

            CreateStartingState();
        }
Example #2
0
        private void LookAndMergeOrSlide(int x, int y)
        {
            int j = y - 1;

            if (j >= 0)
            {
                while (j >= 0)
                {

                    if (GameTable[GetRightCoordx(x, y), GetRightCoordy(x, y)].Value == GameTable[GetRightCoordx(x, j), GetRightCoordy(x, j)].Value
                            && !GameTable[GetRightCoordx(x, j), GetRightCoordy(x, j)].Merged)
                    {
                        break;
                    }
                    else
                    {
                        if (GameTable[GetRightCoordx(x, j), GetRightCoordy(x, j)].Value == 0)
                        {
                            if (j == 0)
                            {
                                break;
                            }
                            else
                            {
                                j--;
                            }
                        }
                        else
                        {
                            j++;
                            break;
                        }
                    }
                }
                if (j != y)
                {
                    int xjnew = GetRightCoordx(x, j);
                    int xynew = GetRightCoordx(x, y);
                    int jnew = GetRightCoordy(x, j);
                    int ynew = GetRightCoordy(x, y);

                    if (GameTable[xynew, ynew].Value == GameTable[xjnew, jnew].Value)
                    {
                        GameTable[xjnew, jnew].From.Add(new Coordinates(xynew, ynew));
                        GameTable[xjnew, jnew].Merged = true;
                        GameTable[xjnew, jnew].Value = 2 * GameTable[xynew, ynew].Value;
                        GameTable[xynew, ynew] = new Cell();
                    }
                    else
                    {
                        GameTable[xjnew, jnew].From.Add(new Coordinates(xynew, ynew));
                        GameTable[xjnew, jnew].Merged = false;
                        GameTable[xjnew, jnew].Value = GameTable[xynew, ynew].Value;
                        GameTable[xynew, ynew] = new Cell();
                    }
                }
                else
                {
                    int xynew = GetRightCoordx(x, y);
                    int ynew = GetRightCoordy(x, y);
                    GameTable[xynew, ynew].From.Add(new Coordinates(xynew, ynew));
                }
            }
        }
Example #3
0
        private void CreateStartingState()
        {
            for (int i = 0; i < SIZE; i++)
            {
                for (int j = 0; j < SIZE; j++)
                {
                    GameTable[i, j] = new Cell();
                    GameTable[i, j].Value = 0;
                }
            }
            int starter = GetRandomStarter();
            Coordinates coords = GetRandomCoordinates();
            GameTable[coords.X, coords.Y].Value = starter;

            int starter2 = GetRandomStarter();
            Coordinates coords2 = GetRandomCoordinates();
            while (coords2.Equals(coords))
            {
                coords2 = GetRandomCoordinates();
            }
            GameTable[coords2.X, coords2.Y].Value = starter2;
        }