示例#1
0
文件: Program.cs 项目: jvlppm/Tetris
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Tetris game = new Tetris())
     {
         game.Run();
     }
 }
示例#2
0
        public static void FromTetromino(Tetris tetrisState, Tetromino tetromino, int startAngle, float time)
        {
            for (int x = 0; x < 4; x++)
                for (int y = 0; y < 4; y++)
                {
                    if (tetromino.Structure[x, y])
                    {
                        Tuple<int, int> XY = Tuple.Create(tetromino.X + x, tetromino.Y + y);
                        Transition t;
                        if (tetrisState.Transitions.ContainsKey(XY))
                        {
            #if diagnose
                            Debug.WriteLine("({0},{1}) reused for rotation", XY.Item1, XY.Item2);
            #endif
                            t = tetrisState.Transitions[XY];
                        }
                        else
                        {
            #if diagnose
                            Debug.WriteLine("({0},{1}) Created for rotation", XY.Item1, XY.Item2);
            #endif
                            t = new Transition(tetrisState, XY, time);
                        }

                        t.AddRotation(startAngle, new Vector2(tetromino.X + 2, tetromino.Y + 2));
                    }
                }
        }
 public static void Main(string[] args)
 {
     using (Tetris game = new Tetris()) {
         game.Run();
         //Thread thread = new Thread(new ThreadStart(game.Run));
         //thread.Start();
     }
 }
示例#4
0
 public Transition(Tetris tetrisState, Tuple<int, int> finalBlockTargetPosition, float time, bool noAdd = false)
 {
     this.TetrisState = tetrisState;
     this.FinalBlockTargetPosition = finalBlockTargetPosition;
     this.TransitionTime = time;
     if (!noAdd)
     {
         Register();
     }
 }
示例#5
0
 /// <summary>
 /// getting components and adding listeners
 /// </summary>
 public void Start()
 {
     m_Label1 = GameObject.Find("Label");
     label1   = m_Label1.GetComponent <Text>();
     button1  = m_Button1.GetComponent <Button>();
     button1.onClick.AddListener(delegate { Tetris.SetMode(1); });
     button2 = m_Button2.GetComponent <Button>();
     button2.onClick.AddListener(delegate { Tetris.SetMode(2); });
     button3 = m_Button3.GetComponent <Button>();
     button3.onClick.AddListener(Exit);
 }
示例#6
0
 static void Main(string[] args)
 {
     try
     {
         Tetris.ProcessFile(@"input.txt", @"output.txt");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
     }
 }
示例#7
0
        private void ResetSettings()
        {
            // сбрасываем настройки игры

            Properties.Settings.Default.Reset();
            Properties.Settings.Default.Save();

            Tetris.TankWidth  = Properties.Settings.Default.TankWidth;
            Tetris.TankHeight = Properties.Settings.Default.TankHeight;
            Tetris.FigureSet  = Properties.Settings.Default.FigureSet;
            Tetris.ColorSet   = Properties.Settings.Default.ColorSet;

            Tetris.Initialize();
        }
示例#8
0
 public static Game getInstance(Tetris tetris = null, Score score = null)
 {
     if (instance == null)
     {
         if (tetris == null || score == null)
         {
             return(null);
         }
         instance    = new Game();
         Game.score  = score;
         Game.tetris = tetris;
     }
     return(instance);
 }
示例#9
0
        /// <summary>
        /// init all objects
        /// </summary>
        public void Start()
        {
            RootGameObject = GameObject.Find("Root");
            tetris         = RootGameObject.GetComponent <Tetris>();

            glass   = new Glass(Mode);
            checker = new Checker(glass);
            DoInit  = true;

            figures   = new Figures(Mode);
            NewFigure = true;

            userInput = new UserInput();
            DoUpdate  = false;
            GameOver  = false;
        }
        private void FourD_Click(object sender, RoutedEventArgs e)
        {
            var fourD = new DateTime(2019, 12, 28);

            if (IsAble(fourD))
            {
                var tetris = new Tetris.Tetris();
                tetris.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                tetris.ShowDialog();
            }
            else
            {
                MessageBox.Show
                    ($"Only {Delta(fourD)} more days to go!", "Too Early!",
                    MessageBoxButton.OK);
            }
        }
        public static void AskForRestart()
        {
            Console.SetCursorPosition(36, 22);
            Console.Write("Restart: Y/N ");
            string playerDecision = Console.ReadLine();

            if (playerDecision.ToLower().Equals("y"))
            {
                Console.Clear();
                Launcher.DrawBorder();
                Tetris.StartGame();
            }
            else
            {
                Launcher.MainMenu();
            }
        }
示例#12
0
        private async void SendBlockToPlayer(object sender, TetrisEventArgs e)
        {
            if (Players.Count <= 1)
            {
                return;
            }

            Tetris tetris      = sender as Tetris;
            int    garbageLine = GetGarbageLine(e);

            foreach (Tetris player in Players)
            {
                if (player.PlayerId != tetris?.PlayerId)
                {
                    await Task.Run(() => player.SetGarbageLine(garbageLine));
                }
            }
        }
示例#13
0
        /** */
        protected void init()
        {
            this.game = new Tetris();
            game.setView(this);

            this.KeyDown += new KeyEventHandler(keyPressed);

            this.Size = new System.Drawing.Size(640, 422);

            //
            image    = new Bitmap(640, 400);
            graphics = Graphics.FromImage(image);

            patterns = new Bitmap("tetris.png");

            thread = new Thread(run);
            thread.Start();
        }
示例#14
0
        private void Form1_Load(object sender, EventArgs e)
        {
            System.Threading.Thread.CurrentThread.Name = "FormThread";

            this.pictureBox1.Width  = Piece.BLOCK_WIDTH * 11;
            this.pictureBox1.Height = Piece.BLOCK_WIDTH * 20;
            this.ActiveControl      = this.textBox2;

            m_painter = new Painter(this.pictureBox1);
            m_painter.Start();
            m_tetris = new Tetris();
            m_tetris.Stage.AddUpdateListener(OnUpdateCanvas);
            m_tetris.Updated += new TetrisUpdateDelegate(OnUpdateStatus);

            o  = new KeyStateBackgroundWatcher(50, OnKeyDown, Keys.Down, Keys.Left, Keys.Right, Keys.S);
            o2 = new KeyStateBackgroundWatcher(150, OnKeyDown, Keys.Space);
            o.Watch();
            o2.Watch();
        }
示例#15
0
        private void Form1_Load(object sender, EventArgs e)
        {
            System.Threading.Thread.CurrentThread.Name = "FormThread";

            this.pictureBox1.Width = Piece.BLOCK_WIDTH * 11;
            this.pictureBox1.Height = Piece.BLOCK_WIDTH * 20;
            this.ActiveControl = this.textBox2;

            m_painter = new Painter(this.pictureBox1);
            m_painter.Start();
            m_tetris = new Tetris();
            m_tetris.Stage.AddUpdateListener(OnUpdateCanvas);
            m_tetris.Updated += new TetrisUpdateDelegate(OnUpdateStatus);

            o = new KeyStateBackgroundWatcher(50, OnKeyDown, Keys.Down, Keys.Left, Keys.Right, Keys.S);
            o2 = new KeyStateBackgroundWatcher(150, OnKeyDown, Keys.Space);
            o.Watch();
            o2.Watch();
        }
示例#16
0
 /// <summary>
 /// Makes an effort to validate the game.
 /// </summary>
 /// <param name="game"></param>
 /// <returns></returns>
 private static bool GameIsValid(Tetris game)
 {
     if (game.Level < 0)
     {
         return(false);
     }
     if (game.RowsRemovedAtCurrentLevel < 0)
     {
         return(false);
     }
     if (game.RowsRemovedInTotal < 0)
     {
         return(false);
     }
     if (game.Fieldgrid == null)
     {
         return(false);
     }
     else
     {
         if (game.Fieldgrid.Field.GetLength(0) == Grid.GRIDHEIGHT && game.Fieldgrid.Field.GetLength(1) == Grid.GRIDWIDTH)
         {
             bool allValuesAreValid = true;
             for (int row = 0; row < Grid.GRIDHEIGHT && allValuesAreValid; ++row)
             {
                 for (int column = 0; column < Grid.GRIDWIDTH && allValuesAreValid; ++column)
                 {
                     if (game.Fieldgrid.Field[row, column] < 0 || game.Fieldgrid.Field[row, column] > 7)
                     {
                         return(false);
                     }
                 }
             }
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
示例#17
0
        /// <summary>
        /// Starts a new game.
        /// </summary>
        public void StartNewGame()
        {
            KillGame();
            GameUserIterface = new TetrisGUI();
            Model            = new Tetris();
            GameUserIterface.GameController = this;
            Model.GameController            = this;

            game = new Thread(Model.PlayGame);
            GameUserIterface.Grid = Model.Fieldgrid;
            game.Start();

            GameUserIterface.ActiveTetromino = Model.ActiveTetromino;


            UpdateScore();
            UpdateLevel();
            UpdateLineCount();

            GameUserIterface.Show();
        }
示例#18
0
        static List <Tetris> GetTetris()
        {
            Tetris tetris = new Tetris(0, 0);
            var    type   = GetTetrisTypes();

            //var type = TetrisTypes.Square; ;
            if (TetrisTypes.Square == type)
            {
                return(tetris.SquareType());
            }
            else if (TetrisTypes.L_Type == type)
            {
                return(tetris.L_Type());
            }
            else if (TetrisTypes.T_Type == type)
            {
                return(tetris.T_Type());
            }
            else
            {
                return(tetris.StickType());
            }
        }
示例#19
0
 public void MainMenu()
 {
     Console.Clear();
     Header();
     Console.WriteLine("    Controls: Arrow Keys + Spacebar");
     Console.WriteLine();
     if (menuSpace == 0)
     {
         Console.BackgroundColor = ConsoleColor.White;
         Console.ForegroundColor = ConsoleColor.Black;
         Console.WriteLine("   Start Game   ");
         Console.BackgroundColor = ConsoleColor.Black;
         Console.ForegroundColor = ConsoleColor.White;
         Console.WriteLine("   Scoreboarrd   ");
         Console.WriteLine("   Exit   ");
     }
     else if (menuSpace == 1)
     {
         Console.WriteLine("   Start Game   ");
         Console.BackgroundColor = ConsoleColor.White;
         Console.ForegroundColor = ConsoleColor.Black;
         Console.WriteLine("   Scoreboarrd   ");
         Console.BackgroundColor = ConsoleColor.Black;
         Console.ForegroundColor = ConsoleColor.White;
         Console.WriteLine("   Exit   ");
     }
     else if (menuSpace == 2)
     {
         Console.WriteLine("   Start Game   ");
         Console.WriteLine("   Scoreboarrd   ");
         Console.BackgroundColor = ConsoleColor.White;
         Console.ForegroundColor = ConsoleColor.Black;
         Console.WriteLine("   Exit   ");
         Console.BackgroundColor = ConsoleColor.Black;
         Console.ForegroundColor = ConsoleColor.White;
     }
     bool ck = true;
     while (ck)
     {
         ConsoleKeyInfo key = Console.ReadKey();
         if(key.Key == ConsoleKey.UpArrow)
         {
             if (menuSpace > 0)
             {
                 menuSpace--;
                 ck = false;
             }
         }
         else if (key.Key == ConsoleKey.DownArrow)
         {
             if (menuSpace < 2)
             {
                 menuSpace++;
                 ck = false;
             }
         }
         else if (key.Key == ConsoleKey.Spacebar)
         {
             if(menuSpace == 0)
             {
                 Tetris game = new Tetris();
                 game.dropRate = 1000;
                 game.Game();
             }
             if(menuSpace == 1)
             {
                 if (File.Exists(Scoreboard.path))
                 {
                     scoreboard();
                 }
                 else Console.WriteLine("   No scores recorderd yet");
             }
             if (menuSpace == 2)
             {
                 Environment.Exit(0);
             }
         }
     }
     MainMenu();
 }
示例#20
0
 private void frmGUI_Load(object sender, System.EventArgs e)
 {
     t = new Tetris();
 }
示例#21
0
 public Tetromino(Tetris tetrisState)
 {
     this.TetrisState = tetrisState;
 }
示例#22
0
        public static void DrawBorder()
        {
            SoundPlayer sp = new SoundPlayer();

            sp.SoundLocation = "Sounds/ingameSound.wav";
            if (HasMusic)
            {
                sp.PlayLooping();
            }

            Console.CursorVisible = false;
            Console.Clear();

            //Main field vertical lines
            for (int height = 1; height <= 22; height++)
            {
                Console.SetCursorPosition(0, height);
                Console.Write(VerticalLine);
                Console.SetCursorPosition(11, height);
                Console.Write(VerticalLine);
            }
            //Main field corners
            Console.SetCursorPosition(0, 0);
            Console.Write(TopLeftCorner);
            Console.SetCursorPosition(11, 0);
            Console.Write(TopRightCorner);
            Console.SetCursorPosition(0, 23);
            Console.Write(BottomLeftCorner);
            Console.SetCursorPosition(11, 23);
            Console.Write(BottomRightCorner);

            //Main field horizontal lines
            Console.SetCursorPosition(1, 0);
            for (int width = 0; width <= 9; width++)
            {
                Console.Write(HorizontalLine);
            }
            Console.SetCursorPosition(1, 23);
            for (int width = 0; width <= 9; width++)
            {
                Console.Write(HorizontalLine);
            }

            //Next block vertical lines
            for (int height = 0; height < 6; height++)
            {
                Console.SetCursorPosition(36, 9 + height);
                Console.Write(VerticalLine);
                Console.SetCursorPosition(45, 9 + height);
                Console.Write(VerticalLine);
            }

            //Next block corners + horizontal lines
            Console.SetCursorPosition(36, 9);
            Console.Write(TopLeftCorner);
            for (int width = 0; width < 8; width++)
            {
                Console.Write(HorizontalLine);
            }
            Console.Write(TopRightCorner);
            Console.SetCursorPosition(36, 15);
            Console.Write(BottomLeftCorner);
            for (int width = 0; width < 8; width++)
            {
                Console.Write(HorizontalLine);
            }
            Console.Write(BottomRightCorner);

            //Next Block text
            Console.SetCursorPosition(39, 10);
            Console.Write("NEXT");

            //Score field corners + horizontal lines
            Console.SetCursorPosition(33, 0);
            Console.Write(TopLeftCorner);
            for (int width = 0; width < 14; width++)
            {
                Console.Write(HorizontalLine);
            }
            Console.Write(TopRightCorner);
            Console.SetCursorPosition(33, 3);
            Console.Write(BottomLeftCorner);
            for (int width = 0; width < 14; width++)
            {
                Console.Write(HorizontalLine);
            }
            Console.Write(BottomRightCorner);

            //Score field vertical lines
            Console.SetCursorPosition(30, 1);
            for (int heitgh = 0; heitgh < 2; heitgh++)
            {
                Console.SetCursorPosition(33, 1 + heitgh);
                Console.Write(VerticalLine);
                Console.SetCursorPosition(48, 1 + heitgh);
                Console.Write(VerticalLine);
            }
            //Score field text
            Console.SetCursorPosition(38, 1);
            Console.Write("SCORES");

            //Level field corners + horizontal lines
            Console.SetCursorPosition(30, 4);
            Console.Write(TopLeftCorner);
            for (int width = 0; width < 7; width++)
            {
                Console.Write(HorizontalLine);
            }
            Console.Write(TopRightCorner);

            Console.SetCursorPosition(30, 8);
            Console.Write(BottomLeftCorner);
            for (int i = 0; i < 7; i++)
            {
                Console.Write(HorizontalLine);
            }
            Console.Write(BottomRightCorner);

            //Level field vertical lines
            for (int height = 0; height < 3; height++)
            {
                Console.SetCursorPosition(30, 5 + height);
                Console.Write(VerticalLine);
                Console.SetCursorPosition(38, 5 + height);
                Console.Write(VerticalLine);
            }
            //Level field text
            Console.SetCursorPosition(32, 5);
            Console.Write("LEVEL");

            //Lines field corners + horizontal lines
            Console.SetCursorPosition(43, 4);
            Console.Write(TopLeftCorner);
            for (int width = 0; width < 7; width++)
            {
                Console.Write(HorizontalLine);
            }
            Console.Write(TopRightCorner);

            Console.SetCursorPosition(43, 8);
            Console.Write(BottomLeftCorner);
            for (int i = 0; i < 7; i++)
            {
                Console.Write(HorizontalLine);
            }
            Console.Write(BottomRightCorner);

            //Lines field vertical lines
            for (int height = 0; height < 3; height++)
            {
                Console.SetCursorPosition(43, 5 + height);
                Console.Write(VerticalLine);
                Console.SetCursorPosition(51, 5 + height);
                Console.Write(VerticalLine);
            }
            //Lines field text
            Console.SetCursorPosition(45, 5);
            Console.Write("LINES");

            //Are you ready text
            Console.SetCursorPosition(3, 10);
            Console.WriteLine("Ready?");
            Console.CursorLeft = 3;
            Console.Write("(Y/N) ");
            string playerDecision = Console.ReadLine();

            if (playerDecision.ToLower().Equals("y"))
            {
                Tetris.StartGame();
            }
            else
            {
                MainMenu();
            }
        }
示例#23
0
        /** */
        protected void init() {
            this.game = new Tetris();
            game.setView(this);

            this.KeyDown += new KeyEventHandler(keyPressed);

            this.Size = new System.Drawing.Size(640, 422);

            //
            image = new Bitmap(640, 400);
            graphics = Graphics.FromImage(image);

            patterns = new Bitmap("tetris.png");

            thread = new Thread(run);
            thread.Start();
        }
示例#24
0
        public static void FromTetromino(Tetris tetrisState, Tetromino tetromino, int startX, int startY, float time, bool noAdd = false)
        {
            for (int x = 0; x < 4; x++)
                for (int y = 0; y < 4; y++)
                {
                    if (tetromino.Structure[x, y])
                    {
                        Tuple<int, int> XY = Tuple.Create(tetromino.X + x, tetromino.Y + y);
                        Transition t;
                        if (tetrisState.Transitions.ContainsKey(XY))
                            t = tetrisState.Transitions[XY];
                        else
                        {
            #if diagnose
                            Debug.WriteLine("({0},{1}) Created for tet translation", XY.Item1, XY.Item2);
            #endif
                            t = new Transition(tetrisState, XY, time);
                        }

                        t.AddTranslation(new Vector2((tetromino.X - startX), (tetromino.Y - startY)));
                    }
                }
        }
示例#25
0
 public Tetromino(Tetris tetrisState)
 {
     this.TetrisState = tetrisState;
 }
示例#26
0
 public Score(Tetris tetris)
 {
     this.tetris = tetris;
 }
示例#27
0
        static void Main(string[] args)
        {
            Tetris tetris = new Tetris();

            tetris.start();
        }
示例#28
0
        public PrikazIgre(TipIgre tig)
        {
            igra = new Tetris(tig);
            this.tig = tig;

            //ucitavanje
            img = new Bitmap(Properties.Resources.tile_mask);
            img1 = new Bitmap(Properties.Resources.tile_mask);
            img2 = new Bitmap(Properties.Resources.pattern);

            InitializeComponent();

            //velicina kockice
            int velicina = 24;
            //resize kockice s obzirom na formu max(1000px, 800px)
            while((((tig.Stupaca + 2) * velicina) +300)>1000 && (((tig.Redaka + 2) * 24) + 20)> 800){
                velicina -= 2;
            }
            //resize forme
            this.ClientSize = new Size(((tig.Stupaca + 2) * velicina) + 300, ((tig.Redaka + 2) * velicina) + 20);
            this.panel1.Width = (tig.Stupaca + 2) * velicina;
            this.panel1.Height = (tig.Redaka + 2) * velicina;

            //resize bitmapa
            img1 = (Image)new Bitmap(img1, new Size(panelSljedeciPrvi.Width / 4, panelSljedeciPrvi.Height / 4));
            img = (Image)new Bitmap(img, new Size(panel1.Width / (tig.Stupaca + 2), panel1.Height / (tig.Redaka + 2)));
            img2 = (Image)new Bitmap(img2, new Size(panel1.Width / (tig.Stupaca + 2), panel1.Height / (tig.Redaka + 2)));

            //bitmap
            bit = new Bitmap(panel1.Size.Width, panel1.Size.Height);
            Graphics g = Graphics.FromImage(bit);

            g.Clear(Color.White);

            int w = panel1.Width / (tig.Stupaca + 2);
            int h = panel1.Height / (tig.Redaka + 2);

            for (int r = 0; r < tig.Redaka + 2; ++r)
            {
                for (int s = 0; s < tig.Stupaca + 2; ++s)
                {
                    if (r == 0 || s == 0 || r == (tig.Redaka + 1) || s == (tig.Stupaca + 1))
                    {
                        g.FillRectangle(Brushes.DarkGray, new Rectangle(new Point((s * w) + 1, (r * h) + 1), new Size(w - 3, h - 3)));
                        g.DrawImage(img, new Point(s * w, r * h));
                    }
                    else
                    {
                        g.DrawImage(img2, new Point(s * w, r * h));
                    }
                }
            }
            panel1.BackgroundImage = bit;
            
            //Bitmap sljedeci
            bit_sljedeci = new Bitmap(panelSljedeciPrvi.Size.Width, panelSljedeciPrvi.Size.Height);

            //label color
            this.label1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#282d34");
            this.lbl_nivo.ForeColor = System.Drawing.ColorTranslator.FromHtml("#282d34");
            this.label4.ForeColor = System.Drawing.ColorTranslator.FromHtml("#282d34");
            this.label5.ForeColor = System.Drawing.ColorTranslator.FromHtml("#282d34");
            this.lbl_brzina.ForeColor = System.Drawing.ColorTranslator.FromHtml("#282d34");

            this.SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.DoubleBuffer,
                true);
            typeof(Panel).InvokeMember("DoubleBuffered",
                BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                null, panel1, new object[] { true });
            typeof(Panel).InvokeMember("DoubleBuffered",
                BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                null, panelSljedeciPrvi, new object[] { true });
            typeof(Panel).InvokeMember("DoubleBuffered",
                  BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                  null, panelSljedeciDrugi, new object[] { true });

            tableLayoutPanel1.BackgroundImage = null;
            tableLayoutPanel1.BackColor = Color.DarkSeaGreen;
        }
示例#29
0
 private void Form1_Load(object sender, EventArgs e)
 {
     t = new Tetris();
 }
示例#30
0
        /// <summary>
        /// Loads a game from file.
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static Tetris LoadGameFromFile(string filename)
        {
            try
            {
                string   file             = System.IO.File.ReadAllText(filename);
                Gamefile gameDeserialized = JsonConvert.DeserializeObject <Gamefile>(file);
                Tetris   loadedGame       = new Tetris(gameDeserialized.Board, gameDeserialized.Level, gameDeserialized.Score, gameDeserialized.RowsRemovedInTotal, gameDeserialized.RowsRemovedAtCurrentLevel);
                if (GameIsValid(loadedGame))
                {
                    return(loadedGame);
                }
                else
                {
                    return(null);
                }
            }
#pragma warning disable CS0168 // Variable is declared but never used
            catch (System.IO.DirectoryNotFoundException e)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                Console.WriteLine("Could not find directory.");
            }
#pragma warning disable CS0168 // Variable is declared but never used
            catch (System.IO.IOException e)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                Console.WriteLine("Something went wrong.");
            }
#pragma warning disable CS0168 // Variable is declared but never used
            catch (UnauthorizedAccessException e)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                Console.WriteLine("Unauthorized access.");
            }
