示例#1
0
        public void TestCanMoveRightNotOK01()
        {
            Tetromino  block = new Tetromino(TetrisGame.NB_COLUMNS - 1, 6, TetrominoType.Square);
            TetrisGame game  = new TetrisGame();

            Assert.IsFalse(block.CanMoveRight(game));
        }
示例#2
0
        public void TestCanMoveRightOK02()
        {
            Tetromino  block = new Tetromino(7, TetrisGame.NB_ROWS / 2, TetrominoType.Square);
            TetrisGame game  = new TetrisGame();

            Assert.IsTrue(block.CanMoveRight(game));
        }
示例#3
0
 public GameWorld(TetrisGame game)
 {
     this.game               = game;
     random                  = new Random();
     gameState               = GameState.Init;
     font                    = TetrisGame.ContentManager.Load <SpriteFont>("SpelFont");
     menuFont                = TetrisGame.ContentManager.Load <SpriteFont>("MenuFont");
     background              = TetrisGame.ContentManager.Load <Texture2D>("TETRIS");
     controls                = TetrisGame.ContentManager.Load <Texture2D>("Controls");
     endScreen               = TetrisGame.ContentManager.Load <Texture2D>("Gameover");
     emptyCell               = TetrisGame.ContentManager.Load <Texture2D>("block");
     normalTheme             = TetrisGame.ContentManager.Load <Song>("Normaltheme");
     hardTheme               = TetrisGame.ContentManager.Load <Song>("Hardtheme");
     nock                    = TetrisGame.ContentManager.Load <SoundEffect>("nock");
     rowDel                  = TetrisGame.ContentManager.Load <SoundEffect>("rowDel");
     lvlUp                   = TetrisGame.ContentManager.Load <SoundEffect>("lvlUp");
     gameOver                = TetrisGame.ContentManager.Load <SoundEffect>("youLose");
     MediaPlayer.IsRepeating = true;
     grid                    = new TetrisGrid();
     nrBlocks                = 7;
     nextBlock               = Random.Next(nrBlocks);
     ResetBlock();
     dropSpeed    = 1000;
     previousTime = 0;
     timePressed  = 0;
 }
示例#4
0
        public void TestCanMoveLeftNotOK01()
        {
            Tetromino  block = new Tetromino(1, TetrisGame.NB_ROWS - 2, TetrominoType.Square);
            TetrisGame game  = new TetrisGame();

            Assert.IsTrue(block.CanMoveLeft(game));
        }
示例#5
0
        public void Render(IStateOwner pOwner, Graphics pRenderTarget, MenuStateMultiOption Source, MenuStateMenuItemGDIPlusDrawData Element)
        {
            Font   useFont       = MenuStateTextMenuItemGDIRenderer.GetScaledFont(pOwner, Source.FontFace, Source.FontSize);
            var    OptionManager = Source.OptionManagerBase;
            var    Bounds        = Element.Bounds;
            String sLeftCover    = "< ";
            String sRightCover   = ">";

            var PrevItem = OptionManager.GetTextBase(OptionManager.PeekPreviousBase());
            var NextItem = OptionManager.GetTextBase(OptionManager.PeekNextBase());

            sLeftCover  = PrevItem + sLeftCover;
            sRightCover = sRightCover + NextItem;
            var MeasureLeft  = pRenderTarget.MeasureString(sLeftCover, useFont);
            var MeasureRight = pRenderTarget.MeasureString(sRightCover, useFont);

            PointF LeftPos  = new PointF(Bounds.Left - MeasureLeft.Width, Bounds.Top + (Bounds.Height / 2) - MeasureLeft.Height / 2);
            PointF RightPos = new PointF(Bounds.Right, Bounds.Top + (Bounds.Height / 2) - MeasureRight.Height / 2);

            if (Source.Activated)
            {
                TetrisGame.DrawText(pRenderTarget, useFont, sLeftCover, new SolidBrush(Source.ForeColor), new SolidBrush(Source.ShadowColor), LeftPos.X, LeftPos.Y);
                TetrisGame.DrawText(pRenderTarget, useFont, sRightCover, new SolidBrush(Source.ForeColor), new SolidBrush(Source.ShadowColor), RightPos.X, RightPos.Y);
            }
            base.Render(pOwner, pRenderTarget, Source, Element);
        }
