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 StartPage()
 {
     InitializeComponent();
     Narrator.displayIntro(msgTxt);
     continueBtn.Visibility = Visibility.Hidden;
     newBtn.Visibility      = Visibility.Hidden;
 }
Esempio n. 3
0
        public void Button_Click(object sender, RoutedEventArgs e)
        {
            checkWin();
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (((Button)battleGrid.Children.Cast <UIElement>().First(f => Grid.GetRow(f) == i && Grid.GetColumn(f) == j)).Equals((Button)sender))
                    {
                        if (this.gamePageData.playerBoard.shoot(new Square(j, i)) && !firstship)
                        {
                            Narrator.shipdown(NarratorTxt, null);
                            firstship = true;
                        }

                        this.gamePageData.playerBoard.updateGrid();

                        /* Reset the idle counter */
                        this.currIdleTimeLeft = this.gamePageData.boardPlacementData.getIdleTime();

                        aiMove();
                    }
                }
            }
            checkWin();
        }
Esempio n. 4
0
        private void playerTurn_Tick(object sender, EventArgs e)
        {
            if (--this.currIdleTimeLeft <= 0)
            {
                aiMove();
                if (turnCount < 5 && !silence)
                {
                    Narrator.timedout(NarratorTxt, null);
                }

                this.currIdleTimeLeft = this.gamePageData.boardPlacementData.getIdleTime();
            }
        }
Esempio n. 5
0
        public BoardPlacement(StartPageData startPageData)

        {
            InitializeComponent(); completeClean();

            this.startPageData = startPageData;

            Narrator.placing(narratorTxt, startPageData.getPlayerName());

            battleboard = new Board(battleGrid);
            battleships = new Ship[5];

            randomize(battleships);
        }
        public BoardPlacement(StartPageData startPageData)

        {
            InitializeComponent(); completeClean();
            /* Saving startPageData from previous StartPage while the user is choosing his ships and settings*/
            this.startPageData = startPageData;

            Narrator.placing(narratorTxt, startPageData.getPlayerName());

            battleboard = new Board(battleGrid);
            battleships = new Ship[5];

            randomize(battleships);
        }
Esempio n. 7
0
 private void playerTurn_Tick(object sender, EventArgs e)
 {
     /* If the user runs out of time... */
     if (--this.currIdleTimeLeft <= 0)
     {
         /* ... Let the ai play*/
         aiMove();
         if (turnCount < 5 && !silence)
         {
             Narrator.timedout(NarratorTxt, null);
         }
         /* Reset the idleTime counter */
         this.currIdleTimeLeft = this.gamePageData.boardPlacementData.getIdleTime();
     }
 }
Esempio n. 8
0
        /**
         * Button pressed after name is entered.
         *
         * @author karina
         **/
        private void sendBtn_Click(object sender, RoutedEventArgs e)
        {
            string name = nameTxt.Text;

            nameTxt.Visibility     = Visibility.Hidden;
            sendBtn.Visibility     = Visibility.Hidden;
            newBtn.Visibility      = Visibility.Visible;
            continueBtn.Visibility = Visibility.Hidden;

            if (PlayerDB.getDB().isPlayerExist(name))
            {
                Narrator.displayNameFoundSaved(msgTxt, name);
                continueBtn.Visibility = Visibility.Visible;
            }
            else
            {
                Narrator.newName(msgTxt, name);
            }
        }
Esempio n. 9
0
        /* The ai plays a move can be called by Button_Click and when the user's idle time is over */
        private void aiMove()
        {
            if (turnCount == 0)
            {
                Narrator.firstturn(NarratorTxt, null);
            }
            else if (turnCount == 1)
            {
                Narrator.secondturn(NarratorTxt, null);
            }
            else if (turnCount > 10 && !silence)
            {
                Narrator.normal(NarratorTxt, null);
                silence = true;
            }

            idleTimeDispatcher.Stop();
            battleGrid.IsEnabled = false;
            this.gamePageData.aiBoard.shoot(this.gamePageData.ai.MakeMove(this.gamePageData.aiBoard));
            this.gamePageData.aiBoard.updateGrid();
            turnCount++;
            battleGrid.IsEnabled = true;
            idleTimeDispatcher.Start();
        }
Esempio n. 10
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();
        }