예제 #1
0
        public void GameEndVerify_GameEndScoring_ShouldFail()
        {
            GameState gs   = new GameState();
            Player    p1   = new Player();
            Tile      tile = new Tile('A', 12);

            p1.PlayingTiles.Add(tile);

            Player p2 = new Player();

            tile = new Tile('B', 10);
            p2.PlayingTiles.Add(tile);

            Player p3 = new Player();


            gs.ListOfPlayers.Add(p1);
            gs.ListOfPlayers.Add(p2);
            gs.ListOfPlayers.Add(p3);

            foreach (Player p in gs.ListOfPlayers)
            {
                foreach (Tile t in p.PlayingTiles)
                {
                    p1.Score += AllTiles.ScoreOfLetter(t.TileChar);
                    p2.Score -= AllTiles.ScoreOfLetter(t.TileChar);
                }
            }

            bool result = GameEndVerify.GameEndScoring(gs);

            Assert.IsFalse(result);
        }
예제 #2
0
        /// <summary>
        /// Places the miens randomly on the board
        /// </summary>
        /// <param name="tile">the tile to not put bomb in because it is the first tile clicked</param>
        private void PlaceMines(Tile tile)
        {
            Progress = GameProgress.InProgress;

            //Place mines after the first mine has been uncovered
            var    placedMines = 0;
            Random rand        = new Random();

            while (placedMines != TotalMines)
            {
                int xRow = rand.Next(0, Rows - 1);
                int xCol = rand.Next(0, Columns - 1);
                foreach (var t in AllTiles.Where(singleTile => singleTile.Row == xRow && singleTile.Column == xCol))
                {
                    if (t != tile && t.Type != TileType.Bomb)
                    {
                        AllTiles[AllTiles.IndexOf(t)].Type = TileType.Bomb;
                        placedMines++;
                    }
                }
            }

            //Storing instances of adjacentTiles in every tile and changing
            foreach (var singleTile in AllTiles)
            {
                singleTile.InitializeAdjacentTile(this);
                singleTile.ChangeContent();
            }

            stopwatch.Start();
            dispatcherTimer.Start();
        }
예제 #3
0
        public void GameEndVerify_GameEndScoring_TilebagLessThanSeven_And_ExistsPlayerNoTiles_ShouldPass()
        {
            GameState gs   = new GameState();
            Player    p1   = new Player();
            Tile      tile = new Tile('A', 12);

            p1.PlayingTiles.Add(tile);

            Player p2 = new Player();

            tile = new Tile('B', 10);
            p2.PlayingTiles.Add(tile);

            Player p3 = new Player();


            gs.ListOfPlayers.Add(p1);
            gs.ListOfPlayers.Add(p2);
            gs.ListOfPlayers.Add(p3);

            foreach (Player p in gs.ListOfPlayers)
            {
                foreach (Tile t in p.PlayingTiles)
                {
                    p1.Score += AllTiles.ScoreOfLetter(t.TileChar);
                    p2.Score -= AllTiles.ScoreOfLetter(t.TileChar);
                }
            }

            gs.TilesBag.ListTiles.RemoveRange(5, 94);

            bool result = GameEndVerify.GameEndScoring(gs);

            Assert.IsTrue(result);
        }
예제 #4
0
        /// <summary>
        /// Toggles the <see cref="TileState"/> of the passed in tile
        /// </summary>
        /// <param name="tile">the tile to toggle the state of</param>
        private void ToggleTileState(Tile tile)
        {
            var index = AllTiles.IndexOf(tile);

            if (tile.State == TileState.Covered)
            {
                AllTiles[index].State = TileState.Flagged;
                --RemainingMines;
            }
            else if (tile.State == TileState.Flagged)
            {
                if (Settings.AllowQuestionMark)
                {
                    AllTiles[index].State = TileState.QuestionMarked;
                }
                else
                {
                    AllTiles[index].State = TileState.Covered;
                }
                ++RemainingMines;
            }
            else if (tile.State == TileState.QuestionMarked)
            {
                AllTiles[index].State = TileState.Covered;
            }
        }
