Exemple #1
0
        public Game(MainWindow mw, Canvas canvas, Canvas newBallCanvas)
        {
            this.mainWindow = mw;
            this.canvas = canvas;
            this.newBallCanvas = newBallCanvas;

            canvas.Children.Clear();
            newBallCanvas.Children.Clear();

            random = new Random();

            directions = new List<Point>();
            directions.Add(new Point(1, 0));
            directions.Add(new Point(-1, 0));
            directions.Add(new Point(0, 1));
            directions.Add(new Point(0, -1));

            balls = new List<Ball>();
            new_balls = new List<Ball>();

            board = new Ball[9, 9];

            for (int i = 0; i < 5; ++i)
            {
                Ball ball = new Ball(this, randomColor(), randomLocation());
                addBall(ball);
            }

            generateNewBalls();

            drawBalls();

            drawNewBalls();
        }
Exemple #2
0
        public void clickedTo(int x, int y)
        {
            if (ballMoving) return;

            if (selectedBall != null) selectedBall.stopAnimation();

            if (board[x, y] != null && board[x, y] == selectedBall)
            {
                selectedBall = null;
                return;
            }

            if (board[x, y] != null)
            {
                selectedBall = board[x, y];
                return;
            }

            if (selectedBall != null)
            {
                board[selectedBall.location.x, selectedBall.location.y] = null;
                ballMoving = true;
                last_point = new Point(x, y);
                selectedBall.moveTo(x, y);
                board[x, y] = selectedBall;
                selectedBall = null;
            }
        }
Exemple #3
0
 public void generateNewBalls()
 {
     new_balls.Clear();
     for (int i = 0; i < 3; ++i) {
         Ball ball = new Ball(this, randomColor());
         new_balls.Add(ball);
     }
 }
Exemple #4
0
 public void addBall(Ball ball)
 {
     balls.Add(ball);
     board[ball.location.x, ball.location.y] = ball;
 }