Esempio n. 1
0
        private void CreateNewGame()
        {
            tilingGrid = TilingGrid.GetInstance();

            PlayerEntity p1 = null, p2 = null;

            int mapId;

            switch (gameMode)
            {
                case GameMode.SINGLE:
                    // Load an arbitrary map
                    mapId = rand.Next(Consts.NUMBER_OF_CUSTOM_MAPS);
                    gridMap.Load(Content.Load<GridData>(Utils.GetMapFileName(mapId.ToString())));

                    gridMap.IntializeNewMap();
                    tilingGrid.Load(
                        Consts.GRID_LEFT, Consts.GRID_TOP,
                        Consts.TILE_WIDTH, Consts.TILE_HEIGHT);

                    p1 = new PlayerEntity(
                        Consts.PLAYER1_PANEL_LEFT, Consts.PLAYER1_PANEL_TOP,
                        Consts.PLAYER_PANEL_WIDTH, Consts.PLAYER_PANEL_HEIGHT,
                        p1Name, "Single");
                    p1.PlayerController = PlayerGameController.GetInstance();
                    p2 = new PlayerEntity(
                        Consts.PLAYER2_PANEL_LEFT, Consts.PLAYER2_PANEL_TOP,
                        Consts.PLAYER_PANEL_WIDTH, Consts.PLAYER_PANEL_HEIGHT,
                        "COMPUTER", "AI");
                    p2.PlayerController = GetAIPlayer(rand.Next(Consts.NUMBER_OF_AIS));
                    break;

                case GameMode.MULTI:
                    // Load an arbitrary map
                    mapId = rand.Next(Consts.NUMBER_OF_CUSTOM_MAPS);
                    gridMap.Load(Content.Load<GridData>(Utils.GetMapFileName(mapId.ToString())));

                    gridMap.IntializeNewMap();
                    tilingGrid.Load(
                        Consts.GRID_LEFT, Consts.GRID_TOP,
                        Consts.TILE_WIDTH, Consts.TILE_HEIGHT);

                    p1 = new PlayerEntity(
                        Consts.PLAYER1_PANEL_LEFT, Consts.PLAYER1_PANEL_TOP,
                        Consts.PLAYER_PANEL_WIDTH, Consts.PLAYER_PANEL_HEIGHT,
                        p1Name, "Single");
                    p1.PlayerController = PlayerGameController.GetInstance();
                    p2 = new PlayerEntity(
                        Consts.PLAYER2_PANEL_LEFT, Consts.PLAYER2_PANEL_TOP,
                        Consts.PLAYER_PANEL_WIDTH, Consts.PLAYER_PANEL_HEIGHT,
                        p2Name, "Single");
                    p2.PlayerController = PlayerGameController.GetInstance();
                    break;

                case GameMode.NETWORK:
                    PlayerGameControllerOnline.RoomId = roomName;
                    PlayerGameControllerOnline.MyName = p1Name;
                    PlayerGameControllerOnline.Connect();

                    int myTurn = PlayerGameControllerOnline.Turn;
                    mapId = PlayerGameControllerOnline.MapId;
                    gridMap.Load(Content.Load<GridData>(Utils.GetMapFileName(mapId.ToString())));

                    gridMap.IntializeNewMap();
                    tilingGrid.Load(
                        Consts.GRID_LEFT, Consts.GRID_TOP,
                        Consts.TILE_WIDTH, Consts.TILE_HEIGHT);

                    if (myTurn == 0)
                    {
                        p1 = new PlayerEntity(
                            Consts.PLAYER1_PANEL_LEFT, Consts.PLAYER1_PANEL_TOP,
                            Consts.PLAYER_PANEL_WIDTH, Consts.PLAYER_PANEL_HEIGHT,
                            PlayerGameControllerOnline.MyName, "Single");
                        p1.PlayerController = PlayerGameControllerOnline.GetInstance(ControllerOwner.ME);
                        p2 = new PlayerEntity(
                            Consts.PLAYER2_PANEL_LEFT, Consts.PLAYER2_PANEL_TOP,
                            Consts.PLAYER_PANEL_WIDTH, Consts.PLAYER_PANEL_HEIGHT,
                            PlayerGameControllerOnline.OpName, "Single");
                        p2.PlayerController = PlayerGameControllerOnline.GetInstance(ControllerOwner.OPPONENT);
                    }
                    else if (myTurn == 1)
                    {
                        p2 = new PlayerEntity(
                            Consts.PLAYER1_PANEL_LEFT, Consts.PLAYER1_PANEL_TOP,
                            Consts.PLAYER_PANEL_WIDTH, Consts.PLAYER_PANEL_HEIGHT,
                            PlayerGameControllerOnline.MyName, "Single");
                        p2.PlayerController = PlayerGameControllerOnline.GetInstance(ControllerOwner.ME);
                        p1 = new PlayerEntity(
                            Consts.PLAYER2_PANEL_LEFT, Consts.PLAYER2_PANEL_TOP,
                            Consts.PLAYER_PANEL_WIDTH, Consts.PLAYER_PANEL_HEIGHT,
                            PlayerGameControllerOnline.OpName, "Single");
                        p1.PlayerController = PlayerGameControllerOnline.GetInstance(ControllerOwner.OPPONENT);
                    }

                    // Online mode is under construction
                    break;

                default:
                    break;
            }

            playerTurn = PlayerTurn.GetInstance();
            playerTurn.NewGame(p1, p2, 0);
        }
Esempio n. 2
0
 public static TilingGrid GetInstance()
 {
     if (instance == null)
         instance = new TilingGrid();
     return instance;
 }