예제 #5
0
 public void UnblockAllTemporarilyBlockedTiles()
 {
     foreach (var tile in AllTiles.Where(a => a.IsTemporarilyBlocked))
     {
         tile.IsTemporarilyBlocked = false;
     }
 }
예제 #6
0
    void Start()
    {
        allTiles         = GetComponent <AllTiles>();
        _placeController = GetComponent <PlaceController>();

        for (int i = 0; i < buttons.Length; i++)
        {
            buttons[i].GetComponent <Image>().sprite = allTiles.tiles[i].sprite;
        }
    }
예제 #7
0
        private void ReLayout(bool tiles, bool chits)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            if (tiles)
            {
                if (TilePlacementComboBox.SelectedIndex == 0)
                {
                    switch (LayoutComboBox.SelectedIndex)
                    {
                    case 1:
                        ExtendedRandomLayout();
                        break;

                    case 2:
                        TwoPlayerRandomLayout();
                        break;

                    default:
                        DefaultRandomLayout();
                        break;
                    }
                    if (!chits)
                    {
                        if (EnsureDesertHasNoChits() && EnforceChitRule == true)
                        {
                            EnforceCommonChitRule();
                        }
                    }
                }
            }
            if (chits)
            {
                switch (ChitPlacementComboBox.SelectedIndex)
                {
                case 1:
                    return;

                default:
                    RandomChitLayout(AllTiles, GetChitGroup());
                    break;
                }
                if (LayoutComboBox.SelectedIndex == 2)
                {
                    AllTiles.First(t => t.Chits.Any(c => c.AlphaOrder == "B")).Chits.Add(ProductionChit.DefaultChits.First(c => c.AlphaOrder == "H"));
                }
                if (EnforceChitRule == true)
                {
                    EnforceCommonChitRule();
                }
            }
        }
예제 #8
0
        public void GameEndVerify_TilebagLessThanSeven_Lessthan7Tilebags_ShouldPass()
        {
            GameState gs = new GameState();
            AllTiles  at = new AllTiles();

            gs.TilesBag.ListTiles.Clear(); //?

            bool result = GameEndVerify.TilebagLessThanSeven(gs);

            Assert.IsTrue(result);
        }
예제 #9
0
        public void GameEndVerify_TilebagLessThanSeven_Morethan7Tilebags_ShouldPass()
        {
            GameState gs    = new GameState();
            AllTiles  tiles = new AllTiles();

            gs.TilesBag.MakeTiles();

            bool result = GameEndVerify.TilebagLessThanSeven(gs);

            Assert.IsFalse(result);
        }
예제 #10
0
        public void AllTiles_ScoreOfLetter_IllegalCharacter_Should_Return_0()
        {
            // Arrange

            // Act
            var result = AllTiles.ScoreOfLetter('*');

            // Reset

            // Assert
            Assert.AreEqual(0, result);
        }
예제 #11
0
 public static void Draw()
 {
     Drawn    = new Dictionary <int, Tile>();
     TilesBag = new AllTiles();
     for (int i = 0; i < GameState.GSInstance.NumOfPlayers; i++)
     {
         Drawn.Add(i, TilesBag.ListTiles[rnd.Next(0, TilesBag.ListTiles.Count)]);
     }
     ListGot = Drawn.Values.ToList();
     ListGot.Sort();
     GameState.GSInstance.PlayerNow = Drawn.FirstOrDefault(x => x.Value == ListGot[0]).Key;
 }
예제 #12
0
        public void AllTiles_ScoreOfLetter_O_Should_Return_1()
        {
            // Arrange

            // Act
            var result = AllTiles.ScoreOfLetter('O');

            // Reset

            // Assert
            Assert.AreEqual(1, result);
        }
