public void Initialize() { oldKeyboardState = null; selectedCol = 0; isOver = false; youGoFirst = false; opponentsName = null; c4Game.ConnectionEstablished += ConnectionEstablishedHandler; c4Game.Disconnected += DisconnectedHandler; c4Game.GameStarted += GameStartedHandler; c4Game.IllegalMove += IllegalMoveHandler; c4Game.MoveMade += MoveMadeHandler; c4Game.Tick += TickHandler; // load all our content now spriteBatch = new SpriteBatch(owner.GraphicsDevice); boardTexture = owner.Content.Load<Texture2D>("board"); blackChecker = owner.Content.Load<Texture2D>("black-ch"); redChecker = owner.Content.Load<Texture2D>("red-ch"); whiteChecker = owner.Content.Load<Texture2D>("white-ch"); log = owner.Content.Load<Texture2D>("logo"); sider = owner.Content.Load<Texture2D>("side"); board = new Sprite(boardTexture, new Vector2( columnWidth, Connect4.screenHeight - boardTexture.Height - (rowHeight / 2)), boardDepth); logo = new Sprite(log, new Vector2(Connect4.screenWidth / 2 - log.Width / 2, 0), logoDepth); leftSider = new Sprite(sider, new Vector2( 0, Connect4.screenHeight - sider.Height), boardDepth); rightSider = new Sprite(sider, new Vector2( board.Position.X + boardTexture.Width, Connect4.screenHeight - sider.Height), boardDepth, SpriteEffects.FlipHorizontally); //initialized just to ensure we don't get a null pointer exception in update/draw selectionChecker = new Sprite(blackChecker, new Vector2(-1000, -1000), checkerDepth); font = owner.Content.Load<SpriteFont>("kongtext2"); float x = board.Position.X + boardTexture.Width + columnWidth; youText = new TextSprite("", font, new Vector2(x, board.Position.Y), textDepth); vs = new TextSprite("", font, new Vector2(x, board.Position.Y + (rowHeight * 3) / 2), textDepth); opponentText = new TextSprite("", font, new Vector2(x, board.Position.Y + rowHeight * 3), textDepth); generalMessage = new TextSprite("", font, new Vector2(x, board.Position.Y + (rowHeight * 9) / 2), textDepth); c4Game.StartConnection(hostName, port); }
public void Initialize() { oldKeyboardState = null; generalMessage = " "; font = owner.Content.Load<SpriteFont>("smallfont"); spriteBatch = new SpriteBatch(owner.GraphicsDevice); Texture2D log = owner.Content.Load<Texture2D>("logo"); logo = new Sprite(log, new Vector2(Connect4.screenWidth / 2 - log.Width / 2, 0), everythingDepth); Texture2D instr = owner.Content.Load<Texture2D>("instructions"); instructions = new Sprite(instr, new Vector2(0, Connect4.screenHeight - instr.Height), everythingDepth); string userNameString = "username: "******"hostname: " + hostName.ToString(); string portString = "port number: " + port.ToString(); string toWrite = userNameString + "\n" + hostNameString + "\n" + portString + "\n" + generalMessage; oneLineSize = font.MeasureString(" ").Y; float textHeight = font.MeasureString(toWrite).Y; Vector2 curPos = new Vector2(textXPos, (instructions.Position.Y - logo.Texture.Height) / 2 - textHeight / 2 + logo.Texture.Height); Vector2 originalPos = curPos; userNameEntry = new TextSprite(userNameString, font, curPos, everythingDepth); curPos.Y += oneLineSize; hostNameEntry = new TextSprite(userNameString, font, curPos, everythingDepth); curPos.Y += oneLineSize; portEntry = new TextSprite(portString, font, curPos, everythingDepth); curPos.Y += oneLineSize; showMessage = new TextSprite(generalMessage, font, curPos, everythingDepth); Texture2D smallChecker = owner.Content.Load<Texture2D>("red-sch"); // these may look like magic numbers: they basically are. Just some fine-tuning of the position, that's all. selectionChecker = new Sprite(smallChecker, new Vector2(originalPos.X - 18, originalPos.Y - 1), everythingDepth); switch (selection) { case SelectedString.userName: userNameEntry.PulseColors(pulse1, pulse2, pulsePeriod); break; case SelectedString.hostName: selectionChecker.Position = new Vector2(selectionChecker.Position.X, selectionChecker.Position.Y + oneLineSize); hostNameEntry.PulseColors(pulse1, pulse2, pulsePeriod); break; case SelectedString.port: selectionChecker.Position = new Vector2(selectionChecker.Position.X, selectionChecker.Position.Y + 2 * oneLineSize); portEntry.PulseColors(pulse1, pulse2, pulsePeriod); break; default: break; } if (!eventInputInitialized) { EventInput.Initialize(owner.Window); eventInputInitialized = true; } EventInput.CharEntered += CharacterEntered; }