Exemple #1
0
 private void Timer_Tick(object sender, EventArgs e)
 {
     if (!UserPlayer.IsLevelSolved(UserPlayer.MyGame.LevelGroup, UserPlayer.MyGame.LevelNumber))
     {
         UserPlayer.MyGame.Grid.TimeElapsed += UserPlayer.MyGame.Grid.DefaultTick;
     }
     elapsedTimeLabel.Text = $"Time: {UserPlayer.MyGame.Grid.TimeElapsed:mm\\:ss}";
 }
Exemple #2
0
        private void resetButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are You Sure?", "Reset", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }
            UserPlayer.Levels.RegularLevels[UserPlayer.MyGame.LevelGroup][UserPlayer.MyGame.LevelNumber].Reset();
            connectedPipesLabel.Text    = $"Flows: 0/{UserPlayer.MyGame.Grid.Paths.Count}";
            elapsedTimeLabel.Text       = "Time: 00:00";
            pipeFinishedLabel.Text      = $"Pipe: {UserPlayer.MyGame.Grid.FinishedPercent}%";
            UserPlayer.ChangedSomething = true;
            Text = $"Flow - {UserPlayer.Name}*";

            UserPlayer.MyGame.Grid.TimeElapsed = new TimeSpan();
            if (UserPlayer.IsLevelSolved(UserPlayer.MyGame.LevelGroup, UserPlayer.MyGame.LevelNumber))
            {
                UserPlayer.SolvedLevels[UserPlayer.MyGame.LevelGroup].Remove(UserPlayer.MyGame.LevelNumber);
            }

            Invalidate();
        }