예제 #13
0
        /// <summary>
        /// Opens the tile that is passed in
        /// </summary>
        /// <param name="tile">the tile to open</param>
        private void OpenTile(Tile tile)
        {
            //Since we cannot open any tile which is flagged or question marked or uncovered, we just don't do anything and return
            if (tile.State != TileState.Covered)
            {
                return;
            }

            tile.State = TileState.Uncovered;

            //If it is a new game, set up the board and all it's tiles
            if (Progress == GameProgress.NewGame)
            {
                PlaceMines(tile);
            }

            //Show the dialog that the player lost since s/he clicked on a mine
            if (tile.Type == TileType.Bomb)
            {
                Progress = GameProgress.GameEnd;
                bool isWin = false;
                dispatcherTimer.Stop();
                stopwatch.Stop();
                new SoundPlayer(Properties.Resources.Lose).Play();
                Service.ShowDialog("GameEnd", new DialogParameters($"isWin={isWin}"), result => GameEndCallback(result));
                return;
            }

            //If the tile has a number in it, do not open any adjacent tiles
            if (tile.Type == TileType.Number)
            {
                return;
            }

            //Here is the logic of opening all the relevant tiles.
            //First when the tiles are initialized, all the tile's IsItAdjacentTile property will be false
            //So when the user clicks on the tile, it checks if it is false and then turns the property to true for all of it's adjacent tiles
            //If the adjacent tile is empty tile, it will do the same loop for them too until all of the empty tiles are opened and the tiles with numbers are left
            if (!tile.IsItAdjacentTile || (tile.IsItAdjacentTile && tile.Type == TileType.None))
            {
                for (int index = 0; index < AllTiles[AllTiles.IndexOf(tile)].AdjacentTiles.Count; index++)
                {
                    //Since AllTiles and the AdjacentTiles(of the Tile instance that is passed in) have the same instances of objects
                    //We are making changes only to the instances in AllTiles to keep track of all of them
                    AllTiles[AllTiles.IndexOf(tile)].AdjacentTiles[index].IsItAdjacentTile = true;
                }
                foreach (var adjacentTile in tile.AdjacentTiles)
                {
                    OpenTile(adjacentTile);
                }
            }
        }
예제 #14
0
        public void AllTiles_Empty_Should_Return_False()
        {
            // Arrange
            AllTiles tiles = new AllTiles();

            // Act
            var result = tiles.Empty();

            // Reset

            // Assert
            Assert.AreEqual(false, result);
        }
예제 #15
0
        public void AllTiles_Empty_Should_Return_True()
        {
            // Arrange
            AllTiles tiles = new AllTiles();

            // Act
            tiles.ListTiles.Clear();
            var result = tiles.Empty();

            // Reset

            // Assert
            Assert.AreEqual(true, result);
        }
예제 #16
0
        private void InitialiseGameBoard()
        {
            GameBoard = new Tile[Width, Height];

            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    GameBoard[x, y] = new Tile(x, y);
                }
            }

            AllTiles.ToList().ForEach(o => o.FindNeighbours(GameBoard));
        }
예제 #17
0
 /// <summary>
 /// Populates the <see cref="AllTiles"/>
 /// </summary>
 private void InitlializeTiles()
 {
     AllTiles.Clear();
     for (int i = 0; i < Rows; i++)
     {
         for (int j = 0; j < Columns; j++)
         {
             AllTiles.Add(new Tile()
             {
                 Row    = i,
                 Column = j,
                 State  = TileState.Covered
             });
         }
     }
 }
예제 #18
0
    private void Start()
    {
        statsController = GetComponent <StatsController>();
        placeController = GetComponent <PlaceController>();
        allTiles        = GetComponent <AllTiles>();

        tilemap          = GameObject.FindGameObjectWithTag("Tilemap").GetComponent <Tilemap>();
        cameraFollow     = GameObject.FindGameObjectWithTag("MCamera").GetComponent <CameraController>();
        healthController = GameObject.FindGameObjectWithTag("Health Controller").GetComponent <HealthController>();
        gameController   = GameObject.FindGameObjectWithTag("Game Controller").GetComponent <GameController>();

        if (gameController.actualMode == GameController.SceneMode.Editor)
        {
            isEditor = true;
        }
        StartCoroutine(ShowMessage("Click ESC to quit.", 4f));
    }
