Esempio n. 1
0
        public ScoreBoard(GamePageData previousGame, int score)
        {
            InitializeComponent();

            if (score == 0)
            {
                Narrator.youLost(narrTxt, previousGame.boardPlacementData.GetStartPageData().getPlayerName());
            }
            else
            {
                Narrator.youWin(narrTxt, previousGame.boardPlacementData.GetStartPageData().getPlayerName());
            }

            db = ScoreDB.getDB();


            db.records.Add(new ScoreRecord(previousGame.boardPlacementData.GetStartPageData().getPlayerName(), score));
            db.records.Sort();

            string scoreTable = "";

            for (int i = 0; i < 10 && i < db.records.Count; i++)
            {
                scoreTable += (i + 1) + ". " + db.records.ElementAt(i).ToString() + "\n";
            }

            msgTxt.Text = scoreTable;
        }
Esempio n. 2
0
 public void saveGame(GamePageData save)
 {
     if (this.isPlayerSavedInList(save.boardPlacementData.GetStartPageData().getPlayerName()))
     {
         this.saves.Remove(save);
     }
     this.saves.Add(save);
 }
Esempio n. 3
0
 public void saveGame(GamePageData save)
 {
     /* If there is already a save, remove it*/
     if (this.isPlayerSavedInList(save.boardPlacementData.GetStartPageData().getPlayerName()))
     {
         this.saves.Remove(save);
     }
     this.saves.Add(save);
 }
Esempio n. 4
0
        public Game(GamePageData gamePageData)
        {
            this.gamePageData = gamePageData;

            startMainTimer(this.gamePageData.getTimeSec(), this.gamePageData.getTimeMin(), this.gamePageData.getTimeHour());

            InitializeComponent();

            /* get time from gamePageData, from its boardPlacementData */
            initPlayerTicker(this.gamePageData.boardPlacementData.getIdleTime());

            /* Attach both board to the correct Grid objects */
            /* Because after serialization, Grid are not shallow copied */
            this.gamePageData.playerBoard.grid = battleGrid;
            this.gamePageData.aiBoard.grid     = battleGrid_Copy;

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Button inGrid = new Button();
                    inGrid.Click += Button_Click;

                    battleGrid.Children.Add(inGrid);
                    Grid.SetRow(inGrid, i);
                    Grid.SetColumn(inGrid, j);
                }
            }

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Button inGrid = new Button();

                    battleGrid_Copy.Children.Add(inGrid);
                    Grid.SetRow(inGrid, i);
                    Grid.SetColumn(inGrid, j);
                }
            }

            this.gamePageData.playerBoard.updateGrid();
            this.gamePageData.aiBoard.updateGrid();
        }
Esempio n. 5
0
        public Game(GamePageData gamePageData)
        {
            this.gamePageData = gamePageData;

            startMainTimer(this.gamePageData.getTimeSec(), this.gamePageData.getTimeMin(), this.gamePageData.getTimeHour());

            InitializeComponent();


            initPlayerTicker(this.gamePageData.boardPlacementData.getIdleTime());


            this.gamePageData.playerBoard.grid = battleGrid;
            this.gamePageData.aiBoard.grid     = battleGrid_Copy;

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Button inGrid = new Button();
                    inGrid.Click += Button_Click;

                    battleGrid.Children.Add(inGrid);
                    Grid.SetRow(inGrid, i);
                    Grid.SetColumn(inGrid, j);
                }
            }

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Button inGrid = new Button();

                    battleGrid_Copy.Children.Add(inGrid);
                    Grid.SetRow(inGrid, i);
                    Grid.SetColumn(inGrid, j);
                }
            }

            this.gamePageData.playerBoard.updateGrid();
            this.gamePageData.aiBoard.updateGrid();
        }
Esempio n. 6
0
        public Game(BoardPlacementData boardPlacementData)
        {
            InitializeComponent();
            Narrator.startplaying(NarratorTxt, null);

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Button inGrid = new Button();
                    inGrid.Click += Button_Click;

                    battleGrid.Children.Add(inGrid);
                    Grid.SetRow(inGrid, i);
                    Grid.SetColumn(inGrid, j);
                }
            }

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Button inGrid = new Button();

                    battleGrid_Copy.Children.Add(inGrid);
                    Grid.SetRow(inGrid, i);
                    Grid.SetColumn(inGrid, j);
                }
            }

            Ai ai;

            level = boardPlacementData.getLevel().ToString();

            switch (boardPlacementData.getLevel())
            {
            case AiLevel.EASY:
                ai = new Easy();
                break;

            case AiLevel.MEDIUM:
                ai = new Medium();
                break;

            case AiLevel.HARD:
                ai = new Hard();
                break;

            default:
                throw new NotSupportedException("ai unknown");
            }

            Board aiBoard = new Board(battleGrid_Copy);

            battleGrid_Copy.IsEnabled = false;
            for (int i = 0; i < boardPlacementData.getAiShip().Length; i++)
            {
                aiBoard.placeShip(new Ship(boardPlacementData.getAiShip()[i].position));
            }

            Board playerBoard = new Board(battleGrid);

            for (int i = 0; i < boardPlacementData.getPlayerShip().Length; i++)
            {
                playerBoard.placeShip(new Ship(boardPlacementData.getPlayerShip()[i].position));
            }

            this.gamePageData = new GamePageData(boardPlacementData, 0, 0, 0, 0, playerBoard, aiBoard, ai);

            initPlayerTicker(this.gamePageData.boardPlacementData.getIdleTime());

            startMainTimer(this.gamePageData.getTimeSec(), this.gamePageData.getTimeMin(), this.gamePageData.getTimeHour());

            idleTimeDispatcher.Start();
        }