示例#6
0
 private void Awake()
 {
     scoringSystem    = GetComponent <TetrisScore> ();
     garbageGenerator = GetComponent <GarbageGenerator>();
     board            = GetComponent <TetrisBoard>();
     game             = GetComponent <TetrisGame>();
 }
示例#7
0
    public void Start()
    {
        Time.fixedDeltaTime = 1.0f / Constants.FRAME_RATE;

        game = new TetrisGame();
        game.Setup(Data);
    }
        public void Render(IStateOwner pOwner, Graphics pRenderTarget, PauseGameState Source, BaseDrawParameters Element)
        {
            if (!Source.DrawDataInitialized)
            {
                InitDrawData(pOwner, Source, Element);
                Source.DrawDataInitialized = true;
            }
            Graphics g          = pRenderTarget;
            var      Bounds     = Element.Bounds;
            var      FallImages = Source.FallImages;
            //Render the paused state.
            Font   usePauseFont = TetrisGame.GetRetroFont(24, pOwner.ScaleFactor);
            String sPauseText   = "Pause";
            SizeF  Measured     = g.MeasureString(sPauseText, usePauseFont);

            g.FillRectangle(Brushes.Gray, Bounds);
            foreach (var iterate in FallImages)
            {
                iterate.Draw(g);
            }

            g.ResetTransform();
            PointF DrawPos = new PointF(Bounds.Width / 2 - Measured.Width / 2, Bounds.Height / 2 - Measured.Height / 2);

            TetrisGame.DrawText(g, usePauseFont, sPauseText, Brushes.White, Brushes.Black, DrawPos.X, DrawPos.Y);
            //retrieve the renderer for the MenuState object.
            base.Render(pOwner, pRenderTarget, Source, Element);
        }
示例#9
0
 public void RedrawStatusbarTetrominoBitmaps(IStateOwner Owner, GameplayGameState State, RectangleF Bounds)
 {
     lock (LockTetImageRedraw)
     {
         State.SetTetrominoImages(TetrisGame.GetTetrominoBitmaps(Bounds, State.PlayField.Theme, State.GameHandler, State.PlayField, (float)Owner.ScaleFactor));
     }
 }
示例#10
0
        uint AppearanceTimeDifference = 500; //aiming for 50ms here
        public PrimaryBlockAppearanceState(GameplayGameState startupState)
        {
            SortedList <Guid, Blocks.LineSeriesPrimaryBlock> appearanceshuffler = new SortedList <Guid, Blocks.LineSeriesPrimaryBlock>();

            StandardState = startupState;
            //set all Primary Blocks to invisible and force a redraw.

            var field = StandardState.PlayField.Contents;

            for (int x = 0; x < StandardState.PlayField.ColCount; x++)
            {
                for (int y = 0; y < StandardState.PlayField.RowCount; y++)
                {
                    var block = field[y][x];
                    if (block is Blocks.LineSeriesPrimaryBlock lsmb)
                    {
                        lsmb.Visible = false;
                        appearanceshuffler.Add(Guid.NewGuid(), lsmb);
                    }
                }
            }
            AppearanceBlocks = new Queue <Blocks.LineSeriesPrimaryBlock>(appearanceshuffler.Values);
            StandardState.PlayField.HasChanged = true; //since we made them all invisible I'd say that counts as a change!
            LastAppearanceTick = TetrisGame.GetTickCount();
        }
示例#11
0
 private void Awake()
 {
     tetrisGame   = GetComponent <TetrisGame>();
     tetrisBoard  = GetComponent <TetrisBoard>();
     playerScript = GetComponent <Player>();
     ChangeState(new FillState(Cooldown));
 }
示例#12
0
        public void OnDrawing(TetrisGame game, TetrisGame.DrawEventArgs e)
        {
            // Repaint all ( May be ineffient --> Only repaint the region of block? )
            Square[,] image = game.Image;
            int i, j;

            for (i = 0; i < game.Height; i++)
            {
                for (j = 0; j < game.Width; j++)
                {
                    try
                    {
                        rect[i, j].Dispatcher.Invoke(
                            new Action(
                                delegate
                        {
                            rect[i, j].Fill = new SolidColorBrush(colors[image[i, j] == null ? 0 : (image[i, j].Color < colors.Length ? image[i, j].Color : colors.Length - 1)]);
                            //Trace.WriteLine(String.Format("{0}, {1}: {2}", i, j, image[i, j] == null ? 0 : image[i, j].Color));
                        }
                                ));
                    }
                    catch
                    {
                    }
                }
            }
        }
