Ejemplo n.º 1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var parameters = (TetrisInput)e.Parameter;

            generateGrid(TetrisSettings.Width, TetrisSettings.Height);
            this.boardOccupation = new bool[width, height];
            this.boardFills      = new Rectangle[width, height];
            this.game            = new TetrisGame(width, height);

            this.ann     = new ANN(ANNSettings.Weights, ANNSettings.Input, ANNSettings.Hidden);
            this.package = new PlacementPackage()
            {
                RemovedRows = 0
            };

            SolidColorBrush blackBrush = new SolidColorBrush(Colors.Black);

            for (int x = 0; x < this.width; x++)
            {
                for (int y = 0; y < this.height; y++)
                {
                    var block = new Rectangle();
                    block.Fill   = transparentBrush;
                    block.Stroke = blackBrush;
                    Grid.SetColumn(block, x);
                    Grid.SetRow(block, y);
                    board.Children.Add(block);
                    boardFills[x, y] = block;
                }
            }
        }
Ejemplo n.º 2
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     TetrisGame tetris = new TetrisGame();
     Application.Run(tetris);
 }
Ejemplo n.º 3
0
        public MainForm()
        {
            Game       = new TetrisGame();
            Game.Score = 0; Game.GameOver = true;

            Saver.Load();

            GF = new GameField(18, 12);

            Preview             = new TetrisField(4, 4);
            Preview.BorderColor = Preview.BackColor;

            Random rnd = new Random();

            // Типа сплэш
            for (int row = 0; row < GF.TilesHeight; row++)
            {
                for (int col = 0; col < GF.TilesWidth; col++)
                {
                    TileType t = (TileType)rnd.Next(0, 7);
                    GF.SetCell(row, col, t);
                }
            }

            Game.StateChanged += new EventHandler(Game_StateChanged);

            InitializeComponent();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (TetrisGame game = new TetrisGame())
     {
         game.Run();
     }
 }
Ejemplo n.º 5
0
 static void Main()
 {
     using (var game = new TetrisGame())
     {
         game.Run();
     }
 }
Ejemplo n.º 6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            TetrisGame tetris = new TetrisGame();

            Application.Run(tetris);
        }
Ejemplo n.º 7
0
Archivo: Form1.cs Proyecto: s4lt3d/NEAT
        private void Form1_Load(object sender, EventArgs e)
        {
            Image i = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            pictureBox1.Image = i;
            tetris            = new TetrisGame(10, 20, i);
            timer1.Enabled    = true;
        }
Ejemplo n.º 8
0
        public TetrisGrid(TetrisGame setGame, Rectangle setGridRect, Rectangle setNextBlockRect)
            : base(setGame)
        {
            mGame     = setGame;
            mGridRect = setGridRect;

            mNextBlock = new NextBlock(mGame, setNextBlockRect);
            mGame.Components.Add(mNextBlock);
        }
Ejemplo n.º 9
0
 public TetrisPlayingANN(double[] weights, bool eval = true)
 {
     this.tetrisGame = new TetrisGame(TetrisSettings.Width, TetrisSettings.Height);
     this.ann        = new ANN(weights, ANNSettings.Input, ANNSettings.Hidden);
     if (eval)
     {
         this.Evaluate();
     }
 }
Ejemplo n.º 10
0
        public MainWindow()
        {
            InitializeComponent();
            initializeScreen();
            initializeTimer();
            InitilizeKeyboard();

            _game = new TetrisGame(_screenMemory, TotalLines, getTime, () => _gamePad);

            _game.InitGame();
        }
