Example #1
0
        public override void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }

            base.Dispose();

            CurrentSeat  = 0;
            DeskCards    = null;
            DeskSeat     = -1;
            DeskCardType = CardType.None;

            LastOpSeat = -1;
#if SERVER
            Win.Clear();
            IsWindup = false;
#endif
        }
Example #2
0
 public static void Clear()
 => Win.Clear(BackgroundColor);
Example #3
0
        public void Start()
        {
            DateTime currentTime = DateTime.Now;

            while (Win.IsOpen)
            {
                Win.DispatchEvents();

                double elapsed = (DateTime.Now - currentTime).TotalSeconds;

                if (elapsed < 1.0 / FPS)
                {
                    continue;
                }

                currentTime = DateTime.Now;

                Win.Clear(BackColor);

                if (!Stopped)
                {
                    Snakes.RemoveAll(snake => snake.Dead);

                    GameField.Update(Snakes);
                    Snakes.ForEach(snake => snake.Update(GameField, Snakes));

                    foreach (DividingStudentSnake created in CreatedSnakes)
                    {
                        Snakes.Add(created);
                    }
                    CreatedSnakes.Clear();
                }

                Win.Draw(GameField);
                Snakes.ForEach(snake => snake.Draw(Win, RenderStates.Default, GameField.CellWidthPixel, GameField.CellHeightPixel));

                for (int i = 0; i < Snakes.Count; ++i)
                {
                    DividingStudentSnake snake = Snakes[i];
                    BRAIN_SHAPE.Size = new Vector2f(
                        snake.Brain.BrainWidth * GameField.CellWidthPixel,
                        snake.Brain.BrainHeight * GameField.CellHeightPixel
                        );

                    BRAIN_SHAPE.Position = new Vector2f(
                        (snake.Head.Position.X - snake.Brain.BrainWidth / 2) * GameField.CellWidthPixel,
                        (snake.Head.Position.Y - snake.Brain.BrainHeight / 2) * GameField.CellHeightPixel
                        );

                    Win.Draw(BRAIN_SHAPE);

                    Text score = new Text($"{i + 1}) size = {snake.Body.Count + 1}; energy = {snake.CurrentEnergy}; " +
                                          $"daughters = {snake.TotalCreated}; mutations = {snake.Brain.Mutations}", FONT)
                    {
                        FillColor     = Color.Black,
                        CharacterSize = 24
                    };

                    score.Position = new Vector2f(GameField.Width * GameField.CellWidthPixel + 60, i * 25 + 20);
                    Win.Draw(score);

                    RectangleShape colorIndicator = new RectangleShape(new Vector2f(20, 20))
                    {
                        OutlineColor = Color.Black,
                        FillColor    = snake.BodyColor
                    };

                    colorIndicator.Position = new Vector2f(GameField.Width * GameField.CellWidthPixel + 30, i * 25 + 25);
                    Win.Draw(colorIndicator);
                }

                DrawExtra();
                Win.Display();
            }
        }