示例#13
0
        private static readonly IDictionary <string, AchievementState> States = new Dictionary <string, AchievementState>(); // 全体成就状态

        public static void Bind(TetrisGame game, string name = "")                                                           // 静态方法,绑定游戏
        {
            if (name == "")
            {
                return;
            }
            if (!States.ContainsKey(name)) // 如果没有现在的用户,设定为新用户
            {
                States[name] = new AchievementState();
            }
            game.AchievementState = States[name];
            game.GameEndEvent    += new TetrisGame.GameEndCallback( // 更新最高分
                delegate(object sender, TetrisGame.GameEndEventArgs e)
            {
                if (e.Score > game.AchievementState.HighScore)
                {
                    game.AchievementState.HighScore = e.Score;
                }
            }
                );
            game.UpdateEndEvent += new TetrisGame.UpdateEndCallback( // 更新总消除行数
                delegate(TetrisGame sender, TetrisGame.UpdateEndEventArgs e)
            {
                game.AchievementState.TotalClearBar += game.TickClearedBars;
                AchievementSystem.UpdateHighest();
            });
            new SeqClearBind().Bind(game); // 绑定子系统
            new HardSurviveBind().Bind(game);
        }
示例#14
0
        static void Main(string[] args)
        {
            Dimension gridSize     = new Dimension(11, 17);
            int       fallingSpeed = 700;

            controls = new Dictionary <char, Command>()
            {
                ['w'] = Command.ROTATE,
                ['a'] = Command.MOVE_LEFT,
                ['s'] = Command.MOVE_DOWN,
                ['d'] = Command.MOVE_RIGHT,
                [' '] = Command.DROP
            };
            ConsoleGameFrame gameFrame = new ConsoleGameFrame(gridSize);

            game = new TetrisGame(gridSize, fallingSpeed);
            game.OnTetrominoStateChanged += gameFrame.DisplayTetromino;
            game.OnBoardStateChanged     += gameFrame.DisplayBoard;
            game.OnGameOver += () =>
            {
                gameFrame.DisplayGameOver();
                IsRunning = false;
            };
            game.Start();
            new Thread(ReadKey).Start();
        }
示例#15
0
        public void TestCanMoveDownNotOK04()
        {
            Tetromino  block = new Tetromino(4, 237483878, TetrominoType.Square);
            TetrisGame game  = new TetrisGame();

            Assert.IsFalse(block.CanMoveDown(game));
        }
示例#16
0
        public void TestCanMoveDownNotOK03()
        {
            Tetromino  block = new Tetromino(1, TetrisGame.NB_ROWS - 2, TetrominoType.Square);
            TetrisGame game  = new TetrisGame();

            Assert.IsFalse(block.CanMoveDown(game));
        }
示例#17
0
 void Start()
 {
     game                     = new TetrisGame();
     timeUntilFall            = fallDelay;
     TetrominoController.cube = cube;
     CreateNewPiece();
 }
