예제 #1
0
 public void LoadMap()
 {
    var path =  EditorUtility.OpenFilePanel("Select a Map", @"\Assets\Maps", "map");
    if (path.Length == 0)
        return;
    StreamReader Mapreader = new StreamReader(path);
    Mapreader.ReadLine();
    var htext = Mapreader.ReadLine().Split(' ')[1];
    var wtext = Mapreader.ReadLine().Split(' ')[1];
    Mapreader.ReadLine();
    var height  = Int32.Parse(htext);
    var width = Int32.Parse(wtext);
    Char[] mapline = new char[width];
    Char[,] FinalMap = new char[height,width];
    for (int i = 0; i < height; ++i)
    {
        mapline = Mapreader.ReadLine().ToCharArray();
        for (int j = 0; j < width; ++j)
        {
            FinalMap[i, j] = mapline[j];
        }
    }
    AiMap = FinalMap;
    DrawMap(FinalMap, GameMap = CreateGrid(tilesize, height, width));
 }
예제 #2
0
 public Board(Board newState)
 {
     this.board = (char[,])newState.board.Clone();
     //this.board = newState.board;
     this.width = newState.width;
     this.height = newState.height;
 }
예제 #3
0
 public Labirynth()
 {
     this.playerPositionX = px;
     this.playerPositionY = py;
     this.matrix = this.GenerateMatrix();
     this.scoreBoard = new OrderedMultiDictionary<int, string>(true);
 }
예제 #4
0
        public void DrawBank(char[,] grid)
        {
            if (graphics != null && this.Width > 0 && this.Height > 0)
            {
                this.currentgrid = (char[,])grid.Clone();
                graphics.Clear(Color.White);
                float boxwidth = this.Width / grid.GetLength(0);
                float boxheight = this.Height / grid.GetLength(1);
                if (boxheight == 0)
                    return;
                Pen basic = new Pen(Brushes.Black, 2);
                Font font = new System.Drawing.Font("Consolas", boxheight);
                for (int x = 0; x < grid.GetLength(0); x++)
                {
                    for (int y = 0; y < grid.GetLength(1); y++)
                    {
                        graphics.DrawRectangle(basic, x * boxwidth, y * boxheight, boxwidth, boxheight);
                        char current = grid[x, y];
                        SizeF size = graphics.MeasureString(current.ToString(), font);
                        float centerx = (x * boxwidth) + (boxwidth / 2);
                        float centery = (y * boxheight) + (boxheight / 2);
                        float truex = centerx - (size.Width / 2);
                        float truey = centery - (size.Height / 2);
                        graphics.DrawString(current.ToString(), font, Brushes.Black, truex, truey);

                    }
                }
            }
        }
        public void abajoCola()
        {
            char charAux = ' ';
            findIndicesB(); // find col & row of "b" position in bMat[]
            int i = row + 1;

            temporalMat = bMat;
            if (i <= 1)
            {
                charAux = temporalMat[i, col]; // charAux = caracter a borrar;
                temporalMat[i, col] = temporalMat[row, col]; //
                temporalMat[row, col] = charAux; //
            }
            else
            {
                //indice fuera de alcance
            }

            edoProces = matrixToCadena(); // temporalMat[] to edoProces

            if (!repetidoCola.Contains(edoProces))
            {
                //repetidoCola.Enqueue(edoProces);
                cola.Enqueue(edoProces);
            }
        }
        public static void Main()
        {
            matrix = new[,]
            {
                { ' ', ' ', ' ', '*', ' ', ' ', ' '},
                { '*', '*', ' ', '*', ' ', '*', ' '},
                { ' ', ' ', ' ', '*', ' ', ' ', ' '},
                { '*', '*', '*', '*', '*', '*', ' '},
                { ' ', ' ', ' ', ' ', '*', '*', ' '},
                { ' ', ' ', ' ', ' ', ' ', ' ', ' '}
            };

            for (var row = 0; row < matrix.GetLength(0); row++)
            {
                for (var col = 0; col < matrix.GetLength(1); col++)
                {
                    if (matrix[row, col] == '*')
                    {
                        continue;
                    }

                    currentCount = 0;
                    FindPath(row, col);

                    if (currentCount > maxCount)
                    {
                        maxCount = currentCount;
                    }
                }
            }

            Console.WriteLine(maxCount);
        }
예제 #7
0
        public void GenerateField()
        {
            Random random = new Random();
            int minesToInsert = Constants.MinesToInsert;

            while (minesToInsert > 0)
            {
                for (int i = 0; i < this.field.GetLength(0); i++)
                {
                    if (minesToInsert == 0)
                    {
                        break;
                    }

                    for (int j = 0; j < this.field.GetLength(1); j++)
                    {
                        if (minesToInsert == 0)
                        {
                            break;
                        }

                        int randomNumber = random.Next(0, 3);

                        if (randomNumber == 1)
                        {
                            this.field[i, j] = Constants.MinesSymbol;
                            minesToInsert--;
                        }
                    }
                }
            }

            this.field = MatrixGenerator.GenerateMatrix(this.field, Constants.MinesSymbol);
        }
예제 #8
0
 protected GameObject(MatrixCoords topLeft, char[,] body, Lane lane)
 {
     this.TopLeft = topLeft;
     this.lane = lane;
     int imageRows = body.GetLength(0);
     int imageCols = body.GetLength(1);
     this.body = this.CopyBodyMatrix(body);
 }
예제 #9
0
    // Update is called once per frame
    public void Update()
    {
        Map = MapGen.GetMap();

        for (int i = 0; i < Paths.Count; i++)
            if (!Paths[i].Complete)
                StartPathPlanning(i);
    }
예제 #10
0
 public void Reset()
 {
     GameBoardValues = new[,]
     {
         { ' ', ' ', ' ' },
         { ' ', ' ', ' ' },
         { ' ', ' ', ' ' }
     };
 }
예제 #11
0
        protected GameObject(MatrixCoords topLeft, char[,] body)
        {
            this.TopLeft = topLeft;

            int imageRows = body.GetLength(0);
            int imageCols = body.GetLength(1);

            this.body = this.CopyBodyMatrix(body);

            this.IsDestroyed = false;
        }
예제 #12
0
파일: GameObject.cs 프로젝트: nedevny/skier
        protected GameObject(FieldCoordinates topLeft, char[,] body)
        {
            this.TopLeft = topLeft;

            int imageRows = body.GetLength(0);
            int imageCols = body.GetLength(1);

            this.body = this.CopyBodyMatrix(body);

            this.IsHit = false;
            this.IsGone = false;
        }
        public static void Main()
        {
            graph = ReadGraph();
            int countAreas;
            var areasCounts = FindNumberOfAreas(out countAreas);

            Console.WriteLine("Areas: {0}", countAreas);
            foreach (var areaCount in areasCounts)
            {
                Console.WriteLine("Letter {0} -> {1}", areaCount.Key, areaCount.Value);
            }
        }
예제 #14
0
        // construktor na obektite
        protected GameObject(MatrixCoords topLeft, char[,] body)
        {
            // wytre6na matrica rawna na podadenta
            this.TopLeft = topLeft;

            int imageRows = body.GetLength(0);
            int imageCols = body.GetLength(1);
            // kopirame w body
            this.body = this.CopyBodyMatrix(body);
            // ne e uni6tojena
            this.IsDestroyed = false;
        }
예제 #15
0
 public MineSweeper()
 {
     this.command = string.Empty;
     this.playingField = CreatePlayingField();
     this.minesPositionsField = PlantMines();
     this.achievedPoints = 0;
     this.mineExploded = false;
     this.playersScore = new List<Player>(6);
     this.row = 0;
     this.column = 0;
     this.gameStarted = false;
     this.playerWonTheGame = false;
 }
예제 #16
0
        public Board(int rows, int cols)
        {
            if (rows < 0 || cols < 0)
            {
                throw new ArgumentOutOfRangeException("Rows and Cols must be grated than 0");
            }

            this.Rows = rows;
            this.Cols = cols;

            this.boardHiddenBombs = this.CreateBoard(this.Rows, this.Cols);
            this.boardNotHiddenBombs = this.CreateBoardNotHiddenBombs(this.Rows, this.Cols);
        }
