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); }
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(); }
public override void play( IGameplay g, int slotIndex ) { g.buildUnit( slotIndex, this ); if (runner != null) g.enqueueAction (delegate(IGameplay g2) { runner (g, slotIndex); }); }
protected override ControllerState HandleOtherInput(string key, IGameplay gameplay) { gameplay.GoTo(ParsePosition(key)); return gameplay.WhoWins() != BoardMark._ ? GameOver : Play; }
public GameScreen(MainWindow mainWindow, IGameplay gameplay) { InitializeComponent(); DataContext = this; this.mainWindow = mainWindow; GameInstance = new Game(this, gameplay, mainWindow.Size); }
public Game(GameScreen gameScreen, IGameplay gameplay, GridSize gridType) { Gameplay = gameplay; Screen = gameScreen; GameGrid = new Grid(gridType); Painter = new Painting(this, gridType); gameplay.OnGameInit(this); }
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); }
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); } }
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); } }
public GameController(IView view, IGameplay gameplay) { _view = view; _gameplay = gameplay; _gameplay.Changed += (s, a) => UpdateView(ControllerState.Play); }
virtual public void play( IGameplay g, int slotIndex ) { if (runner != null) runner (g, slotIndex); }
private void button2_Click(object sender, EventArgs e) // for offline { init__(); gameplay = new Gameplay_Offline(); }
public abstract string ToString(IGameplay gameplay);
public void Init(IGameplay gameplay) { this.gameplay = gameplay; }
protected abstract ControllerState HandleOtherInput(string key, IGameplay gameplay);
public override string ToString(IGameplay gameplay) { return "Game over. (R)epeat once again or (Q)uit?"; }
protected override ControllerState HandleOtherInput(string key, IGameplay gameplay) { return this; }
public override string ToString(IGameplay gameplay) { return "Play with the Computer? (Y/N)"; }
public string GetPlayStatus(IGameplay gameplay) { return gameplay.WhoWins() != BoardMark._ ? String.Format("{0} wins!", gameplay.WhoWins()) : String.Format("{0} goes:", gameplay.WhoGoesNow); }
public override string ToString(IGameplay gameplay) { return gameplay.Board + "\n\r\n\r" + GetPlayStatus(gameplay); }
public EngineViewModel(IStartScreen startScreen, IGameplay gameplay, IScoreboard scoreboard) { this.StartScreen = startScreen; this.Gameplay = gameplay; this.Scoreboard = scoreboard; }
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; } }