Пример #1
0
 public void StartGame()
 {
     Game1 game = new Game1(gridSize,new IPAddress(serverIP), serverPort, new IPAddress(clientIP), clientPort);
     //Game1 game = new Game1(new IPAddress(new byte[] { 127, 0, 0, 1 }), 6000,new IPAddress(new byte[] { 127, 0, 0, 1 }),7000);
     game.Run();
 }
Пример #2
0
        public Game1(int size,IPAddress serverIP, int serverPort, IPAddress clientIP, int clientPort)
        {
            columnsGrid = rowsGrid = size;
            p0 = new PlayerInfo(-1, -1);
            p1 = new PlayerInfo(-1, -1);
            p2 = new PlayerInfo(-1, -1);
            p3 = new PlayerInfo(-1, -1);
            p4 = new PlayerInfo(-1, -1);
            gs = new GameSocket(serverIP, serverPort, clientIP, clientPort);
            game = this;
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            arena = new char[columnsGrid, columnsGrid];
            tankGrid = new int[columnsGrid, columnsGrid];
            cellWidth = gridSizeInPixels / columnsGrid;
            cellHeight = gridSizeInPixels / rowsGrid;
            //arena[0, 1] = 's'; arena[9, 0] = 's'; arena[9, 1] = 's'; arena[9, 2] = 's'; arena[8, 1] = 's'; arena[8, 0] = 's'; arena[5, 0] = 'w'; arena[5, 1] = 'w'; arena[4, 0] = 'w'; arena[4, 1] = 'w'; arena[6, 9] = 'b'; arena[6, 8] = 'b'; arena[5, 9] = 'b'; arena[5, 8] = 'b';

            players[0] = p0; players[1] = p1; players[2] = p2; players[3] = p3; players[4] = p4;

            for (int i = 0; i < tankGrid.GetLength(0); i++)//initializing tankgrid for all -1s
            {
                for (int j = 0; j < tankGrid.GetLength(0); j++)
                {
                    tankGrid[i, j] = -1;
                }
            }

            gs.setGrid(arena, p0, p1, p2, p3, p4, gridSizeInPixels, columnsGrid);

            tankCentre = new Vector2(49, 49);//origin needs to be defined with respect to the original image
            tankScale = cellWidth * 1f / 100;
            bulletCentre = new Vector2(500, 500);//origin needs to be defined with respect to the original image
            bulletScale = cellWidth * 1f / 1000;
            playerCentre = new Vector2(50, 50);//origin needs to be defined with respect to the original image
            coinsCentre = new Vector2(50, 50);
            lifepackCentre = new Vector2(50, 50);
            coinsScale = lifepackScale = cellWidth * 1f / 100;

            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            bulletTimer.Elapsed += new ElapsedEventHandler(bulletTimer_Elapsed);
        }