예제 #19
0
        // Utility class for scoring
        public static int ScoreCalc(int fix, int j, int jM, string direction, char[,] b, BoardTiles bt)
        {
            int        sum          = 0;
            List <int> WordMultiply = new List <int>();

            if (direction == "h")
            {
                for (int q = j; q <= jM; ++q)
                {
                    if (b[fix, q] != '\0')
                    {
                        sum += AllTiles.ScoreOfLetter(b[fix, q]) * bt.LetterMultiplier(fix, q);
                        if (bt.WordMultiplier(fix, q) != 1)
                        {
                            WordMultiply.Add(bt.WordMultiplier(fix, q));
                        }
                    }
                }
                foreach (int n in WordMultiply)
                {
                    sum *= n;
                }
            }
            else if (direction == "v")
            {
                for (int q = j; q <= jM; ++q)
                {
                    if (b[q, fix] != '\0')
                    {
                        sum += AllTiles.ScoreOfLetter(b[q, fix]) * bt.LetterMultiplier(q, fix);
                        if (bt.WordMultiplier(q, fix) != 1)
                        {
                            WordMultiply.Add(bt.WordMultiplier(q, fix));
                        }
                    }
                }
                foreach (int n in WordMultiply)
                {
                    sum *= n;
                }
            }
            return(sum);
        }
예제 #20
0
파일: Data.cs 프로젝트: Stydla/AOC2020
        public void CreateGrid()
        {
            var tiles = AllTiles.Where(x => x.Point != null);
            int xMin  = tiles.Min(x => x.Point.X);
            int xMax  = tiles.Max(x => x.Point.X);
            int yMin  = tiles.Min(x => x.Point.Y);
            int yMax  = tiles.Max(x => x.Point.Y);



            for (int i = yMin, iGrid = 0; i <= yMax; i++, iGrid++)
            {
                Grid.Add(new List <Tile>());
                for (int j = xMin; j <= xMax; j++)
                {
                    Tile t = tiles.Where(x => x.Point.X == j && x.Point.Y == i).First();
                    Grid[iGrid].Add(t);
                }
            }
        }
예제 #21
0
파일: Data.cs 프로젝트: Stydla/AOC2020
 public void CreateAllTiles()
 {
     foreach (Tile t in Tiles)
     {
         Tile tmp = t;
         AllTiles.Add(tmp);
         AllTiles.Add(tmp.FlipLeftRight());
         AllTiles.Add(tmp.FlipTopDown());
         for (int i = 0; i < 3; i++)
         {
             tmp = tmp.RotateRight();
             AllTiles.Add(tmp);
             if (i == 0)
             {
                 AllTiles.Add(tmp.FlipLeftRight());
                 AllTiles.Add(tmp.FlipTopDown());
             }
         }
     }
 }
