示例#1
0
 public void NextTurn(Player player)
 {
     lblName.Text = player.Name;
     lblName.Font = new Font(lblName.Font.Name, lblName.Font.Size, lblName.Font.Style);
     Bitmap Avatar = player.getAvatar(0);
     pbAvatar.Size = new Size((int)(Avatar.Size.Width * 6 / 5 * width_ratio), (int)(Avatar.Size.Height * 6 / 5 * height_ratio));
     pbAvatar.BackgroundImage = Avatar;
     pbDice.Image = drawDice(gDice, diceBitmap, (int)(5 * (width_ratio + height_ratio) / 2), new Pen(Color.Black), new SolidBrush(Color.Black), 0);
     Bitmap power = new Bitmap(Image.FromFile("power" + player.Power + ".png"));
     pbPower.BackgroundImage = power;
     lblPower.Font = new Font(lblPower.Font.Name, lblPower.Font.Size, lblPower.Font.Style);
     lblPower.Text = "Power: " + player.Power + "/4";
     for (int i = 0; i < GameBoard.Count; i++)
     {
         Bitmap currentAvatar;
         if (i == GameBoard.Active)
             currentAvatar = GameBoard[i].getAvatar(1);
         else
             currentAvatar = GameBoard[i].getAvatar(-1);
         if (GameBoard[i].AvatarNumber == 3)
             gDisplay.DrawImage(currentAvatar, 25 * width_ratio, (i * 72 + 20 + i * 15) * height_ratio, 65 * width_ratio, 72 * height_ratio);
         else if (GameBoard[i].AvatarNumber == 1)
             gDisplay.DrawImage(currentAvatar, 8 * width_ratio, (i * 72 + 20 + i * 15) * height_ratio, 60 * width_ratio, 72 * height_ratio);
         else if (GameBoard[i].AvatarNumber == 0)
             gDisplay.DrawImage(currentAvatar, 10 * width_ratio, (i * 72 + 20 + i * 15) * height_ratio, 65 * width_ratio, 72 * height_ratio);
         else
             gDisplay.DrawImage(currentAvatar, 15 * width_ratio, (i * 72 + 15 + i * 15) * height_ratio, 60 * width_ratio, 72 * height_ratio);
         gDisplay.DrawString(GameBoard[i].Name, new Font("Times New Roman", 14 * (width_ratio + height_ratio) / 2, FontStyle.Regular), new SolidBrush(Color.Black), 80 * width_ratio, (i * 72 + 20 + i * 15) * height_ratio);
         gDisplay.DrawImage(Image.FromFile("power" + GameBoard[i].Power + ".png"), 80 * width_ratio, ((i * 72 + 20 + i * 15) + 20) * height_ratio, 70 * width_ratio, 20 * height_ratio);
     }
     pbPlayers.Image = displayBitmap;
     //width_ratio = 1;
     //height_ratio = 1;
 }
示例#2
0
 public FormBattle(Player player1, Player player2)
 {
     this.player1 = player1;
     this.player2 = player2;
     rollFlag1 = true;
     rollFlag2 = true;
     randNum = 0;
     InitializeComponent();
 }
