Beispiel #1
0
        private IGameplay ChooseGame(List <IGameplay> games)
        {
            IGameplay game = null;

            do
            {
                WriteMessage("Giochi disponibili");
                for (int i = 1; i <= games.Count; i++)
                {
                    WriteMessage($"{i}) {games[i - 1].Description}");
                }
                int gameOption = AskForInt();
                try
                {
                    game = games[gameOption - 1];
                }
                catch (Exception)
                {
                    WriteMessage("Opzione non valida (invio per continuare)");
                    Console.ReadLine();
                    Console.Clear();
                }
            }while (game == null);

            return(game);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            #region Pre-Preparazione liste
            /* Creazione ed aggiunta degl'handler nella lista degl'handler. */
            List <IUIHandler> handlers = new List <IUIHandler>();
            UIConsoleHandler  cnsHnd   = new UIConsoleHandler();
            handlers.Add(cnsHnd);

            /* Creazione del dizionario d'anagrammi locale (già popolato nella classe). */
            //List<IAnagramRepo> anagramRepos = new List<IAnagramRepo>();
            LocalAnagramRepo localRepo    = new LocalAnagramRepo();
            IAnagramRepo     selectedRepo = localRepo;


            /* Creazione e popolamento della lista dei gameplay. */
            List <IGameplay> gameplays = new List <IGameplay>();
            Training         training  = new Training();
            gameplays.Add(training);
            Challenge challenge = new Challenge();
            gameplays.Add(challenge);
            #endregion

            foreach (IUIHandler handler in handlers)
            {
                handler.WriteStringToUI("Anagrammi!");
                handler.WriteStringToUI("");

                /* Visualizza modalità. */
                handler.WriteStringToUI("Modalità disponibili:");
                handler.WriteStringToUI("Codice\tNome\tDescrizione");
                foreach (IGameplay gameplayMode in gameplays)
                {
                    handler.WriteStringToUI($"- {gameplayMode.Code.ToLower()}\t{gameplayMode.Name}");
                    handler.WriteStringToUI($"\t\t{gameplayMode.Description}");
                    handler.WriteStringToUI($"");
                }

                /* Scelta modalità. */
                IGameplay selectedGameplay = SelectGameplay(gameplays, handler);
                selectedGameplay.RunGameplay(selectedRepo, handlers);
            }



            /*
             * cnsHnd.WriteStringToUI("Scrittura tramite handler");
             *
             * string test01 = cnsHnd.AskForString("prova");
             * cnsHnd.WriteStringToUI(test01);
             *
             * cnsHnd.WriteStringToUI(cnsHnd.AskForString("Richiesta d\'input"));
             */


            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.Write("Premere [Invio] per uscire ... ");
            Console.ReadLine();
        }
Beispiel #3
0
	public override void play( IGameplay g, int slotIndex ) { 
		g.buildUnit( slotIndex, this );
		if (runner != null)
			g.enqueueAction (delegate(IGameplay g2) {
				runner (g, slotIndex);
			});
	}
Beispiel #4
0
        protected override ControllerState HandleOtherInput(string key, IGameplay gameplay)
        {
            gameplay.GoTo(ParsePosition(key));

            return gameplay.WhoWins() != BoardMark._
                ? GameOver
                : Play;
        }
Beispiel #5
0
        public GameScreen(MainWindow mainWindow, IGameplay gameplay)
        {
            InitializeComponent();
            DataContext = this;

            this.mainWindow = mainWindow;

            GameInstance = new Game(this, gameplay, mainWindow.Size);
        }
Beispiel #6
0
        public Game(GameScreen gameScreen, IGameplay gameplay, GridSize gridType)
        {
            Gameplay = gameplay;
            Screen   = gameScreen;

            GameGrid = new Grid(gridType);
            Painter  = new Painting(this, gridType);

            gameplay.OnGameInit(this);
        }
Beispiel #7
0
        private void Play()
        {
            IWordsRepository repo  = new WordsRepository(new FileDictionaryLoader());
            List <IGameplay> games = new List <IGameplay>
            {
                new Training(repo),
                new Match(repo)
            };

            IGameplay game = ChooseGame(games);

            game.Run(this);
        }
Beispiel #8
0
 public virtual ControllerState Handle(string key, IGameplay gameplay)
 {
     switch (key.ToUpper())
     {
         case "Q":
             return Quit;
         case "R":
             gameplay.Reset();
             return Play;
         default:
             return HandleOtherInput(key.ToUpper(), gameplay);
     }
 }
Beispiel #9
0
        private void button1_Click(object sender, EventArgs e) // for online
        {
            onlineGame_init__();
            init__();

            var     isServer = checkBox1.Checked;
            IServer server;

            if (isServer)
            {
                server = new Server();
            }
            else
            {
                server = new Client();
            }
            if (server != null)
            {
                gameplay = new Gameplay_Online(server, isServer);
            }
        }
Beispiel #10
0
 public GameController(IView view, IGameplay gameplay)
 {
     _view = view;
     _gameplay = gameplay;
     _gameplay.Changed += (s, a) => UpdateView(ControllerState.Play);
 }
Beispiel #11
0
	virtual public void play( IGameplay g, int slotIndex ) {
		if (runner != null)
			runner (g, slotIndex);
	}
Beispiel #12
0
 private void button2_Click(object sender, EventArgs e) // for offline
 {
     init__();
     gameplay = new Gameplay_Offline();
 }
Beispiel #13
0
 public abstract string ToString(IGameplay gameplay);
Beispiel #14
0
 public void Init(IGameplay gameplay)
 {
     this.gameplay = gameplay;
 }
Beispiel #15
0
 protected abstract ControllerState HandleOtherInput(string key, IGameplay gameplay);
Beispiel #16
0
 public override string ToString(IGameplay gameplay)
 {
     return "Game over. (R)epeat once again or (Q)uit?";
 }
Beispiel #17
0
 protected override ControllerState HandleOtherInput(string key, IGameplay gameplay)
 {
     return this;
 }
Beispiel #18
0
 public override string ToString(IGameplay gameplay)
 {
     return "Play with the Computer? (Y/N)";
 }
Beispiel #19
0
 public string GetPlayStatus(IGameplay gameplay)
 {
     return gameplay.WhoWins() != BoardMark._
                ? String.Format("{0} wins!", gameplay.WhoWins())
                : String.Format("{0} goes:", gameplay.WhoGoesNow);
 }
Beispiel #20
0
 public override string ToString(IGameplay gameplay)
 {
     return gameplay.Board + "\n\r\n\r" + GetPlayStatus(gameplay);
 }
Beispiel #21
0
 public EngineViewModel(IStartScreen startScreen, IGameplay gameplay, IScoreboard scoreboard)
 {
     this.StartScreen = startScreen;
     this.Gameplay    = gameplay;
     this.Scoreboard  = scoreboard;
 }
Beispiel #22
0
 protected override ControllerState HandleOtherInput(string key, IGameplay gameplay)
 {
     switch (key)
     {
         case "Y":
             gameplay.Setup(true);
             return Play;
         case "N":
             gameplay.Setup(false);
             return Play;
         default:
             return Setup;
     }
 }