Пример #1
0
        public Player(string name, Point2D point, ConsoleColor color, Statistics stat, Direction direction = Direction.up, int speed = 1) {
            this.name = name;            
            this.point = point;
            this.oldPoint = new Point2D(this.point.X, this.point.Y);
            this.color = color;
            this.stat = stat;
            this.oldDirection = direction;
            this.direction = direction;
            this.speed = speed;
            this.Changed = true;
            this.isShooter = false;            
            this.model = new TankModel(new Point2D(point.X, point.Y), direction, color, name[0]);
            this.bullet = new Bullet(new Point2D(X, Y), model.Color, direction);
            this.timeToMove = new Stopwatch();
            this.timeToShoot = new Stopwatch();           

            timeToMove.Start();
            timeToShoot.Start();            
        }
Пример #2
0
        static void Handler() {
            while (true) {
                if (receivedPackaged.Count > 0) {
                    string[] package = receivedPackaged.Dequeue().Split('¶');

                    #region Обработчик пакетов
                    if (package[0] == "0" && package.Length == 11) { //первый пакет

                        string name = package[1];
                        Point2D point = new Point2D(Int32.Parse(package[2]), Int32.Parse(package[3]));
                        ConsoleColor color = (ConsoleColor)Int32.Parse(package[4]);
                        Statistics stat = new Statistics(Int32.Parse(package[5]),
                            Int32.Parse(package[6]),
                            Int32.Parse(package[7]),
                            Int32.Parse(package[8]));
                        Direction direction = (Direction)Int32.Parse(package[9]);
                        int id = Int32.Parse(package[10]);

                        players.Add(id, new Player(name, point, color, stat, direction));

                        screen.updateTitle();
                    } else if (package[0] == "1" && package.Length == 3) {// движение

                        int id = Int32.Parse(package[2]);
                        players[id].move((Direction)Int32.Parse(package[1]), false);

                    } else if (package[0] == "2" && package.Length == 9) {// выстрел

                        int damage = Convert.ToInt32(package[1]);
                        int speed = Convert.ToInt32(package[2]);
                        char icon = Convert.ToChar(package[3]);
                        Point2D point = new Point2D(Int32.Parse(package[4]), Int32.Parse(package[5]));
                        Direction direction = (Direction)Convert.ToInt32(package[6]);
                        ConsoleColor color = (ConsoleColor)Convert.ToInt32(package[7]);
                        int id = Int32.Parse(package[8]);

                        players[id].Bullet = new Bullet(point, color, direction, icon, speed, damage);
                        players[id].shot();

                    } else if (package[0] == "3" && package.Length == 3){// симулируется попадание
                        int idWhom = Int32.Parse(package[1]);
                        int idShooter = Int32.Parse(package[2]);
                        try {                            
                            players[idWhom].Stat.Health -= players[idShooter].Bullet.Damage;
                            if (players[idWhom].Stat.Health <= 0) {
                                players[idWhom].Stat.Health = players[idWhom].Stat.MaxHealth;
                                players[idWhom].Stat.Deaths++;
                                players[idShooter].Stat.Kills++;
                            }
                            players[idShooter].Bullet.Alive = false;

                        } catch { // если ключа нет, значит это я

                            myPlayer.Stat.Health -= players[idShooter].Bullet.Damage;
                            if (myPlayer.Stat.Health <= 0) {
                                myPlayer.Stat.Health = myPlayer.Stat.MaxHealth;
                                myPlayer.Stat.Deaths++;
                                if (players[idShooter].Stat.Health + 2 <= players[idShooter].Stat.MaxHealth) {
                                    players[idShooter].Stat.Health += 2;
                                } else {
                                    players[idShooter].Stat.Health = players[idShooter].Stat.MaxHealth;
                                }
                                players[idShooter].Stat.Kills++;
                            }
                            players[idShooter].Bullet.Alive = false;
                        }
                    } else if (package[0] == "4" && package.Length == 4 || package.Length == 3) {// воскрешение (3-себя)
                        int x = Int32.Parse(package[1]);
                        int y = Int32.Parse(package[2]);

                        if (package.Length == 4) {
                            int id = Int32.Parse(package[3]);
                            players[id].revive(new Point2D(x, y));
                        } else {
                            myPlayer.revive(new Point2D(x, y));
                        }
                    } else if (package[0] == "5" && package.Length == 1) {
                        packages.Enqueue("5");
                    } else if (package[0] == "6" && package.Length == 2) {
                        int id = Int32.Parse(package[1]);
                        players[id].clear(true);
                        players.Remove(id);
                        screen.RankingWindow.RankingList.Remove(id);
                        screen.RankingWindow.Changed = true;
                        screen.updateTitle();
                    } 
                    continue;
                    #endregion
                    
                }
                Thread.Sleep(1);
            }
        }