Exemplo n.º 1
0
        private void GameSetUp()
        {
            // this function will run when the program loads

            MyCanvas.Focus();                                   // set my canvas as the main focus for the program

            gameTimer.Tick    += GameLoop;                      // link the game loop event to the time tick
            gameTimer.Interval = TimeSpan.FromMilliseconds(20); // set time to tick every 20 milliseconds
            gameTimer.Start();                                  // start the time
            currentGhostStep = ghostMoveStep;                   // set current ghost step to the ghost move step

            // below pac man and the ghosts images are being imported from the images folder and then we are assigning the image brush to the rectangles
            ImageBrush pacmanImage = new ImageBrush();

            pacmanImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/pacman.jpg"));
            pacman.Fill             = pacmanImage;

            ImageBrush redGhost = new ImageBrush();

            redGhost.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/red.jpg"));
            redGuy.Fill          = redGhost;

            ImageBrush orangeGhost = new ImageBrush();

            orangeGhost.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/orange.jpg"));
            orangeGuy.Fill          = orangeGhost;

            ImageBrush pinkGhost = new ImageBrush();

            pinkGhost.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/pink.jpg"));
            pinkGuy.Fill          = pinkGhost;
        }
        private void StartGame()
        {
            MyCanvas.Focus();
            int temp = 300;

            score    = 0;
            gameOver = false;
            Canvas.SetTop(flappyBird, 190);

            foreach (var x in MyCanvas.Children.OfType <Image>())
            {
                if ((string)x.Tag == "obs1")
                {
                    Canvas.SetLeft(x, 500);
                }
                if ((string)x.Tag == "obs2")
                {
                    Canvas.SetLeft(x, 800);
                }
                if ((string)x.Tag == "obs3")
                {
                    Canvas.SetLeft(x, 1100);
                }
                if ((string)x.Tag == "clouds")
                {
                    Canvas.SetLeft(x, 300 + temp);
                    temp = 800;
                }

                gameTimer.Start();
            }
        }
Exemplo n.º 3
0
        public MainWindow(string nazwaGracza)
        {
            InitializeComponent();

            nazGracza = nazwaGracza;

            licznikGry.Interval = TimeSpan.FromMilliseconds(20);
            licznikGry.Tick    += petla;
            licznikGry.Start();

            MyCanvas.Focus(); //zeby onkeje zastartowaly

            ImageBrush tło = new ImageBrush();

            tło.ImageSource     = new BitmapImage(new Uri("pack://application:,,,/obiekty/purple.png"));
            tło.TileMode        = TileMode.Tile;
            tło.Viewport        = new Rect(0, 0, 0.15, 0.15);
            tło.ViewportUnits   = BrushMappingMode.RelativeToBoundingBox;
            MyCanvas.Background = tło;

            ImageBrush ObGracza = new ImageBrush();

            ObGracza.ImageSource = new BitmapImage(new Uri("pack://application:,,,/obiekty/player.png"));
            gracz.Fill           = ObGracza;
        }
        /// <summary>
        /// Starts application
        /// </summary>
        private void StartGame()
        {
            MyCanvas.Focus();

            int temp = 300;

            score = 0;

            gameOver = false;

            Canvas.SetTop(flappyBird, 190);                       // default position once started

            foreach (var x in MyCanvas.Children.OfType <Image>()) // any item apart of the game will have a loop
            {
                if ((string)x.Tag == "obs1")                      // first pipe item obstacle
                {
                    Canvas.SetLeft(x, 500);
                }
                if ((string)x.Tag == "obs2") // second pipe obstacle
                {
                    Canvas.SetLeft(x, 800);
                }
                if ((string)x.Tag == "obs3") // third pipe obstacle
                {
                    Canvas.SetLeft(x, 1100);
                }
                if ((string)x.Tag == "cloud") // background cloud item
                {
                    Canvas.SetLeft(x, 300 + temp);
                    temp = 800;
                }
            }

            gameTimer.Start();
        }
Exemplo n.º 5
0
        private void StartGame() //Klass som håller koll på om spelet ska startas och hur.
        {
            MyCanvas.Focus();

            int temp = 300;

            score = 0; //Startar med score:0

            gameover = false;
            Canvas.SetTop(flappyBird, 190);                       //Startar med fågeln på en höjd av 190

            foreach (var x in MyCanvas.Children.OfType <Image>()) // En loop där alla eliment som är en bild går igenom
            {
                if ((string)x.Tag == "obs1")                      //Gör så att tuberna samt målnen rör sig in i bilden.
                {
                    Canvas.SetLeft(x, 500);
                }
                if ((string)x.Tag == "obs2")
                {
                    Canvas.SetLeft(x, 800);
                }
                if ((string)x.Tag == "obs3")
                {
                    Canvas.SetLeft(x, 1100);
                }

                if ((string)x.Tag == "cloud")
                {
                    Canvas.SetLeft(x, 300 + temp);
                    temp = 800;
                }
            }

            gameTimer.Start();
        }
        //MAIN WINDOW INITIALIZE
        public AsteroidShooter()
        {
            InitializeComponent();

            gameTimer.Interval = TimeSpan.FromMilliseconds(20);

            //Link The Game Engine To The Game Timer & Start
            gameTimer.Tick += gameEngine;
            gameTimer.Start();
            MyCanvas.Focus();

            //Initialize The Main Window Canvas Background Using An Image
            ImageBrush backgroundImage = new ImageBrush();

            backgroundImage.ImageSource   = new BitmapImage(new Uri("pack://application:,,,/Images/Background.png"));
            backgroundImage.TileMode      = TileMode.Tile;
            backgroundImage.Viewport      = new Rect(0, 0, 0.15, 0.15);
            backgroundImage.ViewportUnits = BrushMappingMode.RelativeToBoundingBox;
            MyCanvas.Background           = backgroundImage;


            //Initialize The Player Sprite
            ImageBrush playerImage = new ImageBrush();

            playerImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Player.png"));
            player.Fill             = playerImage;
        }
        public MainWindow()
        {
            InitializeComponent();

            MyCanvas.Focus();

            this.Cursor = Cursors.None;

            backgroundImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/background.png"));
            MyCanvas.Background         = backgroundImage;

            scopeImage.Source           = new BitmapImage(new Uri("pack://application:,,,/images/sniper-aim.png"));
            scopeImage.IsHitTestVisible = false;

            ghostSprite.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/ghost.png"));

            DummyMoveTimer.Tick    += DummyMoveTick;
            DummyMoveTimer.Interval = TimeSpan.FromMilliseconds(rand.Next(800, 2000));
            DummyMoveTimer.Start();

            showGhostTimer.Tick    += GhostAnimation;
            showGhostTimer.Interval = TimeSpan.FromMilliseconds(20);
            showGhostTimer.Start();

            topLocation = new List <int> {
                270, 540, 23, 540, 270, 23
            };
            bottomLocation = new List <int> {
                128, 678, 420, 678, 128, 420
            };
        }
Exemplo n.º 8
0
        private void GameSetUp()
        {
            //this function will run when the program loads
            MyCanvas.Focus(); //set my canvas as the main focus for the program

            gameTimer.Tick += GameLoop; //link the game loop event to the time tick
            gameTimer.Interval = TimeSpan.FromMilliseconds(20);
            gameTimer.Start();
            currentGhostStep = ghostMoveStep;

            ImageBrush pacmanImage = new ImageBrush();
            pacmanImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/pacman.jpg"));
            pacman.Fill = pacmanImage;

            ImageBrush redGhost = new ImageBrush();
            redGhost.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/red.jpg"));
            redGuy.Fill = redGhost;

            ImageBrush orangeGhost = new ImageBrush();
            orangeGhost.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/orange.jpg"));
            orangeGuy.Fill = orangeGhost;

            ImageBrush pinkGhost = new ImageBrush();
            pinkGhost.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/pink.jpg"));
            pinkGuy.Fill = pinkGhost;
        }
Exemplo n.º 9
0
        public MainWindow()
        {
            InitializeComponent();

            gameTimer.Interval = TimeSpan.FromMilliseconds(20);
            gameTimer.Tick    += GameLoop;
            gameTimer.Start();

            MyCanvas.Focus();

            ImageBrush bg = new ImageBrush();

            bg.ImageSource =
                new BitmapImage(
                    new Uri("pack://application:,,,/Images/purple.png"));
            bg.TileMode         = TileMode.Tile;
            bg.Viewport         = new Rect(0, 0, 0.15, 0.15);
            bg.ViewportUnits    = BrushMappingMode.RelativeToBoundingBox;
            MyCanvas.Background = bg;

            ImageBrush playerImage = new ImageBrush();

            playerImage.ImageSource =
                new BitmapImage(new Uri("pack://application:,,,/Images/player.png"));
            Player.Fill = playerImage;
        }
