예제 #1
0
        protected void TilteEvent(Tilte t)
        {
            switch (GameSequence)
            {
            case GameSequences.SELECT_START_POINT:
                if (t.State == Tilte.States.EMPTY)
                {
                    t.State = Tilte.States.START;

                    if (Update(t))
                    {
                        // player must be do a choice !
                        GameSequence = GameSequences.MOOVED;
                    }
                    else
                    {
                        GameSequence = GameSequences.END;
                        TilteEvent(t);
                    }
                }
                break;

            case GameSequences.MOOVED:
                if (t.State == Tilte.States.START)
                {
                    ClearTiltles();
                    GameSequence = GameSequences.SELECT_START_POINT;
                    tiltePrev    = null;
                }
                else if (t.State == Tilte.States.CHOISE)
                {
                    t.State = Tilte.States.VALIDATED;
                    RemoveChoiseTiltles();
                    if (Update(t))
                    {
                        // player must be do a choice !
                        GameSequence = GameSequences.MOOVED;
                    }
                    else
                    {
                        GameSequence = GameSequences.END;
                        TilteEvent(t);
                    }
                }
                break;

            case GameSequences.END:
                if (NoEmptyTilte())
                {
                    Win = true;
                    AllStartTiltes();
                }
                GameSequence = GameSequences.RESTART;
                break;

            case GameSequences.RESTART:
                ResetGame();
                break;
            }
        }
예제 #2
0
 public void ResetGame()
 {
     Win = false;
     ClearTiltles();
     GameSequence = GameSequences.SELECT_START_POINT;
     tiltePrev    = null;
 }
예제 #3
0
        private void Play(GamePlay gamePlay, Tilte eventTilte, List <String> previousStrEvent)
        {
            numberOfGames++;

            previousStrEvent.Add(String.Format("[{0}, {1}]", eventTilte.X, eventTilte.Y));
            gamePlay.TilteEvent(eventTilte.X, eventTilte.Y);

            while (true)
            {
                var chooseTiltes = gamePlay.Tiltes.Where(_ => _.State == Tilte.States.CHOISE).ToList();

                if (chooseTiltes.Count == 0)
                {
                    numberOfLoose++;
                    return;
                }
                if (chooseTiltes.Count == 1)
                {
                    previousStrEvent.Add(String.Format("[{0}, {1}]", chooseTiltes[0].X, chooseTiltes[0].Y));
                    gamePlay.TilteEvent(chooseTiltes[0].X, chooseTiltes[0].Y);

                    if (gamePlay.GameSequence == GamePlay.GameSequences.RESTART)
                    {
                        if (gamePlay.Win)
                        {
                            listOfWinParty.Add(numberOfWinabbleGames, previousStrEvent);
                            numberOfWinabbleGames++;
                        }
                        else
                        {
                            numberOfLoose++;
                        }
                        return;
                    }
                }
                else
                {
                    string choiseString = "";
                    foreach (Tilte tc in chooseTiltes)
                    {
                        choiseString += String.Format("[{0}, {1}] ", tc.X, tc.Y);
                    }

                    previousStrEvent.Add(String.Format("choose of {0}: ", chooseTiltes.Count) + choiseString);

                    List <GamePlay>       gp = new List <GamePlay>();
                    List <List <String> > pe = new List <List <String> >();

                    foreach (Tilte tc in chooseTiltes)
                    {
                        gp.Add(new GamePlay(gamePlay));
                        pe.Add(new List <String>(previousStrEvent));
                    }

                    for (int i = 0; i < chooseTiltes.Count; i++)
                    {
                        Play(gp[i], chooseTiltes[i], pe[i]);
                    }



                    return;
                }
            }
        }
예제 #4
0
        private bool Update(Tilte t)
        {
            // Auto move in the selected direction...
            if (tiltePrev != null)
            {
                if (t.Y == tiltePrev.Y && t.X - 1 == tiltePrev.X)
                {
                    if (UpdateTilteState(Tilte.States.VALIDATED, t.X + 1, t.Y))
                    {
                        tiltePrev = t;
                        return(Update(GetTilte(t.X + 1, t.Y)));
                    }
                }
                else if (t.Y == tiltePrev.Y && t.X + 1 == tiltePrev.X)
                {
                    if (UpdateTilteState(Tilte.States.VALIDATED, t.X - 1, t.Y))
                    {
                        tiltePrev = t;
                        return(Update(GetTilte(t.X - 1, t.Y)));
                    }
                }
                else if (t.Y - 1 == tiltePrev.Y && t.X == tiltePrev.X)
                {
                    if (UpdateTilteState(Tilte.States.VALIDATED, t.X, t.Y + 1))
                    {
                        tiltePrev = t;
                        return(Update(GetTilte(t.X, t.Y + 1)));
                    }
                }
                else if (t.Y + 1 == tiltePrev.Y && t.X == tiltePrev.X)
                {
                    if (UpdateTilteState(Tilte.States.VALIDATED, t.X, t.Y - 1))
                    {
                        tiltePrev = t;
                        return(Update(GetTilte(t.X, t.Y - 1)));
                    }
                }
            }
            tiltePrev = t;

            bool canMoove = false;

            canMoove |= CanMoove(t.X, t.Y - 1);
            canMoove |= CanMoove(t.X, t.Y + 1);
            canMoove |= CanMoove(t.X - 1, t.Y);
            canMoove |= CanMoove(t.X + 1, t.Y);

            if (canMoove)
            {
                UpdateTilteState(Tilte.States.CHOISE, t.X, t.Y - 1);
                UpdateTilteState(Tilte.States.CHOISE, t.X, t.Y + 1);
                UpdateTilteState(Tilte.States.CHOISE, t.X - 1, t.Y);
                UpdateTilteState(Tilte.States.CHOISE, t.X + 1, t.Y);

                return(true);
            }
            else
            {
                return(false);
                // end !
            }
        }
예제 #5
0
 public TilteClickedEventArgs(Tilte t)
 {
     Tilte = t;
 }
예제 #6
0
 public Tilte(Tilte previousTilte)
 {
     X     = previousTilte.X;
     Y     = previousTilte.Y;
     State = previousTilte.State;
 }