示例#18
0
        public void TestCanMoveDownOK01( )
        {
            Tetromino  block = new Tetromino(7, 0, TetrominoType.Square);
            TetrisGame game  = new TetrisGame();

            Assert.IsTrue(block.CanMoveDown(game));
        }
        public override void Render(IStateOwner pOwner, Graphics pRenderTarget, UnpauseDelayGameState Source, BaseDrawParameters Element)
        {
            Graphics g      = pRenderTarget;
            var      Bounds = Element.Bounds;

            RenderingProvider.Static.DrawElement(pOwner, pRenderTarget, Source._ReturnState, Element);
            //Draw Faded out overlay to darken things up.
            DrawFadeOverlay(g, Bounds);
            //draw a centered Countdown

            if (Source.LastSecond != Source.timeremaining.Seconds)
            {
                //emit a sound.
                TetrisGame.Soundman.PlaySound(pOwner.AudioThemeMan.GameOverShade.Key, pOwner.Settings.std.EffectVolume);
                Source.LastSecond = Source.timeremaining.Seconds;
                Source.lastMillis = 1000;
            }

            double SecondsLeft  = Math.Round(Source.timeremaining.TotalSeconds, 1);
            String sSecondsLeft = Source.timeremaining.ToString("%s");
            double Millis       = (double)Source.timeremaining.Milliseconds / 1000d; //millis in percent. We will use this to animate the unpause time left.

            Millis = Math.Min(Millis, Source.lastMillis);
            float useSize     = (float)(64f * (1 - (Millis)));
            var   SecondsFont = TetrisGame.GetRetroFont(useSize, pOwner.ScaleFactor);
            var   MeasureText = g.MeasureString(sSecondsLeft, SecondsFont);

            PointF DrawPosition = new PointF(Bounds.Width / 2 - MeasureText.Width / 2, Bounds.Height / 2 - MeasureText.Height / 2);

            g.DrawString(sSecondsLeft, SecondsFont, Brushes.White, DrawPosition);
            Source.lastMillis = Millis;
        }
示例#20
0
        public void BoardDrawing()
        {
            var game = new TetrisGame(new Vec2i(10, 20), new PlayerScoreFile("helo.txt"));

            var board = new TetrisBoard(new Vec2i(6, 12));

            board.Draw(new Tetromino(TetrisCell.L, new int[, ] {
                { 0, 0, 1 },
                { 1, 1, 1 },
                { 0, 0, 0 },
            }), new Vec2i(2, 5));
            board.Draw(new Tetromino(TetrisCell.T, new int[, ] {
                { 0, 1, 0 },
                { 1, 1, 1 },
                { 0, 0, 0 },
            }), new Vec2i(1, 4));

            // I'm sorry
            var expected_board = new TetrisCell[12][] {
                new TetrisCell[6] {
                    0, 0, 0, 0, 0, 0
                },
                new TetrisCell[6] {
                    0, 0, 0, 0, 0, 0
                },
                new TetrisCell[6] {
                    0, 0, 0, 0, 0, 0
                },
                new TetrisCell[6] {
                    0, 0, 0, 0, 0, 0
                },
                new TetrisCell[6] {
                    0, 0, TetrisCell.T, 0, 0, 0
                },
                new TetrisCell[6] {
                    0, TetrisCell.T, TetrisCell.T, TetrisCell.T, TetrisCell.L, 0
                },
                new TetrisCell[6] {
                    0, 0, TetrisCell.L, TetrisCell.L, TetrisCell.L, 0
                },
                new TetrisCell[6] {
                    0, 0, 0, 0, 0, 0
                },
                new TetrisCell[6] {
                    0, 0, 0, 0, 0, 0
                },
                new TetrisCell[6] {
                    0, 0, 0, 0, 0, 0
                },
                new TetrisCell[6] {
                    0, 0, 0, 0, 0, 0
                },
                new TetrisCell[6] {
                    0, 0, 0, 0, 0, 0
                },
            };

            Assert.Equal(expected_board, board.Cells);
        }
示例#21
0
        public void TestCanMoveDownNotOK02( )
        {
            Tetromino  block = new Tetromino(1, TetrisGame.NB_ROWS - 3, TetrominoType.Square);
            TetrisGame game  = new TetrisGame( );

            game.FreezeContent(TetrisGame.NB_ROWS - 1, 1);
            Assert.IsFalse(block.CanMoveDown(game));
        }
示例#22
0
        public void TestCanMoveRightNotOK02()
        {
            Tetromino  block = new Tetromino(9, 7, TetrominoType.Square);
            TetrisGame game  = new TetrisGame();

            game.FreezeContent(7, 10);
            Assert.IsFalse(block.CanMoveRight(game));
        }
 /// <summary>
 /// Draw the score on the screen
 /// </summary>
 /// <param name="score">the score of the player</param>
 private void DrawScore(int score)
 {
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.SetCursorPosition(columns + 3, 6);
     Console.Write($"Score: {score}");
     Console.SetCursorPosition(columns + 3, 7);
     Console.Write($"Level: {TetrisGame.GetLevelFromScore(score)}");
 }
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="keyPressEventHandler"></param>
 /// <param name="startingAwaiter"></param>
 /// <param name="tetrisGame"></param>
 public Startup(KeyPressEventHandler keyPressEventHandler,
                StartingAwaiter startingAwaiter,
                TetrisGame tetrisGame)
 {
     _keyPressEventHandler = keyPressEventHandler;
     _startingAwaiter      = startingAwaiter;
     _tetrisGame           = tetrisGame;
 }
