Example #1
0
        private void Receive()
        {
            CheckForIllegalCrossThreadCalls = false;
            var cmd = _command.ReceiveCommand();

            switch ((Enums.Commands)cmd.Id)
            {
            case Enums.Commands.Chat:
                Chat chat = (Chat)cmd;
                ChatRichText.AppendText(chat.sender + ": " + chat.text + "\n");
                sendMsgTextBox.Clear();
                break;

            case Enums.Commands.Response:
                Response intro = (Response)cmd;
                ChatRichText.AppendText("SERVER: " + intro.text + "\n");
                break;

            case Enums.Commands.PlayerList:
                PlayerList playerList = (PlayerList)cmd;
                Helping.PlayerList(playerList, playersRichTextBox);
                _gameData.playerList = playerList;
                break;

            case Enums.Commands.TimeLeft:
                timerGame.Tick += TimerGame_Tick;

                TimeLeft time = (TimeLeft)cmd;
                dateTime = time.time;

                timerGame.Interval = 1000;
                timerGame.Start();
                //TimeLeft time = (TimeLeft) cmd;
                //timeLabel.Text = Helping.TimeLeft(time.time);
                break;

            case Enums.Commands.MapSize:
                MapSize mapSize = (MapSize)cmd;
                _gameData.mapSize = mapSize;
                _gameData.width   = formGame.Width;
                _gameData.height  = formGame.Height;
                break;

            case Enums.Commands.PlayerCoords:
                _gameData.playerCoords = (PlayerCoords)cmd;
                break;

            case Enums.Commands.VisibleObjects:
                _gameData.visibleObjects = (VisibleObjects)cmd;
                start = true;
                formGame.Invalidate();
                break;

            case Enums.Commands.VisiblePlayers:
                _gameData.visiblePlayers = (VisiblePlayers)cmd;
                break;

            case Enums.Commands.GameOver:
                MessageBox.Show("GAME OVER", "Сообщение", MessageBoxButtons.OK);
                _command.CloseConnect();
                this.Close();
                break;
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            VisibleObjects visibleObjects;
            VisiblePlayers visiblePlayers;
            PlayerCoords   playerCoords;

            foreach (var val in list)
            {
            }



            int x = playerCoords.row;
            int y = playerCoords.col;

            foreach (var map_object in visibleObjects.map_objects)
            {
                if (map_object.type == Enums.MapObjects.mapObject(Enums.MapObject.WALL))
                {
                    g.DrawImage(new Bitmap("wall.jpg"),
                                map_object.row * size + width / 2 - x * size - size / 2,
                                map_object.col * size + height / 2 - y * size - size / 2,
                                size, size);
                }
                if (map_object.type == Enums.MapObjects.mapObject(Enums.MapObject.EXIT))
                {
                    g.DrawLine(new Pen(Color.Red, 2),
                               map_object.row * size + width / 2 - x * size - size / 2,
                               map_object.col * size + height / 2 - y * size - size / 2,
                               map_object.row * size + width / 2 - x * size - size / 2 + size,
                               map_object.col * size + height / 2 - y * size - size / 2 + size);

                    g.DrawLine(new Pen(Color.Red, 2),
                               map_object.row * size + width / 2 - x * size - size / 2 + size,
                               map_object.col * size + height / 2 - y * size - size / 2,
                               map_object.row * size + width / 2 - x * size - size / 2,
                               map_object.col * size + height / 2 - y * size - size / 2 + size);
                }
            }

            foreach (var player in visiblePlayers.players)
            {
                g.DrawString(player.name, new Font(FontFamily.GenericMonospace, size / 2),
                             new SolidBrush(Helping.playerColor(player.name, playerList)),
                             player.row * size + width / 2 - x * size - size / 2 + size / 2 - player.name.Length / 2 * size / 2,
                             player.col * size + height / 2 - y * size - size / 2 - size);

                g.DrawImage(new Bitmap("war.jpg"),
                            player.row * size + width / 2 - x * size - size / 2,
                            player.col * size + height / 2 - y * size - size / 2,
                            size, size);
            }

            g.DrawImage(new Bitmap("player.png"),
                        width / 2 - size / 2,
                        height / 2 - size / 2,
                        size, size);

            g.DrawString(name, new Font(FontFamily.GenericMonospace, size / 2),
                         new SolidBrush(Helping.playerColor(name, playerList)),
                         width / 2 - size / 2 + size / 2 - name.Length / 2 * size / 2,
                         height / 2 - size / 2 - size);
        }