예제 #17
0
        public void Start()
        {
            do
            {
                if (this.welcomeMessege) this.WelcomeMsg();

                Console.Write("Enter row and column: ");
                this.command = Console.ReadLine().Trim();

                if (this.command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out this.row) &&
                        int.TryParse(command[2].ToString(), out this.col) &&
                        this.row < this.playField.GetLength(0) &&
                        this.col < this.playField.GetLength(1))
                    {
                        this.command = "turn";
                    }
                }

                switch (this.command)
                {
                    case "top":
                        Commands.HighScores(highscores);
                        break;
                    case "restart":
                        this.playField = Commands.CreatePlayField();
                        this.bombs = Commands.PlaceBombs();
                        Commands.PrintField(this.playField);
                        this.dead = false;
                        this.welcomeMessege = false;
                        break;
                    case "exit":
                        break;
                    case "turn":
                            this.Turn();
                        break;
                    default:
                        Console.WriteLine("\nError! Invalid command\n");
                        break;
                }

                if (this.dead) this.OnDeath();
                if (this.winner) this.OnWin();
            }
            while (this.command != "exit");
            Console.WriteLine("Made in Bulgaria!");
            Console.WriteLine("Bye.");
        }
예제 #18
0
        public void Start()
        {
            Console.WriteLine(@"Welcome to ""Battle Field"" game. ");

            //string readBuffer = null;

            int size = GetFieldSize();

            // if (size > 10 || size <= 0)
            //{
            //    Start();
            //}
            //else{

            gameField = GameServices.GenerateField(size);
            StartInteraction();
               // }
        }
예제 #19
0
    public static void Main()
    {
        labyrinth = InputLabyrinth();
        string path = FindShortestPath();

        if(path == null)
        {
            Console.WriteLine("No exit!");
        }
        else if(path == "")
        {
            Console.WriteLine("Start is at the exit.");
        }
        else
        {
            Console.WriteLine("Shortest exit: " + path);
        }
    }
예제 #20
0
        public static void Main()
        {
            //matrix = new[,]{
            //    { ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' '},
            //    { ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' '},
            //    { ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' '},
            //    { ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' '}
            //};

            matrix = new[,]{
                { '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' '},
                { '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' '},
                { '*', ' ', ' ', '*', '*', '*', '*', '*', ' ', ' '},
                { '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' '},
                { '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' '}
            };

            rows = matrix.GetLength(0);
            cols = matrix.GetLength(1);

            isVisited = new bool[rows, cols];
            var connectedAreas = new SortedSet<ConnectedArea>();

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    if (!isVisited[i, j] && matrix[i, j] != '*')
                    {
                        var area = new ConnectedArea(i,j,0);
                        FindConnectedArea(i, j, area);
                        connectedAreas.Add(area);
                    }
                }
            }

            int counter = 1;
            Console.WriteLine("Total areas found: " + connectedAreas.Count);
            foreach (var arr in connectedAreas)
            {
                Console.WriteLine($"Area #{counter} at ({arr.X}, {arr.Y}), size: {arr.Size}");
            }
        }
예제 #21
0
        private static void Main()
        {
#if DEBUG
            var filePath = "../../input.txt";
            using (var reader = new StreamReader(filePath)) //COMMNET THIS LINE

            {

                Console.SetIn(reader); //COMMNET THIS LINE
#endif

                //New Code Starts Here
                matrix = BuildMatrix();
                var commands = Console.ReadLine();

                //get the starting player position
                getPlayerPosition();

                //main loop
                foreach (var command in commands)
                {
                    //Move Player
                    MovePlayer(command);
                    DebugPrint();
                    //Move bunnies
                    MoveBunnies();
                    DebugPrint();

                    //Check Win / Dead condition
                    CheckWinLoose();
                    
                }
#if DEBUG
        }
#endif
        }
예제 #22
0
        public void Start()
        {
            Console.WriteLine(@"Welcome to ""Battle Field"" game. ");
            int size = 0;
            string readBuffer = null;

            Console.Write("Enter battle field size: n=");
            readBuffer = Console.ReadLine();

            while (!int.TryParse(readBuffer, out size))
            {
                Console.WriteLine("Wrong format!");
                Console.Write("Enter battle field size: n=");

            }

            if (size > 10 || size <= 0)
            { Start(); }
            else{

                gameField = GameServices.GenerateField(size);
                StartInteraction();
            }
        }
        public void GenerateLabyrinthMatrix()
        {
            char[,] testMatrix;
            int rowsCount = this.Matrix.GetLength(0);
            int colsCount = this.Matrix.GetLength(1);
            int exitsCount = 0;

            do
            {
                this.Matrix = CreateRandomMatrix(rowsCount,colsCount );

                testMatrix = this.Matrix.Clone() as char[,];
                exitsCount = CountLabyrinthExits(rowsCount / 2, colsCount / 2, testMatrix);
            } while (exitsCount == 0);
        }
예제 #24
0
 public static LineDetails ForRow(char[,] board, int row) => new LineDetails(false, row, board);
예제 #25
0
 private void ResetGrid(char[,] grid)
 {
 }
예제 #26
0
 public Tile(int id, char[,] tile)
 {
     this.ID = id;
     _tile   = tile;
 }
예제 #27
0
        public int CountTurnedOnPixelsAfterIterations(
            char[,] gridOfPixels,
            Dictionary <char[, ], char[, ]> rules,
            int totalIterations
            )
        {
            for (int iteration = 0; iteration < totalIterations; iteration++)
            {
                int size = gridOfPixels.GetLength(0);

                int squaresPerSide;
                int smallSquareSize;
                if (size % 2 == 0)
                {
                    squaresPerSide  = size / 2;
                    smallSquareSize = 2;
                }
                else
                {
                    squaresPerSide  = size / 3;
                    smallSquareSize = 3;
                }

                char[,] enhancedGridOfPixels = new char[
                    squaresPerSide * (smallSquareSize + 1),
                    squaresPerSide *(smallSquareSize + 1)
                                               ];

                for (int i = 0; i < squaresPerSide; i++)
                {
                    for (int j = 0; j < squaresPerSide; j++)
                    {
                        char[,] smallSquare = new char[smallSquareSize, smallSquareSize];

                        int x = 0;
                        for (int k = i * smallSquareSize; k < i * smallSquareSize + smallSquareSize; k++)
                        {
                            int y = 0;
                            for (int h = j * smallSquareSize; h < j * smallSquareSize + smallSquareSize; h++)
                            {
                                smallSquare[x, y] = gridOfPixels[k, h];
                                y++;
                            }
                            x++;
                        }

                        char[,] smallSquareOutput = GetOutputAfterRule(smallSquare, rules);
                        int outputSquareSize = smallSquareOutput.GetLength(0);

                        for (x = 0; x < outputSquareSize; x++)
                        {
                            for (int y = 0; y < outputSquareSize; y++)
                            {
                                enhancedGridOfPixels[i * outputSquareSize + x, j *outputSquareSize + y] =
                                    smallSquareOutput[x, y];
                            }
                        }
                    }
                }

                gridOfPixels = enhancedGridOfPixels;
            }

            int turnedOnPixels = CountGridTurnedOnPixels(gridOfPixels);

            return(turnedOnPixels);
        }
예제 #28
0
    public bool IsValidSudoku(char[,] board)
    {
        #region 横排列
        for (int i = 0; i < 9; i++)
        {
            Hashtable hashtable = new Hashtable();
            for (int j = 0; j < 9; j++)
            {
                if (hashtable.Contains(board[i, j]) && board[i, j].Equals('.') == false)
                {
                    return(false);
                }
                else if (board[i, j].Equals('.') == false)
                {
                    hashtable.Add(board[i, j], board[i, j]);
                }
            }
        }
        #endregion

        #region 纵排列
        for (int j = 0; j < 9; j++)
        {
            Hashtable hashtable = new Hashtable();
            for (int i = 0; i < 9; i++)
            {
                if (hashtable.Contains(board[i, j]) && board[i, j].Equals('.') == false)
                {
                    return(false);
                }
                else if (board[i, j].Equals('.') == false)
                {
                    hashtable.Add(board[i, j], board[i, j]);
                }
            }
        }
        #endregion

        #region 3x3排列
        Hashtable[] hashtableA = new Hashtable[9];
        for (int i = 0; i < 9; i++)
        {
            hashtableA[i] = new Hashtable();
        }
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                if (hashtableA[3 * (i / 3) + j / 3].Contains(board[i, j]) && board[i, j].Equals('.') == false)
                {
                    return(false);
                }
                else if (board[i, j].Equals('.') == false)
                {
                    hashtableA[3 * (i / 3) + j / 3].Add(board[i, j], board[i, j]);
                }
            }
        }

        #endregion


        return(true);
    }
