private void Form1_Load(object sender, EventArgs e) { SetStyle(ControlStyles.OptimizedDoubleBuffer, true); while (game == null) { Thread.Sleep(1); } //UpdatePlayerDisplay(); tableTable.ColumnStyles[2].Width = 700f / 1592f * MainPanel.Width; tableTable.RowStyles[2].Height = 350f / 850f * MainPanel.Height; //Console.WriteLine(Table.Location); //Console.WriteLine("LOG 1: " + MainPanel.Width); setChoice(1); setName(DatabaseConn.getUsername()); setMoney(DatabaseConn.getMoney()); setImage(DatabaseConn.getImage()); UpdatePlayers(); }
private async void button3_Click_1(object sender, EventArgs e) { LoginData data = await Login.ShowDialog("Login to your ConcreteGames account below.", "Login to your ConcreteGames Account"); DatabaseConn.setUsername(data.username); DatabaseConn.setMoney(data.money); DatabaseConn.setImage(data.image); Console.WriteLine(DatabaseConn.getImage()); new Start().Show(); this.Hide(); }
public Start() { InitializeComponent(); playerBox1.setName(DatabaseConn.getUsername()); playerBox1.setMoney(DatabaseConn.getMoney()); playerBox1.setImage(DatabaseConn.getImage()); playerBox1.setClickForName(delegate { DatabaseConn.setUsername(Prompt.ShowDialog("Enter a new username: "******"Enter a new username")); playerBox1.setName(DatabaseConn.getUsername()); }); try { new DatabaseConn("", "").DownloadAndSet(); } catch (Exception) { } }
public static async Task <LoginData> ShowDialog(string text, string caption) { Form login = new Form() { Width = 500, Height = 170, FormBorderStyle = FormBorderStyle.FixedDialog, Text = caption, StartPosition = FormStartPosition.CenterScreen }; Label textLabel = new Label() { Width = 400, Left = 50, Top = 20, Text = text }; TextBox username = new TextBox() { Text = DatabaseConn.getUsername() == "Player" ? "" : DatabaseConn.getUsername(), Left = 50, Top = 50, Width = 400 }; TextBox password = new TextBox() { Left = 50, Top = 70, Width = 400 }; Button confirmation = new Button() { Text = "Login", Left = 350, Width = 100, Top = 90, DialogResult = DialogResult.OK }; confirmation.Click += (sender, e) => { login.Close(); }; login.Controls.Add(username); login.Controls.Add(password); login.Controls.Add(confirmation); login.Controls.Add(textLabel); login.AcceptButton = confirmation; LoginData data = new LoginData(); if (login.ShowDialog() == DialogResult.OK) { var x = new DatabaseConn(username.Text, password.Text); var y = await x.Download(); return(y); } else { return(data); } }
public void connection() { var ws = new WebSocket("ws://concretegames.net:667/socket/?EIO=2&transport=websocket"); GameMain.server = ws; //Console.WriteLine(ws); ws.OnMessage += (sender, e) => { if (e.Data == "connected") { SendMessage(ws, "connected"); } else { try { UpdateMessage message = JsonConvert.DeserializeObject <UpdateMessage>(e.Data); player = message.player; game = message; Image[] DiceImages = new Image[] { null, Properties.Resources._1, Properties.Resources._2, Properties.Resources._3, Properties.Resources._4, Properties.Resources._5, Properties.Resources._6 }; gamemain.Invoke((Action) delegate { List <string> pbIDs = new List <string>(); List <string> gpIDs = new List <string>(); foreach (var p in gamemain.pBoxes) { pbIDs.Add(p.id); } foreach (var gp in game.players) { gpIDs.Add(gp.socketId); } foreach (var pid in pbIDs) { if (!gpIDs.Contains(pid)) { //remove player foreach (var pbox in gamemain.pBoxes) { if (pbox.id == pid) { gamemain.pBoxes.Remove(pbox); gamemain.Controls.Remove(pbox); break; } } } } foreach (var gpid in gpIDs) { if (!pbIDs.Contains(gpid)) { //add player var pb = new PlayerBox(); pb.id = gpid; gamemain.pBoxes.Add(pb); gamemain.Controls.Add(pb); pb.Hide(); pb.Parent = gamemain.MainPanel; pb.BringToFront(); } } try { var rollpb = new PictureBox(); rollpb.Size = new Size(130, 130); rollpb.Location = new Point((gamemain.Table.Location.X + gamemain.Table.Width / 2) - rollpb.Width / 2, (gamemain.Table.Location.Y + gamemain.Table.Height / 2) - rollpb.Height / 2); rollpb.Name = "roll"; rollpb.Parent = gamemain.MainPanel; rollpb.BackColor = Color.Transparent; rollpb.Image = DiceImages[1]; rollpb.SizeMode = PictureBoxSizeMode.StretchImage; rollpb.BackgroundImage = gamemain.BackgroundImage; gamemain.Controls.Add(rollpb); rollpb.Show(); rollpb.BringToFront(); } catch (Exception) { } try { ((PictureBox)gamemain.Controls.Find("roll", false)[0]).Image = DiceImages[game.roll]; } catch (Exception) { //Console.WriteLine(x); } try { switch (player.status) { case "Lost Game": gamemain.oldstatus.Text = "Lost the Game!"; gamemain.oldstatus.BackColor = Color.Yellow; Alert.ShowDialog("You lost the game!", "You Lost"); break; case "Lost Bet": gamemain.oldstatus.Text = "Lost the Bet!"; break; case "Won Game!": gamemain.oldstatus.Text = "Won the Game!"; Alert.ShowDialog("You WON the game!", "You Won!"); break; case "Won Bet!": gamemain.oldstatus.Text = "Won the Bet!"; break; default: break; } gamemain.money.Text = "You have: $" + player.money; gamemain.name.Text = player.name; gamemain.status.Text = player.status; gamemain.betval.Text = "Bet $" + gamemain.setBet + " on:"; gamemain.choice.Image = DiceImages[gamemain.setC]; gamemain.timeout.Text = (30 - player.timeout).ToString(); gamemain.room_code.Text = player.room_code; gamemain.UpdatePlayers(); DatabaseConn.setMoney(player.money); new DatabaseConn("", "").Upload(); if (player.timeouts >= 3) { Alert.ShowDialog("You have been kicked from the game for being idle.", "You have been kicked."); Application.Exit(); } } catch (Exception) { //Console.WriteLine(x); } }); } catch (Exception) { //Console.WriteLine(x); } } }; ws.OnError += (sender, e) => { Console.WriteLine("Error: " + e.Message); //Console.WriteLine(sender); }; ws.OnOpen += (sender, e) => { connected = true; }; ws.Connect(); ws.OnClose += (sender, e) => { if (!gamemain.fromQuitButton) { gamemain.quit_Click(sender, e); } }; //Console.ReadKey(true); }