Beispiel #1
0
        static void Main(string[] args)
        {
            Engine.Initialize();

            Menu     = new Menu();
            nivel1   = new nivel1();
            nivel2   = new nivel2();
            GameOver = new GameOver();
            Win      = new Win();

            DateTime fechaInicio         = DateTime.Now;
            float    tiempoFrameAnterior = 0;

            while (true)
            {
                TimeSpan tiempoDesdeInicio = DateTime.Now - fechaInicio;
                tiempoActual        = (float)tiempoDesdeInicio.TotalSeconds;
                deltaTime           = tiempoActual - tiempoFrameAnterior;
                tiempoFrameAnterior = tiempoActual;

                Engine.Clear();
                if (estadoActual == estado.menu)
                {
                    Menu.Actualizar();
                    Menu.Dibujar();
                }
                else if (estadoActual == estado.nivel1)
                {
                    nivel1.MapNivel1();
                    nivel1.Actualizar();
                    nivel1.Dibujar();
                }
                else if (estadoActual == estado.nivel2)
                {
                    nivel2.MapNivel2();
                    nivel2.Actualizar();
                    nivel2.Dibujar();
                }
                else if (estadoActual == estado.gameover)
                {
                    GameOver.Actualizar();
                    GameOver.Dibujar();
                }
                else if (estadoActual == estado.win)
                {
                    Win.Actualizar();
                    Win.Dibujar();
                }
                Engine.Show();
            }
        }
Beispiel #2
0
        public override void Update(GameResult e)
        {
            if (_repository == null)
            {
                return;
            }


            Win evnt = e as Win;

            if (evnt == null)
            {
                return;
            }

            Player p = _repository.FindPlayerByID(e.Player);

            _repository.AddExp(p, _gainer.Gain());
        }
Beispiel #3
0
        /// <summary>
        /// Checks if the game should be ended and who is the winner
        /// </summary>
        public void DetermineGameEnd()
        {
            Win result = new Win();

            if (drawDeckViewer.Controls.Count == 0)
            {
                if (playerDeckViewer.Controls.Count == 0 && enemyDeckViewer.Controls.Count == 0)
                {
                    //It's a tie!
                    this.Parent.Controls.Add(result);
                    result.LabelText = "Tie Game";

                    if (this.Parent is PlayDurak)
                    {
                        PlayDurak.SetScreenVisible(this.Parent.Controls, result);
                    }
                }
                else if (playerDeckViewer.Controls.Count == 0)
                {
                    //The human player wins!
                    this.Parent.Controls.Add(result);
                    result.LabelText = "You Win !!";

                    if (this.Parent is PlayDurak)
                    {
                        PlayDurak.SetScreenVisible(this.Parent.Controls, result);
                    }
                }
                else
                {
                    //The AI wins!
                    this.Parent.Controls.Add(result);
                    result.LabelText = "You are the Durak!";
                    if (this.Parent is PlayDurak)
                    {
                        PlayDurak.SetScreenVisible(this.Parent.Controls, result);
                    }
                }
            }
        }
Beispiel #4
0
        StepScore Minimax(FieldContext gameProcess, PlayerCell first, PlayerCell flag, int deep, int col, Win aWin)
        {
            StepScore s = StepScoreZero;

            if (deep != 0)
            {
                gameProcess.Field[gameProcess.FreePositions[col], col] = gameProcess.GetOppositePlayer(flag);//(flag % 2) + 1;-opposite
                gameProcess.FreePositions[col]++;
            }
            int c = gameProcess.EndOfTheGame(gameProcess.GetOppositePlayer(flag));

            aWin.W = 0;
            if (c != -1 && deep == 1)
            {
                s.Score = Heuristic.heuristic(gameProcess, first, gameProcess.GetOppositePlayer(flag));
                s.Step  = col;
                aWin.W  = 1;
                gameProcess.FreePositions[col]--;
                gameProcess.Field[gameProcess.FreePositions[col], col] = 0;
                return(s);
            }
            if (c != -1 || deep == 3)
            {
                if (col != -1)
                {
                    s.Score = Heuristic.heuristic(gameProcess, first, gameProcess.GetOppositePlayer(flag));
                    s.Step  = col;
                    gameProcess.FreePositions[col]--;//не работает
                    gameProcess.Field[gameProcess.FreePositions[col], col] = 0;
                    return(s);
                }
            }

            StepScore a = StepScoreZero;

            a.Step = -1;

            if ((deep + 1) % 2 == 0)
            {
                a.Score = (long)-1e15;
            }
            else
            {
                a.Score = (long)1e15;
            }

            for (int i = 0; i < gameProcess.QuanCols; i++)
            {
                if (gameProcess.FreePositions[i] != gameProcess.QuanRows)
                {
                    StepScore f = Minimax(gameProcess, first, gameProcess.GetOppositePlayer(flag), deep + 1, i, aWin);
                    if (aWin.W != 0)
                    {
                        return(f);
                    }
                    if ((deep + 1) % 2 == 0 && a.Score < f.Score)
                    {
                        a.Score = f.Score;
                        a.Step  = i;
                    }

                    if ((deep + 1) % 2 != 0 && a.Score > f.Score)
                    {
                        a.Score = f.Score;
                        a.Step  = i;
                    }
                }
            }
            if (deep != 0)
            {
                gameProcess.FreePositions[col]--;
                gameProcess.Field[gameProcess.FreePositions[col], col] = 0;
            }
            return(a);
        }
