public static void FrogAtSafeZone(Frog frog)
 {
     if (frog.Y == 24)
     {
         if (frog.WasInSafeZone == false)
         {
             frog.WasInSafeZone = true;
             frog.Score += 50;
         }
     }
 }
예제 #2
0
파일: Frogger.cs 프로젝트: banthar/frogger
        public FroggerScreen()
            : base(640, 480)
        {
            help_image = Image.FromFile(Config.GetDataDir() + "help.png");
            victory_image = Image.FromFile(Config.GetDataDir() + "victory.png");

            this.boards = new Stack<FroggerBoard>();

            this.boards.Push(BoardLoader.LoadBoard("main_board.conf"));

            this.frog = boards.Peek().Get<Frog>();
        }
예제 #3
0
파일: Engine.cs 프로젝트: hatrox/frogger
        public void AddObject(GameObject obj)
        {
            if (obj is Vehicle)
            {
                Vehicle tempVehicle = obj as Vehicle;
                for (int i = 0; i < tempVehicle.Length; i++)
                {
                    this.allObjects.Add(new Vehicle(new Coordinates(tempVehicle.TopLeft.Row, tempVehicle.TopLeft.Col + i), tempVehicle.Speed));
                }
            }
            else if (obj is Frog)
            {
                playerFrog = obj as Frog;
                this.frogStartingPosition = playerFrog.TopLeft;
            }

            this.allObjects.Add(obj);
        }
        public bool DetectCollisions(Frog frog, List<Figure> figures, List<Terrain> terrains)
        {
            CollisionDispater.frog = frog;
            Func<DrawableObject, bool> containsFrog = CollisionDispater.containsFrog;
            Terrain currentTerrain = (Terrain)terrains.Single(containsFrog);
            if (!currentTerrain.Passable())
            {
                if (!figures.Any(containsFrog))
                {
                    return true;
                }
            }
            // This check works only for figures consisted on one row
            bool hasCollision = figures.Any(figure => figure.IsObsticle() && frog.Y == figure.Y && frog.X + frog.Body[0].Length > figure.X && frog.X < figure.X + figure.Body[0].Length);
            if (hasCollision)
            {
                return true;
            }

            return false;
        }
예제 #5
0
        private static FroggerObject ObjectFromFields_real(FroggerBoard board, string[] fields)
        {
            FroggerObject fo = null;

            Point p = new Point(ParseFloat(fields[1]), ParseFloat(fields[2]));

            switch (fields[0].ToLower().Replace("_",""))
            {
                case "frog":
                    fo = new Frog(board, p);
                    break;
                case "rock":
                    fo = new Rock(board, p);
                    break;
                case "log":
                    fo = new Log(board, p);
                    fo.Go(new Point(ParseFloat(fields[3]), ParseFloat(fields[4])), float.PositiveInfinity);
                    break;
                case "littlefrog":
                    fo = new LittleFrog(board, p);
                    break;
                case "fly":
                    fo = new Fly(board, p);
                    break;
                case "leaf":
                    fo = new Leaf(board, p);
                    fo.Go(new Point(ParseFloat(fields[3]), ParseFloat(fields[4])), float.PositiveInfinity);
                    break;
                case "home":
                    fo = new Home(board, p);
                    break;
                case "bridge":
                    fo = new Bridge(board, p, fields[3]);
                    break;
                default:
                    return null;
            }

            return fo;
        }
        public static void FrogAtTop(Frog newFrog, ref int startReach, SoundPlayer frogSound, StringBuilder frogsAtTheTop1, StringBuilder frogsAtTheTop2, StringBuilder frogsAtTheTop3)
        {
            if (newFrog.ReachedTop > startReach)
            {
                //frogSound.Play();
                newFrog.Score        += 100;
                newFrog.WasInSafeZone = false;

                switch (startReach)
                {
                case 0:
                    frogsAtTheTop1.Append("           @ @  - Mmm!");
                    frogsAtTheTop2.Append("          \\(_)/");
                    frogsAtTheTop3.Append("           \\ / ");
                    break;

                case 1:
                    frogsAtTheTop1.Append("       @ @  - O Yeah!");
                    frogsAtTheTop2.Append("             \\(_)/");
                    frogsAtTheTop3.Append("              \\ / ");
                    break;

                case 2:
                    frogsAtTheTop1.Append("    @ @  - Keep");
                    frogsAtTheTop2.Append("             \\(_)/ going!");
                    frogsAtTheTop3.Append("              \\ / ");
                    break;

                case 3:
                    frogsAtTheTop1.Append("     @ @  - One More");
                    frogsAtTheTop2.Append("    \\(_)/ and you're");
                    frogsAtTheTop3.Append("            \\ /   done!");
                    break;
                }
                newFrog.speed -= 3;
                startReach++;
                Engine.speed++;
            }
        }
        public static void FrogAtTop(Frog newFrog, ref int startReach, SoundPlayer frogSound, StringBuilder frogsAtTheTop1, StringBuilder frogsAtTheTop2, StringBuilder frogsAtTheTop3)
        {
            if (newFrog.ReachedTop > startReach)
            {
                //frogSound.Play();
                newFrog.Score += 100;
                newFrog.WasInSafeZone = false;

                switch (startReach)
                {
                    case 0:
                        frogsAtTheTop1.Append("           @ @  - Mmm!");
                        frogsAtTheTop2.Append("          \\(_)/");
                        frogsAtTheTop3.Append("           \\ / ");
                        break;
                    case 1:
                        frogsAtTheTop1.Append("       @ @  - O Yeah!");
                        frogsAtTheTop2.Append("             \\(_)/");
                        frogsAtTheTop3.Append("              \\ / ");
                        break;
                    case 2:
                        frogsAtTheTop1.Append("    @ @  - Keep");
                        frogsAtTheTop2.Append("             \\(_)/ going!");
                        frogsAtTheTop3.Append("              \\ / ");
                        break;
                    case 3:
                        frogsAtTheTop1.Append("     @ @  - One More");
                        frogsAtTheTop2.Append("    \\(_)/ and you're");
                        frogsAtTheTop3.Append("            \\ /   done!");
                        break;
                }
                newFrog.speed -= 3;
                startReach++;
                Engine.speed++;
            }
        }