Exemple #3
0
        private void MainGameForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.X > 500) // level choosing
            {
                int groupOrLevel = UserPlayer.Levels.IsGroupOrLevelUnderMouse(e.X, e.Y, out int groupLevel);

                if (groupOrLevel > 0)
                {
                    UserPlayer.MyGame.LevelGroup  = groupLevel;
                    UserPlayer.MyGame.LevelNumber = 1;
                }
                else if (groupOrLevel < 0)
                {
                    UserPlayer.MyGame.LevelNumber = groupLevel;
                }

                if (UserPlayer.MyGame.LevelGroup * UserPlayer.MyGame.LevelNumber != 0)
                {
                    continueLabel.Visible  = false;
                    UserPlayer.MyGame.Grid =
                        UserPlayer.Levels.RegularLevels[UserPlayer.MyGame.LevelGroup][UserPlayer.MyGame.LevelNumber];
                    GridIsSet = true;
                    connectedPipesLabel.Text =
                        $"Flows: {UserPlayer.MyGame.Grid.BetterCompletedPipes.Values.Count(v => v)}/{UserPlayer.MyGame.Grid.Paths.Count}";
                    pipeFinishedLabel.Text = $"Pipe: {UserPlayer.MyGame.Grid.FinishedPercent}%";
                    if (Timer != null)
                    {
                        Timer.Tick -= Timer_Tick;
                    }
                    Timer = new Timer {
                        Interval = 1000
                    };
                    Timer.Tick += Timer_Tick;

                    if (!UserPlayer.IsLevelSolved(UserPlayer.MyGame.LevelGroup, UserPlayer.MyGame.LevelNumber))
                    {
                        elapsedTimeLabel.Text = "Time: 00:00";
                        UserPlayer.MyGame.Grid.TimeElapsed = new TimeSpan();
                    }

                    Timer.Start();
                    Invalidate();
                }

                return;
            }


            if (e.Button != MouseButtons.Left || !GridIsSet)
            {
                return;
            }
            var Cell = UserPlayer.MyGame.Grid.GetCellUnderMouse(e.X, e.Y);

            if (Cell.Color == Color.Black)
            {
                return;
            }

            if (UserPlayer.IsLevelSolved(UserPlayer.MyGame.LevelGroup, UserPlayer.MyGame.LevelNumber))
            {
                resetButton_Click(null, null);

                return;
            }

            MouseIsDown = true;
            UserPlayer.MyGame.FirstColor = Cell.Color;
            LastVisitedCell = UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].LastAddedCell;
            PrevCell        = Cell;

            if (Cell is InitialCell && UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.Count > 2)
            {
                var node = UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.First;

                while (node != null)
                {
                    var next = node.Next;

                    if (node.Value is InitialCell)
                    {
                        foreach (Cell[] row in UserPlayer.MyGame.Grid.Cells)
                        {
                            foreach (Cell cell in row)
                            {
                                if (Equals(cell, node.Value))
                                {
                                    node.Value.PipeDirection.Clear();
                                    node.Value.IsConnected   = false;
                                    node.Value.NumberOfPipes = 0;

                                    goto Outside;
                                }
                            }
                        }
                    }

                    if (node.Value is NormalCell)
                    {
                        UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.Remove(node);

                        foreach (Cell[] row in UserPlayer.MyGame.Grid.Cells)
                        {
                            foreach (Cell cell in row)
                            {
                                if (Equals(cell, node.Value))
                                {
                                    node.Value.PipeDirection.Clear();
                                    node.Value.Color         = Color.Black;
                                    node.Value.IsConnected   = false;
                                    node.Value.NumberOfPipes = 0;

                                    goto Outside;
                                }
                            }
                        }
                    }

Outside:

                    node = next;
                }

                connectedPipesLabel.Text =
                    $"Flows: {UserPlayer.MyGame.Grid.BetterCompletedPipes.Values.Count(v => v)}/{UserPlayer.MyGame.Grid.Paths.Count}";
                pipeFinishedLabel.Text = $"Pipe: {UserPlayer.MyGame.Grid.FinishedPercent}%";
            }
            else if (UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.Count > 2) // started
            {
                if (UserPlayer.MyGame.Grid.ColorUpDownStart[UserPlayer.MyGame.FirstColor] == 1)     // clear down
                {
                    var node = UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.Find(Cell)?.Next;

                    while (node?.Value is NormalCell)
                    {
                        var next = node.Next;
                        UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.Remove(node);

                        foreach (Cell[] row in UserPlayer.MyGame.Grid.Cells)
                        {
                            foreach (Cell cell in row)
                            {
                                if (Equals(cell, node.Value))
                                {
                                    node.Value.PipeDirection.Clear();
                                    node.Value.Color         = Color.Black;
                                    node.Value.IsConnected   = false;
                                    node.Value.NumberOfPipes = 0;

                                    goto Outside;
                                }
                            }
                        }

Outside:
                        node = next;
                    }
                }
                else // clear up
                {
                    var node = UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.Find(Cell)?.Previous;

                    while (node?.Value is NormalCell)
                    {
                        var prev = node.Previous;
                        UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.Remove(node);

                        foreach (Cell[] row in UserPlayer.MyGame.Grid.Cells)
                        {
                            foreach (Cell cell in row)
                            {
                                if (Equals(cell, node.Value))
                                {
                                    node.Value.PipeDirection.Clear();
                                    node.Value.Color         = Color.Black;
                                    node.Value.IsConnected   = false;
                                    node.Value.NumberOfPipes = 0;

                                    goto Outside;
                                }
                            }
                        }

Outside:
                        node = prev;
                    }
                }

                UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].Update();
                connectedPipesLabel.Text =
                    $"Flows: {UserPlayer.MyGame.Grid.BetterCompletedPipes.Values.Count(v => v)}/{UserPlayer.MyGame.Grid.Paths.Count}";
                pipeFinishedLabel.Text = $"Pipe: {UserPlayer.MyGame.Grid.FinishedPercent}%";
            }


            if (Equals(Cell, UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.First.Value))
            {
                UserPlayer.MyGame.Grid.ColorUpDownStart[UserPlayer.MyGame.FirstColor] = 1;
            }
            else if (Equals(Cell, UserPlayer.MyGame.Grid.Paths[UserPlayer.MyGame.FirstColor].PathList.Last.Value))
            {
                UserPlayer.MyGame.Grid.ColorUpDownStart[UserPlayer.MyGame.FirstColor] = -1;
            }

            Invalidate();
        }