Ejemplo n.º 1
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     MENU = new Menu();
     try
     {
         PlayerEntities playerEntity = new PlayerEntities();
         Player         player1      = new Player();
         var            pl           = (from player in playerEntity.Players
                                        where player.P_Username == this.txtUsername.Text.Trim()
                                        select player).SingleOrDefault();
         if (pl != null)
         {
             if (this.txtPassword.Text.Trim() == pl.P_Password.Trim())
             {
                 pl.P_State = true;
                 playerEntity.SaveChanges();
                 DialogResult a;
                 a = MessageBox.Show("Login Success! Click Ok to play game", "Success", MessageBoxButtons.OK);
                 if (a == DialogResult.OK)
                 {
                     this.Close();
                     this.Visible = false;
                     MENU.ptPlayNow_Click(sender, e);
                 }
             }
         }
         else
         {
             MessageBox.Show("Username is not defined");
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 2
0
        private void btnRG_Click_1(object sender, EventArgs e)
        {
            bool           success      = true;
            PlayerEntities playerEntity = new PlayerEntities();
            Player         player1      = new Player();
            var            pl           =
                from p in playerEntity.Players
                select p;

            //Kiem tra username trong database
            foreach (var p in pl)
            {
                if (this.txtUS.Text.Trim() == p.P_Username.Trim())
                {
                    success = false;
                    MessageBox.Show("Username have been taken!");
                }
            }
            if (success)
            {
                player1.P_Username = this.txtUS.Text.Trim();
                player1.P_Password = this.txtPW.Text.Trim();
                player1.P_Score    = 0;
                player1.P_State    = false;
                playerEntity.Players.Add(player1);
                playerEntity.SaveChanges();
                MessageBox.Show("Register successfully!");
                this.txtUS.ResetText();
                this.txtPW.ResetText();
            }
        }
Ejemplo n.º 3
0
        private void ptTetris_Click(object sender, EventArgs e)
        {
            PlayerEntities playerEntity = new PlayerEntities();
            Player         player1      = new Player();
            var            pl           = (from player in playerEntity.Players
                                           where player.P_State == true
                                           select player).SingleOrDefault();

            if (pl != null)
            {
                pl.P_State = false;
                playerEntity.SaveChanges();
            }
            MENU.Show();
            this.Close();
        }
Ejemplo n.º 4
0
        public DataTable GetData()
        {
            int            count        = 0;
            PlayerEntities playerEntity = new PlayerEntities();
            Player         player1      = new Player();
            var            sorted_score = playerEntity.Players.OrderByDescending(c => c.P_Score);;
            DataTable      dt           = new DataTable();

            dt.Columns.Add("Username");
            dt.Columns.Add("Score");

            foreach (var p in sorted_score)
            {
                dt.Rows.Add(p.P_Username, p.P_Score);
                if (count >= 10)
                {
                    count = 0;
                    break;
                }
                count++;
            }
            return(dt);
        }
Ejemplo n.º 5
0
        public MainWindow(Menu menu)
        {
            InitializeComponent();
// this.lb_name_acc.BackColor = Color.Transparent;
            PlayerEntities playerEntity = new PlayerEntities();
            Player         player1      = new Player();
            var            pl           = (from player in playerEntity.Players
                                           where player.P_State == true
                                           select player).SingleOrDefault();

            if (pl != null)
            {
                this.pn_info_player.Visible = true;
                this.lb_name_acc.Text       = pl.P_Username.Trim();
                this.lb_name_score.Text     = pl.P_Score.ToString();
            }
            else
            {
                this.pn_info_player.Visible = false;
            }

            MENU = menu;
            MENU.Hide();
            this.Size    = this.MaximumSize;
            lbScore.Text = String.Format("{0,7}", "");
            //level = int.Parse(lbLevel.Text);
            level                = 1;
            MainGrid             = new Grid(myPanel1, 10, 20);
            myPanel1.Width       = MainGrid.Width;
            myPanel1.Height      = MainGrid.Height;
            ExtraGrid            = new Grid(myPanel2, 4, 4);
            myPanel2.Width       = ExtraGrid.Width;
            myPanel2.Height      = ExtraGrid.Height;
            board                = new Board(MainGrid, ExtraGrid);
            mainWindowController = new MainWindowController(board, this, this.level);
        }