Exemple #1
0
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            //if the player presses space, go back to the town screen
            if (spaceDown == true)
            {
                //stop menu timer
                gameTimer.Enabled = false;

                // Goes to the town screen
                TownScreen ts   = new TownScreen();
                Form       form = this.FindForm();

                form.Controls.Add(ts);
                form.Controls.Remove(this);

                ts.Location = new Point((form.Width - ts.Width) / 2, (form.Height - ts.Height) / 2);
            }
            //else if the game over text hasn't been fully written out yet, continue to write it out
            else if (gameOverText != gameOverTextWritten)
            {
                foreach (char c in gameOverText)
                {
                    gameOverTextWritten += c;
                    Refresh();
                    Thread.Sleep(50);
                }
            }
        }
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            //update the position of the player collision
            playerRec = new Rectangle(player.x, player.y, player.size, player.size);

            #region fighting area code

            //if it is the enemy's turn...
            if (enemyTurn == true && enemyTurnCounter > 0)
            {
                enemyTurnCounter--;

                EnemyAttack(enemyTurnCounter);

                #region player movement
                //player movement
                if (dDown == true && player.x < arenaWalls[1].X - arenaWalls[1].Width - player.size)
                {
                    player.MoveLeftRight(5);
                }
                if (aDown == true && player.x > arenaWalls[0].X + arenaWalls[0].Width)
                {
                    player.MoveLeftRight(-5);
                }
                if (wDown == true && player.y > arenaWalls[2].Y + arenaWalls[2].Height)
                {
                    player.MoveUpDown(-5);
                }
                if (sDown == true && player.y < arenaWalls[3].Y - arenaWalls[3].Height - player.size)
                {
                    player.MoveUpDown(5);
                }
                #endregion player movement
            }

            //if the enemy turn is over
            #region enemy turn over

            else if (enemyTurn == true && enemyTurnCounter <= 0)
            {
                //reset the enemy turn counter
                enemyTurnCounter = 500;
                enemyTurn        = false;

                //reset the arena walls
                Rectangle leftWall   = new Rectangle(fightRec.X, fightRec.Y - 250, 5, 200);
                Rectangle rightWall  = new Rectangle(mercyRec.X + 135, mercyRec.Y - 250, 5, 200);
                Rectangle topWall    = new Rectangle(fightRec.X, fightRec.Y - 250, 848, 5);
                Rectangle bottomWall = new Rectangle(fightRec.X, fightRec.Y - 50, 848, 5);

                //add the walls to the arena walls list
                arenaWalls.Clear();
                arenaWalls.Add(leftWall);
                arenaWalls.Add(rightWall);
                arenaWalls.Add(topWall);
                arenaWalls.Add(bottomWall);

                //set the player on the fight button
                player.x = fightRec.X + 15;
                player.y = fightRec.Y + 15;
            }

            #endregion enemy turn over
            #endregion fighting area code

            #region buttons code

            //if player is in the buttons and menus...
            else
            {
                if (fightMenuSelected == true)
                {
                    FightUI();
                }
                if (actMenuSelected == true)
                {
                    ActMenu();
                }
                if (itemMenuSelected == true)
                {
                    ItemMenu();
                }

                //check which button the player is currently on and set it to the blank version of the button's sprite
                //if player moves to a different button, change button sprite back and set player position to the new button
                #region fight
                if (playerRec.IntersectsWith(fightRec))
                {
                    fightSprite = Resources.fightButtonBlank;

                    //go into the fight menu
                    if (spaceDown == true)
                    {
                        //hide the text output box
                        textOutput.Visible = false;

                        //set boolean for fight menu check to true
                        fightMenuSelected = true;

                        //set the attackRec position for fighting
                        attackRec = new Rectangle(50, 338, 15, 190);

                        //move the player off-screen during player attack
                        player.x = -20;
                        player.y = -20;

                        Thread.Sleep(150);
                    }
                    if (dDown == true)
                    {
                        fightSprite = Resources.fightButton;
                        player.x    = actRec.X + 15;
                        player.y    = actRec.Y + 15;

                        Thread.Sleep(150);
                    }
                }
                #endregion fight

                #region act
                if (playerRec.IntersectsWith(actRec))
                {
                    actSprite       = Resources.actButtonBlank;
                    actMenuSelected = false;

                    //go into the act menu
                    if (spaceDown == true)
                    {
                        //set actions to be visible and put player in the action menu
                        MenuDisplay();

                        //setup the act menu for the current enemy
                        ActMenuText();

                        //set boolean for act menu check to true
                        actMenuSelected = true;

                        Thread.Sleep(150);
                    }
                    if (aDown == true)
                    {
                        actSprite = Resources.actButton;
                        player.x  = fightRec.X + 15;
                        player.y  = fightRec.Y + 15;

                        Thread.Sleep(150);
                    }
                    if (dDown == true)
                    {
                        actSprite = Resources.actButton;
                        player.x  = itemRec.X + 15;
                        player.y  = itemRec.Y + 15;

                        Thread.Sleep(150);
                    }
                }

                #endregion act

                #region item
                if (playerRec.IntersectsWith(itemRec))
                {
                    itemSprite       = Resources.itemButtonBlank;
                    itemMenuSelected = false;

                    //go into the item menu
                    if (spaceDown == true)
                    {
                        //set actions to be visible and put player in the action menu
                        MenuDisplay();

                        //setup the item menu for the current enemy
                        ItemMenuText();

                        //set boolean for item menu check to true
                        itemMenuSelected = true;

                        Thread.Sleep(150);
                    }
                    if (aDown == true)
                    {
                        itemSprite = Resources.itemButton;
                        player.x   = actRec.X + 15;
                        player.y   = actRec.Y + 15;

                        Thread.Sleep(150);
                    }
                    if (dDown == true)
                    {
                        itemSprite = Resources.itemButton;
                        player.x   = mercyRec.X + 15;
                        player.y   = mercyRec.Y + 15;

                        Thread.Sleep(150);
                    }
                }
                #endregion item

                #region mercy
                if (playerRec.IntersectsWith(mercyRec))
                {
                    //check if the enemy is spare-able and set the button sprite accordingly
                    if (canSpare == true)
                    {
                        mercySprite = Resources.mercyButtonSpareBlank;
                    }
                    else
                    {
                        mercySprite = Resources.mercyButtonBlank;
                    }

                    //go into the mercy menu
                    if (spaceDown == true)
                    {
                        //check if the enemy is spare-able or not
                        if (canSpare == false)
                        {
                            //set the action result
                            actText[0] = "* You showed mercy." + "\n\n* ...";

                            //call the menu disappear method
                            MenuDisappear(-1);
                        }
                        else
                        {
                            //set the action result to show that the player won
                            actText[0] = "* You Won!";

                            //call the menu disappear method
                            MenuDisappear(0);

                            //go back to the town screen
                            TownScreen ts   = new TownScreen();
                            Form       form = this.FindForm();
                            form.Controls.Add(ts);
                            form.Controls.Remove(this);
                            ts.Focus();
                        }
                    }
                    if (aDown == true)
                    {
                        if (canSpare == true)
                        {
                            mercySprite = Resources.mercyButtonSpare;
                        }
                        else
                        {
                            mercySprite = Resources.mercyButton;
                        }

                        player.x = itemRec.X + 15;
                        player.y = itemRec.Y + 15;

                        Thread.Sleep(150);
                    }
                }
                #endregion mercy
            }

            #endregion buttons code

            //update the health bar and hp label depending on the player's hp
            remainingHPRec.Width = player.hp * 2;
            hpValueLabel.Text    = player.hp + " / 40";

            //update the enemy's health bar depending on the enemey's hp
            enemyRemainingHPRec.Width = enemy.hp * 2;

            Refresh();
        }