예제 #22
0
        public static void Init(IResourceProvider _resourceProvider, IDrawHelper _drawHelper)
        {
            Rp         = _resourceProvider;
            DrawHelper = _drawHelper;

            Rp.RegisterFont(EFonts.COMMON, Constants.RESOURCES_FONT_FILE, 12);
            Rp.RegisterFont(EFonts.SMALL, Constants.RESOURCES_FONT_FILE, 8);

            AllTiles.Add(ETileset.NONE, new TileSet(Rp.CreateTile(0, 0, FColor.Empty)));

            if (Constants.GAME_MODE && World.XResourceRoot.TileSets.Count > 0)
            {
                foreach (var xTileSet in World.XResourceRoot.TileSets)
                {
                    var set = new TileSet();
                    AllTiles.Add(xTileSet.Tileset, set);
                    var array = xTileSet.Children.OrderBy(_info => _info.Order).ToArray();
                    for (var index = 0; index < array.Length; index++)
                    {
                        var tileInfo = array[index];
                        var atile    = Rp.CreateTile(tileInfo.Cx, tileInfo.Cy, tileInfo.Color.GetFColor());
                        TileSetInfoProvider.SetOpacity(xTileSet.Tileset, index, tileInfo.Opacity);
                        set.AddTile(atile);
                    }
                }
                foreach (var xTileSet in World.XResourceRoot.TerrainSets)
                {
                    var set = new TileSet();
                    AllTerrainTilesets.Add(xTileSet.Terrains, set);
                    foreach (var tileInfo in xTileSet.Children.OrderBy(_info => _info.Order))
                    {
                        set.AddTile(Rp.CreateTile(tileInfo.Cx, tileInfo.Cy, tileInfo.Color.GetFColor()));
                    }
                }
            }
            else
            {
                throw new ApplicationException("База ресурсов не содержит информации от тайлах.");
            }
        }
    public static int CheckTile(TileBase tile)
    {
        TileButton.Tiles i  = TileButton.Tiles.None;
        AllTiles         aT = PuzzleEditorController.instance.allTiles;

        if (tile == aT.groundTile)
        {
            i = TileButton.Tiles.Ground;
        }
        else if (tile == aT.darkGroundTile)
        {
            i = TileButton.Tiles.DarkGround;
        }
        else if (tile == aT.verticalWallTile)
        {
            i = TileButton.Tiles.VerticalWall;
        }
        else if (tile == aT.horizontalWallTile)
        {
            i = TileButton.Tiles.HorizontalWall;
        }
        else if (tile == aT.LUCornerTile)
        {
            i = TileButton.Tiles.LUCorner;
        }
        else if (tile == aT.LDCornerTile)
        {
            i = TileButton.Tiles.LDCorner;
        }
        else if (tile == aT.RUCornerTile)
        {
            i = TileButton.Tiles.RUCorner;
        }
        else if (tile == aT.RDCornerTile)
        {
            i = TileButton.Tiles.RDCorner;
        }
        else if (tile == aT.DeadEndUp)
        {
            i = TileButton.Tiles.DeadEndUp;
        }
        else if (tile == aT.DeadEndDown)
        {
            i = TileButton.Tiles.DeadEndDown;
        }
        else if (tile == aT.DeadEndLeft)
        {
            i = TileButton.Tiles.DeadEndLeft;
        }
        else if (tile == aT.DeadEndRight)
        {
            i = TileButton.Tiles.DeadEndRight;
        }
        else if (tile == aT.DeadContinuousLeft)
        {
            i = TileButton.Tiles.DeadContinuousLeft;
        }
        else if (tile == aT.DeadContinuousRight)
        {
            i = TileButton.Tiles.DeadContinuousRight;
        }
        else if (tile == aT.DeadContinuousUp)
        {
            i = TileButton.Tiles.DeadContinuousUp;
        }
        else if (tile == aT.DeadContinuousDown)
        {
            i = TileButton.Tiles.DeadContinuousDown;
        }
        else if (tile == aT.RotatingCylinder)
        {
            i = TileButton.Tiles.RotatingCylinder;
        }
        else if (tile == aT.LightsPanel)
        {
            i = TileButton.Tiles.lightsPanel;
        }

        return((int)i);
    }
예제 #24
0
    TileBase GetTileFromInt(int id, AllTiles allTiles)
    {
        TileBase tile = null;

        switch ((TileButton.Tiles)id)
        {
        case TileButton.Tiles.Ground:
            tile = allTiles.groundTile;
            break;

        case TileButton.Tiles.DarkGround:
            tile = allTiles.darkGroundTile;
            break;

        case TileButton.Tiles.VerticalWall:
            tile = allTiles.verticalWallTile;
            break;

        case TileButton.Tiles.HorizontalWall:
            tile = allTiles.horizontalWallTile;
            break;

        case TileButton.Tiles.LUCorner:
            tile = allTiles.LUCornerTile;
            break;

        case TileButton.Tiles.LDCorner:
            tile = allTiles.LDCornerTile;
            break;

        case TileButton.Tiles.RUCorner:
            tile = allTiles.RUCornerTile;
            break;

        case TileButton.Tiles.RDCorner:
            tile = allTiles.RDCornerTile;
            break;

        case TileButton.Tiles.DeadEndUp:
            tile = allTiles.DeadEndUp;
            break;

        case TileButton.Tiles.DeadEndDown:
            tile = allTiles.DeadEndDown;
            break;

        case TileButton.Tiles.DeadEndRight:
            tile = allTiles.DeadEndRight;
            break;

        case TileButton.Tiles.DeadEndLeft:
            tile = allTiles.DeadEndLeft;
            break;

        case TileButton.Tiles.DeadContinuousLeft:
            tile = allTiles.DeadContinuousLeft;
            break;

        case TileButton.Tiles.DeadContinuousRight:
            tile = allTiles.DeadContinuousRight;
            break;

        case TileButton.Tiles.DeadContinuousUp:
            tile = allTiles.DeadContinuousUp;
            break;

        case TileButton.Tiles.DeadContinuousDown:
            tile = allTiles.DeadContinuousDown;
            break;

        case TileButton.Tiles.RotatingCylinder:
            tile = allTiles.RotatingCylinder;
            break;

        case TileButton.Tiles.lightsPanel:
            tile = allTiles.LightsPanel;
            break;
        }

        return(tile);
    }