Exemplo n.º 10
0
        /// <summary>
        /// This method starts the game and makes the canvas the focus of the program so it runs faster.
        /// It also resets the game after a game over.
        /// It also contains a for each loop that loops through all the images and then it specifice what we want to move and where to move it through tags.
        /// Starts the gametimer.
        /// </summary>
        private void StartGame()
        {
            MyCanvas.Focus();

            int temp = 300;

            score = 0;

            gameOver = false;
            Canvas.SetTop(flappyBird, 190);
            //Loops through if statements that contain iamges and checks the obstacale and clouds and moves them to their starter position.
            foreach (var x in MyCanvas.Children.OfType <Image>())
            {
                if ((string)x.Tag == "obs1")
                {
                    Canvas.SetLeft(x, 500);
                }
                if ((string)x.Tag == "obs2")
                {
                    Canvas.SetLeft(x, 800);
                }
                if ((string)x.Tag == "obs3")
                {
                    Canvas.SetLeft(x, 1100);
                }
                if ((string)x.Tag == "cloud")
                {
                    Canvas.SetLeft(x, 300 + temp);
                    temp = 800;
                }
            }

            gameTimer.Start();
        }
Exemplo n.º 11
0
        private void aloitaPeli()
        {
            MyCanvas.Focus();

            int temp = 300;

            peliPaattyi = false;
            Canvas.SetTop(Lintu, 190);

            foreach (var x in MyCanvas.Children.OfType <Image>())
            {
                if ((string)x.Tag == "este1")
                {
                    Canvas.SetLeft(x, 500);
                }

                if ((string)x.Tag == "este2")
                {
                    Canvas.SetLeft(x, 800);
                }

                if ((string)x.Tag == "este3")
                {
                    Canvas.SetLeft(x, 1100);
                }

                if ((string)x.Tag == "cloud")
                {
                    Canvas.SetLeft(x, 300 + temp);
                    temp = 800;
                }
            }

            peliAika.Start();
        }
Exemplo n.º 12
0
        // Will make to custom functions.

        private void GameSetUp()
        {
            MyCanvas.Focus();

            gameTimer.Tick    += GameLoop;
            gameTimer.Interval = TimeSpan.FromMilliseconds(20);
            gameTimer.Start();
            currentGhostStep = ghostMoveStep;

            // Import images.

            ImageBrush pacmanImage = new ImageBrush();

            pacmanImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/pacman.jpg"));
            pacman.Fill             = pacmanImage;

            ImageBrush redGhost = new ImageBrush();

            redGhost.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/red.jpg"));
            redGuy.Fill          = redGhost;

            ImageBrush pinkGhost = new ImageBrush();

            pinkGhost.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/pink.jpg"));
            pinkGuy.Fill          = pinkGhost;

            ImageBrush orangeGhost = new ImageBrush();

            orangeGhost.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/orange.jpg"));
            orangeGuy.Fill          = orangeGhost;
        }
Exemplo n.º 13
0
 public MainWindow()
 {
     InitializeComponent();
     MyCanvas.Focus();
     gametimer.Tick    += GameLoop;
     gametimer.Interval = TimeSpan.FromMilliseconds(20);
     StartGame();
 }
Exemplo n.º 14
0
        private void StartGame()
        {
            MyCanvas.Focus();

            gameOver = false;

            Canvas.SetLeft(F1, 220);

            lifes = 1;

            dis = 0;

            foreach (var y in MyCanvas.Children.OfType <Image>())
            {
                if ((string)y.Tag == "Line1")
                {
                    Canvas.SetTop(y, 300);
                }

                if ((string)y.Tag == "Line2")
                {
                    Canvas.SetTop(y, 210);
                }

                if ((string)y.Tag == "Line3")
                {
                    Canvas.SetTop(y, 120);
                }

                if ((string)y.Tag == "Line4")
                {
                    Canvas.SetTop(y, 30);
                }
                if ((string)y.Tag == "Line5")
                {
                    Canvas.SetTop(y, -60);
                }

                if ((string)y.Tag == "car1")
                {
                    Canvas.SetTop(y, -400);
                }
                if ((string)y.Tag == "car2")
                {
                    Canvas.SetTop(y, -100);
                }
                if ((string)y.Tag == "car3")
                {
                    Canvas.SetTop(y, -340);
                }
                if ((string)y.Tag == "car4")
                {
                    Canvas.SetTop(y, -200);
                }
            }
            gameTimer.Start();
        }