예제 #8
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //set remaining lives to label
            label_lives_left.Text = "LIVES LEFT: " + (game.to_loose - game.dead_frogs).ToString();

            //prepare a list of objects to delete (objects that got out of map)
            //cant remove them immidietally because of foreach loops
            List <MovingGameObject> to_remove = new List <MovingGameObject>();

            if (game.state == GameState.Running)
            {
                //spawn items based on set rules
                for (int i = 0; i < game.spawning.Length; i++)
                {
                    //process rules
                    string   spawn_rule = game.spawning[i];
                    string[] rules      = spawn_rule.Split(' ');

                    string type = rules[0];
                    //each object has a frequency in the rule, frequency means the object will spawn every n-th tick
                    int frequency;
                    //left or right
                    string where;

                    switch (type)
                    {
                    case "log":
                        frequency = int.Parse(rules[3]);
                        //not time to spawn
                        if (tick % frequency != 0)
                        {
                            break;
                        }
                        where = rules[1];
                        //length of the log
                        short length = short.Parse(rules[2]);

                        if (where == "left")
                        {
                            //spawn new log on left (negative x, so it doesn't appear all at once)
                            game.movingObjects.Add(new Log(game, 0 - length, i, length));
                        }
                        else
                        {
                            //spawn new log on right, last argument meaning movement in opposite direction
                            game.movingObjects.Add(new Log(game, game.tiles_horizontal - 1, i, length, true));
                        }
                        break;

                    case "car":
                        frequency = int.Parse(rules[2]);
                        if (tick % frequency != 0)
                        {
                            break;
                        }
                        where = rules[1];
                        if (where == "left")
                        {
                            //spawn new car on left
                            game.movingObjects.Add(new Car(game, -1, i));
                        }
                        else
                        {
                            //spawn new car on right, last argument meaning movement in opposite direction
                            game.movingObjects.Add(new Car(game, game.tiles_horizontal, i, true));
                        }
                        break;

                    //if incorrect or empty rule has been passed don't do anything
                    default:
                        break;
                    }
                }

                //draw game background
                game.bg.draw();

                //for detection if frog is on the log
                game.current_frog.on_log = false;

                //process every moving object
                foreach (var obj in game.movingObjects)
                {
                    //car
                    if (obj.GetType() == typeof(Car))
                    {
                        //car moves every 4th tick
                        if (tick % 4 == 0)
                        {
                            //move car
                            obj.move();
                            //if car got out of screen, prepare it for removal
                            if (obj.x == game.tiles_horizontal || obj.x == -1)
                            {
                                to_remove.Add(obj);
                            }
                        }
                        //draw car
                        obj.draw();
                    }
                    //log
                    else if (obj.GetType() == typeof(Log))
                    {
                        //convert MovingObject to Log because MovingObject doesn't have length attribute
                        Log log = (Log)obj;
                        //log moves every 4th tick
                        if (tick % 4 == 0)
                        {
                            //detect frog on the log
                            if (log.y == game.current_frog.y && (game.current_frog.x >= log.x && game.current_frog.x <= (log.x + log.length - 1)))
                            {
                                //move frog in the same direction
                                if (log.moving_left)
                                {
                                    game.current_frog.move_left();
                                }
                                else
                                {
                                    game.current_frog.move_right();
                                }
                            }
                            //move log
                            log.move();
                            //if log got out of screen, prepare it for removal
                            if (log.x == game.tiles_horizontal || log.x + log.length == -1)
                            {
                                to_remove.Add(log);
                            }
                        }
                        //detect frog on the log, duplicate because this needs to happen every tick
                        if (log.y == game.current_frog.y && (game.current_frog.x >= log.x && game.current_frog.x <= (log.x + log.length - 1)))
                        {
                            game.current_frog.on_log = true;
                        }
                        //draw log
                        log.draw();
                    }
                    //move and draw any other object, currently not any
                    else
                    {
                        obj.move();
                        obj.draw();
                    }
                }
                //draw every static object - lilypads, not active frogs
                foreach (var obj in game.staticObjects)
                {
                    obj.draw();
                }

                //kill frog that is in river but not on log
                if (game.background_tiles[game.current_frog.y] == "river" && !game.current_frog.on_log)
                {
                    game.state = GameState.FrogDead;
                }

                //move and draw active frog
                game.current_frog.move();
                game.current_frog.draw();

                //if frog reached last tile, check if it died - fell into water or won - landed on lilypad
                if (game.background_tiles[game.current_frog.y] == "river_end")
                {
                    bool dead = true;
                    //go through every statuc object, check only lilypads
                    foreach (var obj in game.staticObjects)
                    {
                        if (obj.GetType() == typeof(LilyPad))
                        {
                            //if there is frog on the lilypad, its not dead
                            if (obj.x == game.current_frog.x)
                            {
                                dead = false;
                            }
                        }
                    }
                    if (!dead)
                    {
                        //frog on lilypad
                        game.state = GameState.FrogOnLilypad;
                    }
                    else
                    {
                        //dead
                        game.state = GameState.FrogDead;
                    }
                }

                //go through every moving object, check if any car hit frog
                foreach (var obj in game.movingObjects)
                {
                    if (obj.GetType() == typeof(Car))
                    {
                        if (obj.x == game.current_frog.x && obj.y == game.current_frog.y)
                        {
                            //kill the frog
                            game.state = GameState.FrogDead;
                            //no need to continue
                            break;
                        }
                    }
                }

                //if frog got out of screen (only possible on log), kill it
                //checking x coordinate
                if (game.current_frog.x < 0 || game.current_frog.x >= game.tiles_horizontal)
                {
                    game.state = GameState.FrogDead;
                }
                //checking y coordinate
                else if (game.current_frog.y < 0 || game.current_frog.y >= game.tiles_vertical)
                {
                    game.state = GameState.FrogDead;
                }

                //finally remove every object that should be removed
                foreach (var obj in to_remove)
                {
                    game.movingObjects.Remove(obj);
                }

                //create new Graphics on the screen
                display_graphics = CreateGraphics();
                //display prepared bitmap
                display_graphics.DrawImage(bitmap, 0, 0);
                //reset pressed key, results in better movement
                game.key_pressed = KeyPressed.none;
                //increase tick counter
                tick++;
            }
            //frog died
            if (game.state == GameState.FrogDead)
            {
                //increase dead frog counter
                game.dead_frogs++;
                //if amount is reached game is over
                if (game.dead_frogs == game.to_loose)
                {
                    game.state = GameState.Loss;
                }
                //make a new frog
                else
                {
                    Frog new_frog = new Frog(game);
                    game.current_frog = new_frog;
                    game.state        = GameState.Running;
                }
            }
            //frog got onto lilypad
            if (game.state == GameState.FrogOnLilypad)
            {
                //make the frog static
                game.staticObjects.Add(game.current_frog);
                game.frog_wins++;
                //if all lilypads are full, game is won
                if (game.frog_wins == game.to_win)
                {
                    game.state = GameState.Win;
                }
                else
                {
                    //create a new frog
                    Frog new_frog = new Frog(game);
                    game.current_frog = new_frog;
                    game.state        = GameState.Running;
                }
            }
            //player won, game over
            if (game.state == GameState.Win)
            {
                //stop the game
                game.state = GameState.NotStarted;
                //display popup window
                MessageBox.Show("GAME WON!");
                //delete grpahics, restart the window into main menu
                this.Refresh();
                //show all menu buttons
                toggleMenuButtons();
                in_menu = true;
            }
            //player lost, game over
            if (game.state == GameState.Loss)
            {
                //stop the game
                game.state = GameState.NotStarted;
                //display popup window
                MessageBox.Show("GAME OVER!");
                //delete grpahics, restart the window into main menu
                this.Refresh();
                //show all menu buttons
                toggleMenuButtons();
                in_menu = true;
            }
        }
