private void LoadPictureBoxes(GameStateView gameStateView) { wallPictureBoxes = Enumerable.Repeat(0, gameStateView.Walls.Count).Select(c => new PictureBox { BackColor = Color.MidnightBlue, Margin = new Padding(4), SizeMode = PictureBoxSizeMode.Zoom, TabStop = false }).ToArray(); coinPictureBoxes = Enumerable.Repeat(0, gameStateView.Coins.Count).Select(c => new PictureBox { Image = Properties.Resources.cccc, Margin = new Padding(4), Size = coinSize, SizeMode = PictureBoxSizeMode.StretchImage, TabStop = false }).ToArray(); pinkGhost = CreateGhostPictureBox(Properties.Resources.pink_guy); yellowGhost = CreateGhostPictureBox(Properties.Resources.yellow_guy); redGhost = CreateGhostPictureBox(Properties.Resources.red_guy); playerPictureBoxes = new Dictionary <string, PictureBox>(); DrawGhosts(); // Draw once DrawWalls(gameStateView.Walls); // Draw once DrawCoins(gameStateView.Coins); // Draw once pictureBoxesReady = true; }
void Start() { if (GameStateView.HasState(GameState.gameReloaded)) { EventCoordinator.TriggerEvent(EventName.System.SceneLoaded(), GameMessage.Write()); } }
private void UpdatePlayers(GameStateView gameStateView) { List <string> updatedPlayers = new List <string>(); foreach (Player player in gameStateView.Players) { if (!playerPictureBoxes.TryGetValue(player.PlayerId, out PictureBox pictureBox)) { pictureBox = CreatePlayerPictureBox(); InitializeDrawing(pictureBox); playerPictureBoxes.Add(player.PlayerId, pictureBox); } // Update labels for playing player if (player.PlayerId == this.Pid) { ScoreLabel.SetPropertyThreadSafe(() => ScoreLabel.Text, String.Format("Player {0} Score: {1}", Pid, player.Score.ToString())); if (!player.Alive) { GameStatusLabel.SetPropertyThreadSafe(() => GameStatusLabel.Text, "You are dead"); } } if (player.Alive) { if (pictureBox.Tag == null || ((Direction)pictureBox.Tag) != player.Direction) { Direction direction = pictureBox.Tag == null ? Direction.RIGHT : player.Direction; Bitmap updatedBitmap = DirectionToResource(direction); if (updatedBitmap != null) { pictureBox.Image = updatedBitmap; pictureBox.Tag = direction; } } pictureBox.Location = new Point(player.X, player.Y); } else { pictureBox.Visible = false; } updatedPlayers.Add(player.PlayerId); } // Remove removed players foreach (string playerId in playerPictureBoxes.Keys.Except(updatedPlayers).ToList()) { if (playerPictureBoxes.TryGetValue(playerId, out PictureBox pictureBox)) { this.Controls.Remove(pictureBox); playerPictureBoxes.Remove(playerId); } } }
public TState CreateState <TState>(GameStateModel model, GameStateView view) where TState : GameState { // Activator used due to limitations of accessing constructors in generic methods // (where only parameterless constructor calls are allowed) TState state = (TState)Activator.CreateInstance(typeof(TState), model, view); return(state); }
private void UpdateCoins(GameStateView gameStateView) { int i = 0; foreach (Coin coin in gameStateView.Coins) { coinPictureBoxes[i].Visible = coin.Visible; i++; } }
void Update() { if (!GameStateView.HasState(GameState.started) || GameStateView.HasState(GameState.ended)) { return; } HandleInput(); UpdateReleased(); UpdateVolume(); transform.localPosition = new Vector3(this.start.x, (this.verticalOffset - this.swipeRadius) * this.AnchorMultiplier + this.start.y, 0); transform.localRotation = Quaternion.Euler(0, 0, -this.rotation * this.AnchorMultiplier); }
internal void UpdateScore(GameStateView gameStateView) { foreach (Player p in gameStateView.Players) { if (p.PlayerId == this.Pid) { this.score = p.Score; ScoreLabel.SetPropertyThreadSafe(() => ScoreLabel.Text, "Score: " + score.ToString()); //ScoreLabel.Text = "Player " + this.Pid + " Score: " + score.ToString(); } } }
private void UpdateGhosts(GameStateView gameStateView) { foreach (Ghost ghost in gameStateView.Ghosts) { switch (ghost.Color) { case GhostColor.Pink: pinkGhost.Location = new Point(ghost.X, ghost.Y); break; case GhostColor.Yellow: yellowGhost.Location = new Point(ghost.X, ghost.Y); break; case GhostColor.Red: redGhost.Location = new Point(ghost.X, ghost.Y); break; } } }
internal void ApplyGameStateView(GameStateView gameStateView) { if (!pictureBoxesReady) { LoadPictureBoxes(gameStateView); } if (gameStateView.GameOver) { GameStatusLabel.SetPropertyThreadSafe(() => this.GameStatusLabel.Text, "Game Over!"); } else if (gameStateView.RoundId >= 0) { GameStatusLabel.SetPropertyThreadSafe(() => this.GameStatusLabel.Text, "Game On!"); } if (!gameStateView.GameOver) { //UpdateScore(gameStateView); UpdateCoins(gameStateView); UpdateGhosts(gameStateView); UpdatePlayers(gameStateView); } }
public InventoryState(GameStateModel model, GameStateView view) : base(model, view) { _webService = GameController.Instance.WebService; _view = View as InventoryStateView; _model = Model as InventoryStateModel; }
public GameState(GameStateModel model, GameStateView view) { Model = model; View = view; }
public async void SetState(Type stateType) { GameState state = null; if (stateType == typeof(LoginState)) { GameStateModel model = GameStateFactory .Instance .CreateModel <LoginStateModel>(); GameStateView view = await GameStateFactory .Instance .CreateViewAsync <LoginStateView>("LoginStateView"); LoginState loginState = GameStateFactory .Instance .CreateState <LoginState>(model, view); state = loginState; } else if (stateType == typeof(LobbyState)) { GameStateModel model = GameStateFactory .Instance .CreateModel <LobbyStateModel>(); GameStateView view = await GameStateFactory .Instance .CreateViewAsync <LobbyStateView>("LobbyStateView"); LobbyState lobbyState = GameStateFactory .Instance .CreateState <LobbyState>(model, view); state = lobbyState; } else if (stateType == typeof(InventoryState)) { GameStateModel model = GameStateFactory .Instance .CreateModel <InventoryStateModel>(); GameStateView view = await GameStateFactory .Instance .CreateViewAsync <InventoryStateView>("InventoryStateView"); InventoryState inventoryState = GameStateFactory .Instance .CreateState <InventoryState>(model, view); state = inventoryState; } else if (stateType == typeof(StoreState)) { GameStateModel model = GameStateFactory .Instance .CreateModel <StoreStateModel>(); GameStateView view = await GameStateFactory .Instance .CreateViewAsync <StoreStateView>("StoreStateView"); StoreState storeState = GameStateFactory .Instance .CreateState <StoreState>(model, view); state = storeState; } else if (stateType == typeof(IngameState)) { GameStateModel model = GameStateFactory .Instance .CreateModel <IngameStateModel>(); GameStateView view = await GameStateFactory .Instance .CreateViewAsync <IngameStateView>("IngameStateView"); IngameState ingameState = GameStateFactory .Instance .CreateState <IngameState>(model, view); state = ingameState; } else if (stateType == typeof(LeaderboardState)) { GameStateModel model = GameStateFactory .Instance .CreateModel <LeaderboardStateModel>(); GameStateView view = await GameStateFactory .Instance .CreateViewAsync <LeaderboardStateView>("LeaderboardStateView"); LeaderboardState leaderboardState = GameStateFactory .Instance .CreateState <LeaderboardState>(model, view); state = leaderboardState; } else { // do the catch Debug.LogError("Setting state for an unknown state type " + stateType.GetType()); } if (state != null) { SwitchState(state); } }