Exemple #3
0
        private void ButtonMenu()
        {
            #region new game
            if (playerRec.IntersectsWith(newGameRec))
            {
                if (spaceDown == true)
                {
                    //play menu select sound
                    menuSelectSound.Play();

                    //stop menu timer
                    menuTimer.Enabled = false;

                    //stop the music
                    music.Stop();

                    //reset the player xml
                    playerXmlReset();

                    // Goes to the town screen
                    TownScreen ts   = new TownScreen();
                    Form       form = this.FindForm();

                    form.Controls.Add(ts);
                    form.Controls.Remove(this);
                }
                if (dDown == true)
                {
                    //play menu move sound
                    menuMoveSound.Play();

                    playerRec = new Rectangle(resumeRec.X + 5, resumeRec.Y + 5, 20, 20);
                    dDown     = false;

                    Thread.Sleep(150);
                }
            }
            #endregion new game

            #region resume
            if (playerRec.IntersectsWith(resumeRec))
            {
                if (spaceDown == true)
                {
                    //play menu select sound
                    menuSelectSound.Play();

                    //stop menu timer
                    menuTimer.Enabled = false;

                    //stop the music
                    music.Stop();

                    // Goes to the town screen
                    TownScreen ts   = new TownScreen();
                    Form       form = this.FindForm();

                    form.Controls.Add(ts);
                    form.Controls.Remove(this);
                }
                if (aDown == true)
                {
                    //play menu move sound
                    menuMoveSound.Play();

                    playerRec = new Rectangle(newGameRec.X + 5, newGameRec.Y + 5, 20, 20);
                    aDown     = false;

                    Thread.Sleep(150);
                }
                if (dDown == true)
                {
                    //play menu move sound
                    menuMoveSound.Play();

                    playerRec = new Rectangle(controlsRec.X + 5, controlsRec.Y + 5, 20, 20);
                    dDown     = false;

                    Thread.Sleep(150);
                }
            }
            #endregion resume

            #region controls
            if (playerRec.IntersectsWith(controlsRec))
            {
                //go into the settings menu
                if (spaceDown == true)
                {
                    //play menu select sound
                    menuSelectSound.Play();

                    //stop menu timer
                    menuTimer.Enabled = false;

                    // Goes to the controls screen
                    ControlsScreen cs   = new ControlsScreen();
                    Form           form = this.FindForm();

                    form.Controls.Add(cs);
                    form.Controls.Remove(this);

                    cs.Location = new Point((form.Width - cs.Width) / 2, (form.Height - cs.Height) / 2);
                }
                if (aDown == true)
                {
                    //play menu move sound
                    menuMoveSound.Play();

                    playerRec = new Rectangle(resumeRec.X + 5, resumeRec.Y + 5, 20, 20);
                    aDown     = false;

                    Thread.Sleep(150);
                }
                if (dDown == true)
                {
                    //play menu move sound
                    menuMoveSound.Play();

                    playerRec = new Rectangle(exitRec.X + 5, exitRec.Y + 5, 20, 20);
                    dDown     = false;

                    Thread.Sleep(150);
                }
            }
            #endregion controls

            #region exit
            if (playerRec.IntersectsWith(exitRec))
            {
                //exit the game
                if (spaceDown == true)
                {
                    //play menu select sound
                    menuSelectSound.Play();

                    Application.Exit();
                }
                if (aDown == true)
                {
                    //play menu move sound
                    menuMoveSound.Play();

                    playerRec = new Rectangle(controlsRec.X + 5, controlsRec.Y + 5, 20, 20);
                    aDown     = false;

                    Thread.Sleep(150);
                }
            }
            #endregion exit
        }