예제 #1
0
        private void timerAnim_Tick(object sender, EventArgs e)
        {
            Tuple <int, int> selectedDirection = player.GetOffset();

            xOffset = selectedDirection.Item2 * (animCount - 2) * SIDE / STEPS;
            yOffset = selectedDirection.Item1 * (animCount - 2) * SIDE / STEPS;
            if (animCount == 2)
            {
                canMove = true;
                timerAnim.Stop();
                if (player.X == WORLD_WIDTH && player.Y == 1)
                {
                    scoreTimer.Stop();
                    simpleSound.Stop();
                    Invalidate();
                    String message = "You beat the game in " + timePassed.ToString() + " seconds and won " + player.score.ToString() + " points!";
                    MessageBox.Show(message, "CONGRATULATIONS!");
                    NameInput nameInput = new NameInput();
                    nameInput.Show();
                    player.name = nameInput.name;
                    if (difficulty == DIFFICULTY.easy)
                    {
                        easyHighScores.Add(player);
                    }
                    if (difficulty == DIFFICULTY.medium)
                    {
                        mediumHighScores.Add(player);
                    }
                    if (difficulty == DIFFICULTY.hard)
                    {
                        hardHighScores.Add(player);
                    }

                    Close();
                }
            }
            else
            {
                animCount++;
            }
            Invalidate();
        }
예제 #2
0
        private void Camera(object sender, PaintEventArgs e)
        {
            lock (syncLock)
            {
                Graphics g = e.Graphics;
                player.Move();
                for (int k = 0; k < STEPS; k++)
                {
                    g.Clear(Color.White);
                    Tuple <int, int> selectedDirection = player.GetOffset();
                    int xOffset = selectedDirection.Item2 * (k - 2) * SIDE / STEPS;
                    int yOffset = selectedDirection.Item1 * (k - 2) * SIDE / STEPS;
                    for (int i = -3; i < 5; i++)
                    {
                        for (int j = -3; j < 5; j++)
                        {
                            if (outOfBounds(player.Y + i, player.X + j))
                            {
                                g.FillRectangle(brush, (j + 2) * SIDE + xOffset, (i + 2) * SIDE + yOffset, SIDE, SIDE);
                            }
                            else if (maze[player.Y + i, player.X + j])
                            {
                                g.FillRectangle(brush, (j + 2) * SIDE + xOffset, (i + 2) * SIDE + yOffset, SIDE, SIDE);
                            }
                            else if ((player.Y + i) == 1 && (player.X + j) == WORLD_WIDTH)
                            {
                                g.FillRectangle(doorBrush, (j + 2) * SIDE + xOffset, (i + 2) * SIDE + yOffset, SIDE, SIDE); //door
                            }
                        }
                    }
                    player.Draw(g);
                    // if (k!=STEPS-1)
                    Thread.Sleep(TIMER_INTERVAL);
                }


                if (player.X == WORLD_WIDTH && player.Y == 1)
                {
                    scoreTimer.Stop();
                    simpleSound.Stop();
                    String message = "You beat the game in " + timePassed.ToString() + " seconds and won " + player.score.ToString() + " points!";
                    MessageBox.Show(message, "CONGRATULATIONS!");
                    NameInput nameInput = new NameInput();
                    nameInput.Show();
                    player.name = nameInput.name;
                    if (difficulty == DIFFICULTY.easy)
                    {
                        easyHighScores.Add(player);
                    }
                    if (difficulty == DIFFICULTY.medium)
                    {
                        mediumHighScores.Add(player);
                    }
                    if (difficulty == DIFFICULTY.hard)
                    {
                        hardHighScores.Add(player);
                    }

                    Close();
                }

                canMove = true;
            }
        }