当前位置: 首页>>代码示例>>C#>>正文


C# Queue.Last方法代码示例

本文整理汇总了C#中Queue.Last方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Last方法的具体用法?C# Queue.Last怎么用?C# Queue.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Queue的用法示例。


在下文中一共展示了Queue.Last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShortestSequence

    /// <summary>
    /// Traverses the solution tree (all possible operations) by using BFS with queue.
    /// Stops when the end number is reached.
    /// There are two optimizations - discards numbers greater than the end number,
    /// and skips numbers that have already been processed (to avoid repeating branches).
    /// The numbers are stored in a node structure, where each number has a parent (except the first).
    /// The numbers already visited are stored in a hash table, so we can quickly check them.
    /// </summary>
    /// <param name="n">The start number.</param>
    /// <param name="m">The end number.</param>
    private static IEnumerable<int> ShortestSequence(int n, int m, Func<int, int>[] operations)
    {
        var queue = new Queue<Node>();
        var visited = new HashSet<int>();
        bool finished = false;

        queue.Enqueue(new Node(n));
        while (!finished)
        {
            var currentNode = queue.Dequeue();
            int value = currentNode.Value;

            foreach (var operation in operations)
            {
                int next = operation(value);
                if (next <= m && !visited.Contains(next))
                {
                    queue.Enqueue(new Node(next, currentNode));
                    visited.Add(next);
                    if (next == m)
                    {
                        finished = true;
                        break;
                    }
                }
            }
        }

        return GetSequence(queue.Last());
    }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:40,代码来源:ShortestSequenceOfOps.cs

示例2: GameWorld

        public GameWorld()
        {
            hero = new Hero();
            player = new Player(hero);
            infoPanel = new InfoPanel(hero);
            eManager = new EnemyManager(hero);
            laser = new Laser(hero);

            stop = false;
            accelerationTimer = new Timer(15);
            SpeedReference = StartSpeed;
            Speed = SpeedReference;

            onscreen = new Queue<GameWorldRegion>();
            upcoming = new Queue<GameWorldRegion>();

            // set the enemy manager for the weapon
            hero.setEnemies(eManager.getEnemies());

            // first element on screen
            onscreen.Enqueue(new Space(hero, eManager.getEnemies(), leftEdge));

            // fill the rest of the exisiting screen
            while (onscreen.Last().rightEdge() <= rightEdge)
            {
                onscreen.Enqueue(nextElement(onscreen));
            }

            // prep upcoming elements
            upcoming.Enqueue(nextElement(onscreen));
        }
开发者ID:GameThemedGroup,项目名称:OLD-Dyehard-todelete,代码行数:31,代码来源:GameWorld.cs

示例3: ReturnsToQueueInReverseOrder

 public void ReturnsToQueueInReverseOrder()
 {
     var queue = new Queue<int>();
     var hourTrack = new Track(queue, 2);
     hourTrack.AddBall(1);
     hourTrack.AddBall(2);
     hourTrack.AddBall(3);
     Assert.AreEqual(0, hourTrack.Length);
     Assert.AreEqual(2, queue.First());
     Assert.AreEqual(3, queue.Last());
 }
开发者ID:c0de,项目名称:BallClock,代码行数:11,代码来源:TrackTests.cs

示例4: Main

        public static void Main()
        {
            int n = 2;
            Queue<int> numbers = new Queue<int>();

            numbers.Enqueue(n);
            Console.WriteLine(numbers.Peek());

            for (int i = 0; i < 50; i++)
            {
                int currentNumber = numbers.Dequeue();

                numbers.Enqueue(currentNumber + 1);
                Console.WriteLine(numbers.Last());

                numbers.Enqueue(currentNumber * 2 + 1);
                Console.WriteLine(numbers.Last());

                numbers.Enqueue(currentNumber + 2);
                Console.WriteLine(numbers.Last());
            }
        }
开发者ID:baretata,项目名称:CSharpDSA,代码行数:22,代码来源:FirstFiftyMembers.cs

