Exemple #1
0
 public GameParameter(string p1Name, TimeSpan p1Time, int p1Score, string p2Name, TimeSpan p2Time, int p2Score, int[,] tabBoard, int turn, int playerTurn)
 {
     this.p1Name     = p1Name;
     this.p1Time     = p1Time;
     this.p1Score    = p1Score;
     this.p2Name     = p2Name;
     this.p2Time     = p2Time;
     this.p2Score    = p2Score;
     this.turn       = turn;
     newBoard        = new int[NB_ROW, NB_COL];
     this.p1Time     = p1Time;
     this.p2Time     = p2Time;
     this.playerTurn = playerTurn;
     p1Stopwatch     = new MyStopwatch(p1Time);
     p2Stopwatch     = new MyStopwatch(p2Time);
     CopyBoard(tabBoard);
 }
Exemple #2
0
        /// <summary>
        /// Function that will instanciate all the parameters/attributes necessary for a game.
        /// </summary>
        /// <param name="g">g = default if "new game" button is clicked</param>
        private void InitializeGame(GameParameter g = default(GameParameter))
        {
            board = new Board(NB_ROW, NB_COL);

            if (mainBox.GetPlayerTokenPath(1) != "")
            {
                token1 = new Token(mainBox.GetPlayerTokenPath(1));
            }
            else
            {
                token1 = new Token(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..\Assets\Tokens\token1.png"));
            }

            if (mainBox.GetPlayerTokenPath(2) != "")
            {
                token2 = new Token(mainBox.GetPlayerTokenPath(2));
            }
            else
            {
                token2 = new Token(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..\Assets\Tokens\token2.png"));
            }

            //New game
            if (g.Equals(default(GameParameter)))
            {
                player1 = new Player(token1, mainBox.GetPlayerName(1), 1);
                player2 = new Player(token2, mainBox.GetPlayerName(2), 2);

                timerP1 = new MyStopwatch();
                timerP2 = new MyStopwatch();

                lblPlayer1Score.DataContext = new Player {
                    Score = player1.Score
                };
                lblPlayer2Score.DataContext = new Player {
                    Score = player2.Score
                };

                lblPlayerTurn.Content = player1.Name + "'s turn :";

                isPlayer1   = true;
                nbFreeCells = (NB_ROW * NB_COL) - 4;
                turn        = 1;
            }

            //Loaded game. Attributes/Properties will be charged by data in GameParameter struct
            else
            {
                player1 = new Player(token1, g.p1Name, 1);
                player2 = new Player(token2, g.p2Name, 2);

                board.SetBoard(g.newBoard);

                if (g.playerTurn == 2)
                {
                    isPlayer1                   = false;
                    lblPlayerTurn.Content       = player2.Name + "'s turn :";
                    lblPlayerImgTurn.Background = player2.Token.ImgBrush;
                }
                else
                {
                    isPlayer1                   = true;
                    lblPlayerTurn.Content       = player1.Name + "'s turn :";
                    lblPlayerImgTurn.Background = player1.Token.ImgBrush;
                }

                timerP1 = g.p1Stopwatch;
                timerP2 = g.p2Stopwatch;

                if (isPlayer1)
                {
                    timerP1.Start();
                }
                else
                {
                    timerP2.Start();
                }

                nbFreeCells = board.GetFreeCells();
                turn        = g.turn;
            }

            lblPlayer1.Content = player1.Name;
            lblPlayer2.Content = player2.Name;
            CheckScore();

            //Timer used to update lblPlayer1/2Time
            timerUpdate          = new Timer(10);
            timerUpdate.Elapsed += Timer_tick;
            timerUpdate.Start();

            // Initialize Rules
            rules = new Rules(board, player1, player2, tokenGrid, NB_ROW, NB_COL);
        }