예제 #9
0
파일: Frogger.cs 프로젝트: banthar/frogger
        protected override void OnPaint()
        {
            if (is_help_visible)
            {
                this.DrawImage(help_image);
                return;
            }

            if (is_victory_visible)
            {
                this.DrawImage(victory_image);
                return;
            }

            Clear(0x2061af);

            float dt=((float)(System.Environment.TickCount-time))/1000.0f;
            time=System.Environment.TickCount;

            boards.Peek().Tick(dt);

            FroggerBoard board = boards.Peek();
            boards.Peek().Draw(this);

            if (board.State != BoardState.Active)
            {

                switch (board.State)
                {
                    case BoardState.InnerLevel:
                        Clear(0x000000);
                        boards.Push(board.inner_board);
                        break;
                    case BoardState.Lost:
                        Clear(0x880000);
                        boards.Pop();
                        break;
                    case BoardState.Won:
                        Clear(0xffffff);
                        boards.Pop();
                        if (boards.Count == 0)
                            is_victory_visible = true;
                        break;
                }

                if (boards.Count == 0)
                    boards.Push(BoardLoader.LoadBoard("main_board.conf"));

                boards.Peek().State = BoardState.Active;
                frog = boards.Peek().Get<Frog>();

                Flip();
                Sleep(100);

                //usuń oczekujące klawisze
                ClearEvents();

            }
        }
        public static void WinOrLose(Frog newFrog)
        {
            if (newFrog.LivesLeft == 0 && newFrog.Score != 0)
            {
                List<Frog> frogs = new List<Frog>();
                frogs.Add(new Frog("Alexander", 500));
                frogs.Add(new Frog("Ivan", 450));
                frogs.Add(new Frog("Pesho", 250));
                frogs.Add(new Frog("Gosho", 200));
                frogs.Add(new Frog(newFrog.Name, newFrog.Score));
                List<Frog> SortedList = frogs.OrderByDescending(o => o.Score).ToList();

                try
                {
                    using (Stream stream = File.Open("data.txt", FileMode.Create))
                    {
                        BinaryFormatter bin = new BinaryFormatter();
                        bin.Serialize(stream, SortedList);
                    }
                }
                catch (IOException)
                {
                }
            }
            if (newFrog.LivesLeft == 0)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                string[,] gameOver = new string[,]
                    {
                        {"                                                         ","          .-'''-.                                           "},
                        {"                                                         ","         '   _    \\                                         "},
                        {"                  __  __   ___        __.....__          ","      /   /` '.   .----.     .----.  __.....__              "},
                        {"  .--.           |  |/  `.'   `.  .-''         '.        ","     .   |     \\  '\\    \\   /    .-''         '.            "},
                        {" /.''\\          |   .-.  .-.   '/     .-''\"'-.  `.      ","     |   '      |  ''   '. /'   /     .-''\"'-.  `..-,.--.   "},
                        {"| |  | |     __  |  |  |  |  |  /     /________\\   \\     ","     \\    \\     / / |    |'    /     /________\\   |  .-. |  "},
                        {" \\`-' /   .:--.'.|  |  |  |  |  |                  |     ","      `.   ` ..' /  |    ||    |                  | |  | |  "},
                        {" /(\"'`   / |   \\ |  |  |  |  |  \\    .-------------'     ","         '-...-'`   '.   `'   .\\    .-------------| |  | |  "},
                        {" \\ '---. `\" __ | |  |  |  |  |  |\\    '-.____...---.     ","                     \\        / \\    '-.____...---| |  '-   "},
                        {"  /'\"\"'.\\ .'.''| |__|  |__|  |__| `.             .'      ","                      \\      /   `.             .'| |       "},
                        {" ||     |/ /   | |_                 `''-...... -'        ","                       '----'      `\\''-...... -' | |       "},
                        {" \\'. __//\\ \\._,\\ '/                                      ","                                                  |_|       "},
                        {"  `'---'  `--'  `\"                                       ","                                                            "}
                    };
                for (int row = 0; row < gameOver.GetLength(0); row++)
                {
                    for (int col = 0; col < gameOver.GetLength(1); col++)
                    {
                        if (col % 2 == 0)
                            Console.WriteLine(gameOver[row, col].PadLeft(80, ' '));
                    }

                }
                Console.WriteLine();
                for (int row = 0; row < gameOver.GetLength(0); row++)
                {
                    for (int col = 0; col < gameOver.GetLength(1); col++)
                    {
                        if (col % 2 != 0)
                            Console.WriteLine(gameOver[row, col].PadLeft(80, ' '));
                    }

                }
                Console.WriteLine();
                Environment.Exit(0);

            }
            else if (newFrog.ReachedTop == 5)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Green;
                string[] levelComplete = new string[]
                    {
                    @"           _____                                            ",
                    @"          / ____\    __     _____    ____                   ",
                    @"         / /  ____  /  \   /     \ _/ __ \                  ",
                    @"         \ \___/ / /_--_\ |  Y Y  \\  ___/                  ",
                    @"          \_____/ /_/  \_\|__|_|  / \___  >                 ",
                    @"                                \/      \/                  ",
                    @"                                .__            __           ",
                    @"  ____   ____    _____  ______  |  |    ____ _/  |_   ____  ",
                    @"_/ ___\ /  _ \  /     \ \____ \ |  |  _/ __ \\   __\_/ __ \ ",
                    @"\  \___(  <_> )|  Y Y  \|  |_> >|  |__\  ___/ |  |  \  ___/ ",
                    @" \___  >\____/ |__|_|  /|   __/ |____/ \___  >|__|   \___  >",
                    @"     \/              \/ |__|               \/            \/ "
                    };
                string[] gameName = new string[]
                    {
                        @"  .----------------------------------------------------------------.  ",
                        @" /  .-.    ______ _____   ____   _____  _____ ______ _____     .-.  \ ",
                        @"|  /   \  |  ____|  __ \ / __ \ / ____|/ ____|  ____|  __ \   /   \  |",
                        @"| |\_.  | | |__  | |__) | |  | | |  __| |  __| |__  | |__) | |    /| |",
                        @"|\|  | /| |  __| |  _  /| |  | | | |_ | | |_ |  __| |  _  /  |\  | |/|",
                        @"| `---' | | |    | | \ \| |__| | |__| | |__| | |____| | \ \  | `---' |",
                        @"|       | |_|    |_|  \_\\____/ \_____|\_____|______|_|  \_\ |       |",
                        @"|       |----------------------------------------------------|       |",
                        @"\       |                                                    |       /",
                        @" \     /                                                      \     / ",
                        @"  `---'                                                        `---'  ",
                    };
                foreach (var text in levelComplete)
                {
                    Console.WriteLine(text.PadLeft(80, ' '));
                }
                Console.WriteLine();
                Console.WriteLine();
                foreach (var text in gameName)
                {
                    Console.WriteLine(text.PadLeft(80, ' '));
                }
                Environment.Exit(0);
            }
        }
        public static void Main()
        {
            string fullPath = Path.GetFullPath(@"..\..\Frog Sound.wav");
            SoundPlayer frogSound = new SoundPlayer(fullPath);
            Console.WindowWidth = 100;
            Console.WindowHeight = 49;
            Console.BufferHeight = 49;
            Console.BufferWidth = 100;
            int speed = 30;
            int startReach = 0;

            Frog newFrog = new Frog(Environment.MachineName, 0);
            // Cars coming from right
            Enemy firstRightCar = new Car();
            Enemy secondRightCar = new Bus();
            Enemy thirdRightCar = new Truck();
            Enemy fourthRightCar = new Truck();
            Enemy fifthRightCar = new Bus();
            Enemy sixthRightCar = new Car();

            // Cars coming from left
            Enemy firstLeftCar = new Bus();
            Enemy secondLeftCar = new Car();
            Enemy thirdLeftCar = new Truck();
            Enemy fourthLeftCar = new Car();
            Enemy fifthLeftCar = new Truck();
            Enemy sixthLeftCar = new Bus();

            // Tunnels
            Tunnel firstTunnel = new Tunnel();
            Tunnel secondTunnel = new Tunnel();
            Tunnel thirdTunnel = new Tunnel();

            //Bridges
            Bridge firstBridge = new Bridge();
            Bridge secondBridge = new Bridge();

            // Frogs that are displayed when frog reaches top
            StringBuilder frogsAtTheTop1 = new StringBuilder();
            StringBuilder frogsAtTheTop2 = new StringBuilder();
            StringBuilder frogsAtTheTop3 = new StringBuilder();

            // Lifes info
            StringBuilder infoLives = new StringBuilder();
            infoLives.Append("Lives: ");
            infoLives.Append(newFrog.LivesLeft);

            // Read music file
            try
            {
                string musicFilePath = Path.GetFullPath(@"..\..\music.wav");
                var music = new SoundPlayer(musicFilePath);
                music.PlayLooping();

            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Music file not available");
            }

            Menu.DrawMenu();
            while (true)
            {
                ConsoleKeyInfo choice = Console.ReadKey();
                if (choice.Key == ConsoleKey.D1 || choice.Key == ConsoleKey.Enter)
                {
                    break;
                }
                else if (choice.Key == ConsoleKey.D2)
                {
                    // Show highscore
                    Console.Clear();
                    try
                    {
                        using (Stream stream = File.Open("data.txt", FileMode.Open))
                        {
                            BinaryFormatter bin = new BinaryFormatter();
                            var frogs2 = (List<Frog>) bin.Deserialize(stream);
                            int a = 0;
                            int cursorline = 2;
                            Console.SetCursorPosition(45, 0);
                            Console.WriteLine("HIGHSCORES");
                            foreach (Frog frog in frogs2)
                            {
                                a++;
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.SetCursorPosition(40, cursorline);
                                cursorline += 2;
                                Console.WriteLine("{0}.{1} has {2} points",a ,frog.Name, frog.Score);
                            }
                        }
                    }
                    catch (IOException)
                    {
                        Console.WriteLine("Error: File not found");
                    }
                    catch
                    {
                        Console.WriteLine("Highscore cannot be visualized");
                    }
                }
                else if (choice.Key == ConsoleKey.D3)
                {
                    // Show credits
                    Console.Clear();
                    Console.WriteLine("Project made for TELERIK Academy by: Team SERPENT FLY");
                    Console.WriteLine("The contributors of this project are: ");
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Radostin Angelov, Teodor Hanev, Nikolai Mishev,");
                    Console.WriteLine("Liubomir Svilenov, Ivan Vasilev, Krasimir Stoyanov,");
                    Console.WriteLine("Konstantin Malinov, Dobromira Boytcheva and Silvia Ivanova");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine();
                    Console.WriteLine("Thank you for playing and have a nice day!");
                }
                else if (choice.Key == ConsoleKey.D4)
                {
                    // Show Rules
                    Console.Clear();
                    Console.Write(new string(' ', 46));
                    Console.WriteLine("Rules:");
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Help the froggie cross the busy road and navigate it to a calmer " +
                                      "and safer place – the wonderful \nhome swamp, at the top of the " +
                                      "screen! \nYou guide the frog using the following navigation keys: \"↑\"" +
                                      " for up, \"↓\" - down, \"←\" - left, and \n\"→\" - right, and each "+
                                      "pressing of the respective key of direction causes the frog to hop " +
                                      "once in \nthat direction. \n\nThe game starts at the bottom of the " +
                                      "screen. In general the screen is divided in two: the lower and the " +
                                      "upper halves of it represent a heavy traffic road with various motor" +
                                      " vehicles: cars, trucks, \nbuses, which move at different speeds. " +
                                      "There are also tunnels and bridges, on which the frog can't \njump " +
                                      "and must go around them. So your job is not an easy task! The froggie" +
                                      " should pass through that traffic chaos in attempt to reach the upper" +
                                      " part of the screen. In the middle of the play area is a \"Safe Zone\"" +
                                      " – a place where the little frog can have some rest before continuing " +
                                      "its dangerous \njourney. The frog has only three lives! If it gets hit" +
                                      " by a vehicle, the frog remains with one life less. And when the " +
                                      "froggie is run over by a vehicle three times – the game is over." +
                                      "\n\nEnjoy the game!");
                }
                else if (choice.Key == ConsoleKey.D5 || choice.Key == ConsoleKey.Escape)
                {
                    Environment.Exit(1);
                }
                else
                {
                    Menu.DrawMenu();
                }
            }

            while (true)
            {
                Console.Clear();
                FrogFinishes.ConsoleFill(frogsAtTheTop1, frogsAtTheTop2, frogsAtTheTop3);
                newFrog.Move();
                newFrog.Draw();
                // Bridges
                firstBridge.FirstBridge();
                firstBridge.DrawBridge(12, 59);
                secondBridge.SecondBridge();
                secondBridge.DrawBridge(36, 60);
                // Right cars
                firstRightCar.MoveRight(17);
                firstRightCar.CheckCrash(newFrog, 42, 6);
                firstRightCar.DrawCar(42);
                secondRightCar.MoveRight(17);
                secondRightCar.DrawCar(36);
                secondRightCar.CheckCrash(newFrog, 36, 16);
                thirdRightCar.DrawCar(30);
                thirdRightCar.CheckCrash(newFrog, 30, 10);
                thirdRightCar.MoveRight(28);
                fourthRightCar.DrawCar(21);
                fourthRightCar.CheckCrash(newFrog, 21, 10);
                fourthRightCar.MoveRight(11);
                fifthRightCar.DrawCar(15);
                fifthRightCar.CheckCrash(newFrog, 15, 16);
                fifthRightCar.MoveRight(30);
                sixthRightCar.DrawCar(9);
                sixthRightCar.CheckCrash(newFrog, 9, 6);
                sixthRightCar.MoveRight(6);
                //Tunnels
                firstTunnel.FirstCarTunnel();
                firstTunnel.DrawFirstTunnel(42, 12);
                secondTunnel.SecondCarTunnel();
                secondTunnel.DrawFirstTunnel(30, 19);
                thirdTunnel.SecondCarTunnel();
                thirdTunnel.DrawFirstTunnel(15, 19);
                // Left cars
                firstLeftCar.DrawCar(27);
                firstLeftCar.CheckCrash(newFrog, 27, 16);
                firstLeftCar.MoveLeft(17);
                secondLeftCar.DrawCar(33);
                secondLeftCar.MoveLeft(7);
                secondLeftCar.CheckCrash(newFrog, 33, 6);
                thirdLeftCar.DrawCar(39);
                thirdLeftCar.MoveLeft(11);
                thirdLeftCar.CheckCrash(newFrog, 39, 10);
                fourthLeftCar.DrawCar(18);
                fourthLeftCar.CheckCrash(newFrog, 18, 6);
                fourthLeftCar.MoveLeft(7);
                fifthLeftCar.DrawCar(12);
                fifthLeftCar.CheckCrash(newFrog, 12, 10);
                fifthLeftCar.MoveLeft(11);
                sixthLeftCar.DrawCar(6);
                sixthLeftCar.CheckCrash(newFrog, 6, 16);
                sixthLeftCar.MoveLeft(17);

                DrawStats(1, newFrog.LivesLeft, newFrog.Score);

                FrogFinishes.FrogAtSafeZone(newFrog);
                // Check if the frog reached the top and print a frog at the top
                FrogFinishes.FrogAtTop(newFrog, ref startReach, frogSound, frogsAtTheTop1, frogsAtTheTop2, frogsAtTheTop3);
                // Check if the frog has lost all lifes or won the game
                FrogFinishes.WinOrLose(newFrog);
                Thread.Sleep(newFrog.speed);
            }
        }
