-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* visual changes and starting on connecting. * changes for connecting view * Connecting Screen
- Loading branch information
Showing
5 changed files
with
103 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Content; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using Microsoft.Xna.Framework.Input; | ||
using System; | ||
|
||
namespace Client.Menu | ||
{ | ||
internal class ConnectingView | ||
public class ConnectingView : GameStateView | ||
{ | ||
private SpriteFont font; | ||
private string connectingMessage = "Connecting to Server"; | ||
private bool isConnected = false; | ||
private double elapsedTimeSinceLastAttempt = 0; | ||
private const double attemptInterval = 2000; // Attempt to connect every 2 seconds | ||
private double periodUpdateTime = 500; // Update period for visual | ||
|
||
public override void loadContent(ContentManager contentManager) | ||
{ | ||
font = contentManager.Load<SpriteFont>("Fonts/menu"); | ||
} | ||
|
||
public override MenuStateEnum processInput(GameTime gameTime) | ||
{ | ||
if (Keyboard.GetState().IsKeyDown(Keys.Escape)) | ||
{ | ||
return MenuStateEnum.MainMenu; // Or another state if cancelling connection attempt | ||
} | ||
if (isConnected) | ||
{ | ||
return MenuStateEnum.GamePlay; // Transition to GamePlay upon successful connection | ||
} | ||
return MenuStateEnum.Connecting; // Stay on Connecting view if not yet connected | ||
} | ||
|
||
public override void update(GameTime gameTime) | ||
{ | ||
elapsedTimeSinceLastAttempt += gameTime.ElapsedGameTime.TotalMilliseconds; | ||
|
||
// Attempt to connect every 2 seconds | ||
if (!isConnected && elapsedTimeSinceLastAttempt >= attemptInterval) | ||
{ | ||
isConnected = connectToServer(); | ||
elapsedTimeSinceLastAttempt = 0; // Reset timer after each attempt | ||
} | ||
} | ||
|
||
public override void render(GameTime gameTime) | ||
{ | ||
m_spriteBatch.Begin(); | ||
Vector2 position = new Vector2(m_graphics.PreferredBackBufferWidth / 2, m_graphics.PreferredBackBufferHeight / 2); | ||
Vector2 origin = font.MeasureString(connectingMessage) / 2; | ||
m_spriteBatch.DrawString(font, connectingMessage, position - origin, Color.White); | ||
m_spriteBatch.End(); | ||
} | ||
|
||
private bool connectToServer() | ||
{ | ||
// Attempt to connect to the server | ||
return MessageQueueClient.instance.initialize("localhost", 3000); | ||
} | ||
|
||
public override void RegisterCommands() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters