Exemplo n.º 1
0
 private static void insert(Score score, int position)
 {
     for (int counter = 8; counter >= position; counter--)
     {
         scores[counter + 1] = scores[counter];
     }
     scores[position] = score;
 }
Exemplo n.º 2
0
 public static void addScore(Score score)
 {
     for (int counter = 0; counter < 10; counter++)
     {
         if (scores[counter] == null || scores[counter].Points < score.Points)
         {
             insert(score, counter);
             WriteToFile();
             sortScores();
             return;
         }
     }
 }
Exemplo n.º 3
0
 public static void ReadFromFile()
 {
     Array.Clear(scores, 0, scores.Length);
     string line = "";
     using (StreamReader sr = new StreamReader("Content/Highscores.txt"))
     {
         while (true)
         {
             for (int counter = 0; counter < scores.Length; counter++)
             {
                 line = sr.ReadLine();
                 if (line == null)
                 {
                     break;
                 }
                 String[] array = line.Split(new Char[] { ',' });
                 scores[counter] = new Score(array[0], int.Parse(array[1]));
             }
             break;
         }
         sr.Close();
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Add the SpriteBatch service
            Services.AddService(typeof(SpriteBatch), spriteBatch);            

            //Load 2D textures
            tetrisBackground = Content.Load<Texture2D>("background");
            tetrisTextures = Content.Load<Texture2D>("tetris");

            // Load game font
            gameFont = Content.Load<SpriteFont>("font");

            // Create game field
            board = new Board(this, ref tetrisTextures, blockRectangles);
            board.Initialize();
            Components.Add(board);

            // Save player's score and game level
            score = new Score(this, gameFont);
            score.Initialize();
            Components.Add(score);

            // Load game record
            using (StreamReader streamReader = File.OpenText("record.dat"))
            {
                string player = null;
                if ((player = streamReader.ReadLine()) != null)
                    score.RecordPlayer = player;
                int record = 0;
                if ((record = Convert.ToInt32(streamReader.ReadLine())) != 0)
                    score.RecordScore = record;
            }
        }
Exemplo n.º 5
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (!esValido())
            {
                nuevoPuntaje = new Score("jojos");
            }
            else
            {
                nuevoPuntaje = new Score(txtNombre.Text);
            }

            nuevoPuntaje.horas    = hrs;
            nuevoPuntaje.minutos  = mins;
            nuevoPuntaje.segundos = segs;
            nuevoPuntaje.puntos   = puntos;

            FileInfo archivo = new FileInfo("marcador.xml");

            //Guardar archivo
            //Si el archivo de guardado existe
            if (archivo.Exists)
            {
                XmlSerializer xs = new XmlSerializer((new List <Score>().GetType()));

                StreamReader sr = new StreamReader("marcador.xml");

                List <Score> registroPuntos = (List <Score>)xs.Deserialize(sr);
                sr.Close();
                Score temporal = new Score();

                //Si hay  menos de 10 marcadores guardados
                if (registroPuntos.Count < 10)
                {
                    //Agregalo a la lista
                    registroPuntos.Add(nuevoPuntaje);

                    //Ordena la lista por metodo burbuja.
                    for (int i = 0; i < registroPuntos.Count - 1; i++)
                    {
                        for (int j = i + 1; j < registroPuntos.Count; j++)
                        {
                            if (registroPuntos[j].puntos > registroPuntos[i].puntos)
                            {
                                temporal          = registroPuntos[i];
                                registroPuntos[i] = registroPuntos[j];
                                registroPuntos[j] = temporal;
                            }
                        }
                    }

                    //Si hay mas de 10 puntajes.
                    //Agregamelo si solo si supera alguno de los puntajes existentes.
                }
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        if (nuevoPuntaje.puntos > registroPuntos[i].puntos)
                        {
                            temporal          = registroPuntos[i];
                            registroPuntos[i] = nuevoPuntaje;
                            nuevoPuntaje      = temporal;
                        }
                    }
                }

                //Guarda el marcador.
                StreamWriter sw = new StreamWriter("marcador.xml");
                xs.Serialize(sw, registroPuntos);
                sw.Close();


                //Si el archivo de puntaje no existe.
                //Creame un nuevo archivo, agregame el puntaje y guarda el marcador.
            }
            else
            {
                XmlSerializer xs             = new XmlSerializer((new List <Score>().GetType()));
                StreamWriter  sw             = new StreamWriter("marcador.xml");
                List <Score>  registroPuntos = new List <Score>();
                registroPuntos.Add(nuevoPuntaje);

                xs.Serialize(sw, registroPuntos);

                sw.Close();
            }

            //Cierra la ventana 'Partida'
            Owner.Close();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sets up global vars to the program
        /// </summary>
        void SetUpGlobalVars()
        {
            //Create the BACKEND grid for the game
            grid    = new Grid(teacher);
            teacher = false;

            holdManager = new Hold();

            for (int i = 0; i < StaticVars.drawGrid.GetLength(0); i++)
            {
                for (int j = 0; j < StaticVars.drawGrid.GetLength(1); j++)
                {
                    StaticVars.drawGrid[i, j] = new Sprite();

                    //Place each block of the grid at the corresponding position of the array
                    StaticVars.drawGrid[i, j].Position = new Vector2f(j * StaticVars.imageSize.X + StaticVars.gridXPos, i * StaticVars.imageSize.Y + StaticVars.gridYPos + StaticVars.imageSize.Y);

                    //drawGrid[i, j].Size = new Vector2f(WINDOW_WIDTH / 10, WINDOW_HEIGHT / 20);
                    //drawGrid[i, j].Size = new Vector2f(20, 20);
                }
            }

            #region End text
            endText = new Text("You have lost\npress space\nto reset\nthe game", StaticVars.font);

            FloatRect textRect = endText.GetLocalBounds();
            endText.Origin   = new Vector2f(textRect.Left + textRect.Width / 2.0f, textRect.Top + textRect.Height / 2.0f);
            endText.Position = new Vector2f(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
            #endregion

            FloatRect textRectPause = StaticVars.pauseText.GetLocalBounds();
            StaticVars.pauseText.Origin   = new Vector2f(textRectPause.Left + textRectPause.Width / 2.0f, textRectPause.Top + textRectPause.Height / 2.0f);
            StaticVars.pauseText.Position = new Vector2f(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);

            //Make it so the game is playing
            gameState = GameState.Playing;

            pieceQueue = new PieceQueue();

            stats = new Stats();

            //Select a new active piece
            NewPiece();

            //Add the piece to the grid, with a movement of 0,0
            grid.AddPiece(activePiece, new Vector2i(0, 0));

            StaticVars.queueSprite.Position    = new Vector2f(StaticVars.gridXPos + StaticVars.imageSize.X * (StaticVars.drawGrid.GetLength(1) + 2.25f), StaticVars.gridYPos);
            StaticVars.holdSprite.Position     = new Vector2f(StaticVars.gridXPos - StaticVars.holdTexture.Size.X - (StaticVars.imageSize.X * 2.25f), StaticVars.gridYPos);
            StaticVars.drawGridSprite.Position = new Vector2f(StaticVars.gridXPos - StaticVars.imageSize.X * 1.5f, StaticVars.gridYPos - StaticVars.imageSize.Y * 2f);

            #region Queue setup

            queueSpriteArray4x4 = new Sprite[3][, ] {
                new Sprite[4, 4],
                new Sprite[4, 4],
                new Sprite[4, 4]
            };

            for (int i = 0; i < queueSpriteArray4x4.Length; i++)
            {
                for (int j = 0; j < queueSpriteArray4x4[0].GetLength(0); j++)
                {
                    for (int k = 0; k < queueSpriteArray4x4[0].GetLength(1); k++)
                    {
                        queueSpriteArray4x4[i][j, k] = new Sprite();

                        queueSpriteArray4x4[i][j, k].Position = new Vector2f(StaticVars.queueSprite.Position.X + StaticVars.imageSize.X * 1.5f + StaticVars.imageSize.X * k,
                                                                             StaticVars.queueSprite.Position.Y + StaticVars.imageSize.Y * 2.5f + StaticVars.imageSize.Y * j + StaticVars.imageSize.Y * (queueSpriteArray4x4[0].GetLength(0) - 1) * i - StaticVars.imageSize.Y);
                    }
                }
            }

            queueSpriteArray1x4 = new Sprite[3][, ] {
                new Sprite[1, 4],
                new Sprite[1, 4],
                new Sprite[1, 4]
            };

            for (int i = 0; i < queueSpriteArray1x4.Length; i++)
            {
                for (int j = 0; j < queueSpriteArray1x4[0].GetLength(0); j++)
                {
                    for (int k = 0; k < queueSpriteArray1x4[0].GetLength(1); k++)
                    {
                        queueSpriteArray1x4[i][j, k] = new Sprite();

                        queueSpriteArray1x4[i][j, k].Position = new Vector2f(StaticVars.queueSprite.Position.X + StaticVars.imageSize.X * 1.5f + StaticVars.imageSize.X * k,
                                                                             StaticVars.queueSprite.Position.Y + StaticVars.imageSize.Y * 2.5f + StaticVars.imageSize.Y * j + StaticVars.imageSize.Y * (queueSpriteArray4x4[0].GetLength(0) - 1) * i + StaticVars.imageSize.Y * 0.5f);
                    }
                }
            }


            queueSpriteArray3x3 = new Sprite[3][, ] {
                new Sprite[3, 3],
                new Sprite[3, 3],
                new Sprite[3, 3]
            };

            for (int i = 0; i < queueSpriteArray3x3.Length; i++)
            {
                for (int j = 0; j < queueSpriteArray3x3[0].GetLength(0); j++)
                {
                    for (int k = 0; k < queueSpriteArray3x3[0].GetLength(1); k++)
                    {
                        queueSpriteArray3x3[i][j, k] = new Sprite();

                        queueSpriteArray3x3[i][j, k].Position = new Vector2f(StaticVars.queueSprite.Position.X + StaticVars.imageSize.X * 1.5f + StaticVars.imageSize.X * k + StaticVars.imageSize.X * 0.5f,
                                                                             StaticVars.queueSprite.Position.Y + StaticVars.imageSize.Y * 2.5f + StaticVars.imageSize.Y * j + StaticVars.imageSize.Y * queueSpriteArray3x3[0].GetLength(0) * i);
                    }
                }
            }

            #endregion

            #region Hold queue

            holdSprite3x3 = new Sprite[3, 3];

            for (int i = 0; i < holdSprite3x3.GetLength(0); i++)
            {
                for (int j = 0; j < holdSprite3x3.GetLength(1); j++)
                {
                    holdSprite3x3[i, j] = new Sprite();

                    holdSprite3x3[i, j].Position = new Vector2f(StaticVars.holdSprite.Position.X + StaticVars.imageSize.X * 1.5f + StaticVars.imageSize.X * j + StaticVars.imageSize.X * 0.5f,
                                                                StaticVars.holdSprite.Position.Y + StaticVars.imageSize.Y * 3.5f + StaticVars.imageSize.Y * i);
                }
            }

            holdSprite4x4 = new Sprite[4, 4];

            for (int i = 0; i < holdSprite4x4.GetLength(0); i++)
            {
                for (int j = 0; j < holdSprite4x4.GetLength(1); j++)
                {
                    holdSprite4x4[i, j] = new Sprite();

                    holdSprite4x4[i, j].Position = new Vector2f(StaticVars.holdSprite.Position.X + StaticVars.imageSize.X * 1.5f + StaticVars.imageSize.X * j,
                                                                StaticVars.holdSprite.Position.Y + StaticVars.imageSize.Y * 2.5f + StaticVars.imageSize.Y * i);
                }
            }

            holdSprite1x4 = new Sprite[1, 4];

            for (int i = 0; i < holdSprite1x4.GetLength(0); i++)
            {
                for (int j = 0; j < holdSprite1x4.GetLength(1); j++)
                {
                    holdSprite1x4[i, j] = new Sprite();

                    holdSprite1x4[i, j].Position = new Vector2f(StaticVars.holdSprite.Position.X + StaticVars.imageSize.X * 1.5f + StaticVars.imageSize.X * j,
                                                                StaticVars.holdSprite.Position.Y + StaticVars.imageSize.Y * 2.5f + StaticVars.imageSize.Y * i + StaticVars.imageSize.Y * 1.5f);
                }
            }

            #endregion

            #region Text

            score = new Score();

            level = new Level();

            realTime = new RealTime();

            #endregion

            menu = new Menu("Play", "Options", "Exit");

            optionsMenu = new Options();

            soundplayer = new SoundPlayer(selectedSong);

            StaticVars.statsSprite.Position = new Vector2f(StaticVars.holdSprite.Position.X, realTime.Position.Y + StaticVars.imageSize.Y);

            StaticVars.controlsText.Position = new Vector2f(StaticVars.queueSprite.Position.X, StaticVars.queueSprite.Position.Y + StaticVars.queueTexture.Size.Y + StaticVars.imageSize.Y);
        }
Exemplo n.º 7
0
        public Partie(MainWindow main, Level level)
        {
            ScoresPartie = new Score();
            ScoresPartie.Read(level.numero);
            this.enregistré = false;
            this.main = main;
            this.level = level;

            main.tetris.Visibility = Visibility.Collapsed;
            Barre.Couleurs = level.Couleurs;
            main.fenetre.Background = new SolidColorBrush(level.backgroundcolor);

            if (level.backgroundcolor == Colors.Black)
            {
                main.Termine.Foreground = new SolidColorBrush(Colors.White);
                main.ScoreNiveau.Foreground = new SolidColorBrush(Colors.White);
                main.ScoreNom.Foreground = new SolidColorBrush(Colors.White);
                main.ScoreScore.Foreground = new SolidColorBrush(Colors.White);
                main.labelScore.Foreground = new SolidColorBrush(Colors.White);
                main.labelScoreLevel.Foreground = new SolidColorBrush(Colors.White);
                main.labelScoreNom.Foreground = new SolidColorBrush(Colors.White);
                main.ScoreActuel.Foreground = new SolidColorBrush(Colors.White);
                main.score.Foreground = new SolidColorBrush(Colors.White);
            }
            else
            {
                main.Termine.Foreground = new SolidColorBrush(Colors.Black);
                main.ScoreNiveau.Foreground = new SolidColorBrush(Colors.Black);
                main.ScoreNom.Foreground = new SolidColorBrush(Colors.Black);
                main.ScoreScore.Foreground = new SolidColorBrush(Colors.Black);
                main.labelScore.Foreground = new SolidColorBrush(Colors.Black);
                main.labelScoreLevel.Foreground = new SolidColorBrush(Colors.Black);
                main.labelScoreNom.Foreground = new SolidColorBrush(Colors.Black);
                main.ScoreActuel.Foreground = new SolidColorBrush(Colors.Black);
                main.score.Foreground = new SolidColorBrush(Colors.Black);
            }

            if (level.numero == 4) {
                main.nyan.Visibility = System.Windows.Visibility.Visible;
                main.image.Visibility = System.Windows.Visibility.Visible;
            }

            test = Barre.Create(); // Test est la barre qui sera en cours de placement
            tabRect = new List<Rectangle>(180);
            main.banniere.Content = "GooOOoooo";
            this.grille = new Table(main, tabRect, level);
            messageTimer = new DispatcherTimer();
            messageTimer.Tick += new EventHandler(messageTimer_Tick);
            messageTimer.Interval = new TimeSpan(0, 0, 0, 0, level.timer);
            messageTimer.Start();

            Thread myThread = new Thread(() => playSong());
            MainWindow.AllThreads.Add(myThread);
            myThread.Start();
            partie = this;

            if(level.numero == 3)
            {
                da= new DoubleAnimation();
                da.From = 0;
                da.To = 360;
                da.Duration = new Duration(TimeSpan.FromSeconds(3));
                da.RepeatBehavior = RepeatBehavior.Forever;
                rt = new RotateTransform(360, main.gameGrid.Width / 2, main.gameGrid.Height / 2);
                main.gameGrid.RenderTransform = rt;
                rt.BeginAnimation(RotateTransform.AngleProperty, da);

            }
            if(level.numero == 5)
            {
                main.gameGrid.RenderTransform = new RotateTransform(180,main.gameGrid.Width /2, main.gameGrid.Height / 2);

                for (int i = 0; i < tabRect.Count; i++)
                {
                        tabRect[i].Fill = new SolidColorBrush(Colors.Black);
                }
            }
        }