예제 #12
0
파일: Level.cs 프로젝트: hatrox/frogger
        public static void DrawLevel(int numberOfLanes, bool inputHeight = false)
        {
            if (!inputHeight)
            {
                Console.WindowHeight = Converter.LanesToHeight(numberOfLanes);
            }
            else
            {
                Console.WindowHeight = numberOfLanes;
            }

            Console.BufferHeight = Console.WindowHeight;
            Console.BufferWidth = Console.WindowWidth;

            ConsoleRenderer renderer = new ConsoleRenderer(Console.WindowHeight - 2, Console.WindowWidth - 1);
            //windowheight - 2 and windowwidth - 1 make a buffering zone for the renderer
            //otherwise we get a terrible performance and I really can't really be bothered
            //to see why

            KeyboardInterface keyInterface = new KeyboardInterface();
            Engine engine = new Engine(renderer, keyInterface);

            Frog frog = new Frog(new Coordinates(Console.WindowHeight - 3, (Console.WindowWidth - 2) / 2));
            engine.AddObject(frog);

            for (int row = 0; row < Console.WindowHeight - 2; row += 2) //adding some road surface markings
            {
                for (int col = 0; col < Console.WindowWidth; col += 2)
                {
                    RoadMarkings markings = new RoadMarkings(new Coordinates(row, col));
                    engine.AddObject(markings);
                }
            }

            for (int row = Console.WindowHeight - 5; row > 0; row -= 2) //adding some cars/trucks
            {
                int speed = RandomGenerators.Speed();

                for (int col = 0; col < Console.WindowWidth - 1; col += 8)
                {
                    Vehicle vehicle = new Vehicle(new Coordinates(row, col), speed, RandomGenerators.TruckLength());
                    engine.AddObject(vehicle);
                }
            }

            engine.AddObject(new ScoreBonus(RandomGenerators.RandomPosition())); //adding a score bonus, which will be automatically regenerated on pickup

            keyInterface.OnDownPressed += (sender, eventInfo) =>
            {
                engine.MoveFrogDown();
            };
            keyInterface.OnUpPressed += (sender, eventInfo) =>
            {
                engine.MoveFrogUp();
            };
            keyInterface.OnLeftPressed += (sender, eventInfo) =>
            {
                engine.MoveFrogLeft();
            };
            keyInterface.OnRightPressed += (sender, eventInfo) =>
            {
                engine.MoveFrogRight();
            };
            keyInterface.OnPausePressed += (sender, eventInfo) =>
            {
                engine.PauseScreen();
            };
            keyInterface.OnExitPressed += (sender, eventInfo) =>
            {
                Environment.Exit(0);
            };

            //Initiliazing the game field
            DrawGrass();
            engine.Run();
        }
        public static void WinOrLose(Frog newFrog)
        {
            if (newFrog.LivesLeft == 0 && newFrog.Score != 0)
            {
                List <Frog> frogs = new List <Frog>();
                frogs.Add(new Frog("Alexander", 500));
                frogs.Add(new Frog("Ivan", 450));
                frogs.Add(new Frog("Pesho", 250));
                frogs.Add(new Frog("Gosho", 200));
                frogs.Add(new Frog(newFrog.Name, newFrog.Score));
                List <Frog> SortedList = frogs.OrderByDescending(o => o.Score).ToList();

                try
                {
                    using (Stream stream = File.Open("data.txt", FileMode.Create))
                    {
                        BinaryFormatter bin = new BinaryFormatter();
                        bin.Serialize(stream, SortedList);
                    }
                }
                catch (IOException)
                {
                }
            }
            if (newFrog.LivesLeft == 0)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                string[,] gameOver      = new string[, ]
                {
                    { "                                                         ", "          .-'''-.                                           " },
                    { "                                                         ", "         '   _    \\                                         " },
                    { "                  __  __   ___        __.....__          ", "      /   /` '.   .----.     .----.  __.....__              " },
                    { "  .--.           |  |/  `.'   `.  .-''         '.        ", "     .   |     \\  '\\    \\   /    .-''         '.            " },
                    { " /.''\\          |   .-.  .-.   '/     .-''\"'-.  `.      ", "     |   '      |  ''   '. /'   /     .-''\"'-.  `..-,.--.   " },
                    { "| |  | |     __  |  |  |  |  |  /     /________\\   \\     ", "     \\    \\     / / |    |'    /     /________\\   |  .-. |  " },
                    { " \\`-' /   .:--.'.|  |  |  |  |  |                  |     ", "      `.   ` ..' /  |    ||    |                  | |  | |  " },
                    { " /(\"'`   / |   \\ |  |  |  |  |  \\    .-------------'     ", "         '-...-'`   '.   `'   .\\    .-------------| |  | |  " },
                    { " \\ '---. `\" __ | |  |  |  |  |  |\\    '-.____...---.     ", "                     \\        / \\    '-.____...---| |  '-   " },
                    { "  /'\"\"'.\\ .'.''| |__|  |__|  |__| `.             .'      ", "                      \\      /   `.             .'| |       " },
                    { " ||     |/ /   | |_                 `''-...... -'        ", "                       '----'      `\\''-...... -' | |       " },
                    { " \\'. __//\\ \\._,\\ '/                                      ", "                                                  |_|       " },
                    { "  `'---'  `--'  `\"                                       ", "                                                            " }
                };
                for (int row = 0; row < gameOver.GetLength(0); row++)
                {
                    for (int col = 0; col < gameOver.GetLength(1); col++)
                    {
                        if (col % 2 == 0)
                        {
                            Console.WriteLine(gameOver[row, col].PadLeft(80, ' '));
                        }
                    }
                }
                Console.WriteLine();
                for (int row = 0; row < gameOver.GetLength(0); row++)
                {
                    for (int col = 0; col < gameOver.GetLength(1); col++)
                    {
                        if (col % 2 != 0)
                        {
                            Console.WriteLine(gameOver[row, col].PadLeft(80, ' '));
                        }
                    }
                }
                Console.WriteLine();
                Environment.Exit(0);
            }
            else if (newFrog.ReachedTop == 5)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Green;
                string[] levelComplete = new string[]
                {
                    @"           _____                                            ",
                    @"          / ____\    __     _____    ____                   ",
                    @"         / /  ____  /  \   /     \ _/ __ \                  ",
                    @"         \ \___/ / /_--_\ |  Y Y  \\  ___/                  ",
                    @"          \_____/ /_/  \_\|__|_|  / \___  >                 ",
                    @"                                \/      \/                  ",
                    @"                                .__            __           ",
                    @"  ____   ____    _____  ______  |  |    ____ _/  |_   ____  ",
                    @"_/ ___\ /  _ \  /     \ \____ \ |  |  _/ __ \\   __\_/ __ \ ",
                    @"\  \___(  <_> )|  Y Y  \|  |_> >|  |__\  ___/ |  |  \  ___/ ",
                    @" \___  >\____/ |__|_|  /|   __/ |____/ \___  >|__|   \___  >",
                    @"     \/              \/ |__|               \/            \/ "
                };
                string[] gameName = new string[]
                {
                    @"  .----------------------------------------------------------------.  ",
                    @" /  .-.    ______ _____   ____   _____  _____ ______ _____     .-.  \ ",
                    @"|  /   \  |  ____|  __ \ / __ \ / ____|/ ____|  ____|  __ \   /   \  |",
                    @"| |\_.  | | |__  | |__) | |  | | |  __| |  __| |__  | |__) | |    /| |",
                    @"|\|  | /| |  __| |  _  /| |  | | | |_ | | |_ |  __| |  _  /  |\  | |/|",
                    @"| `---' | | |    | | \ \| |__| | |__| | |__| | |____| | \ \  | `---' |",
                    @"|       | |_|    |_|  \_\\____/ \_____|\_____|______|_|  \_\ |       |",
                    @"|       |----------------------------------------------------|       |",
                    @"\       |                                                    |       /",
                    @" \     /                                                      \     / ",
                    @"  `---'                                                        `---'  ",
                };
                foreach (var text in levelComplete)
                {
                    Console.WriteLine(text.PadLeft(80, ' '));
                }
                Console.WriteLine();
                Console.WriteLine();
                foreach (var text in gameName)
                {
                    Console.WriteLine(text.PadLeft(80, ' '));
                }
                Environment.Exit(0);
            }
        }