Ejemplo n.º 11
0
 private void ClearBoard()
 {
     this.boardOccupation = new bool[width, height];
     for (int x = 0; x < this.width; x++)
     {
         for (int y = 0; y < this.height; y++)
         {
             boardFills[x, y].Fill = transparentBrush;
         }
     }
     this.game = new TetrisGame(TetrisSettings.Width, TetrisSettings.Height);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Handles the Form Load Event
 /// Loads the Tetris class and hooks up the events
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Form1_Load(object sender, EventArgs e)
 {
     _game = new TetrisGame(this);
     _game.PieceOkToMove            += Game_PieceOkToMove;
     _game.LoadFirstPreviewPicture  += Game_LoadFirstPreviewPicture;
     _game.LoadSecondPreviewPicture += Game_LoadSecondPreviewPicture;
     _game.LoadThirdPreviewPicture  += Game_LoadThirdPreviewPicture;
     _game.LoadHeldPicture          += Game_LoadHeldPicture;
     _game.GameOver += Game_GameOver;
     _okToMove       = true;
     _gameOver       = false;
 }
Ejemplo n.º 13
0
        void Start()
        {
            game   = GetComponent <TetrisGame> ();
            width  = game.width;
            height = game.height;
            float ox = 0, oy = 0;
            float hr = (float)Screen.height / height, wr = (float)Screen.width / width;

            dx = dy = Mathf.Min(hr, wr);
            var rect   = new Rect(0, 0, 1, 1);
            var bgRect = new Rect(0, 0, width, height);

            bgTexture.wrapMode = TextureWrapMode.Repeat;
        }
Ejemplo n.º 14
0
        private void NewGame()
        {
            tetrisGame = new TetrisGame();
            tetrisGame.StateChanged += new EventHandler(Game_StateChanged);
            SetScore(0);

            tmrGame.Interval = 1000;
            tmrGame.Enabled  = true;

            tetrisGame.NextTetromino = Tetromino.RandomTetromino();

            gameField.Clear();

            Refresh();
        }
Ejemplo n.º 15
0
        private void NewGame()
        {
            Game = new TetrisGame();
            Game.StateChanged += new EventHandler(Game_StateChanged);
            SetScore(0);

            GameTimer.Interval = 1000;
            GameTimer.Enabled  = true;

            Game.NextFigure = Figure.RandomFigure();

            GF.Clear();

            Refresh();
        }
Ejemplo n.º 16
0
        readonly Device secDev;            //设备对象
        #endregion

        public MainForm()
        {
            //新建背景音乐线程,循环播放
            musicThread = new Thread(new ThreadStart(delegate { backgroundPlayer.PlayLooping(); }));

            //初始化TetrisGame对象
            tetrisGame = new TetrisGame
            {
                Score    = 0,
                GameOver = true
            };

            //加载存档
            Saver.Load();

            //初始化游戏区域,20×15
            gameField = new GameField(20, 15);

            //初始化“下一个”区域
            nextTetromino = new TetrisField(4, 4);
            //边界(指示器)颜色默认
            nextTetromino.BorderColor = nextTetromino.BackColor;

            //产生随机块
            Random rnd = new Random();

            for (int row = 0; row < gameField.TilesHeight; row++)
            {
                for (int col = 0; col < gameField.TilesWidth; col++)
                {
                    TileType t = (TileType)rnd.Next(0, 7);
                    gameField.SetCell(row, col, t);
                }
            }

            //注册游戏状态变化事件
            tetrisGame.StateChanged += new EventHandler(Game_StateChanged);

            InitializeComponent();

            //初始化声音设备,!当找不到声音设备时将报错!
            secDev = new Device();
            secDev.SetCooperativeLevel(this, CooperativeLevel.Normal);//设置设备协作级别

            //启动背景音乐播放线程
            musicThread.Start();
        }
Ejemplo n.º 17
0
        public MainForm()
        {
            Game        = new TetrisGame();
            Game.Score  = 0; Game.GameOver = true;
            Game.Score2 = 0;

            Saver.Load();

            GF  = new GameField(18, 12);
            GF2 = new GameField(18, 12);/////

            Preview             = new TetrisField(4, 4);
            Preview.BorderColor = Preview.BackColor;

            Preview2             = new TetrisField(4, 4);
            Preview2.BorderColor = Preview2.BackColor;

            Random rnd = new Random();

            // Type splash
            for (int row = 0; row < GF.TilesHeight; row++)
            {
                for (int col = 0; col < GF.TilesWidth; col++)
                {
                    TileType t = (TileType)rnd.Next(0, 7);
                    GF.SetCell(row, col, t);
                }
            }

            //
            for (int row = 0; row < GF2.TilesHeight; row++)
            {
                for (int col = 0; col < GF2.TilesWidth; col++)
                {
                    TileType t = (TileType)rnd.Next(0, 7);
                    GF2.SetCell(row, col, t);
                }
            }
            //

            Game.StateChanged += new EventHandler(Game_StateChanged);
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            InitializeComponent();
        }
Ejemplo n.º 18
0
        public MainWindow()
        {
            InitializeComponent();
            int[][,] styles = { new int[2, 2] {
                                    { 1, 1 }, { 1, 1 }
                                },         new int[1, 4]{
                                    { 1,         1, 1, 1 }
                                },         new int[2, 3]{
                                    { 0,0, 1 }, { 1, 1, 1 }
                                },         new int[2, 3]{
                                    { 1,0, 0 }, { 1, 1, 1 }
                                },         new int[2, 3]{
                                    { 0,1, 0 }, { 1, 1, 1 }
                                } };

            var game = new TetrisGame(Square.Styles(styles), new TimerEngine());

            game.AddDisplay(this);
            _controller = new Controller();
            game.SetController(_controller);
            game.Start();
        }
Ejemplo n.º 19
0
        private static void Main(string[] args)
        {
            /*Console.OutputEncoding = System.Text.Encoding.UTF8;
             * Console.WriteLine("\u0023");
             * Console.CursorVisible = false;
             * ConsoleContainer container = new ConsoleContainer(10, 9);
             * container.SetRenderFrame(container.GenerateEmptyFrame());
             *
             * container.StartRender();
             *
             * do
             * {
             *  container.SetRenderFrame(container.RenderedFrame.RandomizeFrame());
             * } while (true);*/

            // Console.ReadKey();

            //ConsoleContainer.ConsoleWindowRefreshEventProvider prov = ConsoleContainer.ConsoleWindowRefreshEventProvider.GetInstance();
            //prov.RefreshEvent += (s, a) => Console.WriteLine("Frame");

            /*ConsoleContainer c = new ConsoleContainer(10, 20);
             *
             * c.RenderedFrame.CombineWith(4,3 , new[,] { { new Pixel('#'), new Pixel('#'), new Pixel('#') }, { new Pixel(' '), new Pixel('#'), new Pixel(' ') } });
             * c.RenderFrame();*/

            /*for (int i = 0; i < 3; i++)
             * {
             *  Console.WriteLine(Figure.RandomFigure().ToString());
             * }*/

            Game game = new TetrisGame();

            game.StartGame();
            game.RefreshTask.Wait();

            //Console.ReadKey();
        }
Ejemplo n.º 20
0
 static void Main(string[] args)
 {
     using (TetrisGame game = new TetrisGame()) {
         game.Run();
     }
 }
Ejemplo n.º 21
0
		public NextBlock(TetrisGame setGame, Rectangle setNextBlockRect)
			: base(setGame) {
			game = setGame;
			nextBlockRect = setNextBlockRect;
		}
Ejemplo n.º 22
0
 public AiInputHandler(TetrisGame game)
 {
     this.game = game;
 }
Ejemplo n.º 23
0
        public void Update(object sender, EventArgs e)
        {
            Graphics.Clear(Color.Black);
            WindowInfo.CursorPosition = PointToClient(Cursor.Position);

            switch (CurrentState)
            {
            case States.PreIntro:
            {
                CurrentState = States.Intro;
                Intro.Start();
                break;
            }

            case States.Intro:
            {
                Intro.Update();
                Intro.Draw();
                break;
            }

            case States.MainMenuInit:
            {
                Intro.Dispose();
                pictureBox1.Click += MainMenu.OnClick;
                if (GameOver != null)
                {
                    pictureBox1.Click -= GameOver.OnClick;
                    GameOver.Dispose();
                }
                if (TetrisGame != null)
                {
                    TetrisGame.Stop();
                }
                MainMenu.Start();
                CurrentState = States.MainMenu;
                break;
            }

            case States.MainMenu:
            {
                MainMenu.Update();
                MainMenu.Draw();
                break;
            }

            case States.GamePreload:
            {
                TetrisGame         = new TetrisGame(this, MainMenu.GameOptions);
                KeyUp             += TetrisGame.OnKeyUp;
                KeyDown           += TetrisGame.OnKeyDown;
                pictureBox1.Click -= MainMenu.OnClick;
                MainMenu.Stop();
                TetrisGame.Start();
                CurrentState = States.FigureFalling;
                break;
            }

            case States.FigureFalling:
            {
                TetrisGame.Update();
                TetrisGame.Draw();
                break;
            }

            case States.GameOverInit:
            {
                GameOver = new GameOverScreen(this, TetrisGame.Scores);
                KeyUp   -= TetrisGame.OnKeyUp;
                KeyDown -= TetrisGame.OnKeyDown;
                TetrisGame.Dispose();
                CurrentState       = States.GameOver;
                pictureBox1.Click += GameOver.OnClick;
                break;
            }

            case States.GameOver:
            {
                GameOver.Update();
                GameOver.Draw();
                break;
            }

            case States.RowDestroyBegin:
            {
                TetrisGame.Draw();
                _indexes = new List <int>();
                for (int i = 0; i < TetrisGame.Rows; i++)
                {
                    bool flag = true;
                    for (int j = 0; j < TetrisGame.Cols; j++)
                    {
                        if (TetrisGame.Grid[j][i] == null)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        _indexes.Add(i);
                    }
                }
                if (_indexes.Count == 0)
                {
                    CurrentState = States.FigureFalling;
                }
                else
                {
                    _rowBrushes = new List <List <Brush> >();
                    for (int i = 0; i < _indexes.Count; i++)
                    {
                        _rowBrushes.Add(new List <Brush>());
                        for (int j = 0; j < TetrisGame.Cols; j++)
                        {
                            _rowBrushes[i].Add(TetrisGame.Grid[j][_indexes[i]].Brush);
                        }
                    }
                    CurrentState = States.RowDestroying;
                }
                break;
            }

            case States.RowDestroying:
            {
                elapsed += 1000 / 60;
                TetrisGame.Draw();
                if (elapsed > 1000 / 4)
                {
                    elapsed = 0;
                    couner++;
                    if (couner % 2 == 0)
                    {
                        for (int i = 0; i < _indexes.Count; i++)
                        {
                            for (int j = 0; j < TetrisGame.Cols; j++)
                            {
                                TetrisGame.Grid[j][_indexes[i]].Brush = Brushes.Black;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < _indexes.Count; i++)
                        {
                            for (int j = 0; j < TetrisGame.Cols; j++)
                            {
                                TetrisGame.Grid[j][_indexes[i]].Brush = _rowBrushes[i][j];
                            }
                        }
                    }
                    if (couner >= 5)
                    {
                        for (int i = 0; i < _indexes.Count; i++)
                        {
                            for (int j = 0; j < TetrisGame.Cols; j++)
                            {
                                TetrisGame.Grid[j][_indexes[i]] = null;
                            }
                        }
                        _indexes.Sort();
                        _indexes.Reverse();

                        for (int i = 0; i < _indexes.Count; i++)
                        {
                            for (int j = _indexes[i] + i; j > 0; j--)
                            {
                                for (int c = 0; c < TetrisGame.Cols; c++)
                                {
                                    TetrisGame.Grid[c][j] = TetrisGame.Grid[c][j - 1];
                                }
                            }
                        }
                        TetrisGame.Scores += 100 * _indexes.Count * _indexes.Count;

                        CurrentState = States.FigureFalling;
                        couner       = 0;
                    }
                }
                break;
            }

            default:
            {
                break;
            }
            }
            pictureBox1.Image = Bitmap;
        }
Ejemplo n.º 24
0
 public NextBlock(TetrisGame setGame, Rectangle setNextBlockRect)
     : base(setGame)
 {
     game          = setGame;
     nextBlockRect = setNextBlockRect;
 }
Ejemplo n.º 25
0
 public TetrisPlayingANN(TetrisGame tetrisGame, ANN ann)
 {
     this.tetrisGame = tetrisGame;
     this.ann        = ann;
     this.Evaluate();
 }
Ejemplo n.º 26
0
		public TetrisGrid(TetrisGame setGame, Rectangle setGridRect, Rectangle setNextBlockRect)
			: base(setGame) {
			mGame = setGame;
			mGridRect = setGridRect;

			mNextBlock = new NextBlock(mGame, setNextBlockRect);
			mGame.Components.Add(mNextBlock);
		}
Ejemplo n.º 27
0
 void IDisplay.SetGame(TetrisGame game)
 {
     _game = game;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initialises and starts a game of Tetris
 /// </summary>
 private void InitialiseGame()
 {
     game = new TetrisGame(Columns, Rows);
     game.StartGame();
     game.Timer.Tick += (s, e) => UpdateDisplay();
 }
Ejemplo n.º 29
0
 static void Main()
 {
     using (var game = new TetrisGame())
         game.Run();
 }