예제 #29
0
파일: Program.cs 프로젝트: f11lthhh/Zmeya
        public static char[,] CreateArray()
        {
            int difficulty;

Enters:
            Console.WriteLine("Введите уровень сложности 1-лёгкий 2-средний 3-сложный)");
            difficulty = Convert.ToInt32(Console.ReadLine());
            Console.Clear();
            switch (difficulty)
            {
            case 1:
                field   = 10;
                tikrate = 350;
                break;

            case 2:
                field   = 15;
                tikrate = 250;
                break;

            case 3:
                field   = 20;
                tikrate = 150;
                break;

            default:
                Console.WriteLine("Неверно");
                goto Enters;
            }
            Arr = new char[field, field];
            for (int i = 0; i < field; i++)
            {
                for (int j = 0; j < field; j++)
                {
                    if (i == 0 || j == 0 || i == field - 1 || j == field - 1)
                    {
                        Arr[i, j] = '#';
                    }
                    else
                    {
                        Arr[i, j] = ' ';
                    }
                }
            }


            Random rand = new Random();

FoodTicket:
            x = rand.Next(2, field - 2);
            y = rand.Next(2, field - 2);
            q = rand.Next(2, field - 2);
            z = rand.Next(2, field - 2);
            if (x == q && y == z)
            {
                goto FoodTicket;
            }
            else
            {
                Arr[x, y] = '9';
                Arr[q, z] = '@';
            }

            return(Arr);
        }
예제 #30
0
 public Tablero()
 {
     _horizontal    = new[] { 2, 1, -1, -2, -2, -1, 1, 2 };
     _vertical      = new[] { -1, -2, -2, -1, 1, 2, 2, 1 };
     TableroAjedrez = new char[tamanio, tamanio];
 }
예제 #31
0
        static void Main(string[] args)
        {
            // -----------------------------------------------------------------------------
            // 1. FELADAT
            char[,] palya = PalyaGeneralas();


            // -----------------------------------------------------------------------------
            // 2. FELADAT
            Megjelenit(palya);

            // -----------------------------------------------------------------------------
            // 3. FELADAT
            // palyageneralas metódusban van meghívva!

            // -----------------------------------------------------------------------------
            // 4. FELADAT
            //char karakter = MezoLekerdezes(palya);
            //Console.WriteLine("A lekérdezett karakter: " + karakter);

            // -----------------------------------------------------------------------------
            // 5. FELADAT
            double[] coinArany = CoinAranySzamSoronkent(palya);

            for (int i = 0; i < coinArany.Length; i++)
            {
                Console.WriteLine("--" + coinArany[i]);
            }

            // -----------------------------------------------------------------------------
            // 6. FELADAT
            double[] maxCoin = MaxCoinDarabszam(coinArany);

            Console.WriteLine("A max coin-arány indexe: " + maxCoin[0]);
            Console.WriteLine("A max coin-arány értéke: " + maxCoin[1]);

            // -----------------------------------------------------------------------------
            // 7. FELADAT
            int[] ellensegOszloponkent = EllensegOszloponkent(palya);

            // -----------------------------------------------------------------------------
            // 8. FELADAT
            int[] elemekIndexei = new int[ellensegOszloponkent.Length];
            int[] maxEllErtekek = MaxEllensegSzam(ellensegOszloponkent, elemekIndexei);

            Console.WriteLine("Legtöbb ellenség egy oszlopban: " + maxEllErtekek[1]);
            Console.WriteLine("Helye(k): ({0})", maxEllErtekek[0] + 1);
            for (int i = 0; i <= maxEllErtekek[0]; i++)
            {
                Console.WriteLine("\toszlop: " + elemekIndexei[i]);
            }

            // -----------------------------------------------------------------------------
            // 9. FELADAT
            Console.WriteLine("\n\nELŐTTE:");
            for (int i = 0; i < coinArany.Length; i++)
            {
                Console.WriteLine("\t" + coinArany[i]);
            }

            RendezesCsokkenobe(coinArany);

            Console.WriteLine("\n\nUTÁNA:");
            for (int i = 0; i < coinArany.Length; i++)
            {
                Console.WriteLine("\t" + coinArany[i]);
            }
        }
예제 #32
0
 public void RuleFourIsSatisfied(char[,] input, char[,] expectedOutput)
 {
     Assert.True(ArraysEqual(expectedOutput, GameOfLife.NextGeneration(input)));
 }
예제 #33
0
 private static char[] SameRowColumn(ref char[,] keySquare, int row, int col, int encipher)
 {
     return(new char[] { keySquare[Mod((row + encipher), 5), Mod((col + encipher), 5)], keySquare[Mod((row + encipher), 5), Mod((col + encipher), 5)] });
 }
예제 #34
0
 private static char[] SameColumn(ref char[,] keySquare, int col, int row1, int row2, int encipher)
 {
     return(new char[] { keySquare[Mod((row1 + encipher), 5), col], keySquare[Mod((row2 + encipher), 5), col] });
 }
예제 #35
0
 private static char[] SameRow(ref char[,] keySquare, int row, int col1, int col2, int encipher)
 {
     return(new char[] { keySquare[row, Mod((col1 + encipher), 5)], keySquare[row, Mod((col2 + encipher), 5)] });
 }
예제 #36
0
 // This constructor is called automatically by the parent class, ISerializable
 // We get to custom-implement the serialization process here
 public SaveData(SerializationInfo info, StreamingContext ctxt)
 {
     // Get the values from info and assign them to the appropriate properties. Make sure to cast each variable.
     // Do this for each var defined in the Values section above
     ground = (char[,])info.GetValue("ground", typeof(char[,]));
 }
예제 #37
0
        private static string GetWord(direction direction, int index, int n, char[,] arr)
        {
            int start     = 0;
            int end       = 0;
            int increment = 0;

            if (direction == direction.down || direction == direction.right)
            {
                start     = 0;
                end       = n;
                increment = 1;
            }
            else if (direction == direction.up || direction == direction.left)
            {
                start     = n - 1;
                end       = -1;
                increment = -1;
            }

            char   last        = ' ';
            char   current     = ' ';
            string wordMax     = string.Empty;
            string wordCurrent = string.Empty;

            for (int i = start; i != end; i += increment)
            {
                if (direction == direction.left || direction == direction.right)
                {
                    current = arr[index, i];
                }
                else
                {
                    current = arr[i, index];
                }

                if (i == start)
                {
                    wordCurrent += current;
                    wordMax     += current;
                }
                else
                {
                    if (last < current)
                    {
                        wordCurrent += current;

                        if ((i + increment == end) &&
                            (FirstMatchesCondition(wordCurrent, wordMax)))
                        {
                            wordMax = wordCurrent;
                        }
                    }
                    else
                    {
                        if (FirstMatchesCondition(wordCurrent, wordMax))
                        {
                            wordMax = wordCurrent;
                        }
                        wordCurrent  = string.Empty;
                        wordCurrent += current;
                    }
                }

                last = current;
            }

            return(wordMax);
        }
예제 #38
0
 public Maze(char[,] maze)
 {
     this.maze = maze;
 }
 public GiftBlock(MatrixCoords topLeft, char[,] symbols)
     : base(topLeft, symbols)
 {
 }
예제 #40
0
        private static char[, ] MoveInfoOnDisplay(char[, ] arr)
        {
            arr = Symbols.MoveArray(arr);

            return(arr);
        }