示例#25
0
        public static void Bind(TetrisGame game)
        {
            var ss = new ScoreSystem();

            game.ScoreSystem     = ss;
            game.UpdateEndEvent += ss.OnUpdateEnd;
            //game.ClearBarEvent += ss.OnUpdateEnd;
        }
示例#26
0
        public void TestCanMoveLeftNotOK02()
        {
            Tetromino  block = new Tetromino(10, 5, TetrominoType.Square);
            TetrisGame game  = new TetrisGame();

            game.FreezeContent(5, 8);
            Assert.IsFalse(block.CanMoveLeft(game));
        }
示例#27
0
 private void ProcessSpeedUp(TetrisGame game, TetrisGame.UpdateBeginEventArgs e) // 按得分加速
 {
     if (game.ScoreSystem.Score >= _nextSpeedUp)
     {
         game.GameSpeed++;
         _nextSpeedUp += 20;
     }
 }
示例#28
0
    IEnumerator ContinousMove(bool isLeft)
    {
        while (true)
        {
            TetrisGame.GetInstance().MoveTetromino(isLeft ? MoveDirection.Left : MoveDirection.Right);

            yield return(new WaitForSeconds(continousMoveTime));
        }
    }
        public override void Render(IStateOwner pOwner, Graphics pRenderTarget, ViewScoreDetailsState Source, BaseDrawParameters Element)
        {
            var g      = pRenderTarget;
            var Bounds = Element.Bounds;

            RenderingProvider.Static.DrawElement(pOwner, pRenderTarget, Source.BG, new GDIBackgroundDrawData(Bounds));


            Font HeaderFont    = TetrisGame.GetRetroFont(24, pOwner.ScaleFactor);
            Font PlacementFont = TetrisGame.GetRetroFont(10, pOwner.ScaleFactor);
            Font DetailFont    = TetrisGame.GetRetroFont(8, pOwner.ScaleFactor);


            //One thing we draw in every case is the "--SCORE DETAILS--" header text. this is positioned at 5% from the top, centered in the middle of our bounds.
            float Millipercent = (float)DateTime.Now.Ticks / 5000f; //(float)DateTime.Now.Millisecond / 1000;

            var    MeasuredHeader = g.MeasureString(Source._DetailHeader, HeaderFont);
            int    RotateAmount   = (int)(Millipercent * 240);
            Color  UseColor1      = HSLColor.RotateHue(Color.Red, RotateAmount);
            Color  UseColor2      = HSLColor.RotateHue(Color.LightPink, RotateAmount);
            PointF ScorePosition  = new PointF((Bounds.Width / 2) - (MeasuredHeader.Width / 2), Bounds.Height * 0.05f);

            using (LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0, (int)MeasuredHeader.Width, (int)MeasuredHeader.Height), UseColor1, UseColor2, LinearGradientMode.Vertical))
            {
                using (GraphicsPath gp = new GraphicsPath())
                {
                    gp.AddString(Source._DetailHeader, HeaderFont, new Point((int)ScorePosition.X, (int)ScorePosition.Y), StringFormat.GenericDefault);
                    g.FillPath(lgb, gp);
                    g.DrawPath(Pens.White, gp);
                }
            }

            //we also show Xth Place - <NAME> centered below the header using the placementfont.
            String sPlacement = TetrisGame.FancyNumber(Source._Position) + " - " + Source.ShowEntry.Name + " - " + Source.ShowEntry.Score.ToString();

            var measureit = g.MeasureString(sPlacement, PlacementFont);

            PointF DrawPlacement = new PointF(Bounds.Width / 2 - measureit.Width / 2, (float)(ScorePosition.Y + MeasuredHeader.Height * 1.1f));

            g.DrawString(sPlacement, PlacementFont, Brushes.Black, DrawPlacement.X + 3, DrawPlacement.Y + 3);
            g.DrawString(sPlacement, PlacementFont, Brushes.White, DrawPlacement.X, DrawPlacement.Y);

            g.DrawLine(Separator, (float)(Bounds.Width * 0.05f), (float)(DrawPlacement.Y + measureit.Height + 5), (float)(Bounds.Width * 0.95), (float)(DrawPlacement.Y + measureit.Height + 5));


            switch (Source.CurrentView)
            {
            case ViewScoreDetailsState.ViewScoreDetailsType.Details_Tetrominoes:
                DrawTetronimoDetails(Source, g, Bounds);
                break;

            case ViewScoreDetailsState.ViewScoreDetailsType.Details_LevelTimes:
                DrawLevelTimesDetails(Source, g, Bounds);
                break;
            }
        }
