Esempio n. 1
0
        //Initialize the playfield with lewels with random color
        public void InitPlayField(char symbol)
        {
            Random randColor = new Random();

            for (int i = 0; i < boxes.GetLength(0); i++)
            {
                for (int j = 0; j < boxes.GetLength(1); j++)
                {
                    Box box = new Box(i * 4 + 1, j * 4 + 1, symbol, colors[randColor.Next(0, colors.Length)]);
                    box.InitBox(symbol);
                    boxes[i, j] = box;
                }
            }
        }
Esempio n. 2
0
        //Load the last saved game, player and score from a file        
        public static void LoadGame(string filePath, PlayField playField, Player player)
        {
            try
            {
                StreamReader reader = new StreamReader(filePath);
                using (reader)
                {
                    player.Name = reader.ReadLine();
                    player.Score = int.Parse(reader.ReadLine());

                    for (int i = 0; i < playField.GetLength(0); i++)
                    {
                        string line = reader.ReadLine();
                        string[] currentLine = line.Trim().Split(' ');
                        int counter = 0;
                        for (int j = 0; j < currentLine.Length; j += 4)
                        {
                            int x = int.Parse(currentLine[j]);
                            int y = int.Parse(currentLine[j + 1]);
                            char symbol = char.Parse(currentLine[j + 2]);
                            ConsoleColor color = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), currentLine[j + 3]);
                            Box box = new Box(x, y, symbol, color);
                            box.InitBox(symbol);
                            playField[i, counter] = box;
                            counter++;
                        }
                    }
                }
            }
            catch (Exception)
            {
                Console.Clear();
                throw;
            }
        }
Esempio n. 3
0
        static void Swap(Box first, Box second)
        {
            int tempX = first.X;
            int tempY = first.Y;
            first.X = second.X;
            first.Y = second.Y;
            second.X = tempX;
            second.Y = tempY;

            selectionExist = false;
            first.isSelected = false;
            second.isSelected = false;
            first.DrawBox();
            second.DrawBox();

            Box tempJewel = playField[lastSelection[0], lastSelection[1]];
            playField[lastSelection[0], lastSelection[1]] = playField[cursorX, cursorY];
            playField[cursorX, cursorY] = tempJewel;
        }