private void HandleGameMsg(string msg)
        {
            string[] ar = msg.Split(',');
            int      type = int.Parse(ar[0]);
            int      playerNum, x, y, dir, scoreType, score;

            Console.WriteLine("In Handle Game Msg");
            sock.MulticastLoopback = false;
            Debug.Write("TYPE: " + type);
            switch (type)
            {
            case 0:         // peg placement
                x = int.Parse(ar[1]);
                int player = int.Parse(ar[3]);
                if (int.Parse(ar[4]) == 0)
                {
                    Console.WriteLine("Player is: " + player);
                    if (player == 0)
                    {
                        gameArea.insertPieces(Brushes.Red, Game.grid[x, Game.columnHeight(x)]);
                        Game.board[x, Game.HEIGHT - 1 - Game.columnHeight(x)].setColor(Color.Red);
                        Game.currentPlayer = 1;
                        gameArea.freezeBoard(true);
                    }
                    else if (player == 1)
                    {
                        gameArea.insertPieces(Brushes.Yellow, Game.grid[x, Game.columnHeight(x)]);
                        Game.board[x, Game.HEIGHT - 1 - Game.columnHeight(x)].setColor(Color.Yellow);
                        Game.currentPlayer = 0;
                        gameArea.freezeBoard(true);
                    }
                    gameArea.freezeBoard(true);
                }
                else
                {
                    if (player == 0)
                    {
                        gameArea.freezeBoard(false);
                        gameArea.insertPieces(Brushes.Red, Game.grid[x, Game.columnHeight(x)]);
                        Game.board[x, Game.HEIGHT - 1 - Game.columnHeight(x)].setColor(Color.Red);
                        createText("Red");
                    }
                    else if (player == 1)
                    {
                        gameArea.freezeBoard(false);
                        gameArea.insertPieces(Brushes.Yellow, Game.grid[x, Game.columnHeight(x)]);
                        Game.board[x, Game.HEIGHT - 1 - Game.columnHeight(x)].setColor(Color.Yellow);
                        createText("Yellow");
                    }
                }

                break;

            case 1:
                break;
            }
        }