예제 #14
0
 public DangerousEntity(int x, int y, Image image, bool left, PictureBox pictureBox, Frog frog, frogBox frogger)
 {
     //Sets the entity PictureBox
     this.entity = pictureBox;
     //Sets xpos
     this.xpos = x;
     //Sets ypos
     this.ypos = y;
     //Sets frog
     this.frog = frog;
     //Sets image
     this.image = image;
     //Sets left
     this.left = left;
     //Sets instance
     this.instance = frogger;
     //Sets Entity's BackgroundImage
     this.entity.BackgroundImage = image;
     //Sets Entity's BackgroundImageLayout
     this.entity.BackgroundImageLayout = ImageLayout.Stretch;
     //Determines if it is fliped left or right
     this.entity.BackgroundImage.RotateFlip(left ? RotateFlipType.Rotate90FlipNone : RotateFlipType.Rotate270FlipNone);
     //Sets startingLocationX
     this.startingLocationX = x;
     //Sets startingLocationY
     this.startingLocationY = y;
     //Moves the cars position
     changeLocation();
     //move();
     //Thread thread = new Thread(new ThreadStart(Run));
     //thread.Start();
 }
예제 #15
0
        //Ran on start
        private void setUp()
        {
            //Sets the gameOver Label to false
            gameOverLabel.Visible = false;
            //Sets the background image to the map
            this.BackgroundImage = Properties.Resources.Map;
            //Sets the BackgroundImageLayout to Strech
            this.BackgroundImageLayout = ImageLayout.Stretch;
            //Sets Lives = 3
            this.lives = 3;
            //Sets Score = 0
            this.score = 0;
            //Sets time;
            this.time = 0;
            //Creates a new Frog
            frogEntity = new Frog(693, 997, FrogPictureBox, endingBox, this);
            //Sets the game to inSession
            inSession = true;
            //Instantiates a new Dangerous Entity List
            dangerousEntities = new List <DangerousEntity>();

            /*
             * Adds new Dangerous Entities
             */

            dangerousEntities.Add(new DangerousEntity(1029, 828,
                                                      Properties.Resources.aquacar, true, dangerousEntity1, frogEntity, this));

            dangerousEntities.Add(new DangerousEntity(187, 737,
                                                      Properties.Resources.bluecar, false, dangerousEntity2, frogEntity, this));

            dangerousEntities.Add(new DangerousEntity(1206, 534,
                                                      Properties.Resources.greencar, true, dangerousEntity3, frogEntity, this));

            dangerousEntities.Add(new DangerousEntity(342, 433,
                                                      Properties.Resources.orangecar, false, dangerousEntity4, frogEntity, this));

            dangerousEntities.Add(new DangerousEntity(975, 222,
                                                      Properties.Resources.redcar, true, dangerousEntity5, frogEntity, this));

            dangerousEntities.Add(new DangerousEntity(12, 125,
                                                      Properties.Resources.pinkcar, false, dangerousEntity6, frogEntity, this));

            //Doubles

            dangerousEntities.Add(new DangerousEntity(1206, 534,
                                                      Properties.Resources.bluecar, true, dangerousEntity7, frogEntity, this));

            dangerousEntities.Add(new DangerousEntity(985, 433,
                                                      Properties.Resources.tancar, true, dangerousEntity8, frogEntity, this));

            dangerousEntities.Add(new DangerousEntity(167, 125,
                                                      Properties.Resources.aquacar, false, dangerousEntity9, frogEntity, this));

            //Triple

            dangerousEntities.Add(new DangerousEntity(643, 125,
                                                      Properties.Resources.orangecar, false, dangerousEntity10, frogEntity, this));


            //moveDangerousEntities();
            //Starts the times that moves the DangerousEntities
            //Sets the interval to 10
            timer1.Interval = 10;
            timer1.Start();
        }