예제 #25
0
    void ApplyLevel(Level level)
    {
        // Elements
        Dictionary <GameObject, int> elementsToLink = new Dictionary <GameObject, int>();

        for (int i = 0; i < level.levelElements.Count; ++i)
        {
            ElementData ED  = level.levelElements[i];
            Vector3     pos = new Vector3(ED.posX, ED.posY, ED.posZ);
            GameObject  go  = null;

            switch (ED.type)
            {
            case (int)PuzzleElementPlaceHolder.PuzzleElementType.Puzzle:
                go = Instantiate(puzzlePH, pos, puzzlePH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.Player:
                go = Instantiate(playerPH, pos, playerPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.PlatformBox:
                go = Instantiate(platformBoxPH, pos, platformBoxPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.PlatformCircle:
                go = Instantiate(platformCirclePH, pos, platformCirclePH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.Doors:
                go = Instantiate(doorsPH, pos, doorsPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.MovingBox:
                go = Instantiate(movingBoxPH, pos, movingBoxPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.VerticalLeftDoors:
                go = Instantiate(VLDoorsPH, pos, VLDoorsPH.transform.rotation, mainElementsEditor);
                break;

            case (int)PuzzleElementPlaceHolder.PuzzleElementType.VerticalRightDoors:
                go = Instantiate(VRDoorsPH, pos, VRDoorsPH.transform.rotation, mainElementsEditor);
                break;
            }

            if (go)
            {
                go.GetComponent <PuzzleElementPlaceHolder>().ChangeState(PuzzleElementPlaceHolder.States.InLevel);
            }

            LinkElementPlaceholder LEP = go.GetComponent <LinkElementPlaceholder>();
            if (LEP)
            {
                var linkingObjects = PuzzleEditorController.instance.linkingObjects;
                if (!linkingObjects.ContainsKey(go))
                {
                    linkingObjects.Add(go, LEP.type);
                }

                if (ED.elementLinkedPos != -1)
                {
                    foreach (KeyValuePair <GameObject, int> previousElement in elementsToLink)
                    {
                        if (i == previousElement.Value)
                        {
                            previousElement.Key.GetComponent <LinkElementPlaceholder>().elementLinked = go;
                            LEP.elementLinked = previousElement.Key;

                            elementsToLink.Remove(previousElement.Key);
                            break;
                        }
                    }

                    if (!LEP.elementLinked)
                    {
                        elementsToLink.Add(go, ED.elementLinkedPos);
                    }
                }
            }
        }

        // Tiles
        AllTiles allTiles = PuzzleEditorController.instance.allTiles;

        PuzzleEditorController.instance.SetSize(level.size);
        SetCameraSize(level.size);

        for (int i = 0; i < level.groundTiles.Count; ++i)
        {
            TileData   TD  = level.groundTiles[i];
            Vector3Int pos = new Vector3Int(TD.posX, TD.posY, TD.posZ);
            PuzzleEditorController.instance.baseTM.SetTile(pos, GetTileFromInt(TD.id, allTiles));
        }

        for (int i = 0; i < level.collidableTiles.Count; ++i)
        {
            TileData   TD  = level.collidableTiles[i];
            Vector3Int pos = new Vector3Int(TD.posX, TD.posY, TD.posZ);
            PuzzleEditorController.instance.collidable.SetTile(pos, GetTileFromInt(TD.id, allTiles));
        }

        levelName.text        = level.name;
        levelDescription.text = level.description;
        ApplyLevelInfo(level.name, level.creatorName, level.description);
    }