示例#1
0
        public static void Update(MouseState mouse, KeyboardState keyboard)
        {
            Vector2 mousePos = new Vector2(mouse.X, mouse.Y);

            Keys justPressedKey = Keys.None;

            if (keyboard.GetPressedKeys().Length > 0)
            {
                if (prevKeyboard.IsKeyUp(keyboard.GetPressedKeys()[0]))
                {
                    justPressedKey = keyboard.GetPressedKeys()[0];
                }
            }

            for (int i = 0; i < Game1.activePlayerObjs.Count; i++)
            {
                if (Vector2.Distance(mousePos, Game1.activePlayerObjs[i].ScreenLocation) < 45)
                {
                    if (mouse.LeftButton == ButtonState.Pressed && prevMouse.LeftButton == ButtonState.Released)
                    {
                        Game1.activeObj = Game1.activePlayerObjs[i];
                    }
                }
            }

            if (justPressedKey != Keys.None)
            {
                if (justPressedKey == Keys.Escape)                 // Exit
                {
                    Game1.CurrentGame.Exit();
                }

                if (justPressedKey == Keys.Enter)                 // Switch turn
                {
                    if (Game1.activePlayer == Game1.Players[0])
                    {
                        Game1.SwitchTurn(1);
                    }
                    else
                    {
                        Game1.SwitchTurn(0);
                    }
                }

                if (justPressedKey == Keys.N && Game1.activeObj is SettlerDino)                 // Nestle
                {
                    ((SettlerDino)Game1.activeObj).Nestle();
                }

                if (justPressedKey == Keys.Tab)                 // Cycle
                {
                    if (Game1.activeObj is Dino)
                    {
                        int i = Game1.activePlayerDinos.IndexOf((Dino)Game1.activeObj);
                        if (i == Game1.activePlayerDinos.Count - 1)
                        {
                            i = 0;
                        }
                        else
                        {
                            i++;
                        }
                        Game1.activeObj = Game1.activePlayerDinos[i];
                    }
                    else if (Game1.activeObj is Nest)
                    {
                        int i = Game1.activePlayerNests.IndexOf((Nest)Game1.activeObj);
                        if (i == Game1.activePlayerNests.Count - 1)
                        {
                            i = 0;
                        }
                        else
                        {
                            i++;
                        }
                        Game1.activeObj = Game1.activePlayerNests[i];
                    }
                }

                if (Game1.activeObj is Dino)                 // Dino movement
                {
                    Dino selectedDino = (Dino)Game1.activeObj;
                    switch (justPressedKey)
                    {
                    case Keys.NumPad8: selectedDino.MoveOneStep(Direction.N); break;

                    case Keys.NumPad9: selectedDino.MoveOneStep(Direction.NE); break;

                    case Keys.NumPad6: selectedDino.MoveOneStep(Direction.E); break;

                    case Keys.NumPad3: selectedDino.MoveOneStep(Direction.SE); break;

                    case Keys.NumPad2: selectedDino.MoveOneStep(Direction.S); break;

                    case Keys.NumPad1: selectedDino.MoveOneStep(Direction.SW); break;

                    case Keys.NumPad4: selectedDino.MoveOneStep(Direction.W); break;

                    case Keys.NumPad7: selectedDino.MoveOneStep(Direction.NW); break;
                    }
                }
                else if (Game1.activeObj is Nest)                 // Nest commands
                {
                }
            }

            prevKeyboard = Keyboard.GetState();
            prevMouse    = Mouse.GetState();
        }
示例#2
0
        public static void Main(string[] args)
        {
            bool stop   = false;
            int  points = 0;

            List <Tree> trees = new List <Tree>();

            trees.Add(new Tree(new List <char>()
            {
                '|', '|', '|', '|', '|'
            }));
            trees.Add(new Tree(new List <char>()
            {
                '|', '|', '|', '|'
            }));
            trees.Add(new Tree(new List <char>()
            {
                '|', '|', '|'
            }));

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

            int x = 10;
            int y = 10;

            Random rgb   = new Random();
            Tree   tree  = trees[rgb.Next(trees.Count - 1)];
            int    treeX = Console.WindowWidth - 5;
            int    treeY = 10 + 2;

            int  jumpingRounds     = 6;
            int  jumpingPosition   = -3;
            bool fallingDown       = false;
            bool stayingOnTheGound = true;

            while (stop == false)
            {
                Console.SetCursorPosition(0, y + 4);
                Console.Write(new string('_', Console.WindowWidth - 1));

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo usr = Console.ReadKey();
                    if (usr.Key == ConsoleKey.Spacebar)
                    {
                        stayingOnTheGound = false;
                    }
                }

                if (stayingOnTheGound == true)
                {
                    Dino.Print(x, y, Dino.DinoCordinations);
                    //System.Threading.Thread.Sleep(50);
                }
                else
                {
                    if (jumpingRounds == 0)
                    {
                        jumpingRounds     = 6;
                        stayingOnTheGound = true;
                        fallingDown       = false;
                        jumpingPosition   = -3;
                    }
                    else
                    {
                        Dino.Jump(x, y, ref jumpingPosition, ref fallingDown);

                        jumpingRounds--;
                    }
                }
                if (treeX > 0)
                {
                    Tree.PrintTree(treeX, treeY + 2, tree.PartsOftrees);
                    if (points == 700)
                    {
                        trees.Add(new Tree(new List <char>(13)));
                    }
                    // System.Threading.Thread.Sleep(50);
                    //else System.Threading.Thread.Sleep(30);
                    foreach (var dinoPart in Dino.DinoCordinations)
                    {
                        foreach (var treePart in Tree.TreeCordinations)
                        {
                            if (dinoPart.X == treePart.X && dinoPart.Y == treePart.Y)
                            {
                                stop = true;
                            }
                        }
                    }
                    treeX -= 4;
                    Dino.DinoCordinations.Clear();
                    Tree.TreeCordinations.Clear();
                }
                else
                {
                    Tree.downOrhigh = rgb.Next(0, 2);
                    points         += 100;
                    tree            = trees[rgb.Next(0, trees.Count)];
                    treeX           = Console.WindowWidth - 1;
                    Dino.DinoCordinations.Clear();
                }
                Console.SetCursorPosition(0, 0);
                Console.Write("Currnet points; {0}", points);

                System.Threading.Thread.Sleep(50);
                Console.Clear();
            }
            Console.WriteLine("Game over!\n" +
                              "Your points are {0}\n" +
                              "press Enter to continue...", points);
            ConsoleKeyInfo user = Console.ReadKey();

            while (user.Key != ConsoleKey.Enter)
            {
                user = Console.ReadKey();
            }
        }