Exemplo n.º 15
0
        public MainWindow()
        {
            InitializeComponent();

            gameTimer.Interval = TimeSpan.FromMilliseconds(15);
            gameTimer.Tick    += GameLoop;
            gameTimer.Start();

            MyCanvas.Focus();

            MyCanvas.Background = SpriteFactory.getSprite("background").getImageBrush();

            player.Fill = SpriteFactory.getSprite("player").getImageBrush();
        }
Exemplo n.º 16
0
        public MainWindow()
        {
            InitializeComponent();
            MyCanvas.Focus();

            gameTimer.Tick    += GameEngine;
            gameTimer.Interval = TimeSpan.FromMilliseconds(20);

            backgroundSprite.ImageSource = new BitmapImage(new Uri(@"C:\Users\bajer\Documents\Portfolio\.NET\Runner Game\Assets\background.gif"));

            background.Fill  = backgroundSprite;
            background2.Fill = backgroundSprite;

            StartGame();
        }
        public MainWindow()
        {
            InitializeComponent();

            MyCanvas.Focus();

            gameTimer.Tick    += GameEngine;
            gameTimer.Interval = TimeSpan.FromMilliseconds(20);
            gameTimer.Start();

            playerImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/netLeft.png"));
            player1.Fill            = playerImage;

            backgroundImage.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/background.jpg"));
            MyCanvas.Background         = backgroundImage;
        }
Exemplo n.º 18
0
        int score = 0;                                        // återställer eller gör så att sitt score alltid börjar på 0.


        public MainWindow()  // detta är de principer spelet följer när det har startats.
        {
            InitializeComponent();

            MyCanvas.Focus();

            gameTimer.Tick    += GameEngine;
            gameTimer.Interval = TimeSpan.FromMilliseconds(20);

            backgroundSprite.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/background.gif"));

            background.Fill  = backgroundSprite;
            background2.Fill = backgroundSprite;

            StartGame();
        }
Exemplo n.º 19
0
        public MainWindow()
        {
            InitializeComponent();

            MyCanvas.Focus();

            gameTimer.Tick    += GameEngine;
            gameTimer.Interval = TimeSpan.FromMilliseconds(20);

            backgroundSprite.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/background.gif"));

            background.Fill  = backgroundSprite;
            background2.Fill = backgroundSprite;

            Startgame();
        }
Exemplo n.º 20
0
        /// <summary>
        /// Game constructor, creates an instance of a game
        /// </summary>
        public Game(User user)
        {
            client = new FireSharp.FirebaseClient(config);

            FirebaseResponse          response = client.Get("Users/");
            Dictionary <string, User> result   = response.ResultAs <Dictionary <string, User> >();

            //balanceValue.Content = "init";

            foreach (var get in result)
            {
                //string userId = get.Value.Id.ToString().Substring(1, get.Value.Id.ToString().Length - 2) ;
                //string userId = get.Value.Id.ToString() ;
                string db_name        = get.Value.Username.ToString();
                string logged_in_name = user.Username;


                Console.WriteLine(logged_in_name);
                Console.WriteLine(db_name);
                if (db_name.Equals(logged_in_name))
                {
                    Player = user;
                    //balance_Value.Content = get.Value.Balance.ToString();
                    //Player = new User(get.Value.Username.ToString(), get.Value.Password.ToString(), get.Value.Bank.ToString(), get.Value.Iban.ToString(), get.Value.Id.ToString(), get.Value.Balance);
                }
            }



            InitializeComponent();

            MyCanvas.Focus();

            gameTimer.Tick    += GameEngine;
            gameTimer.Interval = TimeSpan.FromMilliseconds(0.01);

            backgroundSprite.ImageSource = new BitmapImage(new Uri("pack://application:,,,/images/background.gif"));

            background.Fill       = backgroundSprite;
            secondBackground.Fill = backgroundSprite;
            MyCanvas.Background   = backgroundSprite;

            StartGame();
        }