#pragma warning disable CS0168 // Variable is declared but never used
            catch (System.Security.SecurityException e)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                Console.WriteLine("Sevurity Error.");
#pragma warning disable CS0168 // Variable is declared but never used
            }
            catch (JsonReaderException e)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                //Could not interprate file as game
#pragma warning disable CS0168 // Variable is declared but never used
            }
            catch (JsonSerializationException e)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                //Could not interprate file as game
#pragma warning disable CS0168 // Variable is declared but never used
            }
            catch (JsonWriterException e)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                //Could not interprate file as game
            }
#pragma warning disable CS0168 // Variable is declared but never used
            catch (Exception e)
#pragma warning restore CS0168 // Variable is declared but never used
            {
                //Other exceptions that might occurr
            }
            return(null);
        }
示例#31
0
 public static void FromRow(Tetris tetrisState, int startRow, int targetRow, float time, bool noAdd = false)
 {
     for (int i = 0; i < Tetris.Width; i++)
     {
         if (tetrisState.Grid[i, targetRow] != Color.Transparent)
         {
             Tuple<int, int> XY = Tuple.Create(i, targetRow);
             Transition t;
             if (tetrisState.Transitions.ContainsKey(XY))
             {
     #if diagnose
                 Debug.WriteLine("({0},{1}) reused for row translation", XY.Item1, XY.Item2);
     #endif
                 t = tetrisState.Transitions[XY];
             }
             else
             {
     #if diagnose
                 Debug.WriteLine("({0},{1}) Created for row translation", XY.Item1, XY.Item2);
     #endif
                 t = new Transition(tetrisState, XY, time);
             }
             t.AddTranslation(new Vector2(0, (targetRow - startRow)));
         }
     }
 }