예제 #41
0
        public void SopaDeLetras(int F, int C, string[] palabra)
        {
            filas  = F;
            colums = C;
            matriz = new char[filas, colums];

            output = new string[colums];


            for (int i = 0; i < filas; i++)
            {
                for (int j = 0; j < colums; j++)
                {
                    matriz[i, j] = '.';
                }
            }

            //Almacena la palabra

            //horizontal normal po ahora cogiendo la primera palabra
            for (int k = 0; k < palabra.Length; k++)
            {
                forma = pos.Next(1, 7);

                /*1:Hotrizontal normal, 2: horizontal revez,  3: vertical, 4: vertical revez
                 * 5: diagonal, 6: diagonal revez
                 *
                 */
                switch (forma)
                {
                case 1:    //Horizontal
                    pfil = pos.Next(0, filas - 1);
                    pcol = pos.Next(0, colums - 1);

                    pActual = palabra[k];
                    int con = pcol;

                    if (pcol + pActual.Length <= colums)     //Revisa que quepa
                    {
                        while (con < pcol + pActual.Length)  //Revisa que los espacios esten vacios
                        {
                            if (matriz[pfil, con].Equals('.'))
                            {
                                vacio = true;
                            }
                            else
                            {
                                vacio = false;
                                forma = 3;
                                break;
                            }
                            con++;
                        }
                        if (pActual.Length + pcol <= colums && vacio == true)
                        {
                            for (int i = pcol; i < (pActual.Length + pcol); i++)    //Agrega
                            {
                                matriz[pfil, i] = pActual[cont];

                                cont++;
                            }
                        }
                        cont = 0;
                    }
                    else
                    {
                        forma = 3;
                    }
                    break;

                case 2:
                    //horizontal revez po ahora cogiendo la segunda palabra
                    pfil = pos.Next(0, filas - 1);
                    pcol = pos.Next(0, colums - 1);

                    pActual = palabra[k];
                    cont    = pActual.Length - 1;
                    con     = pcol;
                    if (pcol + pActual.Length <= colums)     //Revisa que quepa
                    {
                        while (con < pcol + pActual.Length)  //Revisa que los espacios esten vacios
                        {
                            if (matriz[pfil, con].Equals('.'))
                            {
                                vacio = true;
                            }
                            else
                            {
                                vacio = false;
                                forma = 3;
                                break;
                            }
                            con++;
                        }
                        if (pActual.Length + pcol <= colums && vacio == true)
                        {
                            for (int i = pcol; i < (pActual.Length + pcol); i++)
                            {
                                matriz[pfil, i] = pActual[cont];

                                cont--;
                            }
                        }
                        cont = 0;
                    }
                    else
                    {
                        forma = 3;
                    }
                    break;

                case 3:
                    //Vertical normal cogiendo la tercera palabra

                    pfil = pos.Next(0, filas - 1);
                    pcol = pos.Next(0, colums - 1);

                    pActual = palabra[k];
                    int conf = pfil;
                    cont = 0;

                    if (pfil + pActual.Length <= filas)
                    {
                        while (conf < pfil + pActual.Length)     //Revisa que los espacios esten vacios
                        {
                            if (matriz[conf, pcol].Equals('.'))
                            {
                                vacio = true;
                            }
                            else
                            {
                                vacio = false;
                                forma = 5;
                                break;
                            }
                            conf++;
                        }
                        if (pActual.Length + pfil <= filas && vacio == true)
                        {
                            for (int i = pfil; i < (pActual.Length + pfil); i++)
                            {
                                matriz[i, pcol - 1] = pActual[cont];

                                cont++;
                            }
                        }
                        cont = 0;
                    }
                    else
                    {
                        forma = 5;
                    }

                    break;

                case 4:
                    //Vertical revez cogiendo la 4ta palabra

                    pfil = pos.Next(0, filas - 1);
                    pcol = pos.Next(0, colums - 1);

                    pActual = palabra[k];
                    conf    = pfil;
                    if (pfil + pActual.Length <= filas)
                    {
                        while (conf < pfil + pActual.Length)     //Revisa que los espacios esten vacios
                        {
                            if (matriz[conf, pcol].Equals('.'))
                            {
                                vacio = true;
                            }
                            else
                            {
                                vacio = false;
                                forma = 5;
                                break;
                            }
                            conf++;
                        }
                        if (pActual.Length + pfil <= filas && vacio == true)
                        {
                            cont = pActual.Length - 1;
                            for (int i = pfil; i < (pActual.Length + pfil); i++)
                            {
                                matriz[i, pcol] = pActual[cont];

                                cont--;
                            }
                        }
                        cont = 0;
                    }
                    else
                    {
                        forma = 5;
                    }
                    break;

                case 5:
                    //Diagonal Normal cogiendo la5ta palabra

                    pfil = pos.Next(0, filas - 1);
                    pcol = pos.Next(0, colums - 1);

                    pActual = palabra[k];
                    conf    = pfil;
                    con     = pcol;
                    if (pfil + pActual.Length <= filas && pcol + pActual.Length <= colums)
                    {
                        while (conf < pfil + pActual.Length && con < pcol + pActual.Length)     //Revisa que los espacios esten vacios
                        {
                            if (matriz[conf, con].Equals('.'))
                            {
                                vacio = true;
                            }
                            else
                            {
                                vacio = false;
                                forma = 1;
                                break;
                            }
                            conf++;
                            con++;
                        }
                        if (pActual.Length + pfil <= filas && vacio == true)
                        {
                            for (int i = pfil; i < (pActual.Length + pfil); i++)
                            {
                                matriz[i, pcol] = pActual[cont];

                                cont++;
                                pcol++;
                            }
                        }
                        cont = 0;
                    }
                    else
                    {
                        forma = 1;
                    }
                    break;

                case 6:
                    //Diagonal revez con la palabra 6

                    pfil = pos.Next(0, filas - 1);
                    pcol = pos.Next(0, colums - 1);

                    pActual = palabra[k];
                    conf    = pfil;
                    con     = pcol;
                    if (pfil + pActual.Length <= filas && pcol + pActual.Length <= colums)
                    {
                        while (conf < pfil + pActual.Length && con < pcol + pActual.Length)     //Revisa que los espacios esten vacios
                        {
                            if (matriz[conf, con].Equals('.'))
                            {
                                vacio = true;
                            }
                            else
                            {
                                vacio = false;
                                forma = 1;
                                break;
                            }
                            conf++;
                            con++;
                        }
                        if (pActual.Length + pfil <= filas && vacio == true)
                        {
                            cont = pActual.Length - 1;
                            for (int i = pfil; i < (pActual.Length + pfil); i++)
                            {
                                matriz[i, pcol] = pActual[cont];

                                cont--;
                                pcol++;
                            }
                        }
                        cont = 0;
                    }
                    else
                    {
                        forma = 1;
                    }
                    break;
                }
            }



            //Letras al azar
            for (int i = 0; i < filas; i++)
            {
                for (int j = 0; j < colums; j++)
                {
                    ascii = pos.Next(97, 122); //Caracteres ascci al azar


                    char conver = (char)ascii;
                    if (matriz[i, j].Equals('.'))
                    {
                        matriz[i, j] = conver;
                    }
                }
            }

            //Lo imprime

            using (StreamWriter file = new StreamWriter(path, true))
            {
                for (int i = 0; i < filas; i++)
                {
                    for (int j = 0; j < colums; j++)
                    {
                        Console.Write(matriz[i, j] + " ");
                        file.Write(matriz[i, j] + " "); //se agrega información al documento
                    }
                    file.WriteLine();
                    Console.WriteLine();
                }

                file.WriteLine("Palabras: ");

                for (int i = 0; i < palabra.Length; i++)
                {
                    file.Write(" " + palabra[i]);
                }
                file.Close();

                Console.Read();
            }
        }
