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 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); }