public virtual void Build(GameModel game) { menuButton = new ButtonView("Menu", () => OnExit()) { Width = 100, Height = 50, BackgroundColor = new Color(192, 57, 43), TextColor = new Color(255, 255, 255), }; nextButton = new ButtonView("Næste", () => OnNextLevel()) { X = Width - 100, Width = 100, Height = 50, BackgroundColor = game.IsLastLevel || game.IsLevelCompleted == false ? new Color(190, 190, 190) : new Color(40, 120, 130), TextColor = new Color(255, 255, 255), }; restartButton = new ImageView("restart.png", 50, 50) { OnClick = () => game.RestartLevel(), X = 110, Y = 0, BackgroundColor = new Color(192, 57, 43) }; toolTipView = new ToolTipView(game.User.CurrentLevel.Description, 300, 100) { X = Width - 300, Y = 50, Visible = false, OnClick = () => { if (helpButton.OnClick != null && toolTipView.Visible == true) { helpButton.OnClick(); } } }; toolTipView.ArrowPosition = 155; helpButton = new ButtonView( "?", () => { if(game.User.CurrentLevel.Description != "") { if(toolTipView.Visible == true) { helpButton.Text = "?"; toolTipView.Visible = false; } else { helpButton.Text = " Luk "; toolTipView.Visible = true; } } } ) { X = Width - 160, Y = 0, Width = 50, Height = 50, BackgroundColor = game.User.CurrentLevel.Description == "" ? new Color(190, 190, 190) : new Color(40, 120, 130), TextColor = new Color(255, 255, 255), }; progressbar = new ProgressbarStarView(game.ProgressBar, Width - 340, 30) { X = 170, Y = 10 }; identityMenu = new IdentityMenuView(game.ExprModel, Width, 100) { Y = Height - 125 }; expression = new ExpressionView(game.ExprModel, Width - 100, Height - 275, 8) { X = 50, Y = 100, }; Children = new List<View>() { menuButton, nextButton, restartButton, helpButton, progressbar, identityMenu, expression, toolTipView, }; if(OnChanged != null) { OnChanged(); } }
public virtual void Update(GameModel game) { progressbar.Update(game.ProgressBar); identityMenu.Update(game.ExprModel.Identities, game.ExprModel); expression.Update(game.ExprModel); nextButton.BackgroundColor = game.IsLastLevel || game.IsLevelCompleted == false ? new Color(190, 190, 190) : new Color(40, 120, 130); helpButton.BackgroundColor = game.User.CurrentLevel.Description == "" ? new Color(190, 190, 190) : new Color(40, 120, 130); toolTipView.Text = game.User.CurrentLevel.Description; toolTipView.Visible = false; helpButton.Text = "?"; if (OnChanged != null) { OnChanged(); } }
public LevelView(GameModel game) : base(700, 400) { BackgroundColor = new Color(255, 255, 255); Build(game); }
private void loadGameData() { gameAPI.GetCurrentPlayer((user) => { bool unlocked = true; for (int index = 0; index < user.Categories.Count; index++) { // Runs through the levels unlocking all levels where the user have optained atleast 1 star for (int i = 0; i < user.Categories[index].Count; i++) { user.Categories[index][i].Unlocked = unlocked; if(user.Categories[index][i].Stars == 0 && unlocked == true) { unlocked = false; user.CurrentCategoryIndex = index; user.CurrentLevelIndex = 0; } } } gameAPI.GetPlayers((players) => { // loads top 7 players for leaderboard GameModel gameModel = new GameModel(user, players) { OnSaveLevel = (level) => { gameAPI.SaveUserLevelProgress ( level.LevelID, level.CurrentExpression, level.Stars, (IsSaved) => { Console.WriteLine(IsSaved ? "Level saved" : "Could not save"); } ); }, OnCategoryCompleted = (completedCategory) => gameAPI.UserAddBadge( completedCategory.Badge, (IsAdded) => Console.WriteLine(IsAdded ? "Badge added" : "Badge not added") ) }; // Creates the gameview for the user GameView gameView = new GameView(gameModel, context.Width, context.Height) { OnExit = () => { gameAPI.logout((success) => { Console.WriteLine(success ? "Logout success" : "Logout failed"); Start(); }); }, ReloadGame = () => loadGameData() }; context.SetContentView(gameView); }); }); }
public void Build(GameModel game) { CurrentPlayer user = game.User; IEnumerable<Player> players = game.Players; BackgroundColor = new Color(255, 255, 255); WelcomeText = new LabelView("Velkommen " + user.PlayerName) { X = 10, Y = 10, Height = 50, Width = 220 }; BadgesView = new CompositeView(220, 40) { X = WelcomeText.X, Y = WelcomeText.Y + WelcomeText.Height }; BadgeInfoText = new LabelView("Badges: ") { Width = 100, Height = 20, X = -10 }; BadgesView.Add(BadgeInfoText); if (user.Badges != null) { // start spacing half the width of a badge int spacing = -10; foreach (BadgeName badge in user.Badges) { if (PlayerView.badgeDictionary.ContainsKey(badge)) { BadgesView.Add(new ImageView(PlayerView.badgeDictionary[badge], 25, 25) { X = BadgeInfoText.X + BadgeInfoText.Width + spacing, }); } spacing += 30; } } VectorImageView playIcon = new VectorImageView(0, 0, 100, 100) { { 25,25 }, { 75,50 }, { 25,75 } }; LogoutButton = new ButtonView("Log ud", () => { if (OnLogout != null) { OnLogout(); } }) { Width = 50, Height = 15, TextColor = new Color(255, 255, 255), BackgroundColor = new Color(193, 57, 43) }; playIcon.BackgroundColor = new Color(255, 255, 255); PlayButton = new CompositeView(100, 100) { playIcon, }; PlayButton.BackgroundColor = new Color(39, 174, 97); PlayButton.X = 10; PlayButton.Y = BadgesView.Y + BadgesView.Height; VectorImageView levelIcon1 = new VectorImageView(0, 0, 100, 100) { { 20,20 }, { 45,20 }, { 45,45 }, { 20,45 }, { 20,20 }, }; VectorImageView levelIcon2 = new VectorImageView(0, 0, 100, 100) { { 80,20 }, { 80,45 }, { 55,45 }, { 55,20 }, { 80,20 }, }; VectorImageView levelIcon3 = new VectorImageView(0, 0, 100, 100) { { 80,80 }, { 55,80 }, { 55,55 }, { 80,55 }, { 80,80 }, }; VectorImageView levelIcon4 = new VectorImageView(0, 0, 100, 100) { { 20,80 }, { 20,55 }, { 45,55 }, { 45,80 }, { 20,80 }, }; levelIcon1.BackgroundColor = new Color(255, 255, 255); levelIcon2.BackgroundColor = new Color(255, 255, 255); levelIcon3.BackgroundColor = new Color(255, 255, 255); levelIcon4.BackgroundColor = new Color(255, 255, 255); LevelButton = new CompositeView(100, 100) { levelIcon1, levelIcon2, levelIcon3, levelIcon4, }; LevelButton.BackgroundColor = new Color(42, 128, 185); LevelButton.X = PlayButton.X + PlayButton.Width + 20; LevelButton.Y = BadgesView.Y + BadgesView.Height; PlayerList = new PlayerListView(players, 160, 200) { X = LevelButton.X + LevelButton.Width + 20, Y = WelcomeText.Y }; Children = new List<View>(){ LogoutButton, WelcomeText, LevelButton, PlayerList, PlayButton, BadgesView }; }
public TitleView(GameModel game) : base(420, 220) { Build(game); }
public GameView(GameModel game, double width, double height) : base(width, height) { categoryCompletionView = null; game.OnCategoryCompleted += (c) => { categoryCompletionView = new CategoryCompletionView(c, game.IsLastCategory) { OnNext = () => { if (game.IsLastCategory == false) { game.SetLevel(0, c.categoryIndex + 1); SetContent(levelView); } }, OnExit = () => ReloadGame(), }; SetContent(categoryCompletionView); }; BackgroundColor = new Color(255, 255, 255); titleView = new TitleView(game); levelView = new LevelView(game) { OnExit = () => { game.SaveLevel(); SetContent(levelSelectView); }, OnNextLevel = () => { if (game.IsLastLevel == false) { game.SaveLevel(); game.NextLevel(); } } }; levelSelectView = new LevelSelectView(game.User) { OnChanged = () => { SetContent(levelSelectView); Update(game); levelSelectView.Update(game.User); }, OnLevelSelect = (level) => { if (level.Unlocked) { SetContent(levelView); Update(game); game.SetLevel(level.LevelIndex, level.CategoryIndex); } }, OnExit = () => ReloadGame() }; titleView.PlayButton.OnClick = () => SetContent(levelView); titleView.LevelButton.OnClick = () => SetContent(levelSelectView); titleView.OnLogout = () => { if (OnExit != null) { OnExit(); } }; game.OnChanged = Update; SetContent(titleView); }
public void Update(GameModel game) { levelView.Update(game); levelSelectView.Update(game.User); if(OnChanged != null) { OnChanged(); } }