예제 #42
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="size">size</param>
 public Labyrinth(int size)
 {
     this.Size = size;
     this.matrix = this.GenerateMatrix();
 }
        private static void Main()
        {
            string command = string.Empty;

            char[,] playBoard = CreatePlayFields();
            char[,] bombs     = PlantBombs();
            int           pointsCounter = 0;
            bool          grum          = false;
            List <Player> champions     = new List <Player>(6);
            int           row           = 0;
            int           col           = 0;
            bool          isBeginning   = true;
            const int     Max           = 35;
            bool          gameWon       = false;

            do
            {
                if (isBeginning)
                {
                    Console.WriteLine(
                        "Let's play the game Minesweeper. Try to find the cells without mines."
                        + " The command 'top' shows the ranking, by 'restart' you begin a new game, 'exit' exits the game!");
                    PrintPlayBoard(playBoard);
                    isBeginning = false;
                }

                Console.Write("Enter a row and a column : ");
                command = Console.ReadLine().Trim();
                if (command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out col) &&
                        row <= playBoard.GetLength(0) && col <= playBoard.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                case "top":
                    ShowStats(champions);
                    break;

                case "restart":
                    playBoard = CreatePlayFields();
                    bombs     = PlantBombs();
                    PrintPlayBoard(playBoard);
                    grum        = false;
                    isBeginning = false;
                    break;

                case "exit":
                    Console.WriteLine("Bye bye!");
                    break;

                case "turn":
                    if (bombs[row, col] != '*')
                    {
                        if (bombs[row, col] == '-')
                        {
                            ShowNumberOfBombs(playBoard, bombs, row, col);
                            pointsCounter++;
                        }

                        if (Max == pointsCounter)
                        {
                            gameWon = true;
                        }
                        else
                        {
                            PrintPlayBoard(playBoard);
                        }
                    }
                    else
                    {
                        grum = true;
                    }

                    break;

                default:
                    Console.WriteLine("\nYou entered an invalid command\n");
                    break;
                }

                if (grum)
                {
                    PrintPlayBoard(bombs);
                    Console.Write("\nHrrrrrr! You died with {0} points. " + "Enter you nickname: ", pointsCounter);
                    string nickname = Console.ReadLine();
                    Player player   = new Player(nickname, pointsCounter);
                    if (champions.Count < 5)
                    {
                        champions.Add(player);
                    }
                    else
                    {
                        for (int i = 0; i < champions.Count; i++)
                        {
                            if (champions[i].Points < player.Points)
                            {
                                champions.Insert(i, player);
                                champions.RemoveAt(champions.Count - 1);
                                break;
                            }
                        }
                    }

                    champions.Sort((Player r1, Player r2) => r2.Name.CompareTo(r1.Name));
                    champions.Sort((Player r1, Player r2) => r2.Points.CompareTo(r1.Points));
                    ShowStats(champions);

                    playBoard     = CreatePlayFields();
                    bombs         = PlantBombs();
                    pointsCounter = 0;
                    grum          = false;
                    isBeginning   = true;
                }

                if (gameWon)
                {
                    Console.WriteLine("\nYou won");
                    PrintPlayBoard(bombs);
                    Console.WriteLine("Enter your name: ");
                    string imeee  = Console.ReadLine();
                    Player to4kii = new Player(imeee, pointsCounter);
                    champions.Add(to4kii);
                    ShowStats(champions);
                    playBoard     = CreatePlayFields();
                    bombs         = PlantBombs();
                    pointsCounter = 0;
                    gameWon       = false;
                    isBeginning   = true;
                }
            }while (command != "exit");
            Console.Read();
        }
        private static void SelectMatrix()
        {
            Console.Write("Select matrix 1 or 2: ");
            int matrixNumber = int.Parse(Console.ReadLine());
            if (matrixNumber == 1)
            {
                matrix = MatrixOne;
            }
            else if (matrixNumber == 2)
            {
                matrix = MatrixTwo;
            }
            else
            {
                throw new IndexOutOfRangeException("Invalid matrix number");
            }

            numRows = matrix.GetLength(0);
            numCols = matrix.GetLength(1);
        }
        private static char GetNumberOfBombs(char[,] playField, int row, int col)
        {
            int count = 0;
            int rows  = playField.GetLength(0);
            int cols  = playField.GetLength(1);

            if (row - 1 >= 0)
            {
                if (playField[row - 1, col] == '*')
                {
                    count++;
                }
            }

            if (row + 1 < rows)
            {
                if (playField[row + 1, col] == '*')
                {
                    count++;
                }
            }

            if (col - 1 >= 0)
            {
                if (playField[row, col - 1] == '*')
                {
                    count++;
                }
            }

            if (col + 1 < cols)
            {
                if (playField[row, col + 1] == '*')
                {
                    count++;
                }
            }

            if ((row - 1 >= 0) && (col - 1 >= 0))
            {
                if (playField[row - 1, col - 1] == '*')
                {
                    count++;
                }
            }

            if ((row - 1 >= 0) && (col + 1 < cols))
            {
                if (playField[row - 1, col + 1] == '*')
                {
                    count++;
                }
            }

            if ((row + 1 < rows) && (col - 1 >= 0))
            {
                if (playField[row + 1, col - 1] == '*')
                {
                    count++;
                }
            }

            if ((row + 1 < rows) && (col + 1 < cols))
            {
                if (playField[row + 1, col + 1] == '*')
                {
                    count++;
                }
            }

            return(char.Parse(count.ToString()));
        }
예제 #46
0
 private static HashSet <char> UniqueCharsIn(char[,] chars)
 {
     return(new HashSet <char>(chars.Cast <char>().Distinct()));
 }
예제 #47
0
            static bool DidPlayerWin(char[,] board)
            {
                if (board[0, 0] == 'X' && board[0, 1] == 'X' && board[0, 2] == 'X')
                {
                    return(true);
                }
                if (board[1, 0] == 'X' && board[1, 1] == 'X' && board[1, 2] == 'X')
                {
                    return(true);
                }
                if (board[2, 0] == 'X' && board[2, 1] == 'X' && board[2, 2] == 'X')
                {
                    return(true);
                }
                if (board[0, 0] == 'X' && board[1, 0] == 'X' && board[2, 0] == 'X')
                {
                    return(true);
                }
                if (board[0, 1] == 'X' && board[1, 1] == 'X' && board[2, 1] == 'X')
                {
                    return(true);
                }
                if (board[0, 2] == 'X' && board[1, 2] == 'X' && board[2, 2] == 'X')
                {
                    return(true);
                }
                if (board[0, 0] == 'X' && board[1, 1] == 'X' && board[2, 2] == 'X')
                {
                    return(true);
                }
                if (board[0, 2] == 'X' && board[0, 1] == 'X' && board[2, 0] == 'X')
                {
                    return(true);
                }
                if (board[0, 0] == 'O' && board[0, 1] == 'O' && board[0, 2] == 'O')
                {
                    return(true);
                }
                if (board[1, 0] == 'O' && board[1, 1] == 'O' && board[1, 2] == 'O')
                {
                    return(true);
                }
                if (board[2, 0] == 'O' && board[2, 1] == 'O' && board[2, 2] == 'O')
                {
                    return(true);
                }
                if (board[0, 0] == 'O' && board[1, 0] == 'O' && board[2, 0] == 'O')
                {
                    return(true);
                }
                if (board[0, 1] == 'O' && board[1, 1] == 'O' && board[2, 1] == 'O')
                {
                    return(true);
                }
                if (board[0, 2] == 'O' && board[1, 2] == 'O' && board[2, 2] == 'O')
                {
                    return(true);
                }
                if (board[0, 0] == 'O' && board[1, 1] == 'O' && board[2, 2] == 'O')
                {
                    return(true);
                }
                if (board[0, 2] == 'O' && board[0, 1] == 'O' && board[2, 0] == 'O')
                {
                    return(true);
                }

                return(false);
            }
