//Metodo assegnato al pulsante "New Game" che inizializza un altro gioco private void OperationNewGame(IButton button) { if (button.GetType() == typeof(ButtonWithLabel)) { foreach (ButtonGrid bg in _list.Where(b => b.GetType() == typeof(ButtonGrid))) { bg.Used = true; } button.Activated = true; ButtonWithLabel bl = (ButtonWithLabel)button; if (_gameAdapter.GameActive) { _gameAdapter.Logout(); } _gameAdapter.Login(); _selectMode = true; } }
//Metodo per disegnare gli oggetti a schermo protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.White); spriteBatch.Begin(); spriteBatch.Draw(_grid, new Rectangle((int)_gridPosition.X, (int)_gridPosition.Y, 320, 320), Color.White); //Disegna i bottoni foreach (IButton b in _list) { spriteBatch.DrawButton(b, Color.Black); } //Disegna la label "Press New Game" se il gioco non è attivo if (!_gameAdapter.GameActive) { ButtonWithLabel B = new ButtonWithLabel(_font, "Press \"New Game\"", new Vector2(0, 0), _background); B.Position = new Vector2((Window.ClientBounds.Width - B.Dimension.X) / 2, 20); spriteBatch.DrawButton(B, Color.White); } //Disegna il risultato della partita se il gioco è finito if (_gameAdapter.Finished) { String winnerString = "Draw!"; switch (_gameAdapter.CheckWin) { case 1: winnerString = "You Win!"; break; case 2: winnerString = "You Lose!"; break; } ButtonWithLabel winner = new ButtonWithLabel(_font, winnerString, new Vector2(0, 0), _background); winner.Position = new Vector2((Window.ClientBounds.Width - winner.Dimension.X) / 2, (Window.ClientBounds.Height - winner.Dimension.Y) / 2); spriteBatch.DrawButton(winner, Color.White); } //Disegna i pulsanti della selectMode se è attiva if (_selectMode && _gameAdapter.GameActive) { spriteBatch.DrawButton(_buttonFirst, Color.Red); spriteBatch.DrawButton(_buttonSecond, Color.Red); } spriteBatch.End(); base.Draw(gameTime); }
//Metodo utilizato per caricare i contenuti protected override void LoadContent() { spriteBatch = new SpriteBatchExt(GraphicsDevice); //Carica i Texture _oTexture = Content.Load <Texture2D>("O"); _xTexture = Content.Load <Texture2D>("X"); _grid = Content.Load <Texture2D>("Grid"); _background = Content.Load <Texture2D>("Sfondo"); _empty = Content.Load <Texture2D>("Empty"); //Carica i font _font = Content.Load <SpriteFont>("SpriteFont1"); //Inizializzazzione interfaccia utente //Griglia _gridPosition.X = (Window.ClientBounds.Width - 320) / 2; _gridPosition.Y = (Window.ClientBounds.Height - 320) / 2; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { IButton button = new ButtonGrid(_empty, new Rectangle(((int)_gridPosition.X) + 110 * i, ((int)_gridPosition.Y) + 110 * j, 100, 100), i * 3 + j + 1); button.Operation = OperationGrid; _list.Add(button); } } //Bottone New Play ButtonWithLabel buttonPlay = new ButtonWithLabel(_font, "New Game", new Vector2(20, 20), _background); buttonPlay.Operation = OperationNewGame; _list.Add(buttonPlay); //Bottoni della selectMode _buttonFirst = new ButtonWithLabel(_font, "I want to go first!", new Vector2(Window.ClientBounds.Width / 8, Window.ClientBounds.Height - 40), _background); _buttonSecond = new ButtonWithLabel(_font, "I want to go second!", new Vector2(5 * Window.ClientBounds.Width / 8, Window.ClientBounds.Height - 40), _background); _buttonFirst.Operation = OperationFirst; _buttonSecond.Operation = OperationSecond; //Bottone inverti icona _buttonInvert = new ButtonWithLabel(_font, "Your icon " + (_invertedIcon?"O":"X"), new Vector2(20, 50), _background); _buttonInvert.Operation = OperationInvert; _list.Add(_buttonInvert); }
public void DrawButton(ButtonWithLabel button, Color color)//Disegna un ButtonWithLabel { base.Draw(button.Texture, button.Rectangle, Color.White); base.DrawString(button.Font, button.Text, button.Position, color); }