Beispiel #1
0
        public static If produce(Queue<Token> tokens)
        {
            expect(tokens, TokenType.IF);

            Expression expression = ExpressionFactory.produce(tokens);

            expect(tokens, TokenType.DO);

            Block block = BlockFactory.produce(tokens);

            if (tokens.Count != 0 && tokens.First().tokenType == TokenType.ELSE)
            {
                tokens.Dequeue();

                Block elseBlock = null;

                if (tokens.First().tokenType == TokenType.IF)
                {
                    Token firstBlockToken = tokens.First();
                    If ifSymbol = produce(tokens);

                    List<Statement> elseBlockSymbolList = new List<Statement> {ifSymbol};

                    elseBlock = new Block(firstBlockToken, elseBlockSymbolList);
                }
                else {
                    expect(tokens, TokenType.DO);

                    elseBlock = BlockFactory.produce(tokens);
                }

                return new If(expression, block, elseBlock);
            }

            return new If(expression, block);
        } 
Beispiel #2
0
        public static Block produce(Queue<Token> tokens)
        {
            List<Statement> statements = new List<Statement>();

            Token firstBlockToken = tokens.First();
            expect(tokens, TokenType.INDENT);

            while (tokens.Count != 0)
            {
                Statement statement = StatementFactory.produce(tokens);
                if(statement == null)
                    break;
                statements.Add(statement);
            }
            expect(tokens, TokenType.DEDENT);

            return new Block(firstBlockToken, statements);
        }
        public static Primitive produce(Queue<Token> tokens)
        {
            Token token = tokens.First();
            string content = token.content;

            Primitive primitive = null;
            if (token.tokenType == TokenType.BOOLEAN)
            {
                tokens.Dequeue();
                content = content.ToLower();
                primitive = new Bool(token, content == "true");
            }
            else if (token.tokenType == TokenType.TEXT)
            {
                tokens.Dequeue();
                primitive = new Text(token, content);
            }
            else if( token.tokenType == TokenType.NUMBER)
            {
                tokens.Dequeue();
                primitive = new Number(token, Convert.ToDouble(content));
            }
            return primitive;
        }
Beispiel #4
0
        private static void fallingWords(Random ran, string[] textToArrey, int wordsCount, DateTime start)
        {
            int randomWordIndesx = ran.Next(0, textToArrey.Length);
            int randomWordPosition = ran.Next(10, 60);
            string curentWordString = textToArrey[randomWordIndesx];
            Queue<char> que = new Queue<char>();
            foreach (var letter in curentWordString)
            {
                que.Enqueue(letter);
            }

            for (int i = 0; ; i++)
            {
                if (que.Count == 0)
                {
                    wordsCount++;
                    fallingWords(ran, textToArrey, wordsCount, start);
                    break;
                }
                Console.Clear();
                char pressedBuon = new char();
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo a = Console.ReadKey();
                    pressedBuon = a.KeyChar;
                    Console.Clear();
                }

                // var tem = que.First();
                if (que.First() == pressedBuon)
                {
                    que.Dequeue();
                }
                if (i == Console.BufferHeight)
                {
                    DateTime end = DateTime.Now;
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("GAME OVER");
                    var playedTime = end - start;
                    int min = 0;
                    if (playedTime.Minutes > min)
                    {
                        min = playedTime.Minutes;
                    }
                    double playedTimeInSeconds = playedTime.Seconds + (min * 60);
                    double wordsPerSecond = wordsCount / playedTimeInSeconds;
                    Console.WriteLine("Words per minute: {0:0.#}", wordsPerSecond * 60);
                    //Console.WriteLine("play time {0}",playedTime);
                    //Console.WriteLine("seconds={0}",playedTimeInSeconds);
                    //Console.WriteLine(wordsCount);
                    break;
                }
                //print
                Console.SetCursorPosition(randomWordPosition, i);
                Console.Write(new string(' ', curentWordString.Length - que.Count));
                foreach (var letter in que)
                {
                    Console.Write(letter);
                }
                //sleep++
                Thread.Sleep(400);
            }
        }
Beispiel #5
0
        public void BFS(int sx, int sy, int threshhold = 2)
        {
            visit = new bool[WIDTH, WIDTH];
            score = new double[WIDTH, WIDTH];
            prev = new Tuple<int, int>[WIDTH, WIDTH];
            Queue<Tuple<double, Tuple<int, int>>> q = new Queue<Tuple<double, Tuple<int, int>>>();
            q.Enqueue(new Tuple<double, Tuple<int, int>>(1, new Tuple<int, int>(sx, sy)));

            List<int> dx = new List<int>();
            List<int> dy = new List<int>();
            for (int i = -threshhold; i <= threshhold; i++)
                for (int j = -threshhold; j <= threshhold; j++)
                {
                    dx.Add(i);
                    dy.Add(j);
                }
            int loop = 0;
            bool visitTag = false;
            while (q.Count > 0)
            {
                Tuple<double, Tuple<int, int>> min = q.First();

                int x = min.Item2.Item1;
                int y = min.Item2.Item2;
                if (visit[x, y])
                {
                    q.Dequeue();
                    continue;
                }
                loop++;
                //if (loop % 100 == 0)

                visit[x, y] = true;
                for (int i = 0; i < dx.Count; i++)
                {
                    int nx = x + dx[i];
                    int ny = y + dy[i];
                    if (nx < 0) continue;
                    if (nx >= WIDTH) continue;
                    if (ny < 0) continue;
                    if (ny >= WIDTH) continue;
                    if (visit[nx, ny])
                        continue;

                    if (tagMap[nx, ny])
                    {
                        visitTag = true;
                    }
                    else
                    {
                        if (visitTag)
                            continue;
                    }

                    double newscore = score[x, y] + 1;
                    double oldscore = score[nx, ny];
                    if (oldscore == 0 || oldscore > newscore)
                    {
                        score[nx, ny] = newscore;
                        prev[nx, ny] = new Tuple<int, int>(x, y);
                        q.Enqueue(new Tuple<double, Tuple<int, int>>(newscore, new Tuple<int, int>(nx, ny)));
                    }
                }
                q.Dequeue();
            }
        }