예제 #48
0
        public void Solve(char[,] board)
        {
            int m = board.GetLength(0);

            if (m == 0)
            {
                return;
            }
            int n = board.GetLength(1);

            if (n == 0)
            {
                return;
            }

            var q = new Queue <int[]>();


            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if ((i == 0 || i == m - 1 || j == 0 || j == n - 1) && board[i, j] == 'O')
                    {
                        q.Enqueue(new[] { i, j });
                        board[i, j] = 'C';
                    }
                }
            }

            var dirs = new[] { new[] { 0, 1 }, new[] { 0, -1 }, new[] { 1, 0 }, new[] { -1, 0 } };

            while (q.Count != 0)
            {
                var p = q.Dequeue();
                int i = p[0];
                int j = p[1];
                foreach (var dir in dirs)
                {
                    int x = i + dir[0];
                    int y = j + dir[1];

                    // INF is int.Max
                    if (x >= 0 && x < m && y >= 0 && y < n && board[x, y] == 'O')
                    {
                        board[x, y] = 'C';
                        q.Enqueue(new[] { x, y });
                    }
                }
            }

            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (board[i, j] == 'O')
                    {
                        board[i, j] = 'X';
                    }
                    else if (board[i, j] == 'C')
                    {
                        board[i, j] = 'O';
                    }
                }
            }
        }
        private void TurnCharArrayIntoMinimumRows()
        {
            int realNumberOfRows = 0;

            for(int row = 0; row < letterPairs.GetLength(0); row++)
            {
                if(letterPairs[row, 0] == '~')
                {
                    break;
                }

                realNumberOfRows++;
            }

            char[,] tempCharArra = new char[realNumberOfRows, 2];

            for(int row = 0; row < tempCharArra.GetLength(0); row++)
            {
                tempCharArra[row, 0] = letterPairs[row, 0];
                tempCharArra[row, 1] = letterPairs[row, 1];
            }

            letterPairs = tempCharArra;

                /* GI
                 * Was?
                 * Make sure to have real data.
                 * Why show pictures?
                 * Make sure if you use pictures you use at max about two
                 * Does it work on the phone?
                 * If so, take a pic in class and show the admin side
                 * Have you met with mister paterson
                 *
                 * GII
                 * What are the required sections
                 * Amazing project, presentation needs a LOT of work
                 *
                 * GIV
                 * Larger font
                 * Are you really logged in?
                 * Tell the user to click there to show the tip
                 */
        }
예제 #50
0
파일: Program.cs 프로젝트: pikolap/projects
 public HerniObrazovka()
 {
     HerniPole = new Char[rozmer, rozmer];
     PoleStavu = new StavKarty[rozmer, rozmer];
     RozdejKarty();
 }
예제 #51
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.InputLanguageChange:
                dwCharSet = (CharacterSet)(uint)wParam;
                goto case MessageType.Create;

            case MessageType.Create:
                using (DeviceContext dc = window.GetDeviceContext())
                {
                    using (FontHandle font = Gdi.CreateFont(characterSet: dwCharSet, pitch: FontPitch.FixedPitch))
                    {
                        dc.SelectObject(font);
                        dc.GetTextMetrics(out TextMetrics tm);
                        cxChar = tm.AverageCharWidth;
                        cyChar = tm.Height;
                        dc.SelectObject(StockFont.System);
                    }
                }
                goto CalculateSize;

            case MessageType.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;

CalculateSize:

                // calculate window size in characters
                cxBuffer = Math.Max(1, cxClient / cxChar);
                cyBuffer = Math.Max(1, cyClient / cyChar);

                // allocate memory for buffer and clear it
                pBuffer = new char[cxBuffer, cyBuffer];

                // set caret to upper left corner
                xCaret = 0;
                yCaret = 0;

                if (window == Windows.GetFocus())
                {
                    Windows.SetCaretPosition(new Point(xCaret * cxChar, yCaret * cyChar));
                }

                window.Invalidate(true);
                return(0);

            case MessageType.SetFocus:
                // create and show the caret
                window.CreateCaret(default, new Size(cxChar, cyChar));
                Windows.SetCaretPosition(new Point(xCaret * cxChar, yCaret * cyChar));
                window.ShowCaret();
                return(0);

            case MessageType.KillFocus:
                // hide and destroy the caret
                window.HideCaret();
                Windows.DestroyCaret();
                return(0);

            case MessageType.KeyDown:
                switch ((VirtualKey)wParam)
                {
                case VirtualKey.Home:
                    xCaret = 0;
                    break;

                case VirtualKey.End:
                    xCaret = cxBuffer - 1;
                    break;

                case VirtualKey.Prior:
                    yCaret = 0;
                    break;

                case VirtualKey.Next:
                    yCaret = cyBuffer - 1;
                    break;

                case VirtualKey.Left:
                    xCaret = Math.Max(xCaret - 1, 0);
                    break;

                case VirtualKey.Right:
                    xCaret = Math.Min(xCaret + 1, cxBuffer - 1);
                    break;

                case VirtualKey.Up:
                    yCaret = Math.Max(yCaret - 1, 0);
                    break;

                case VirtualKey.Down:
                    yCaret = Math.Min(yCaret + 1, cyBuffer - 1);
                    break;

                case VirtualKey.Delete:
                    for (int x = xCaret; x < cxBuffer - 1; x++)
                    {
                        pBuffer[x, yCaret] = pBuffer[x + 1, yCaret];
                    }

                    pBuffer[cxBuffer - 1, yCaret] = ' ';
                    window.HideCaret();
                    using (DeviceContext dc = window.GetDeviceContext())
                    {
                        using (FontHandle font = Gdi.CreateFont(characterSet: dwCharSet, pitch: FontPitch.FixedPitch))
                        {
                            dc.SelectObject(font);
                            unsafe
                            {
                                fixed(char *c = &pBuffer[xCaret, yCaret])
                                dc.TextOut(
                                    new Point(xCaret * cxChar, yCaret * cyChar),
                                    new ReadOnlySpan <char>(c, cxBuffer - xCaret));
                            }
                            dc.SelectObject(StockFont.System);
                        }

                        window.ShowCaret();
                    }
                    break;
                }
                Windows.SetCaretPosition(new Point(xCaret * cxChar, yCaret * cyChar));
                return(0);

            case MessageType.Char:
                for (int i = 0; i < lParam.LowWord; i++)
                {
                    switch ((char)wParam)
                    {
                    case '\b':         // backspace
                        if (xCaret > 0)
                        {
                            xCaret--;
                            window.SendMessage(MessageType.KeyDown, (uint)VirtualKey.Delete, 1);
                        }
                        break;

                    case '\t':         // tab
                        do
                        {
                            window.SendMessage(MessageType.Char, ' ', 1);
                        } while (xCaret % 8 != 0);
                        break;

                    case '\n':         // line feed
                        if (++yCaret == cyBuffer)
                        {
                            yCaret = 0;
                        }
                        break;

                    case '\r':         // carriage return
                        xCaret = 0;
                        if (++yCaret == cyBuffer)
                        {
                            yCaret = 0;
                        }
                        break;

                    case '\x1B':         // escape
                        for (int y = 0; y < cyBuffer; y++)
                        {
                            for (int x = 0; x < cxBuffer; x++)
                            {
                                pBuffer[x, y] = ' ';
                            }
                        }
                        xCaret = 0;
                        yCaret = 0;
                        window.Invalidate(false);
                        break;

                    default:         // character codes
                        pBuffer[xCaret, yCaret] = (char)wParam;
                        window.HideCaret();
                        using (DeviceContext dc = window.GetDeviceContext())
                        {
                            using (FontHandle font = Gdi.CreateFont(characterSet: dwCharSet, pitch: FontPitch.FixedPitch))
                            {
                                dc.SelectObject(font);
                                unsafe
                                {
                                    fixed(char *c = &pBuffer[xCaret, yCaret])
                                    dc.TextOut(
                                        new Point(xCaret * cxChar, yCaret * cyChar),
                                        new ReadOnlySpan <char>(c, 1));
                                }
                                dc.SelectObject(StockFont.System);
                            }

                            window.ShowCaret();
                        }

                        if (++xCaret == cxBuffer)
                        {
                            xCaret = 0;
                            if (++yCaret == cyBuffer)
                            {
                                yCaret = 0;
                            }
                        }
                        break;
                    }
                }
                Windows.SetCaretPosition(new Point(xCaret * cxChar, yCaret * cyChar));
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    using (FontHandle font = Gdi.CreateFont(0, 0, 0, 0, FontWeight.DoNotCare, false, false, false, dwCharSet,
                                                            OutputPrecision.Default, ClippingPrecision.Default, Quality.Default, FontPitch.FixedPitch, FontFamilyType.DoNotCare, null))
                    {
                        dc.SelectObject(font);
                        unsafe
                        {
                            for (int y = 0; y < cyBuffer; y++)
                                fixed(char *c = &pBuffer[0, y])
                                dc.TextOut(new Point(0, y * cyChar), new ReadOnlySpan <char>(c, cxBuffer));
                        }
                        dc.SelectObject(StockFont.System);
                    }
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
예제 #52
0
 private static char[] DifferentRowColumn(ref char[,] keySquare, int row1, int col1, int row2, int col2)
 {
     return(new char[] { keySquare[row1, col2], keySquare[row2, col1] });
 }