示例#3
0
        private void timerRoll_Tick(object sender, EventArgs e)
        {
            if (diceCount > 15)
            {
                timerRoll.Stop();
                diceCount = 0;
                if(dice==1)
                    rollP1=randNum;
                else if(dice==2)
                    rollP2 = randNum;
                if (!rollFlag1 && !rollFlag2)
                {
                    if (rollP1 < rollP2)
                    {
                        lose = player1;
                        lblWin.Text = player2.Name + " wins!";
                        btnOK.Enabled = true;
                    }
                    else if (rollP1 > rollP2)
                    {
                        lose = player2;
                        lblWin.Text = player1.Name + " wins!";
                        btnOK.Enabled = true;
                    }
                    else
                    {
                        rollFlag1 = true;
                        rollFlag2 = true;
                        lblWin.Text = "You have tied, roll again.";
                        //pbDice.BackgroundImage = drawBattleDice(gDice, diceBitmap, new Pen(Color.White), new SolidBrush(Color.Black), player1.Power, 0);
                        //pbDiceP2.BackgroundImage = drawBattleDice(gDice, diceBitmap, new Pen(Color.White), new SolidBrush(Color.Black), player2.Power, 0);
                    }
                }
                return;
            }
            Random rand = new Random();

            if (dice == 1)
            {
                randNum = rand.Next(DiceNum(player1.Power)) + 1;
                pbDice.Image = drawBattleDice(gDice, diceBitmap, new Pen(Color.White), new SolidBrush(Color.Black), player1.Power, randNum);
            }
            else if (dice == 2)
            {
                randNum = rand.Next(DiceNum(player2.Power)) + 1;
                pbDiceP2.Image = drawBattleDice(gDice, diceBitmap, new Pen(Color.White), new SolidBrush(Color.Black), player2.Power, randNum);
            }
            diceCount++;
        }