示例5: ReturnsToQueueInReverseOrderAndAddsBallToNextQueue

 public void ReturnsToQueueInReverseOrderAndAddsBallToNextQueue()
 {
     var queue = new Queue<int>();
     var hourTrack = new Track(queue, 2);
     var minuteTrack = new Track(queue, 2, hourTrack);
     minuteTrack.AddBall(1);
     minuteTrack.AddBall(2);
     minuteTrack.AddBall(3);
     Assert.AreEqual(0, minuteTrack.Length);
     Assert.AreEqual(1, hourTrack.Length);
     Assert.AreEqual(3, hourTrack.First());
     Assert.AreEqual(2, queue.First());
     Assert.AreEqual(1, queue.Last());
 }
开发者ID:c0de,项目名称:BallClock,代码行数:14,代码来源:TrackTests.cs

示例6: Main

    static void Main()
    {
        // This is an array of 4 positions which we will use for directions
        // Array from the constructor named Position
        Position[] directionsArray = new Position[]
        {
            new Position(0,-1),     // Left
            new Position(0,1),      // Right
            new Position(-1,0),     // Up
            new Position(1,0)       // Down
        };
        // We will use this value for the score
        int score = 0;
        //
        int gameTick = 150;

        // Here we have a thing that generates random numbers
        Random randomNumbersGenerator = new Random();
        // Then we use these numbers to create a random position for the apple
        Position food = new Position(
            randomNumbersGenerator.Next(0,Console.WindowHeight + 2),
            randomNumbersGenerator.Next(0,Console.WindowWidth)
            );

        // This is the int that will tell what direction
        // the snake should go next
        // With this value (from 0 to 3) we can set the default direction of the snake
        int direction = 1;

        // Here we set the buffer of the console so that it is the size of the window
        Console.BufferHeight = Console.WindowHeight;
        Console.BufferWidth = Console.WindowWidth;

        Queue<Position> snakeElements = new Queue<Position>();

        // Starter position of the snake
        for (int i = 0; i <= 5; i++)
        {
            snakeElements.Enqueue(new Position(0, i));
        }

        // Here we create the first 5 chars of the snake and the default position
        foreach (Position position in snakeElements)
        {
            Console.SetCursorPosition(position.col, position.row);
            Console.Write('*');
        }

        while (true)
        {
            // Here we check if the user typed something and if he did we execute the code in the if
            // But if the did not press any key we can continue with our code
            if (Console.KeyAvailable)
            {
                // Here we can see what key the user pressed
                ConsoleKeyInfo userInput = Console.ReadKey();

                // Here we compare what is the key and set the direction with a new
                // value which will use later to get positions from the Position.Array
                if (userInput.Key == ConsoleKey.LeftArrow)
                {
                    direction = 0;
                }
                if (userInput.Key == ConsoleKey.RightArrow)
                {
                    direction = 1;
                }
                if (userInput.Key == ConsoleKey.UpArrow)
                {
                    direction = 2;
                }
                if (userInput.Key == ConsoleKey.DownArrow)
                {
                    direction = 3;
                }
            }

            // With snakeElements.Last we get the position of the snake's head
            Position snakeHead = snakeElements.Last();
            // Here we get a new value for the next position of the snake
            Position nextDirection = directionsArray[direction];
            // Here we create the new head of the snake on the new position
            Position snakeNewHead = new Position(snakeHead.row + nextDirection.row,
                snakeHead.col + nextDirection.col);

            if (snakeNewHead.row < 0 ||
                snakeNewHead.col < 0 ||
                snakeNewHead.row >= Console.WindowHeight - 2 ||
                snakeNewHead.col >= Console.WindowWidth||
                snakeElements.Contains(snakeNewHead))
            {
                for (int i = 9; i >= 0; i--)
                {
                    Console.Clear();
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("||===============||");
                    Console.SetCursorPosition(0, 1);
                    Console.WriteLine("|| GAME OVER !!! ||");
                    Console.SetCursorPosition(0, 2);
                    if (score < 10)
//.........这里部分代码省略.........
开发者ID:eMagicMan,项目名称:Study-CSharp,代码行数:101,代码来源:Snake.cs

示例7: ngrams

        void ngrams(int n)
        {
            Console.Error.WriteLine("Started reading the source textfile at {0}", DateTime.Now.ToLongTimeString());

            Queue<string> buffer = new Queue<string>(n); // To hold a buffer of words/characters before adding to the dictionary
            if(n > 1) buffer.Enqueue(BREAK); // Marks the first word as sentence start, or first char as wordstart
            string ngram = "";

            using (var mappedFile1 = MemoryMappedFile.CreateFromFile(inputfile))
            {
                using (Stream mmStream = mappedFile1.CreateViewStream())
                {
                    using (StreamReader sr = new StreamReader(mmStream, Encoding.UTF8, true))
                    {
                        double filesize = sr.BaseStream.Length;
                        double nextprogress = filesize / 20; // Print out progress at a 5% interval

                        if (wordmode) // Wordmode (in order to gain as much performance as possible, wordmode and charmode are split here to avoid some comparisons in the while loop, though they are allmost the same)
                        {
                            while (!sr.EndOfStream)  //   && sr.BaseStream.Position < 100000    För debug (avbryter stora texter efter ett tag)
                            {
                                var line = sr.ReadLine() + " ";

                                var lineItems = GetWords(line);

                                // Add the ngram to the table (dictionary)
                                foreach (var item in lineItems)
                                {
                                    if ((item == BREAK && buffer.Count > 0 && buffer.Last() == BREAK) || string.IsNullOrWhiteSpace(item)) continue; // Skip if double BREAK or empty string (can happen if ' stands alone or with strange chars)(did not find a bullet proof regex to handle all of this)

                                    buffer.Enqueue(item);

                                    if (buffer.Count >= n) // Now we have a full ngram to add to list
                                    {
                                        ngram = buffer.Dequeue();
                                        for (int i = 0; i < n - 1; i++) ngram += " " + buffer.ElementAt(i);

                                        ngramlist[ngram] = ngramlist.ContainsKey(ngram) ? ngramlist[ngram] + 1 : 1;
                                    }
                                }
                                if (sr.BaseStream.Position > nextprogress) // Print out progress
                                {
                                    Console.Error.WriteLine("{0}% read at {1}", ((double)sr.BaseStream.Position / (double)filesize) * 100, DateTime.Now.ToLongTimeString());
                                    nextprogress = sr.BaseStream.Position + filesize / 100;
                                }
                            }
                            // Add BREAK after last row if not already there
                            if (buffer.Count > 0) // buffer count should be n-1 here
                            {
                                if (!(buffer.Last() == BREAK)) // No need to add double BREAKS in wordmode
                                {
                                    buffer.Enqueue(BREAK);
                                    ngram = buffer.Dequeue();
                                    while (buffer.Count > 0) ngram += " " + buffer.Dequeue();

                                    ngramlist[ngram] = ngramlist.ContainsKey(ngram) ? ngramlist[ngram] + 1 : 1;
                                }
                            }
                        }
                        else // Charmode (almost the same as above wordmode)
                        {
                            while (!sr.EndOfStream)  //   && sr.BaseStream.Position < 100000    För debug (avbryter stora texter efter ett tag)
                            {
                                var line = sr.ReadLine() + "\n";

                                var lineItems = GetChars(line);

                                // Add the ngrams to the table (dictionary)
                                foreach (var item in lineItems)
                                {
                                    if ((item == SPACE || item == BREAK) && buffer.Count > 0 && (buffer.Last() == BREAK || buffer.Last() == SPACE)) continue; // Skip if space after punctuation or double space (did not find a bullet proof regex to handle all of this)
                                    buffer.Enqueue(item);

                                    if (buffer.Count >= n) // Now we have a full ngram to add to list
                                    {
                                        ngram = buffer.Dequeue();
                                        for (int i = 0; i < n - 1; i++) ngram += buffer.ElementAt(i);

                                        ngramlist[ngram] = ngramlist.ContainsKey(ngram) ? ngramlist[ngram] + 1 : 1;
                                    }
                                }
                                if (sr.BaseStream.Position > nextprogress) // Print out progress
                                {
                                    Console.Error.WriteLine("{0}% read at {1}", ((double)sr.BaseStream.Position / (double)filesize) * 100, DateTime.Now.ToLongTimeString());
                                    nextprogress = sr.BaseStream.Position + filesize / 100;
                                }
                            }
                        }
                    }
                }
            }

            // If unigram (1-gram), no need for breaks or spaces... Remove
            if (n == 1) 
            {
                ngramlist.Remove(BREAK);
                ngramlist.Remove(SPACE);
            }

            Console.Error.WriteLine("File read and {0} {1}-grams generated in {2} seconds.\nOutputing...", ngramlist.Count, n, (DateTime.Now - starttime).TotalSeconds.ToString("N01"));
//.........这里部分代码省略.........
开发者ID:cryptolovi,项目名称:Phraser,代码行数:101,代码来源:Program.cs

示例8: ExpandDirectoryEntryMatches

        IEnumerable<string> ExpandDirectoryEntryMatches(string path)
        {
            Queue<string> remaining = new Queue<string>(path.Split('\\'));
            List<string> matches = new List<string>();

            if (remaining.Count == 0)
            {
                return matches;
            }

            try
            {
                string base_path = String.Join(@"\", remaining.Take(remaining.Count - 1));
                NtDirectory root_dir = GetDrive().DirectoryRoot;
                // We'll first try the general case of unglobbed dir and a globbed final name.
                using (NtDirectory base_dir = 
                    remaining.Count > 1 ? NtDirectory.Open(base_path, root_dir, DirectoryAccessRights.Query) 
                                        : root_dir.Duplicate(DirectoryAccessRights.Query))
                {
                    AddMatches(base_dir, BuildRelativePath(base_path, String.Empty), new string[] { remaining.Last() }, matches);
                }
            }
            catch (NtException)
            {
                // If we couldn't open the drive then try brute force approach.
                AddMatches(GetDrive().DirectoryRoot, String.Empty, remaining, matches);
            }

            return matches.Select(s => NTPathToPS(BuildDrivePath(s)));
        }
开发者ID:CaledoniaProject,项目名称:sandbox-attacksurface-analysis-tools,代码行数:30,代码来源:NtObjectManagerProvider.cs

示例9: Main

        static void Main()
        {
            byte right = 0;
            byte left = 1;
            byte down = 2;
            byte up = 3;

            double sleepTime = 100;
            int lastFoodTime = 0;
            int foodDissapearTime = 8000;
            int negativePoints = 0;

            Position[] directions = new Position[]
                {
                    new Position(0,1),//right
                    new Position(0,-1),//left
                    new Position(1,0),//down
                    new Position(-1,0)//up
                };

            Console.BufferHeight = Console.WindowHeight; //fix the problem with snake out from console

            List<Position> obstacles = new List<Position>()
            {
                new Position(12,12),
                new Position(14,40),
                new Position(7,7)
            };

            foreach (Position element in obstacles)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.SetCursorPosition(element.Y, element.X);
                Console.Write("!");
            }


            Random numberGenerator = new Random();
            Position food = new Position(numberGenerator.Next(0, Console.WindowHeight), numberGenerator.Next(0, Console.WindowWidth));

            Queue<Position> snakeElements = new Queue<Position>();

            for (int i = 0; i <= 5; i++)
            {
                snakeElements.Enqueue(new Position(0, i));
            }

            int currDirection = right;

            while (true)
            {
               negativePoints++;//when we move negative points up up 

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo userInput = Console.ReadKey();

                    if (userInput.Key == ConsoleKey.RightArrow)
                    {

                        if (currDirection != left)
                        {
                            currDirection = right;

                        }
                    }

                    if (userInput.Key == ConsoleKey.LeftArrow)
                    {
                        if (currDirection != right)
                        {
                            currDirection = left;

                        }
                    }

                    if (userInput.Key == ConsoleKey.DownArrow)
                    {
                        if (currDirection != up)
                        {
                            currDirection = down;

                        }
                    }

                    if (userInput.Key == ConsoleKey.UpArrow)
                    {
                        if (currDirection != down)
                        {
                            currDirection = up;
                        }
                    }
                }

                Position snakeHead = snakeElements.Last();

                Position nextDirection = directions[currDirection];
                Position snakeNewHead = new Position(snakeHead.X + nextDirection.X, snakeHead.Y + nextDirection.Y);
                /*
                if (snakeNewHead.X < 0)
//.........这里部分代码省略.........
开发者ID:MargaritaSv,项目名称:Snake,代码行数:101,代码来源:Program.cs

示例10: Teleport

 private static bool Teleport(Queue<Position> hitSnake, ref Queue<Position> hittingSnake,
     List<Position> obstacles, Position[] snakeDirections, int snakeStart, int score,
     ref Position prevHead, ref Position newHead, ConsoleColor color)
 {
     if (hitSnake.Contains(newHead) ||
         obstacles.Contains(newHead) ||
         hittingSnake.Contains(newHead))
     {
         foreach (var elem in hittingSnake)
         {
             Console.SetCursorPosition(elem.X, elem.Y);
             Console.WriteLine(" ");
         }
         hittingSnake = GenerateSnake();
         InitialiseSnake(hittingSnake, score - 3, snakeStart, color);
         prevHead = hittingSnake.Last();
         newHead = NewSnakeHead(snakeDirections, 0, ref prevHead);
         return true;
     }
     return false;
 }
开发者ID:RosenTodorov,项目名称:MyProjects,代码行数:21,代码来源:MultiSnake.cs

示例11: QueueExtensions_Last_ThrowsExceptionIfQueueIsEmpty

        public void QueueExtensions_Last_ThrowsExceptionIfQueueIsEmpty()
        {
            var queue = new Queue<Int32>();

            Assert.That(() => queue.Last(),
                Throws.TypeOf<InvalidOperationException>());
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:7,代码来源:QueueExtensionsTest.cs

示例12: ProcessCurve

        /*
        * author:      Florian Ennemoser
        * desc:        Calculates the values for a circle segment.
        * parameters:  curCommand: The currend cnc command including x,y,i and k values
        *              prevCommand: The previous command where the tool is currently positioned
        */
        public void ProcessCurve(Sentence curCommand, Sentence prevCommand, Queue<Vector3D> goBuffer, ref Vector3D absStart)
        {
            if (EpsilonTests.IsNearlyZeroEpsHigh(curCommand.I) && EpsilonTests.IsNearlyZeroEpsHigh(curCommand.K))
                throw new Exception("Either I or K must be greater/less than zero");

            double l = 0.00; // the distance between the start point on the circle segment and the end point on the circle segment
            double r = Math.Sqrt(Math.Abs(curCommand.I) * Math.Abs(curCommand.I) + Math.Abs(curCommand.K) * Math.Abs(curCommand.K)); // circle radius
            double arc = 0.00; //the arc

            if (EpsilonTests.IsNearlyZeroEpsHigh(prevCommand.Y - curCommand.Y)) //special case: angle is 180°
            {
                if (EpsilonTests.IsNearlyZeroEpsHigh(curCommand.I)) //circle origin lies directly on the horizontal axis of start- end endpoint of circle
                {
                    arc = 2 * r * Math.PI * 0.5;
                }
                else
                {
                    l = Math.Abs(prevCommand.X - curCommand.X);
                    arc = Math.Acos(1 - Math.Pow(l, 2) / (2 * Math.Pow(r, 2))) * r;
                }
            }
            else if (EpsilonTests.IsNearlyZeroEpsHigh(Math.Abs(prevCommand.X - curCommand.X) - Math.Abs(curCommand.K)) && EpsilonTests.IsNearlyZeroEpsHigh(Math.Abs(curCommand.I))) //special case: angle is 90° or 270°
            {
                if(IsGreaterHalfCircle())
                    arc = 2 * r * Math.PI * 0.75;
                else
                    arc = 2 * r * Math.PI * 0.25;
            }
            else //angle is ]90°,180°[
            {
                l = Math.Sqrt(Math.Pow(Math.Abs(prevCommand.Y) - Math.Abs(curCommand.Y), 2) + Math.Pow(Math.Abs(prevCommand.X) - Math.Abs(curCommand.X), 2));
                if (IsGreaterHalfCircle())
                    arc = 2 * r * Math.PI -  Math.Acos(1 - Math.Pow(l, 2) / (2 * Math.Pow(r, 2))) * r;
                else
                    arc = Math.Acos(1 - Math.Pow(l, 2) / (2 * Math.Pow(r, 2))) * r;
            }

            Debug.Assert(arc > 0, "The arc must be greater than 0");
            Debug.Assert(r > 0, "The radius must be greater than 0");

               // double segment = 12.566370614359172953850573533118;
               // double segment = 6.28139;
            double segment = 0.2;
            int counter = 1;
            double xPrev = Math.Abs(curCommand.K); //x-distance from circle center point to tool-position of last frame
            double yPrev = Math.Abs(curCommand.I); //y-distance from circle center point to tool-position of last frame
            Quadrant startQuadrant = GetQuadrant(curCommand.I, curCommand.K); //quadrant where arc starts
            Quadrant curQuadrant = startQuadrant;
            Quadrant prevQuadrant = startQuadrant;
            double alpha = CalcStartAngle(curCommand.interpolationMode, r, startQuadrant, curCommand.I);
            Vector3D amount;

            while (segment * counter < arc || EpsilonTests.IsNearlyZeroEpsHigh(arc - segment * counter))
            {
                alpha += segment / r;
                GetQuadrant(alpha, startQuadrant, ref curQuadrant, ref prevQuadrant, curCommand.interpolationMode);
                double deltaX = calcX(ref xPrev, alpha, r, startQuadrant, curQuadrant, prevQuadrant, curCommand.interpolationMode);
                double deltaY = calcY(ref yPrev, alpha, r, startQuadrant, curQuadrant, prevQuadrant, curCommand.interpolationMode);
                prevQuadrant = curQuadrant;
                amount = new Vector3D(deltaX,deltaY,0);

                if (!EpsilonTests.IsGreaterEpsHigh(amount.Length()))
                    throw new Exception("Length too small: " + amount.Length());
                goBuffer.Enqueue(amount);

                counter++;
            }

            double arcLeft = arc - segment * (counter-1);
            if (!EpsilonTests.IsNearlyZeroEpsHigh(arcLeft))
            {
                alpha += arcLeft / r;
                GetQuadrant(alpha, startQuadrant, ref curQuadrant, ref prevQuadrant, curCommand.interpolationMode);
                double deltaX = calcX(ref xPrev, alpha, r, startQuadrant,  curQuadrant, prevQuadrant, curCommand.interpolationMode);
                double deltaY = calcY(ref yPrev, alpha, r, startQuadrant, curQuadrant, prevQuadrant, curCommand.interpolationMode);
                amount = new Vector3D(deltaX, deltaY, 0);
                double l1 = amount.Length();
                if (amount.Length() >= 0.0001)
                    goBuffer.Enqueue(amount);
                else
                {
                    Vector3D last = goBuffer.Last();
                    last.X += amount.X;
                    last.Y += amount.Y;
                    Debug.Assert(last.Z == 0);
                }
            }

            #if DEBUG
            double overallX = 0;
            double overallY = 0;
            foreach (Vector3D v in goBuffer)
            {
                overallX += v.X;
//.........这里部分代码省略.........
开发者ID:NMO13,项目名称:SolidTurn,代码行数:101,代码来源:ArcCalculator.cs

示例13: initialiseGameWorld

        public void initialiseGameWorld()
        {
            //initialise/reset the terrain tile queue
            aTerrainTiles = new Queue<cTerrainTile>();

            //create the first two tiles in the queue
            aTerrainTiles.Enqueue(new cTerrainTile(viewMatrix, projectionMatrix,
                new Vector3(0, 0, 0), rRandomCount));

            aTerrainTiles.Enqueue(new cTerrainTile(viewMatrix, projectionMatrix,
                new Vector3(0, 0, aTerrainTiles.Last().getPosition().Z - 330), rRandomCount));

            //now load both police and player cars
            carPlayer = new cPlayerCar();
            carPlayer.loadModel(mdlPlayerCar, viewMatrix, projectionMatrix);
            carPlayer.setScaleFactor(new Vector3(0.01f, 0.01f, 0.01f));
            carPlayer.setPosition(0, 1.75f, 0);
            carPlayer.buildBoundingBox();
            carPlayer.initialisePhysics();

            carPolice.loadModel(mdlPoliceCar, viewMatrix, projectionMatrix);
            carPolice.setScaleFactor(new Vector3(0.01f, 0.01f, 0.01f));
            carPolice.setPosition(0, 1.75f, 200);
            carPolice.buildBoundingBox();
            carPolice.initialisePhysics();

            //now start playing the music
            MediaPlayer.Play(bgmGameplay);
        }
开发者ID:mbrews10,项目名称:GP3-Coursework,代码行数:29,代码来源:GameState.cs

示例14: Main


//.........这里部分代码省略.........
                        if (userInput.Key == ConsoleKey.LeftArrow)
                        {
                            if (direction != right)
                            {
                                direction = left;
                            }
                        }
                        if (userInput.Key == ConsoleKey.DownArrow)
                        {
                            if (direction != up)
                            {
                                direction = down;
                            }
                        }
                        if (userInput.Key == ConsoleKey.UpArrow)
                        {
                            if (direction != down)
                            {
                                direction = up;
                            }
                        }
                        if (userInput.Key == ConsoleKey.Spacebar)
                        {
                            Console.SetCursorPosition(0, Console.WindowHeight / 2);
                            Console.WriteLine("Your current score is {0}!\nTo resume the game press spacebar again.", foodCounter * 100);
                            userInput = Console.ReadKey();
                            while (userInput.Key != ConsoleKey.Spacebar)
                            {
                                userInput = Console.ReadKey();
                            }
                        }
                    }

                    Position snakeHead = Enumerable.Last(snakeElements);
                    Position nextDirection = directions[direction];
                    Position snakeNewHead = new Position(
                        snakeHead.row + nextDirection.row,
                        snakeHead.col + nextDirection.col);

                    //game over
                    if (snakeNewHead.row < 0 || snakeNewHead.col < 0 || snakeNewHead.row >= Console.WindowHeight
                        || snakeNewHead.col >= Console.WindowWidth || snakeElements.Contains(snakeNewHead))
                    {
                        Console.Clear();
                        Console.SetCursorPosition(35, 10);
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        Console.WriteLine(@"Game Over!
                              Your points are: {0}", foodCounter*100);
                        Console.WriteLine();
                        // Highscore Method / read and print from highscore.txt
                        int currentScore = foodCounter * 100; // scores for level 1
                        HighScore(currentScore);

                        return;
                    }

                    //element adding for snake movement
                    snakeElements.Enqueue(snakeNewHead);
                    Console.SetCursorPosition(snakeNewHead.col, snakeNewHead.row);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("*");

                    //food crossing
                    if (snakeNewHead.col == food.col && snakeNewHead.row == food.row)
                    {
                        do
开发者ID:Fujitzo,项目名称:SoftUni,代码行数:67,代码来源:SnakeGame.cs

示例15: Main


//.........这里部分代码省略.........
                    if (userInput.Key == ConsoleKey.LeftArrow)
                    {
                        if (direction != right)
                        {
                            direction = left;
                        }
                    }

                    if (userInput.Key == ConsoleKey.RightArrow)
                    {
                        if (direction != left)
                        {
                            direction = right;
                        }
                    }

                    if (userInput.Key == ConsoleKey.UpArrow)
                    {
                        if (direction != down)
                        {
                            direction = up;
                        }
                    }

                    if (userInput.Key == ConsoleKey.DownArrow)
                    {
                        if (direction != up)
                        {
                            direction = down;
                        }
                    }
                }

                Positions snakeHead = snakeElements.Last();
                Positions nextDirection = directions[direction];
                Positions snakeNewHead = new Positions(snakeHead.Row + nextDirection.Row, snakeHead.Col + nextDirection.Col);

                if (snakeNewHead.Col < 0)
                {
                    snakeNewHead.Col = Console.WindowWidth - 1;
                }

                if (snakeNewHead.Row < 0)
                {
                    snakeNewHead.Row = Console.WindowHeight - 1;
                }

                if (snakeNewHead.Row >= Console.WindowHeight)
                {
                    snakeNewHead.Row = 0;
                }

                if (snakeNewHead.Col >= Console.WindowWidth)
                {
                    snakeNewHead.Col = 0;
                }

                if (snakeElements.Contains(snakeNewHead) || obstacles.Contains(snakeNewHead))
                {
                    Console.SetCursorPosition(0, 0);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Game Over!");

                    int userPoints = (snakeElements.Count - 5) * 100 - negativePoints;

                    if (Math.Max(userPoints, 0) == 0)
开发者ID:AngataHristov,项目名称:MySnakeGame,代码行数:67,代码来源:Snake.cs


注:本文中的Queue.Last方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。