예제 #16
0
        public static void Main()
        {
            string      fullPath  = Path.GetFullPath(@"..\..\Frog Sound.wav");
            SoundPlayer frogSound = new SoundPlayer(fullPath);

            Console.WindowWidth  = 100;
            Console.WindowHeight = 49;
            Console.BufferHeight = 49;
            Console.BufferWidth  = 100;
            int speed      = 30;
            int startReach = 0;

            Frog newFrog = new Frog(Environment.MachineName, 0);
            // Cars coming from right
            Enemy firstRightCar  = new Car();
            Enemy secondRightCar = new Bus();
            Enemy thirdRightCar  = new Truck();
            Enemy fourthRightCar = new Truck();
            Enemy fifthRightCar  = new Bus();
            Enemy sixthRightCar  = new Car();

            // Cars coming from left
            Enemy firstLeftCar  = new Bus();
            Enemy secondLeftCar = new Car();
            Enemy thirdLeftCar  = new Truck();
            Enemy fourthLeftCar = new Car();
            Enemy fifthLeftCar  = new Truck();
            Enemy sixthLeftCar  = new Bus();

            // Tunnels
            Tunnel firstTunnel  = new Tunnel();
            Tunnel secondTunnel = new Tunnel();
            Tunnel thirdTunnel  = new Tunnel();

            //Bridges
            Bridge firstBridge  = new Bridge();
            Bridge secondBridge = new Bridge();

            // Frogs that are displayed when frog reaches top
            StringBuilder frogsAtTheTop1 = new StringBuilder();
            StringBuilder frogsAtTheTop2 = new StringBuilder();
            StringBuilder frogsAtTheTop3 = new StringBuilder();

            // Lifes info
            StringBuilder infoLives = new StringBuilder();

            infoLives.Append("Lives: ");
            infoLives.Append(newFrog.LivesLeft);

            // Read music file
            try
            {
                string musicFilePath = Path.GetFullPath(@"..\..\music.wav");
                var    music         = new SoundPlayer(musicFilePath);
                music.PlayLooping();
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Music file not available");
            }

            Menu.DrawMenu();
            while (true)
            {
                ConsoleKeyInfo choice = Console.ReadKey();
                if (choice.Key == ConsoleKey.D1 || choice.Key == ConsoleKey.Enter)
                {
                    break;
                }
                else if (choice.Key == ConsoleKey.D2)
                {
                    // Show highscore
                    Console.Clear();
                    try
                    {
                        using (Stream stream = File.Open("data.txt", FileMode.Open))
                        {
                            BinaryFormatter bin        = new BinaryFormatter();
                            var             frogs2     = (List <Frog>)bin.Deserialize(stream);
                            int             a          = 0;
                            int             cursorline = 2;
                            Console.SetCursorPosition(45, 0);
                            Console.WriteLine("HIGHSCORES");
                            foreach (Frog frog in frogs2)
                            {
                                a++;
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.SetCursorPosition(40, cursorline);
                                cursorline += 2;
                                Console.WriteLine("{0}.{1} has {2} points", a, frog.Name, frog.Score);
                            }
                        }
                    }
                    catch (IOException)
                    {
                        Console.WriteLine("Error: File not found");
                    }
                    catch
                    {
                        Console.WriteLine("Highscore cannot be visualized");
                    }
                }
                else if (choice.Key == ConsoleKey.D3)
                {
                    // Show credits
                    Console.Clear();
                    Console.WriteLine("Project made for TELERIK Academy by: Team SERPENT FLY");
                    Console.WriteLine("The contributors of this project are: ");
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Radostin Angelov, Teodor Hanev, Nikolai Mishev,");
                    Console.WriteLine("Liubomir Svilenov, Ivan Vasilev, Krasimir Stoyanov,");
                    Console.WriteLine("Konstantin Malinov, Dobromira Boytcheva and Silvia Ivanova");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine();
                    Console.WriteLine("Thank you for playing and have a nice day!");
                }
                else if (choice.Key == ConsoleKey.D4)
                {
                    // Show Rules
                    Console.Clear();
                    Console.Write(new string(' ', 46));
                    Console.WriteLine("Rules:");
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Help the froggie cross the busy road and navigate it to a calmer " +
                                      "and safer place – the wonderful \nhome swamp, at the top of the " +
                                      "screen! \nYou guide the frog using the following navigation keys: \"↑\"" +
                                      " for up, \"↓\" - down, \"←\" - left, and \n\"→\" - right, and each " +
                                      "pressing of the respective key of direction causes the frog to hop " +
                                      "once in \nthat direction. \n\nThe game starts at the bottom of the " +
                                      "screen. In general the screen is divided in two: the lower and the " +
                                      "upper halves of it represent a heavy traffic road with various motor" +
                                      " vehicles: cars, trucks, \nbuses, which move at different speeds. " +
                                      "There are also tunnels and bridges, on which the frog can't \njump " +
                                      "and must go around them. So your job is not an easy task! The froggie" +
                                      " should pass through that traffic chaos in attempt to reach the upper" +
                                      " part of the screen. In the middle of the play area is a \"Safe Zone\"" +
                                      " – a place where the little frog can have some rest before continuing " +
                                      "its dangerous \njourney. The frog has only three lives! If it gets hit" +
                                      " by a vehicle, the frog remains with one life less. And when the " +
                                      "froggie is run over by a vehicle three times – the game is over." +
                                      "\n\nEnjoy the game!");
                }
                else if (choice.Key == ConsoleKey.D5 || choice.Key == ConsoleKey.Escape)
                {
                    Environment.Exit(1);
                }
                else
                {
                    Menu.DrawMenu();
                }
            }


            while (true)
            {
                Console.Clear();
                FrogFinishes.ConsoleFill(frogsAtTheTop1, frogsAtTheTop2, frogsAtTheTop3);
                newFrog.Move();
                newFrog.Draw();
                // Bridges
                firstBridge.FirstBridge();
                firstBridge.DrawBridge(12, 59);
                secondBridge.SecondBridge();
                secondBridge.DrawBridge(36, 60);
                // Right cars
                firstRightCar.MoveRight(17);
                firstRightCar.CheckCrash(newFrog, 42, 6);
                firstRightCar.DrawCar(42);
                secondRightCar.MoveRight(17);
                secondRightCar.DrawCar(36);
                secondRightCar.CheckCrash(newFrog, 36, 16);
                thirdRightCar.DrawCar(30);
                thirdRightCar.CheckCrash(newFrog, 30, 10);
                thirdRightCar.MoveRight(28);
                fourthRightCar.DrawCar(21);
                fourthRightCar.CheckCrash(newFrog, 21, 10);
                fourthRightCar.MoveRight(11);
                fifthRightCar.DrawCar(15);
                fifthRightCar.CheckCrash(newFrog, 15, 16);
                fifthRightCar.MoveRight(30);
                sixthRightCar.DrawCar(9);
                sixthRightCar.CheckCrash(newFrog, 9, 6);
                sixthRightCar.MoveRight(6);
                //Tunnels
                firstTunnel.FirstCarTunnel();
                firstTunnel.DrawFirstTunnel(42, 12);
                secondTunnel.SecondCarTunnel();
                secondTunnel.DrawFirstTunnel(30, 19);
                thirdTunnel.SecondCarTunnel();
                thirdTunnel.DrawFirstTunnel(15, 19);
                // Left cars
                firstLeftCar.DrawCar(27);
                firstLeftCar.CheckCrash(newFrog, 27, 16);
                firstLeftCar.MoveLeft(17);
                secondLeftCar.DrawCar(33);
                secondLeftCar.MoveLeft(7);
                secondLeftCar.CheckCrash(newFrog, 33, 6);
                thirdLeftCar.DrawCar(39);
                thirdLeftCar.MoveLeft(11);
                thirdLeftCar.CheckCrash(newFrog, 39, 10);
                fourthLeftCar.DrawCar(18);
                fourthLeftCar.CheckCrash(newFrog, 18, 6);
                fourthLeftCar.MoveLeft(7);
                fifthLeftCar.DrawCar(12);
                fifthLeftCar.CheckCrash(newFrog, 12, 10);
                fifthLeftCar.MoveLeft(11);
                sixthLeftCar.DrawCar(6);
                sixthLeftCar.CheckCrash(newFrog, 6, 16);
                sixthLeftCar.MoveLeft(17);

                DrawStats(1, newFrog.LivesLeft, newFrog.Score);

                FrogFinishes.FrogAtSafeZone(newFrog);
                // Check if the frog reached the top and print a frog at the top
                FrogFinishes.FrogAtTop(newFrog, ref startReach, frogSound, frogsAtTheTop1, frogsAtTheTop2, frogsAtTheTop3);
                // Check if the frog has lost all lifes or won the game
                FrogFinishes.WinOrLose(newFrog);
                Thread.Sleep(newFrog.speed);
            }
        }
