예제 #1
0
파일: Game1.cs 프로젝트: HY-Space/HY-Tank
        private void fillscore(PlayerInfo player, int playerno,int scoreorgx,int scoreorgy,int rowGap,int columnGap)
        {
            //Allignment: Right
            spriteBatch.DrawString(body, player.points.ToString(), new Vector2(scoreorgx + columnGap * 2 - body.MeasureString(player.points.ToString()).X-5, scoreorgy + rowGap * playerno), Color.WhiteSmoke);
            spriteBatch.DrawString(body, player.coins.ToString(), new Vector2(scoreorgx + columnGap * 3 - body.MeasureString(player.coins.ToString()).X-5, scoreorgy + rowGap * playerno), Color.WhiteSmoke);
            if (player.health > 0)
                spriteBatch.DrawString(body, player.health.ToString(), new Vector2(scoreorgx + columnGap * 4 - body.MeasureString(player.health.ToString()).X - 5, scoreorgy + rowGap * playerno), Color.WhiteSmoke);
            else
            {
                spriteBatch.DrawString(body, "Dead", new Vector2(scoreorgx + columnGap * 4 - body.MeasureString("Dead").X - 5, scoreorgy + rowGap * playerno), Color.WhiteSmoke);

            }
        }
예제 #2
0
파일: Game1.cs 프로젝트: HY-Space/HY-Tank
        private Vector2 nextCellAssumption(PlayerInfo tank)
        {
            Vector2 nextCellCoordinates = new Vector2();
            switch (tank.direction)
            {
                case 0:
                    {
                        if (tank.coordinates.Y > 1 && !barriers.Contains(arena[tank.coordinates.Y-1,tank.coordinates.X]))
                        {
                            nextCellCoordinates.X = tank.coordinates.X;
                            nextCellCoordinates.Y = tank.coordinates.Y-1;
                        }
                        else
                        {
                            nextCellCoordinates.X = tank.coordinates.X;
                            nextCellCoordinates.Y = tank.coordinates.Y ;
                        }
                        break;
                    }
                case 1:
                    {
                        if (tank.coordinates.X < columnsGrid-1 && !barriers.Contains(arena[tank.coordinates.Y, tank.coordinates.X+1]))
                        {
                            nextCellCoordinates.X = tank.coordinates.X + 1;
                            nextCellCoordinates.Y = tank.coordinates.Y ;
                        }
                        else
                        {
                            nextCellCoordinates.X = tank.coordinates.X;
                            nextCellCoordinates.Y = tank.coordinates.Y;
                        }
                        break;
                    }
                case 2:
                    {
                        if (tank.coordinates.Y < columnsGrid-1 && !barriers.Contains(arena[tank.coordinates.Y + 1, tank.coordinates.X]))
                        {
                            nextCellCoordinates.X = tank.coordinates.X;
                            nextCellCoordinates.Y = tank.coordinates.Y + 1;
                        }
                        else
                        {
                            nextCellCoordinates.X = tank.coordinates.X;
                            nextCellCoordinates.Y = tank.coordinates.Y;
                        }
                        break;
                    }
                case 3:
                    {
                        if (tank.coordinates.X > 1 && !barriers.Contains(arena[tank.coordinates.Y, tank.coordinates.X - 1]))
                        {
                            nextCellCoordinates.X = tank.coordinates.X - 1;
                            nextCellCoordinates.Y = tank.coordinates.Y;
                        }
                        else
                        {
                            nextCellCoordinates.X = tank.coordinates.X;
                            nextCellCoordinates.Y = tank.coordinates.Y;
                        }
                        break;
                    }

            }
            return nextCellCoordinates;
        }
예제 #3
0
파일: Game1.cs 프로젝트: HY-Space/HY-Tank
        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);
        }