示例#32
0
 public void PlayerAdd(Tetris player)
 {
     Players.Add(player);
 }
示例#33
0
        public PrikazIgre(TipIgre tig)
        {
            igra     = new Tetris(tig);
            this.tig = tig;

            //ucitavanje
            img  = new Bitmap(Properties.Resources.tile_mask);
            img1 = new Bitmap(Properties.Resources.tile_mask);
            img2 = new Bitmap(Properties.Resources.pattern);

            InitializeComponent();

            //velicina kockice
            int velicina = 24;

            //resize kockice s obzirom na formu max(1000px, 800px)
            while ((((tig.Stupaca + 2) * velicina) + 300) > 1000 && (((tig.Redaka + 2) * 24) + 20) > 800)
            {
                velicina -= 2;
            }
            //resize forme
            this.ClientSize    = new Size(((tig.Stupaca + 2) * velicina) + 300, ((tig.Redaka + 2) * velicina) + 20);
            this.panel1.Width  = (tig.Stupaca + 2) * velicina;
            this.panel1.Height = (tig.Redaka + 2) * velicina;

            //resize bitmapa
            img1 = (Image) new Bitmap(img1, new Size(panelSljedeciPrvi.Width / 4, panelSljedeciPrvi.Height / 4));
            img  = (Image) new Bitmap(img, new Size(panel1.Width / (tig.Stupaca + 2), panel1.Height / (tig.Redaka + 2)));
            img2 = (Image) new Bitmap(img2, new Size(panel1.Width / (tig.Stupaca + 2), panel1.Height / (tig.Redaka + 2)));

            //bitmap
            bit = new Bitmap(panel1.Size.Width, panel1.Size.Height);
            Graphics g = Graphics.FromImage(bit);

            g.Clear(Color.White);

            int w = panel1.Width / (tig.Stupaca + 2);
            int h = panel1.Height / (tig.Redaka + 2);

            for (int r = 0; r < tig.Redaka + 2; ++r)
            {
                for (int s = 0; s < tig.Stupaca + 2; ++s)
                {
                    if (r == 0 || s == 0 || r == (tig.Redaka + 1) || s == (tig.Stupaca + 1))
                    {
                        g.FillRectangle(Brushes.DarkGray, new Rectangle(new Point((s * w) + 1, (r * h) + 1), new Size(w - 3, h - 3)));
                        g.DrawImage(img, new Point(s * w, r * h));
                    }
                    else
                    {
                        g.DrawImage(img2, new Point(s * w, r * h));
                    }
                }
            }
            panel1.BackgroundImage = bit;

            //Bitmap sljedeci
            bit_sljedeci = new Bitmap(panelSljedeciPrvi.Size.Width, panelSljedeciPrvi.Size.Height);

            //label color
            this.label1.ForeColor     = System.Drawing.ColorTranslator.FromHtml("#282d34");
            this.lbl_nivo.ForeColor   = System.Drawing.ColorTranslator.FromHtml("#282d34");
            this.label4.ForeColor     = System.Drawing.ColorTranslator.FromHtml("#282d34");
            this.label5.ForeColor     = System.Drawing.ColorTranslator.FromHtml("#282d34");
            this.lbl_brzina.ForeColor = System.Drawing.ColorTranslator.FromHtml("#282d34");

            this.SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.DoubleBuffer,
                true);
            typeof(Panel).InvokeMember("DoubleBuffered",
                                       BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                       null, panel1, new object[] { true });
            typeof(Panel).InvokeMember("DoubleBuffered",
                                       BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                       null, panelSljedeciPrvi, new object[] { true });
            typeof(Panel).InvokeMember("DoubleBuffered",
                                       BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                       null, panelSljedeciDrugi, new object[] { true });

            tableLayoutPanel1.BackgroundImage = null;
            tableLayoutPanel1.BackColor       = Color.DarkSeaGreen;
        }
示例#34
0
 public Form1()
 {
     InitializeComponent();
     t = new Tetris(panel1, panel2, ScoreLabel);
 }
示例#35
0
        private void BtnPlay_Click(object sender, EventArgs e)
        {
            Tetris form = new Tetris();

            form.ShowDialog();
        }
示例#36
0
 static void Main()
 {
     using (var game = new Tetris())
         game.Run();
 }
示例#37
0
文件: Menu.cs 项目: GPTrixie/Tetris
        private void start_Click(object sender, EventArgs e)
        {
            Tetris test =new  Tetris();

            int a;
             try
            {
               a = int.Parse(Niveau.Text);
               this.Hide();
               test.Show();
               test.Jouer(musique,a);

            }
            catch(Exception ex)
            {
                erreur.Show();
            }

            // close application
        }