Example #2
0
        public void dropPeg(object sender, EventArgs e)
        {
            Button b = (Button)sender;
            Point  p = b.Location;

            switch (p.X)
            {
            case 290:
                if (columnHeight(0) != -1)
                {
                    switch (currentPlayer)
                    {
                    case 0:
                        form.insertPieces(player1Fill, grid[0, columnHeight(0)]);
                        board[0, HEIGHT - 1 - columnHeight(0)].setColor(Color.Red);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[0, HEIGHT - 2 - columnHeight(0)]));
                        form.loopBack(false);
                        int winningIndex = 0;
                        if (checkWinState(board[0, HEIGHT - 2 - columnHeight(0)]))
                        {
                            winningIndex = 1;
                            createText("Red");
                        }
                        Sender.SendGameMsg(0, 0 + "," + (HEIGHT - 2 - columnHeight(0)) + "," + currentPlayer + "," + winningIndex);

                        form.loopBack(true);

                        currentPlayer = 1;
                        Console.WriteLine("Y: " + (HEIGHT - 1 - columnHeight(0)));
                        //Sender.SendGameMsg(1, "Unfreeze");
                        break;

                    case 1:
                        form.insertPieces(player2Fill, grid[0, columnHeight(0)]);
                        board[0, HEIGHT - 1 - columnHeight(0)].setColor(Color.Yellow);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[0, HEIGHT - 2 - columnHeight(0)]));
                        form.loopBack(false);
                        winningIndex = 0;
                        if (checkWinState(board[0, HEIGHT - 2 - columnHeight(0)]))
                        {
                            createText("Yellow");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 0 + "," + (HEIGHT - 2 - columnHeight(0)) + "," + currentPlayer + "," + winningIndex);

                        form.loopBack(true);

                        currentPlayer = 0;
                        break;
                    }
                }
                break;

            case 390:
                if (columnHeight(1) != -1)
                {
                    switch (currentPlayer)
                    {
                    case 0:
                        form.insertPieces(player1Fill, grid[1, columnHeight(1)]);
                        board[1, HEIGHT - 1 - columnHeight(1)].setColor(Color.Red);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[1, HEIGHT - 2 - columnHeight(1)]));
                        form.loopBack(false);
                        int winningIndex = 0;
                        if (checkWinState(board[1, HEIGHT - 2 - columnHeight(1)]))
                        {
                            createText("Red");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 1 + "," + (HEIGHT - 2 - columnHeight(1)) + "," + currentPlayer + "," + winningIndex);

                        form.loopBack(true);
                        currentPlayer = 1;
                        break;

                    case 1:
                        form.insertPieces(player2Fill, grid[1, columnHeight(1)]);
                        board[1, HEIGHT - 1 - columnHeight(1)].setColor(Color.Yellow);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[1, HEIGHT - 2 - columnHeight(1)]));
                        form.loopBack(false);
                        winningIndex = 0;
                        if (checkWinState(board[1, HEIGHT - 2 - columnHeight(1)]))
                        {
                            createText("Yellow");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 1 + "," + (HEIGHT - 2 - columnHeight(1)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 0;
                        break;
                    }
                }
                break;

            case 490:
                if (columnHeight(2) != -1)
                {
                    switch (currentPlayer)
                    {
                    case 0:
                        form.insertPieces(player1Fill, grid[2, columnHeight(2)]);
                        board[2, HEIGHT - 1 - columnHeight(2)].setColor(Color.Red);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[2, HEIGHT - 2 - columnHeight(2)]));
                        form.loopBack(false);
                        int winningIndex = 0;
                        if (checkWinState(board[2, HEIGHT - 2 - columnHeight(2)]))
                        {
                            createText("Red");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 2 + "," + (HEIGHT - 2 - columnHeight(2)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 1;
                        break;

                    case 1:
                        form.insertPieces(player2Fill, grid[2, columnHeight(2)]);
                        board[2, HEIGHT - 1 - columnHeight(2)].setColor(Color.Yellow);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[2, HEIGHT - 2 - columnHeight(2)]));
                        form.loopBack(false);
                        winningIndex = 0;
                        if (checkWinState(board[2, HEIGHT - 2 - columnHeight(2)]))
                        {
                            createText("Yellow");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 2 + "," + (HEIGHT - 2 - columnHeight(2)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 0;
                        break;
                    }
                }
                break;

            case 590:
                if (columnHeight(3) != -1)
                {
                    switch (currentPlayer)
                    {
                    case 0:
                        form.insertPieces(player1Fill, grid[3, columnHeight(3)]);
                        board[3, HEIGHT - 1 - columnHeight(3)].setColor(Color.Red);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[3, HEIGHT - 2 - columnHeight(3)]));
                        form.loopBack(false);
                        int winningIndex = 0;
                        if (checkWinState(board[3, HEIGHT - 2 - columnHeight(3)]))
                        {
                            createText("Red");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 3 + "," + (HEIGHT - 2 - columnHeight(3)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 1;
                        break;

                    case 1:
                        form.insertPieces(player2Fill, grid[3, columnHeight(3)]);
                        board[3, HEIGHT - 1 - columnHeight(3)].setColor(Color.Yellow);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[3, HEIGHT - 2 - columnHeight(3)]));
                        form.loopBack(false);
                        winningIndex = 0;
                        if (checkWinState(board[3, HEIGHT - 2 - columnHeight(3)]))
                        {
                            createText("Yellow");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 3 + "," + (HEIGHT - 2 - columnHeight(3)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 0;
                        break;
                    }
                }
                break;

            case 690:
                if (columnHeight(4) != -1)
                {
                    switch (currentPlayer)
                    {
                    case 0:
                        form.insertPieces(player1Fill, grid[4, columnHeight(4)]);
                        board[4, HEIGHT - 1 - columnHeight(4)].setColor(Color.Red);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[4, HEIGHT - 2 - columnHeight(4)]));
                        form.loopBack(false);
                        int winningIndex = 0;
                        if (checkWinState(board[4, HEIGHT - 2 - columnHeight(4)]))
                        {
                            createText("Red");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 4 + "," + (HEIGHT - 2 - columnHeight(4)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 1;
                        break;

                    case 1:
                        form.insertPieces(player2Fill, grid[4, columnHeight(4)]);
                        board[4, HEIGHT - 1 - columnHeight(4)].setColor(Color.Yellow);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[4, HEIGHT - 2 - columnHeight(4)]));
                        form.loopBack(false);
                        winningIndex = 0;
                        if (checkWinState(board[4, HEIGHT - 2 - columnHeight(4)]))
                        {
                            createText("Yellow");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 4 + "," + (HEIGHT - 2 - columnHeight(4)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 0;
                        break;
                    }
                }
                break;

            case 790:
                if (columnHeight(5) != -1)
                {
                    switch (currentPlayer)
                    {
                    case 0:
                        form.insertPieces(player1Fill, grid[5, columnHeight(5)]);
                        board[5, HEIGHT - 1 - columnHeight(5)].setColor(Color.Red);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[5, HEIGHT - 2 - columnHeight(5)]));
                        form.loopBack(false);
                        int winningIndex = 0;
                        if (checkWinState(board[5, HEIGHT - 2 - columnHeight(5)]))
                        {
                            createText("Red");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 5 + "," + (HEIGHT - 2 - columnHeight(5)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 1;
                        break;

                    case 1:
                        form.insertPieces(player2Fill, grid[5, columnHeight(5)]);
                        board[5, HEIGHT - 1 - columnHeight(5)].setColor(Color.Yellow);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[5, HEIGHT - 2 - columnHeight(5)]));
                        form.loopBack(false);
                        winningIndex = 0;
                        if (checkWinState(board[5, HEIGHT - 2 - columnHeight(5)]))
                        {
                            createText("Yellow");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 5 + "," + (HEIGHT - 2 - columnHeight(5)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 0;
                        break;
                    }
                }
                break;

            case 890:
                if (columnHeight(6) != -1)
                {
                    switch (currentPlayer)
                    {
                    case 0:
                        form.insertPieces(player1Fill, grid[6, columnHeight(6)]);
                        board[6, HEIGHT - 1 - columnHeight(6)].setColor(Color.Red);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[6, HEIGHT - 2 - columnHeight(6)]));
                        form.loopBack(false);
                        int winningIndex = 0;
                        if (checkWinState(board[6, HEIGHT - 2 - columnHeight(6)]))
                        {
                            winningIndex = 1;
                            createText("Red");
                        }
                        Sender.SendGameMsg(0, 6 + "," + (HEIGHT - 2 - columnHeight(6)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 1;
                        break;

                    case 1:
                        form.insertPieces(player2Fill, grid[6, columnHeight(6)]);
                        board[6, HEIGHT - 1 - columnHeight(6)].setColor(Color.Yellow);
                        System.Diagnostics.Debug.WriteLine(checkWinState(board[6, HEIGHT - 2 - columnHeight(6)]));
                        form.loopBack(false);
                        winningIndex = 0;
                        if (checkWinState(board[6, HEIGHT - 2 - columnHeight(6)]))
                        {
                            createText("Yellow");

                            winningIndex = 1;
                        }
                        Sender.SendGameMsg(0, 6 + "," + (HEIGHT - 2 - columnHeight(6)) + "," + currentPlayer + "," + winningIndex);


                        form.loopBack(true);

                        currentPlayer = 0;
                        break;
                    }
                }
                break;
            }
            freezeBoard(false);
        }