예제 #17
0
 public GameManager()
 {
     InitializeComponent();
     frog = new Frog(this.ClientSize.Width, this.ClientSize.Height, player);
 }
예제 #18
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Random rnd = new Random();

            #region add cars to game

            int carVel;
            int randomCarX1;
            int randomCarX2;
            int randomCarX3;
            int randomCarD;
            int tempCarVel = -1;
            int carOffset  = 500;

            for (int i = 0; i < 7; i++)
            {
                // Create random velocity and direction
                carVel      = rnd.Next(2, 4);
                randomCarD  = rnd.Next(0, 2);
                randomCarX1 = rnd.Next(0, this.picGame.Width);
                randomCarX2 = rnd.Next(0, this.picGame.Width);
                randomCarX3 = rnd.Next(0, this.picGame.Width);

                // Set new velocity if car above has same velocity value
                while (carVel == tempCarVel)
                {
                    carVel = rnd.Next(2, 5);
                }

                // Make sure each car is spaced apart fairly
                while (randomCarX3 < (randomCarX2 + 250) || randomCarX2 < (randomCarX1 + 250))
                {
                    randomCarX1 = rnd.Next(0, this.picGame.Width);
                    randomCarX2 = rnd.Next(0, this.picGame.Width);
                    randomCarX3 = rnd.Next(0, this.picGame.Width);
                }

                this.cars.Add(new Car(50, 50, randomCarX1, carOffset, randomCarD, carVel));
                this.cars.Add(new Car(50, 50, randomCarX2, carOffset, randomCarD, carVel));
                this.cars.Add(new Car(50, 50, randomCarX3, carOffset, randomCarD, carVel));

                // Increment offset
                carOffset += 50;
                tempCarVel = carVel;
            }

            #endregion

            #region add logs to game

            int randomV;
            int randomX1;
            int randomX2;
            int randomD;
            int tempV   = -1;
            int offsetY = 50;

            for (int i = 0; i < 8; i++)
            {
                // Create random velocity and direction
                randomV  = rnd.Next(1, 3);
                randomD  = rnd.Next(0, 2);
                randomX1 = rnd.Next(0, this.Width - 200);
                randomX2 = rnd.Next(0, this.Width - 200);

                // Set new velocity if row above has same velocity value
                while (randomV == tempV)
                {
                    randomV = rnd.Next(1, 3);
                }

                // Make sure each log is spaced apart fairly
                while (randomX2 < (randomX1 + 250))
                {
                    randomX1 = rnd.Next(0, this.Width - 200);
                    randomX2 = rnd.Next(0, this.Width - 200);
                }

                this.logs.Add(new Log(50, 200, randomX1, offsetY, randomD, randomV));
                this.logs.Add(new Log(50, 200, randomX2, offsetY, randomD, randomV));

                // Increment offset
                offsetY += 50;
                tempV    = randomV;
            }

            #endregion

            // Make player icon
            playerIcon = new Frog(50, 50, (this.picGame.Width / 2), (this.picGame.Height - 50));

            // Timer used to call draw method (60FPS)
            Timer play = new Timer();
            play.Interval = 10;
            play.Tick    += new EventHandler(refresh);
            play.Start();
        }
 private void InitializeFrog()
 {
     this.Frog = new Frog(this.Renderer.Width / 2, PLAYGROUND_HEIGHT - 1);
 }