Exemplo n.º 21
0
 private void StartGame()
 {
     MyCanvas.Focus();
     score = 0;
     Canvas.SetTop(rec1, 470);
     obs1HitLine.X1 = 1500;
     obs1HitLine.X2 = 1500;
     obs1HitLine.Y1 = rand.Next(0, 800);
     obs1HitLine.Y2 = obs1HitLine.Y1 + 150;
     obs2HitLine.X1 = 2000;
     obs2HitLine.X2 = 2000;
     obs2HitLine.Y1 = rand.Next(0, 800);
     obs2HitLine.Y2 = obs2HitLine.Y1 + 150;
     obs3HitLine.X1 = 2500;
     obs3HitLine.X2 = 2500;
     obs3HitLine.Y1 = rand.Next(0, 800);
     obs3HitLine.Y2 = obs3HitLine.Y1 + 150;
     gameTimer.Start();
 }
Exemplo n.º 22
0
        public MainWindow()
        {
            InitializeComponent();
            gameTimer.Tick    += GameLoop;
            gameTimer.Interval = TimeSpan.FromMilliseconds(20);
            gameTimer.Start();
            MyCanvas.Focus();
            playerobj = new PlayerObject(72, 42, 400, 300, MyCanvas);
            int x = 0;

            for (int i = 0; i < 15; i++)
            {
                x += 1;
                if (x == 8)
                {
                    x = 1;
                }
                enemies.Add(new EnemyObject(30, 30, 50 + 35 * i, 50, MyCanvas, x));
            }
        }
Exemplo n.º 23
0
        public MainWindow()
        {
            InitializeComponent();

            // Focuses the keyboard interaction to the game window
            MyCanvas.Focus();

            // Manages time based on the DispatcherTimer class
            gameTimer.Tick    += GameEngine;
            gameTimer.Interval = TimeSpan.FromMilliseconds(20);

            // Uses the linked image as the background
            backgroundSprite.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images2/background.gif"));

            // Fills the rectangles in the XAML file with the background images
            background.Fill  = backgroundSprite;
            background2.Fill = backgroundSprite;

            // Runs the method StartGame()
            StartGame();
        }
Exemplo n.º 24
0
        /// <summary>
        /// The StartGame method set some variabels to 0 and moves the pipes to their original position. It also starts the gameTimer
        /// </summary>
        private void StartGame()
        {
            MyCanvas.Focus();

            int temp = 300;

            score = 0;

            gameOver = false;
            Canvas.SetTop(flappyBird, 190);


            //loops thru if statements in the canvas that first checks the obstacle and then moves different obstacels and clouds to their
            //original/correct position
            foreach (var x in MyCanvas.Children.OfType <Image>())
            {
                if ((string)x.Tag == "obs1")
                {
                    Canvas.SetLeft(x, 500);
                }

                if ((string)x.Tag == "obs2")
                {
                    Canvas.SetLeft(x, 800);
                }

                if ((string)x.Tag == "obs3")
                {
                    Canvas.SetLeft(x, 1100);
                }

                if ((string)x.Tag == "cloud")
                {
                    Canvas.SetLeft(x, 300 + temp);
                    temp = 800;
                }

                gameTimer.Start();
            }
        }
Exemplo n.º 25
0
        private void AloitaPeli()
        {
            MyCanvas.Focus();
            Pisteet     = 0;
            PeliPaattyi = false;
            Canvas.SetTop(Lintu, 190);

            foreach (var x in MyCanvas.Children.OfType <Image>())
            {
                if ((string)x.Tag == "obs1")
                {
                    Canvas.SetLeft(x, 500);
                }
                if ((string)x.Tag == "obs2")
                {
                    Canvas.SetLeft(x, 800);
                }
                if ((string)x.Tag == "obs3")
                {
                    Canvas.SetLeft(x, 1100);
                }
            }
            peliAika.Start();
        }
        private void StartGame()
        {
            MyCanvas.Focus();

            score = 0;

            gameOver = false;

            Canvas.SetLeft(vedro, 334);
            Canvas.SetTop(vedro, 410);


            foreach (var x in MyCanvas.Children.OfType <Image>())
            {
                if (x is Image && (string)x.Name == "kapla")
                {
                    Canvas.SetTop(x, rnd.Next(-600, -20));
                }

                if (x is Image && (string)x.Name == "kapla2")
                {
                    Canvas.SetTop(x, rnd.Next(-600, -20));
                }

                if (x is Image && (string)x.Name == "kapla3")
                {
                    Canvas.SetTop(x, rnd.Next(-600, -20));
                }

                if (x is Image && (string)x.Name == "kapla4")
                {
                    Canvas.SetTop(x, rnd.Next(-600, -20));
                }
            }
            gameTimer.Start();
        }