示例#4
0
        private void FormGameBoard_KeyDown(object sender, KeyEventArgs e)
        {
            if (!MoveFlag)
                return;
            else
            {
                if (GameBoard.CheckMove(e.KeyData))
                {
                    GameBoard.Move(e.KeyData, moveCount);
                    moveCount--;
                }
                else
                {

                    if (GameBoard[GameBoard.Active].CurrentPosition.X == 5 && GameBoard[GameBoard.Active].CurrentPosition.Y == 3 && (e.KeyData == Keys.D || e.KeyData == Keys.Right) && (GameBoard.PreviousDirection[GameBoard.Active] != Keys.A && GameBoard.PreviousDirection[GameBoard.Active] != Keys.Left))
                    {
                        GameBoard[GameBoard.Active].X += 2;
                        GameBoard[GameBoard.Active].setAvatar(1);
                        moveCount--;
                        if (moveCount == 0)
                        {
                            GameBoard.PreviousDirection[GameBoard.Active] = Keys.Delete;
                            GameBoard.LastDirection[GameBoard.Active] = e.KeyData;
                        }
                        else
                            GameBoard.PreviousDirection[GameBoard.Active] = e.KeyData;
                    }
                    if (GameBoard[GameBoard.Active].CurrentPosition.X == 7 && GameBoard[GameBoard.Active].CurrentPosition.Y == 3 && (e.KeyData == Keys.A || e.KeyData == Keys.Left) && (GameBoard.PreviousDirection[GameBoard.Active] != Keys.D && GameBoard.PreviousDirection[GameBoard.Active] != Keys.Right))
                    {
                        GameBoard[GameBoard.Active].X -= 2;
                        GameBoard[GameBoard.Active].setAvatar(0);
                        moveCount--;
                        if (moveCount == 0)
                        {
                            GameBoard.PreviousDirection[GameBoard.Active] = Keys.Delete;
                            GameBoard.LastDirection[GameBoard.Active] = e.KeyData;
                        }
                        else
                            GameBoard.PreviousDirection[GameBoard.Active] = e.KeyData;
                    }
                }

                //dragon
                if (GameBoard[GameBoard.Active].X == 12 && GameBoard[GameBoard.Active].Y == 7)
                {
                    RefreshPlayers();
                    if (DialogResult.Yes == MessageBox.Show("Are you sure you want to fight the dragon? If you lose, you will respawn and lose all your bonus power.", "Are you sure", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                        Player player1 = GameBoard[GameBoard.Active];
                        Player dragon = new Player("Dragon", 4);
                        dragon.setAvatar(0);
                        dragon.Power = 3;
                        FormBattle formBattle = new FormBattle(player1, dragon);
                        formBattle.StartPosition = FormStartPosition.CenterScreen;
                        formBattle.StartPosition = FormStartPosition.CenterScreen;
                        formBattle.ShowDialog();
                        formBattle.Lose.CurrentPosition = formBattle.Lose.StartPosition;
                        formBattle.Lose.Power = 1;
                        if (formBattle.Lose.Name == "Dragon")
                        {
                            FormWinner FormWinner = new FormWinner(GameBoard[GameBoard.Active].Name);
                            FormWinner.StartPosition = FormStartPosition.CenterScreen;
                            FormWinner.ShowDialog();
                            this.Close();
                        }
                        else
                        {
                            formBattle.Lose.CurrentPosition = formBattle.Lose.StartPosition;
                            formBattle.Lose.Power = 1;

                            RefreshPlayers();
                        }
                    }
                    moveCount = 0;
                    MoveFlag = false;
                    RollFlag = true;
                    if (GameBoard.Active == GameBoard.Count-1)
                    {
                        numTurns++;
                    }
                    if (GameBoard.Active + 1 == GameBoard.Count)
                        GameBoard.Active = 0;
                    else
                        GameBoard.Active++;
                    //skip the players turn if necessary
                    while (GameBoard.Skip[GameBoard.Active])
                    {
                        if (GameBoard.Active == GameBoard.Count-1)
                        {
                            numTurns++;
                        }
                        GameBoard.Skip[GameBoard.Active] = false;
                        if (GameBoard.Active + 1 == GameBoard.Count)
                        {
                            GameBoard.Active = 0;
                        }
                        else
                            GameBoard.Active++;
                    }
                    NextTurn(GameBoard[GameBoard.Active]);
                    if (autoRollToolStripMenuItem.Checked)
                        pbDice_Click_1(sender, e);
                    return;
                }

                if (moveCount <= 0)
                {
                    RefreshPlayers();
                    Point currentPosition = GameBoard[GameBoard.Active].CurrentPosition;
                    //other player
                    if (GameBoard.OtherPlayers(GameBoard[GameBoard.Active]))
                    {
                        Player player1 = GameBoard.GetOtherPlayer(GameBoard[GameBoard.Active]);
                        Player player2 = GameBoard[GameBoard.Active];
                        Battle[GameBoard.Active]++;
                        for (int i = 0; i < GameBoard.Count; i++)
                        {
                            if (i == GameBoard.Active)
                                continue;
                            if (GameBoard[i].CurrentPosition == GameBoard[GameBoard.Active].CurrentPosition)
                            {
                                Battle[i]++;
                                break;
                            }
                        }
                        FormBattle formBattle = new FormBattle(player1, player2);
                        formBattle.StartPosition = FormStartPosition.CenterScreen;
                        formBattle.ShowDialog();

                        Lose[GameBoard.Active]++;
                        formBattle.Lose.CurrentPosition = formBattle.Lose.StartPosition;
                        formBattle.Lose.Power = 1;
                        currentPosition = GameBoard[GameBoard.Active].CurrentPosition;
                        //count battles lost
                        for (int i = 0; i < GameBoard.Count; i++)
                        {
                            if (GameBoard[i] == formBattle.Lose)
                                Lose[i]++;
                        }
                    }
                    RefreshPlayers();
                    //powerups
                    if (GameBoard.Board[currentPosition.X, currentPosition.Y] == 2)
                    {
                        Random rand = new Random();
                        int eventnumber = rand.Next(17);
                        FormEvent = new FormEvent(eventnumber, dragonsword, GameBoard[GameBoard.Active].Power);
                        FormEvent.StartPosition = FormStartPosition.CenterScreen;
                        FormEvent.ShowDialog();
                        if (eventnumber < 5)
                        {
                            GameBoard[GameBoard.Active].Power++;
                        }
                        else if (eventnumber == 5 || eventnumber == 6)
                        {
                            GameBoard[GameBoard.Active].Power--;
                        }
                        else if (eventnumber == 7)
                        {
                            if (dragonsword == true)
                            {
                                GameBoard[GameBoard.Active].Power += 2;
                                dragonsword = false;
                            }
                            else
                            {
                                GameBoard[GameBoard.Active].Power++;
                            }
                        }
                        else if (eventnumber == 8 || eventnumber == 9) //roll again
                        {
                            if (GameBoard.Active - 1 < 0)
                                GameBoard.Active = GameBoard.Count - 1;
                            else
                                GameBoard.Active--;
                            if (GameBoard.Active == GameBoard.Count - 1)
                                numTurns--;

                        }
                        else if (eventnumber == 10) //lose next turn
                        {
                            GameBoard.Skip[GameBoard.Active] = true;
                        }
                        else if (eventnumber == 11) //advance 1
                        {
                            moveCount = 1;
                            GameBoard.PreviousDirection[GameBoard.Active] = SameDirection(GameBoard.LastDirection[GameBoard.Active]);
                            pbDice.Image = drawDice(gDice, diceBitmap, 5, new Pen(Color.Black), new SolidBrush(Color.Black), 1);
                            return;
                        }
                        else if (eventnumber == 12) //go back 2
                        {
                            moveCount = 2;
                            GameBoard.PreviousDirection[GameBoard.Active] = OppositeDirection(GameBoard.LastDirection[GameBoard.Active]);
                            pbDice.Image = drawDice(gDice, diceBitmap, 5, new Pen(Color.Black), new SolidBrush(Color.Black), 2);
                            return;
                        }
                        else if (eventnumber == 13) //go back 1
                        {
                            moveCount = 1;
                            GameBoard.PreviousDirection[GameBoard.Active] = OppositeDirection(GameBoard.LastDirection[GameBoard.Active]);
                            pbDice.Image = drawDice(gDice, diceBitmap, 5, new Pen(Color.Black), new SolidBrush(Color.Black), 1);
                            return;
                        }
                        else if (eventnumber == 14) //advance 2
                        {
                            moveCount = 2;
                            GameBoard.PreviousDirection[GameBoard.Active] = SameDirection(GameBoard.LastDirection[GameBoard.Active]);
                            pbDice.Image = drawDice(gDice, diceBitmap, 5, new Pen(Color.Black), new SolidBrush(Color.Black), 2);
                            return;
                        }
                        else if (eventnumber == 15) //respawn
                        {
                            players[GameBoard.Active].CurrentPosition = players[GameBoard.Active].StartPosition;
                            RefreshPlayers();
                        }
                        else //lose next turn, +1 power
                        {
                            players[GameBoard.Active].Power++;
                            GameBoard.Skip[GameBoard.Active] = true;
                        }
                    }
                    MoveFlag = false;
                    RollFlag = true;
                    if (GameBoard.Active == GameBoard.Count-1)
                    {
                        numTurns++;
                    }
                    if (GameBoard.Active + 1 == GameBoard.Count)
                        GameBoard.Active = 0;
                    else
                        GameBoard.Active++;
                    //skip the players turn if necessary
                    while (GameBoard.Skip[GameBoard.Active])
                    {
                        if (GameBoard.Active == GameBoard.Count-1)
                        {
                            numTurns++;
                        }
                        GameBoard.Skip[GameBoard.Active] = false;
                        if (GameBoard.Active + 1 == GameBoard.Count)
                        {
                            GameBoard.Active = 0;

                        }
                        else
                            GameBoard.Active++;
                    }
                    NextTurn(GameBoard[GameBoard.Active]);
                    if (autoRollToolStripMenuItem.Checked)
                        pbDice_Click_1(sender, e);
                    return;
                }
                RefreshPlayers();
            }
        }
示例#5
0
 public bool OtherPlayers(Player player)
 {
     for (int i = 0; i < this.Count; i++)
     {
         if (i == active)
             continue;
         if (this[i].CurrentPosition == player.CurrentPosition)
             return true;
     }
     return false;
 }
示例#6
0
 public Player GetOtherPlayer(Player player)
 {
     for (int i = 0; i < this.Count; i++)
     {
         if (i == active)
             continue;
         if (this[i].CurrentPosition == player.CurrentPosition)
             return this[i];
     }
     return player;
 }