コード例 #1
0
ファイル: KulamiEngine.cs プロジェクト: bradleypaul/Kulami
        private void GenerateGameBoard(int boardNum = 0)
        {
            if (boardNum == 0)
            {
                Random rnd = new Random();
                gameBoardNumber = rnd.Next(1, 8);
            }
            else
                gameBoardNumber = boardNum;

            Console.WriteLine("Playing on board #" + gameBoardNumber);
            string startupPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
            string[] lines = System.IO.File.ReadAllLines(startupPath + "/boards/board" + gameBoardNumber + ".txt");
            
            foreach (string line in lines)
            {
                string size = line.Substring(0, 3);
                int row = Convert.ToInt32(size[0].ToString());
                int col = Convert.ToInt32(size[2].ToString());
                Tile t = new Tile(row, col);

                int currentPosition = 4;
                int currentTileRow = 0;
                int currentTileCol = 0;
                for (int i = 0; i < row * col; i++)
                {
                    string coordinate = line.Substring(currentPosition, 5);
                    currentPosition += 5;

                    int holeRow = Convert.ToInt32(coordinate[1].ToString());
                    int holeCol = Convert.ToInt32(coordinate[3].ToString());
                    Hole hole = new Hole(holeRow, holeCol);
                    hole.CanBePlayed = true;
                    t.Holes[currentTileRow, currentTileCol] = hole;

                    currentTileCol++;
                    if (currentTileCol >= col)
                    {
                        currentTileCol = 0;
                        currentTileRow++;
                    }
                }
                currentGame.Board.Tiles.Add(t);
            }
        }
コード例 #2
0
ファイル: Gameboard.cs プロジェクト: bradleypaul/Kulami
        public Gameboard Clone()
        {
            Gameboard copy = new Gameboard();
            foreach (Tile t in tiles)
            {
                Tile newTile = new Tile(t.NumOfRows, t.NumOfCols);
                newTile.Points = t.Points;
                newTile.NumOfRedMarbles = t.NumOfRedMarbles;
                newTile.NumOfBlueMarbles = t.NumOfBlueMarbles;
                newTile.LastPlayedOnByPlayer1 = t.LastPlayedOnByPlayer1;
                newTile.LastPlayedOnByPlayer2 = t.LastPlayedOnByPlayer2;

                for (int r = 0; r < t.NumOfRows; r++)
                {
                    for (int c = 0; c < t.NumOfCols; c++)
                    {
                        Hole newHole = new Hole(t.Holes[r, c].Coord.Row, t.Holes[r, c].Coord.Col);
                        newHole.IsFilled = t.Holes[r, c].IsFilled;
                        newHole.CanBePlayed = t.Holes[r, c].CanBePlayed;
                        newHole.MarbleInHole = t.Holes[r, c].MarbleInHole;
                        newTile.Holes[r, c] = newHole;
                    }
                }
                copy.Tiles.Add(newTile);
            }
            return copy;
        }