예제 #53
0
        private static void Main()
        {
            do
            {
                if (!gameStarted)
                {
                    gameStarted = true;
                    playgroundField = CreatePlaygroundField();
                    bombs = PutTheBombs();
                    PrintStartGameMessage();
                    PrintPlayGroundField(playgroundField);
                    AddNewPlayer();
                }

                Console.Write("Enter row[0...4] and column[0...9], separated by space: ");
                command = Console.ReadLine().Trim();
                if (command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out rowPlayer)
                        && int.TryParse(command[2].ToString(), out colPlayer)
                        && rowPlayer < playgroundField.GetLength(0) && colPlayer < playgroundField.GetLength(1))
                    {
                        command = "turn";
                    }
                }

                switch (command)
                {
                    case "top":
                        PrintRating();
                        break;
                    case "restart":
                        playgroundField = CreatePlaygroundField();
                        bombs = PutTheBombs();
                        PrintPlayGroundField(playgroundField);
                        break;
                    case "exit":
                        Console.WriteLine("Bye, bye, bye!");
                        break;
                    case "turn":
                        if (bombs[rowPlayer, colPlayer] != '*')
                        {
                            if (bombs[rowPlayer, colPlayer] == '-')
                            {
                                SetPlayerOnEnteredPositon();
                                currentPlayer.Score++;
                            }

                            if (MaxTurns == currentPlayer.Score)
                            {
                                PrintWinGameMessage();
                                PrintPlayGroundField(bombs);
                                PrintRating();
                                gameStarted = false;
                            }
                            else
                            {
                                PrintPlayGroundField(playgroundField);
                            }
                        }
                        else
                        {
                            PrintPlayGroundField(bombs);
                            PrintLostGameMessage();
                            PrintRating();
                            gameStarted = false;
                        }

                        break;
                    default:
                        Console.WriteLine("\nInvalid command! Please enter again!\n");
                        break;
                }
            }
            while (command != "exit");

            Console.WriteLine("Made in Bulgaria - Uauahahahahaha!");
            Console.WriteLine("Have a nice day!");
        }
예제 #54
0
 public FindShortestAtoB(char[,] matrix)
 {
     Matrix   = matrix;
     rowCount = matrix.GetLength(0);
     colCount = matrix.GetLength(1);
 }
예제 #55
0
        static void NovaIgra()
        {
            gameInProgress = true;
            cellsOpened = 0;

            playerMatrix = new char[5, 10];
            matrica = new char[5, 10];

            matrica = GenerateMinesweeperMatrix();
            for (int i = 0; i < playerMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < playerMatrix.GetLength(1); j++)
                {
                    playerMatrix[i, j] = '?';
                }
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Welcome to the game “Minesweeper”. Try to reveal all cells without mines. " +
                              "Use 'top' to view the scoreboard, 'restart' to start a new game and 'exit' " +
                              "to quit the game.");
            Console.WriteLine();

            PrintMatrix(playerMatrix);

            while (gameInProgress)
                //abe typo izglejda ama ako napravq metod shte zaema mn mqsto
                //kakvo pravq? -cheta dokat moga
            {
                procheti();
            }
        }
예제 #56
0
 /// <summary>
 /// class constructor that sets initial variable values
 /// </summary>
 /// <param name="mapData">2 dimensional char array containing data of all points on the map</param>
 /// <param name="mapSize">size of the map matrix</param>
 public Map(char[,] mapData, int mapSize)
 {
     MapData = mapData;
     MapSize = mapSize;
 }
예제 #57
0
 static void RemoveElement(ref char[,] map, int elementX, int elementY)
 {
     map[elementX, elementY] = ' ';
 }
예제 #58
0
        static void Main(string[] args)
        {
            Console.Write("Введите строку: ");
            string str = Console.ReadLine();

            char[,] mas = StringToMatrix(str);
            int size = Convert.ToInt32(Math.Sqrt(str.Length));
            //Console.WriteLine(MatrixToString(mas));
            List <int>    l       = new List <int>();
            List <string> results = new List <string>();

            String[] imp_combs = { "__", "_Ы", "ЁЯ", "ЁЬ", "ЁЭ", "ЪЖ", "ЭЁ", "ЪД", "ЦЁ", "УЬ", "ЩЧ", "ЧЙ",
                                   "ШЙ", "ШЗ", "ЫФ", "ЖЩ", "ЖШ", "ЖЦ", "ЫЪ", "ЫЭ", "ЫЮ", "ЫЬ", "ЖЙ", "ЫЫ","ЖЪ",
                                   "ЖЫ", "ЪШ", "ПЙ", "ЪЩ", "ЗЩ", "ЪЧ", "ЪЦ", "ЪУ", "ЪФ", "ЪХ", "ЪЪ", "ЪЫ","ЫО",
                                   "ЖЯ", "ЗЙ", "ЪЬ", "ЪЭ", "ЫА", "НЙ", "ЕЬ", "ЦЙ", "ЬЙ", "ЬЛ", "ЬР", "ПЪ","ЕЫ",
                                   "ЕЪ", "ЬА", "ШЪ", "ЁЫ", "ЁЪ", "ЪТ", "ЩС", "ОЬ", "КЪ", "ОЫ", "ЩХ", "ЩЩ","ЩЪ",
                                   "ЩЦ", "КЙ", "ОЪ", "ЦЩ", "ЛЪ", "МЙ", "ШЩ", "ЦЬ", "ЦЪ", "ЩЙ", "ЙЬ", "ЪГ","ИЪ",
                                   "ЪБ", "ЪВ", "ЪИ", "ЪЙ", "ЪП", "ЪР", "ЪС", "ЪО", "ЪН", "ЪК", "ЪЛ", "ЪМ","ИЫ",
                                   "ИЬ", "ЙУ", "ЩЭ", "ЙЫ", "ЙЪ", "ЩЫ", "ЩЮ", "ЩЯ", "ЪА", "МЪ", "ЙЙ", "ЙЖ","ЬУ",
                                   "ГЙ", "ЭЪ", "УЪ", "АЬ", "ЧЪ", "ХЙ", "ТЙ", "ЧЩ", "РЪ", "ЮЪ", "ФЪ", "УЫ","АЪ",
                                   "ЮЬ", "АЫ", "ЮЫ", "ЭЬ", "ЭЫ", "БЙ", "ЯЬ", "ЬЫ", "ЬЬ", "ЬЪ", "ЯЪ", "ЯЫ","ХЩ",
                                   "ДЙ", "ФЙ" };

            for (int i = 1; i <= size; i++)
            {
                l.Add(i);
            }
            IEnumerable <List <int> > lst = AllCombinations(l, new List <int>());

            foreach (var b in lst)
            {
                int[] list = new int[size];
                int   i    = 0;
                foreach (var a in b)
                {
                    list[i] = a;
                    i++;
                }
                results.Add(MatrixToString(Rearrange(mas, list)));
            }
            Console.WriteLine("    До обработки: " + results.Count + " элементов");
            List <string> results_sorted = new List <string>();
            var           pattern        = @"(.)\1{2}";

            foreach (string res in results)
            {
                int i = 0;
                foreach (string impc in imp_combs)
                {
                    if (res.Contains(impc) || res.First() == '_' || res.Last() == '_' || Regex.IsMatch(res, pattern))
                    {
                        i++;
                    }
                }
                if (i == 0)
                {
                    results_sorted.Add(res);
                }
            }

            Console.WriteLine("    После обработки: " + results_sorted.Count + " элементов");
            Console.ReadLine();
            foreach (string res in results_sorted)
            {
                Console.WriteLine(res);
            }
            Console.WriteLine("-------------------------");
            Console.ReadLine();
            foreach (string res in results)
            {
                Console.WriteLine(res);
            }
            Console.ReadLine();
        }
