/// <summary> /// Adds the word at the game-logic PlayDesk (not at GTK desk - it call this function when put word) /// </summary> /// <returns> /// Correctness of move /// </returns> /// <param name='move'> /// Move /// </param> public bool Play(Move move) { var rack = game.GetActualPlayer().Rack; // All stones are in rack ? try { foreach (MovedStone ms in move.PutedStones) { if (!rack.Contains(ms.c)) { return(false); } } } catch (System.NullReferenceException) { return(false); } // Put! foreach (MovedStone ms in move.PutedStones) { this.desk[ms.i, ms.j] = ms.c; rack.Remove(ms.c); } this.game.historyM.Push(move); // Increase score game.IncActualPlayerScore(move.Score); return(true); }
/// <summary> /// Update statusbar ( best move, last move, actual player) /// </summary> public void changePlayer(Player.Player p) { this.desk.UpdateDesk(game.desk.Desk); this.rack.Change(((Player.Player)p).Rack); this.info.Change(p.Name, game.players); this.OnTurnLabel.Text = "Na tahu: " + game.GetActualPlayer().Name; this.StatusLabelBest.Text = "Nejlepší tah: " + game.bestMove.Word; try { this.StatusLabelLast.Text = "Poslední tah: " + game.historyM.Peek().Word; } catch (InvalidOperationException) { this.StatusLabelLast.Text = "Poslední tah: "; } }
/// <summary> /// Initializes a new instance of the <see cref="Scrabble.GUI.ScrabbleWindow"/> class. /// </summary> /// <param name='isClient'> /// Is client. /// </param> /// <exception cref='System.NullReferenceException'> /// Is thrown when there is an attempt to dereference a null object reference. /// </exception> public ScrabbleWindow(bool isClient = false) : base(Gtk.WindowType.Toplevel) { #region Basic window properties // Basic window properties this.Title = "Scrabble - Hrací deska" + (isClient ? " (klient)" : ""); this.Name = "MainWindow"; this.DoubleBuffered = true; this.SetPosition(WindowPosition.Center); this.Icon = Scrabble.Game.InitialConfig.icon; this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent); this.DefaultWidth = 550; this.DefaultHeight = 700; #endregion this.client = isClient; if (Scrabble.Game.InitialConfig.game == null) { throw new System.NullReferenceException("During Scrabble main widow initialization is Scrabble.Game.InitialConfig.game == null"); } this.game = Scrabble.Game.InitialConfig.game; // General GUI classes this.menu = new MenuHover(this); this.desk = new Desk(this.game); this.rack = new Rack(this.game); this.control = new Control(this.game); this.info = new Info(this.game); this.bottomVbox = new VBox(true, 4); this.bottomVbox.PackStart(rack); this.bottomVbox.PackEnd(control); this.bottomVbox.ShowAll(); this.vertical = new HPaned(); this.vertical.HeightRequest = 100; // Use only CLIENT clientNotice = new Label(); clientNotice.Markup = "<b>Čekám</b> na aktualizaci dat o hře."; clientNotice.TooltipText = "Na portu " + Scrabble.Game.InitialConfig.port.ToString(); // STATUSBAR statusbar = new Statusbar(); statusbar.HeightRequest = 20; statusbar.Homogeneous = true; StatusLabelLast = new Label("Poslední tah:"); StatusLabelBest = new Label("Nejlepší tah:"); OnTurnLabel = new Label("Na tahu:"); statusbar.PackStart(OnTurnLabel, false, false, 0); statusbar.Add(StatusLabelLast); statusbar.PackEnd(StatusLabelBest, false, false, 0); // Vertical divide at bottom this.vertical = new HPaned(); this.vertical.HeightRequest = 100; this.vertical.Add1(bottomVbox); this.vertical.Add2(info); this.mainVbox = new VBox(false, 5); if (isClient) { this.mainVbox.PackStart(clientNotice, false, false, 5); } else { this.mainVbox.PackStart(menu.menuBar, false, false, 0); } this.mainVbox.Add(desk); this.mainVbox.Add(vertical); this.mainVbox.PackEnd(statusbar, false, false, 0); this.Add(mainVbox); this.changePlayer(game.GetActualPlayer()); if (isClient) { DisableButtons(); } }