示例#30
0
    public void StartGame()
    {
        score          = 0;
        Time.timeScale = 1.0f;

        InputController.EnableInput();
        UIManager.GetInstance().HideGameOverPanel();
        UIManager.GetInstance().UpdateScoreText(score);
        TetrisGame.GetInstance().StartNewGame();
    }
示例#31
0
文件: IPiece.cs 项目: brunodfg/Tetris
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameArea"></param>
        public override void JoinGame(TetrisGame gameArea)
        {
            base.JoinGame(gameArea);

            // Define initial
        }
示例#32
0
    void Awake()
    {
        Instance = this;

        _board = new GameObject[BOARD_WIDTH, BOARD_HEIGHT];
        _gridHeirarchy = new GameObject[BOARD_WIDTH, BOARD_HEIGHT];
        _started = false;

        CreateGridHeirarchyObjects();
    }
示例#33
0
    //--------------------------------------------------------------------------
    // Use this for initialization
    void Start()
    {
        mHighScoreBoard = GetComponentInParent<HighScoreComponent>();

        mMainMenu = GameObject.Find("MainMenu");
        mLeftBorder = GameObject.Find("LeftBorder");
        mRightBorder = GameObject.Find("RightBorder");
        mBottomBorder = GameObject.Find("BottomBorder");
        mGameStatusPanel = GameObject.Find("GameStatusPanel");
        mPausePanel = GameObject.Find("PausePanel");
        mGameEndPanel = GameObject.Find("GameEndPanel");
        mHighScorePanel = GameObject.Find("HighScorePanel");

        mTetrisGame = new TetrisGame();
        mTetrisGame.Start();
        ReturnToMainMenu();
    }
示例#34
0
 static void Main(string[] args)
 {
     TetrisGame game = new TetrisGame();
     game.Run();
 }
示例#35
0
文件: Piece.cs 项目: brunodfg/Tetris
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameArea"></param>
        public virtual void JoinGame(TetrisGame gameArea)
        {
            this.GameArea = gameArea;

            #region Validations

            if (this.GameArea == null)
            {
                throw new ArgumentNullException("gameArea");
            }

            if (this.TemplateRotationOrigin == null)
            {
                throw new ArgumentNullException("RotationCenterLocation");
            }

            if (this.FilledBlocks == null || this.FilledBlocks.Count() == 0)
            {
                throw new Exception("The piece is not present on the game area");
            }

            #endregion

            #region Determine initial rotation origin block based on template

            // Based on the piece's template and on the template's rotation origin,
            // determine which of the currently filled blocks is the origin of rotation

            var minXFilledBlock = this.FilledBlocks.Select(b => b.X).Min();
            var minYFilledBlock = this.FilledBlocks.Select(b => b.Y).Min();

            var minXTemplateOrigin = this.Template.Select(l => l.X).Min();
            var minYTemplateOrigin = this.Template.Select(l => l.Y).Min();

            var rotationBlockX = this.TemplateRotationOrigin.X + (minXFilledBlock - minXTemplateOrigin);
            var rotationBlockY = this.TemplateRotationOrigin.Y + (minYFilledBlock - minYTemplateOrigin);

            this.CurrentRotationOriginBlock = this.FilledBlocks.FirstOrDefault(b => b.X == rotationBlockX && b.Y == rotationBlockY);

            #endregion
        }