예제 #59
0
        public void Run()
        {
            do
            {
                if (!this.isRunning)
                {
                    this.renderer.WriteLine("Welcome to Minesweeper! Try to find all cells that do not contain a mine.\n" +
                                      "The 'top' command shows the highscores, 'restart' starts a new game,\n" +
                                      "'exit' stops the game.");
                    this.DrawPlayField(this.playField);
                    this.isRunning = true;
                }

                this.renderer.Write("Please provide row and column numbers: ");
                this.command = this.renderer.ReadLine().Trim();
                if (this.command.Length >= 3)
                {
                    if (int.TryParse(this.command[0].ToString(), out this.row) && int.TryParse(this.command[2].ToString(), out this.column)
                        && this.row <= this.playField.GetLength(0) && this.column <= this.playField.GetLength(1))
                    {
                        this.command = "turn";
                    }
                }

                switch (this.command)
                {
                    case "top":
                        this.ShowHighScores(this.highscores);
                        break;
                    case "restart":
                        this.playField = CreatePlayField();
                        this.mineField = PopulateMinesInField();
                        this.DrawPlayField(this.playField);
                        this.isPlayerAlive = true;
                        this.isRunning = true;
                        break;
                    case "exit":
                        this.renderer.WriteLine("Bye-bye!");
                        break;
                    case "turn":
                        if (this.mineField[this.row, this.column] != '*')
                        {
                            if (this.mineField[this.row, this.column] == '-')
                            {
                                this.ProcessGameTurn(this.playField, this.mineField, this.row, this.column);
                                this.currentPoints++;
                            }

                            if (MaxNumberOfMines == this.currentPoints)
                            {
                                this.areAllMinesFound = true;
                            }
                            else
                            {
                                this.DrawPlayField(this.playField);
                            }
                        }
                        else
                        {
                            this.isPlayerAlive = false;
                        }

                        break;
                    default:
                        this.renderer.WriteLine("\nInvalid command.\n");
                        break;
                }

                if (!this.isPlayerAlive)
                {
                    this.DrawPlayField(this.mineField);
                    this.renderer.Write(string.Format("\nOh noes! You've stepped on a mine! Your score is {0}. " + "Enter your name: ", this.currentPoints));
                    string name = this.renderer.ReadLine();
                    IPlayer t = new Player(name, this.currentPoints);
                    if (this.highscores.Count < 5)
                    {
                        this.highscores.Add(t);
                    }
                    else
                    {
                        for (int i = 0; i < this.highscores.Count; i++)
                        {
                            if (this.highscores[i].Points < t.Points)
                            {
                                this.highscores.Insert(i, t);
                                this.highscores.RemoveAt(this.highscores.Count - 1);
                                break;
                            }
                        }
                    }

                    this.highscores.Sort((IPlayer r1, IPlayer r2) => r2.Name.CompareTo(r1.Name));
                    this.highscores.Sort((IPlayer r1, IPlayer r2) => r2.Points.CompareTo(r1.Points));
                    this.ShowHighScores(this.highscores);

                    this.playField = CreatePlayField();
                    this.mineField = PopulateMinesInField();
                    this.currentPoints = 0;
                    this.isPlayerAlive = true;
                    this.isRunning = false;
                }

                if (this.areAllMinesFound)
                {
                    this.renderer.WriteLine("\nCongratulations! You've opened 35 cells without stepping on a mine!");
                    this.DrawPlayField(this.mineField);
                    this.renderer.WriteLine("Enter your name: ");
                    string name = this.renderer.ReadLine();
                    IPlayer player = new Player(name, this.currentPoints);
                    this.highscores.Add(player);
                    this.ShowHighScores(this.highscores);
                    this.playField = CreatePlayField();
                    this.mineField = PopulateMinesInField();
                    this.currentPoints = 0;
                    this.areAllMinesFound = false;
                    this.isRunning = false;
                }
            }
            while (this.command != "exit");

            this.renderer.Read();
        }
예제 #60
0
        static void Main(string[] args)
        {
            int          playerX = 1, playerY = 1;
            int          coinX, coinY;
            int          bombX, bombY;
            bool         isGameNotEnd   = true;
            bool         playerNotDraw  = true;
            bool         isBombPlanted  = false;
            int          coinsOnMap     = 0;
            int          coinsCollected = 0;
            int          score          = 0;
            int          bombsLeft      = 5;
            char         coinSymbol     = '$';
            char         playerSymbol   = '@';
            char         bombSymbol     = '*';
            char         wallSymbol     = '#';
            ConsoleColor playerColor    = ConsoleColor.Green;
            ConsoleColor coinColor      = ConsoleColor.Yellow;
            ConsoleColor bombColor      = ConsoleColor.Red;

            char[,] map = ReadMap("map1");
            DrawMap(map);
            Console.CursorVisible = false;

            while (coinsOnMap < 10)
            {
                coinX = GetCoordinate(map.GetLength(0));
                coinY = GetCoordinate(map.GetLength(1));
                if (map[coinX, coinY] == ' ')
                {
                    map[coinX, coinY] = coinSymbol;
                    DrawElementOnMap(coinX, coinY, coinSymbol, coinColor);
                    coinsOnMap++;
                }
            }

            while (playerNotDraw)
            {
                playerX = GetCoordinate(map.GetLength(0));
                playerY = GetCoordinate(map.GetLength(1));
                if (map[playerX, playerY] == ' ' && map[playerX, playerY] != coinSymbol)
                {
                    DrawElementOnMap(playerX, playerY, playerSymbol, playerColor);
                    playerNotDraw = false;
                }
            }

            while (isGameNotEnd)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo keyPressed = Console.ReadKey(true);
                    switch (keyPressed.Key)
                    {
                    case ConsoleKey.UpArrow:
                        if (map[playerX - 1, playerY] != wallSymbol)
                        {
                            RemoveElement(playerX, playerY);
                            DrawElementOnMap(--playerX, playerY, playerSymbol, playerColor);
                        }
                        break;

                    case ConsoleKey.DownArrow:
                        if (map[playerX + 1, playerY] != wallSymbol)
                        {
                            RemoveElement(playerX, playerY);
                            DrawElementOnMap(++playerX, playerY, playerSymbol, playerColor);
                        }
                        break;

                    case ConsoleKey.LeftArrow:
                        if (map[playerX, playerY - 1] != wallSymbol)
                        {
                            RemoveElement(playerX, playerY);
                            DrawElementOnMap(playerX, --playerY, playerSymbol, playerColor);
                        }
                        break;

                    case ConsoleKey.RightArrow:
                        if (map[playerX, playerY + 1] != wallSymbol)
                        {
                            RemoveElement(playerX, playerY);
                            DrawElementOnMap(playerX, ++playerY, playerSymbol, playerColor);
                        }
                        break;

                    case ConsoleKey.Spacebar:
                        if (!isBombPlanted && bombsLeft > 0)
                        {
                            map[playerX, playerY] = bombSymbol;
                            isBombPlanted         = true;
                            bombsLeft--;
                        }
                        break;

                    case ConsoleKey.Enter:
                        if (isBombPlanted)
                        {
                            GetCoordinate(map, bombSymbol, out bombX, out bombY);
                            for (int i = bombX - 1; i < bombX + 2; i++)
                            {
                                for (int j = bombY - 1; j < bombY + 2; j++)
                                {
                                    if (i < map.GetLength(0) - 1 && j < map.GetLength(1) - 1)
                                    {
                                        if (map[i, j] == wallSymbol)
                                        {
                                            score += 50;
                                        }
                                        RemoveElement(ref map, i, j);
                                        RemoveElement(i, j);
                                        if (playerX == i && playerY == j)
                                        {
                                            isGameNotEnd = false;
                                            GameResult(2);
                                        }
                                    }
                                }
                            }
                            isBombPlanted = false;
                        }
                        break;

                    case ConsoleKey.Escape:
                        isGameNotEnd = false;
                        break;
                    }
                }

                if (isBombPlanted)
                {
                    GetCoordinate(map, bombSymbol, out bombX, out bombY);
                    DrawElementOnMap(bombX, bombY, bombSymbol, bombColor);
                }

                if (map[playerX, playerY] == coinSymbol)
                {
                    RemoveElement(ref map, playerX, playerY);
                    coinsCollected++;
                    score += 100;
                }

                if (coinsCollected == coinsOnMap)
                {
                    isGameNotEnd = false;
                    GameResult(1);
                }

                WriteScore(map, score, coinsCollected, bombsLeft);
            }
            Console.ReadKey();
        }