Beispiel #5
0
        private void Form1_KeyDown(object sender, KeyEventArgs e) //this is for the controls
        {
            void moveup()
            {
                if (e.KeyCode == Keys.Up || e.KeyCode == Keys.W) //if the W or up arrow key is pressed down then the character will move up
                {
                    character.Top = character.Top - yspeed;
                }
            }

            void movedown()
            {
                if (e.KeyCode == Keys.Down || e.KeyCode == Keys.S) //if the S or down arrow key is pressed down then the character will move down
                {
                    character.Top = character.Top + yspeed;
                }
            }

            void barriers()
            {
                if (character.Left <= 0) //if character hits the left border then it doesn't go off the screen, it'll just bounce off it
                {
                    character.Left = character.Left + 10;
                    counter        = counter - 1;
                }
                if (character.Top <= 0)
                {
                    character.Top = character.Top + yspeed;
                }
                if (character.Top > ClientRectangle.Height - character.Height)
                {
                    character.Top = character.Top - yspeed;
                }
                if (character.Left >= ClientRectangle.Width - 75)
                {
                    character.Left = character.Left - xspeed;
                    counter        = counter - 1;
                }
            }

            void movehorizontal()
            {
                if (e.KeyCode == Keys.Right || e.KeyCode == Keys.D) //if the D or right arrow key is pressed down then the character will move right and gain points
                {
                    character.Left = character.Left + xspeed;
                    counter        = counter + 1;
                    score.Text     = counter.ToString();
                }
                if (e.KeyCode == Keys.Left || e.KeyCode == Keys.A) //if the A or left arrow key is pressed down then the character will move left
                {
                    character.Left = character.Left - xspeed;
                }
            }

            void moveopphorizontal()
            {
                if (e.KeyCode == Keys.Right || e.KeyCode == Keys.D) // and vice-versa, this time if the character moves left then it gains points rather than right (this is for returning to the house)
                {
                    character.Left = character.Left + xspeed;
                }
                if (e.KeyCode == Keys.Left || e.KeyCode == Keys.A)
                {
                    character.Left = character.Left - xspeed;
                    counter        = counter + 1;
                    score.Text     = counter.ToString();
                }
            }

            moveup();
            movedown();
            movehorizontal();
            barriers();


            if (character.Bounds.IntersectsWith(egg1.Bounds))                                     //when the character collects the egg then this will happen
            {
                eggcheck        = 1;                                                              //this is the variable which stops the game from winning without the egg
                messagebox.Text = ("Go back to drop the egg in the safehouse!");                  //updates the text box in the bottom-left corner
                character.Image = Image.FromFile(Application.StartupPath + "\\chickwithegg.png"); //updates the picture
                character.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);                       // flips it horizontally so it's facig left
                egg1.Visible = false;                                                             //makes the egg invisible

                if (messagebox.Text == ("Go back to drop the egg in the safehouse!"))             //this will update the scoring depending on if the chicken has the egg or not
                {
                    moveopphorizontal();
                }
                else
                {
                    movehorizontal();
                }
            }

            void eggdrop()         //when the chicken reaches the house
            {
                if (eggcheck == 1) //saying if the character has the egg then it detects that they have won or else just carry on
                {
                    if (character.Bounds.IntersectsWith(home.Bounds))
                    {
                        egg1.Size       = new Size(50, 50); //changes size and location of the egg
                        egg1.Location   = new Point(139, 203);
                        messagebox.Text = "You Won!";
                        character.Image = Image.FromFile(Application.StartupPath + "\\chickwithbasket.png");
                        var formWin = new Win(); //starts the relaunch process
                        formWin.Show();
                        this.Hide();
                    }
                }
                else
                {
                }
            }

            eggdrop();
        }