public Player(Color col, string name, Key[] control) { if (control.Length != 5) { throw new Exception("Controls must be 5"); } pen = new Pen(col); controls = control; this.name = name; speed = 30; alive = false; all.Add(this); Random rnd = new Random(Guid.NewGuid().ToByteArray().Sum(x => x)); try { Point p = new Point(rnd.Next(40, Balls.BoundsForReflect().Item1 - 70), rnd.Next(40, Balls.BoundsForReflect().Item2 - 70)); area = new Rectangle(p, new Size(50, 50)); } catch (ArgumentOutOfRangeException) { Point p = new Point(rnd.Next(40, Screen.PrimaryScreen.Bounds.Width - 70), rnd.Next(40, Screen.PrimaryScreen.Bounds.Height - 70)); area = new Rectangle(p, new Size(50, 50)); } }
public Player(Color col, string name) { pen = new Pen(col); controls = new Key[] { Key.W, Key.D, Key.S, Key.A, Key.LeftShift }; this.name = name; alive = false; speed = 30; Random rnd = new Random(Guid.NewGuid().ToByteArray().Sum(x => x)); Point p; try { p = new Point(rnd.Next(0, Balls.BoundsForReflect().Item1 - 70), rnd.Next(0, Balls.BoundsForReflect().Item2 - 70)); } catch (ArgumentOutOfRangeException) { p = new Point(rnd.Next(0, Screen.PrimaryScreen.Bounds.Width - 70), rnd.Next(0, Screen.PrimaryScreen.Bounds.Height - 70)); } catch (Exception) { p = new Point(rnd.Next(0, Screen.PrimaryScreen.Bounds.Width - 70), rnd.Next(0, Screen.PrimaryScreen.Bounds.Height - 70)); } area = new Rectangle(p, new Size(50, 50)); all.Add(this); }
//This is for recieved ball form another computer public static Balls FromCode(string code) { string[] codes = code.Split(','); Point p = new Point(int.Parse(codes[0]), int.Parse(codes[1])); var z = new Balls(p, int.Parse(codes[2]), int.Parse(codes[3]), Color.FromArgb(int.Parse(codes[4]))); all.Add(z); return(z); }
public static void NewRound() { foreach (var element in all) { element.currentscore = 0; element.alive = true; Random rnd = new Random(Guid.NewGuid().ToByteArray().Sum(x => x)); Point p = new Point(rnd.Next(0, Balls.BoundsForReflect().Item1 - 70), rnd.Next(0, Balls.BoundsForReflect().Item2 - 70)); element.area = new Rectangle(p, new Size(50, 50)); } }
//set form where we draw public static void SetScreen(Form f) { screen = f; screen.FormClosed += CloseAplication; screen.Paint += Draw; // this is not working I dont know why // Balls.SetBounds(screen.Width, screen.Height); //this is working perfect Balls.SetBounds(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); }
private void CheckMove() { if (Keyboard.IsKeyDown(controls[0])) { for (int i = 0; i < speed; i++) { if (area.Y == 0) { break; } area.Y--; } } if (Keyboard.IsKeyDown(controls[1])) { for (int i = 0; i < speed; i++) { if (area.X == Screen.PrimaryScreen.Bounds.Width - 75) { break; } area.X++; } } if (Keyboard.IsKeyDown(controls[2])) { for (int i = 0; i < speed; i++) { if (area.Y == Screen.PrimaryScreen.Bounds.Height - 75) { break; } area.Y++; } } if (Keyboard.IsKeyDown(controls[3])) { for (int i = 0; i < speed; i++) { if (area.X == 0) { break; } area.X--; } } if (Keyboard.IsKeyDown(controls[4])) { speed = 50; } if (Balls.CheckCollusion(this)) { this.Alive = false; } if (speed > 20) { speed--; } }