Beispiel #1
0
 public void Initialize()
 {
     Container    = UnityLoader.LoadContainer();
     SinglePlayer = Container.Resolve <SinglePlayerGameOption>();
     MultiPLayer  = Container.Resolve <MultiPlayerGameOption>();
     Exit         = Container.Resolve <ExitGameOption>();
 }
        public IGameOption PickOption(IGameOption previousRoundOption, IGameOption[] gameOptions)
        {
            //To simulate computer "thinking"
            Thread.Sleep(500);

            //The computer player chooses the option that would have beat its previous selection.
            // Ex: In round 1, the computer chooses rock, then in round 2 it selects paper.

            //if previous round option is null (which means that it's the first round) then pick at random
            if (previousRoundOption == null)
            {
                Console.WriteLine("\nComputer says: This is the first round, I'm picking whatever option I want!");
                return(gameOptions[new Random().Next(gameOptions.Length)]);
            }

            var option = gameOptions.FirstOrDefault(x => x.HandleOpposingOption(previousRoundOption) == 1);

            if (option == null)
            {
                throw new Exception("No suitable option found");
            }

            Console.WriteLine($"\nComputer says: Since I picked {previousRoundOption} before, I'm picking {option}!");

            return(option);
        }
Beispiel #3
0
        public void ApplyOption(IGameOption option)
        {
            FTrack.Track();
            // To Start, we just have the player to apply stuff to.
            if (Player != null)
            {
                Player.ApplyOption(option);
            }

            if (CurrentDelta != null)
            {
                CurrentDelta.ApplyOption(option);
            }

            if (DailyDelta != null)
            {
                DailyDelta.ApplyOption(option);
            }

            if (null == _currentPage.AppliedOptions)
            {
                _currentPage.AppliedOptions = new AppliedOptionSet();
            }
            _currentPage.AppliedOptions.Add(option);
            //_currentPage.NutrientState = Player.Nutrients;
        }
Beispiel #4
0
        public System.Web.UI.WebControls.Panel RenderOption(IGameOption opt, bool Selectable)
        {
            System.Web.UI.WebControls.Panel optionPanel =
                new System.Web.UI.WebControls.Panel();

            if (Selectable)
            {
                optionPanel.Controls.Add(
                    new System.Web.UI.HtmlControls.HtmlGenericControl("label")
                {
                    ID       = "opt_label_" + opt.OptionName,
                    Controls =
                    {
                        new System.Web.UI.HtmlControls.HtmlInputCheckBox()
                        {
                            Name          = opt.OptionName,
                            ID            = "opt_" + opt.OptionName,
                            ViewStateMode = System.Web.UI.ViewStateMode.Disabled
                        },
                        ImageFromObject(opt.Picture, "", Selectable)
                    }
                }
                    );
            }
            else
            {
                optionPanel.Controls.Add(ImageFromObject(opt.Picture, "", Selectable));
            }
            return(optionPanel);
        }
        public IGameOption PickOption(IGameOption previousRoundOption, IGameOption[] gameOptions)
        {
            //To simulate computer "thinking"
            Thread.Sleep(500);

            Console.WriteLine("\nComputer says: I'm picking whatever option I want!");
            return(gameOptions[_random.Next(gameOptions.Length)]);
        }
Beispiel #6
0
        public void Run(int roundsToWin = 3)
        {
            //To add a new game option type, add it to the GameOptions folder and implement the GameOption interface
            var gameOptions = GetGameOptions();

            //To add a new player type, add it to the Players folder and implement the Player interface
            var players = GetPlayerTypes();

            PrintRules(gameOptions);

            var firstPlayer  = new HumanPlayer("Human");
            var secondPlayer = ConsoleUtils.Prompt("Who do you want to play with?", players);

            var firstPlayerScore  = 0;
            var secondPlayerScore = 0;
            var currentRound      = 0;

            PrintStartGameBanner(firstPlayer, secondPlayer, roundsToWin);

            //We sleep to make it easier to see what's going on
            Thread.Sleep(1000);

            IGameOption previousSecondPlayerRoundOption = null;

            while (firstPlayerScore != roundsToWin && secondPlayerScore != roundsToWin)
            {
                currentRound++;
                Console.WriteLine($"\n------ ROUND {currentRound} -------\n");

                Thread.Sleep(500);

                var firstPlayerOption = firstPlayer.PickOption(null, gameOptions);

                Console.WriteLine($"\n{firstPlayer} picked {firstPlayerOption}");

                var secondPlayerOption = secondPlayer.PickOption(previousSecondPlayerRoundOption, gameOptions);
                previousSecondPlayerRoundOption = secondPlayerOption;

                Console.WriteLine($"\n{secondPlayer} picked {secondPlayerOption}");

                Thread.Sleep(1000);

                var roundOutcome = firstPlayerOption.HandleOpposingOption(secondPlayerOption);

                firstPlayerScore  += (roundOutcome == 1) ? 1 : 0;
                secondPlayerScore += (roundOutcome == 0) ? 1 : 0;

                PrintRoundOutcome(roundOutcome, firstPlayer, firstPlayerOption, secondPlayer, secondPlayerOption);

                Thread.Sleep(1000);

                PrintCurrentScore(firstPlayer, firstPlayerScore, secondPlayer, secondPlayerScore);

                Thread.Sleep(1000);
            }

            PrintWinner(firstPlayerScore > secondPlayerScore ? firstPlayer : secondPlayer, currentRound);
        }
Beispiel #7
0
        public Launcher(System.Web.UI.Page page)
        {
            _foundry    = new FlorineWeb.WebFoundry(page);
            _controller = new Florine.Controller(_foundry);
            _controller.Init();

            IGameOption opt = _foundry.GetChosenOption(_controller);

            if (null != opt)
            {
                _controller.UserOption(opt);
            }
        }
Beispiel #8
0
        public void ApplyOption(IGameOption option)
        {
            option.ImpactPlayer(this);

            NutrientSet Delta = new NutrientSet();

            option.AdjustNutrients(Delta);

            // Now Adjust Based on Targets.


            // Adjust Based on Deltas.
        }
Beispiel #9
0
        // Dumb Hardcoded Implementation - most options don't matter for the flow
        private IPage _nextPage(IGameOption opt)
        {
            // Meta Options
            _context.ReadyNextPage();
            if (null != opt)
            {
                _context.ApplyOption(opt);
            }

            GameState.PageType    nextType;
            GameState.PageSubType nextSubType;
            _foundry.GetNextGameState(_context, opt, out nextType, out nextSubType);
            return(_goToPage(nextType, nextSubType));
        }
Beispiel #10
0
        private void Continue_Handler(object sender, EventArgs e)
        {
            IGameOption          SelectedOptions = null;
            FlorineSkiaOptionSet OptionSet       = PrimaryOptions as FlorineSkiaOptionSet;

            if (null != OptionSet)
            {
                SelectedOptions = OptionSet.Selected;
            }


            IPage Next = _controller.UserOption(SelectedOptions);

            Content = _foundry.RenderPage(_controller.CurrentState);
        }
Beispiel #11
0
        private void PrintRoundOutcome(int roundOutcome, IPlayer firstPlayer, IGameOption firstPlayerOption,
                                       IPlayer secondPlayer, IGameOption secondPlayerOption)
        {
            Console.Write($"\n{firstPlayer} picked {firstPlayerOption} and {secondPlayer} picked {secondPlayerOption} so..., ");

            if (roundOutcome != -1)
            {
                Console.WriteLine(roundOutcome == 1
                    ? $"{firstPlayer} wins this round!"
                    : $"{secondPlayer} wins this round!");
            }
            else
            {
                Console.WriteLine("it's a DRAW!, the game continues...");
            }
        }
Beispiel #12
0
        private void _readyOption(
            PageComponentType pcType,
            IGameOption opt,
            EventHandler PressFunc = null
            )
        {
            if (null == opt)
            {
                return;
            }
            if (null != opt.SubOptions)
            {
                _readyOptionSet(
                    pcType,
                    opt.SubOptions,
                    PressFunc
                    );
                return;
            }
            SKCanvasView            Img  = new SKCanvasView();
            IFlorineSkiaConnectable conn = opt as IFlorineSkiaConnectable;

            if (null != conn)
            {
                conn.ConnectCanvasView(Img);
            }

            IFlorineSkiaEventDriver econn = opt as IFlorineSkiaEventDriver;

            if (null != econn)
            {
                if (null != PressFunc)
                {
                    econn.OnEventTriggered += PressFunc;
                }
            }

            _components.Add(
                new PageComponent(
                    _inc(pcType),
                    Img
                    )
                );
        }
        public int HandleOpposingOption(IGameOption opposingOption)
        {
            if (opposingOption is Rock)
            {
                return(0);
            }
            else if (opposingOption is Paper)
            {
                return(1);
            }
            else if (opposingOption is Scissors)
            {
                return(-1);
            }
            else if (opposingOption is Flamethrower)
            {
                return(1);
            }

            throw new Exception("Undefined behavior for specified type");
        }
Beispiel #14
0
        private IGameOption m_GameOption          = null; // 游戏设置



        //private float startTime = 0;

        /**
         * @brief
         * @param bEditor 编辑器使用
         */
        public void Init(bool bEditor = false)
        {
            if (m_LuaSystem == null)
            {
                //m_LuaSystem = LuaSystemCreator.CreateLuaSystem();
            }
            // 实体系统
            if (m_EntitySys == null)
            {
                m_EntitySys = EntitySystemCreator.CreateEntitySystem(this);
                m_EntitySys.Create();
            }

            if (m_SkillSys == null)
            {
                m_SkillSys = SkillSystemCreator.CreateSkillSystem(this);
                m_SkillSys.Init(bEditor);
            }
            if (m_MapSystem == null)
            {
                m_MapSystem = MapSystemCreator.CreateMapSystem(this, bEditor);
            }
            // 控制器
            if (m_ControllerSys == null)
            {
                m_ControllerSys = ControllerSystemCreator.CreateControllerSystem(this);
                m_ControllerSys.ActiveController(ControllerType.ControllerType_KeyBoard);
            }

            if (m_GameOption == null)
            {
                GameOption op = new GameOption();
                op.Create();
                m_GameOption = op;

                // 应用设置
                //op.ApplyOption();
            }
            //startTime = 0;
        }
Beispiel #15
0
 public FlorineSkiaOption(IGameOption Parent)
 {
     _parent = Parent;
 }
Beispiel #16
0
 public FlorineSkiaOption(IGameOption Parent, FlorineSkiaOptionSet Container)
 {
     _parent    = Parent;
     _container = Container;
 }
Beispiel #17
0
        private IGameOption _renderOption(IGameOption opt, FlorineSkiaOptionSet Container)
        {
            FlorineSkiaOption newOpt = new FlorineSkiaOption(opt, Container);

            if (null != newOpt.SubOptions)
            {
                newOpt.SubOptions = _renderOptionSet(opt.SubOptions);
            }

            // Absurdly Hackity
            String pathType = "food";

            if (opt is Activity)
            {
                //Activity
                newOpt.Description       = ((Activity)opt).Description;
                Container.SelectionModel = FlorineSkiaOptionSet.SelectionType.SELECT_MOVE;
                pathType = "activities";
                string  tokenName   = opt.OptionName;
                SKImage ResultImage = ResourceLoader.LoadImage("Images/" + pathType + "/" + tokenName.ToLower() + ".png");
                newOpt.Picture = new SelectableOptionImage()
                {
                    FoodImage = ((null == ResultImage) ?
                                 (IFlorineSkiaDrawable)(new ImageText(tokenName))
                        : (IFlorineSkiaDrawable)(new FlOval()
                    {
                        mainImage = ResultImage,
                        backgroundColor = new SKPaint()
                        {
                            Color = new SKColor(230, 230, 230)
                        }
                    }))
                };
            }
            else
            {
                // Food
                FlorineSkiaOption SourceOpt = opt as FlorineSkiaOption;
                Food.FoodOption   food_data = opt as Food.FoodOption;
                if (null == food_data && SourceOpt != null)
                {
                    food_data = SourceOpt.SourceOpt as Food.FoodOption;
                }

                if (null != food_data)
                {
                    newOpt.Description = food_data.Parent.Description;
                }
                else
                {
                    newOpt.Description = "Desc Missing";
                }
                List <Tuple <float, SKColor> > MacroNuts = new List <Tuple <float, SKColor> >();
                List <Tuple <float, SKColor> > MicroNuts = new List <Tuple <float, SKColor> >();

                if (null != food_data && food_data.Parent.IsKnown)
                {
                    // Populate nutrient info bars.
                    // List<Tuple<float, SKColor>>

                    foreach (KeyValuePair <Nutrient, NutrientAmount> kvp in food_data.Parent.Nutrients)
                    {
                        FlorineSkiaNutrient AdjNut = new FlorineSkiaNutrient(kvp.Key);
                        float RelativeAmount       = kvp.Key.RatioRDV(kvp.Value);

                        //45 * ((float)(kvp.Value) / (float)(kvp.Key.DailyTarget));
                        //if (RelativeAmount > 45.0f) { RelativeAmount = 45.0f; }
                        if (kvp.Key.Class == Nutrient.NutrientType.Macro)
                        {
                            RelativeAmount *= 180f / 4f;
                            MacroNuts.Add(new Tuple <float, SKColor>(
                                              RelativeAmount,
                                              AdjNut.RingColor
                                              ));
                        }
                        else
                        {
                            if (RelativeAmount > 1f)
                            {
                                RelativeAmount = 1f;
                            }
                            RelativeAmount *= 180 / 6f;
                            MicroNuts.Add(new Tuple <float, SKColor>(
                                              RelativeAmount,
                                              AdjNut.RingColor
                                              ));
                        }
                    }
                }
                string tokenName = opt.OptionName;
                switch (tokenName)
                {
                case "Grilled Cheese":
                    tokenName = "grilledcheese"; break;

                case "Pancakes":
                    tokenName = "pancakes"; break;

                case "Fruit":
                    tokenName = "fruit"; break;

                case "Eggs":
                    tokenName = "eggs"; break;

                case "Cereal":
                    tokenName = "cereal"; break;

                case "Toaster Pastry":
                    tokenName = "toastedpastry"; break;

                case "Toast":
                case "White Toast":
                case "Wheat Toast":
                case "Multigrain Toast":
                    tokenName = "toast"; break;

                case "Strawberry Yogurt":
                    tokenName = "yogurt"; break;

                case "Eggs, Bacon, and Toast":
                    tokenName = "toasteggsbacon"; break;

                case "Hamburger":
                    tokenName = "hamburger"; break;

                case "Chocolate Ice Cream":
                    tokenName = "icecream"; break;

                case "Instant Noodles":
                    tokenName = "instantnoodles"; break;

                case "Lamb Chops":
                    tokenName = "lambchops"; break;

                case "Meatball Sub":
                    tokenName = "meatballhero"; break;

                case "Peanut Butter & Jelly":
                    tokenName = "pbj"; break;

                case "Pepperoni Pizza Slice":
                    tokenName = "pizza"; break;

                case "Vegetable Soup":
                    tokenName = "soup"; break;

                case "Spaghetti":
                    tokenName = "spaghetti"; break;

                case "Spaghetti w/ Meatballs":
                    tokenName = "spaghettiwmeatball"; break;

                case "Sushi Serving":
                    tokenName = "sushi"; break;

                case "Tacos":
                    tokenName = "tacos"; break;

                case "Donuts":
                    tokenName = "donuts"; break;

                case "Cinnamon Roll":
                    tokenName = "cinnamonroll"; break;

                case "Hamburger Combo":
                    tokenName = "hamburgercombo"; break;

                case "Turkey Sandwich":
                    tokenName = "sandwich"; break;

                case "Sandwich with Chips":
                    tokenName = "sandwichwchips"; break;

                case "Salad":
                    tokenName = "salad"; break;

                case "Fruit Smoothie":
                    tokenName = "fruitsmoothie"; break;
                }

                SKImage ResultImage = ResourceLoader.LoadImage("Images/" + pathType + "/" + tokenName + ".png");
                if (opt is FlorineHardCodedData.HardCodedDataFoundry.NoSelectFoodOption)
                {
                    newOpt.Picture = new SelectableOptionImage()
                    {
                        FoodImage = new LayeredImage()
                        {
                            Layers =
                            {
                                new ImageText(opt.OptionName)
                                {
                                    Overflow = ImageText.WrapType.DiamondWrap, FontSize = 32f
                                },
                                new FlOval()
                                {
                                    mainImage       = null,
                                    backgroundColor = new SKPaint()
                                    {
                                        Color = new SKColor(212, 175, 5)
                                    },
                                    RightRing = MicroNuts,
                                    LeftRing  = MacroNuts,
                                }
                            }
                        }
                    };
                }
                else
                {
                    newOpt.Picture = new SelectableOptionImage()
                    {
                        FoodImage = ((null == ResultImage) ?
                                     (IFlorineSkiaDrawable)(new ImageText(opt.OptionName))
                            : (IFlorineSkiaDrawable)(new FlOval()
                        {
                            mainImage = ResultImage,
                            backgroundColor = new SKPaint()
                            {
                                Color = new SKColor(230, 230, 230)
                            },
                            RightRing = MicroNuts,
                            LeftRing = MacroNuts,
                        }))
                    };
                }
            }

            return(newOpt);
        }
Beispiel #18
0
 public void ApplyOption(IGameOption option)
 {
     option.AdjustNutrients(this);
 }
Beispiel #19
0
 public ValidGameOptionChosen(IGameOption gameOption)
 {
     this.gameOption = gameOption;
 }
Beispiel #20
0
 public IPage UserOption(IGameOption opt)
 {
     return(_nextPage(opt));
 }
Beispiel #21
0
        public bool GetNextGameState(GameState CurrentState,
                                     IGameOption selectedOpt,
                                     out GameState.PageType nextType,
                                     out GameState.PageSubType nextSubType
                                     )
        {
            nextType    = CurrentState.CurrentPage.MainType;
            nextSubType = CurrentState.CurrentPage.SubType;

            switch (CurrentState.CurrentPage.MainType)
            {
            case GameState.PageType.Start:
                // TODO: Actual Switch
                //nextType = GameState.PageType.Char_Creation;
                //nextSubType = GameState.PageSubType.Setup;
                nextType    = GameState.PageType.Day_Intro;
                nextSubType = GameState.PageSubType.Daily;
                return(true);

            case GameState.PageType.Char_Creation:
                nextType    = GameState.PageType.Day_Intro;
                nextSubType = GameState.PageSubType.Daily;
                return(true);

            case GameState.PageType.Day_Intro:
                nextType    = GameState.PageType.Select_Meal;
                nextSubType = GameState.PageSubType.Breakfast;
                return(true);

            case GameState.PageType.Select_Meal:
                nextType = GameState.PageType.Summarize_Meal;
                return(true);

            case GameState.PageType.Summarize_Meal:
                nextType = GameState.PageType.Summarize_Activity;
                //if (CurrentState.CurrentPage.SubType == GameState.PageSubType.Dinner)
                //{
                //    nextType = GameState.PageType.Select_Activity;
                //    nextSubType = GameState.PageSubType.Daily;
                //}
                return(true);

            case GameState.PageType.Select_Activity:
                if (selectedOpt == null ||
                    selectedOpt.SubOptions.Count == 0 ||
                    selectedOpt.SubOptions[0].OptionName == "Home")
                {
                    nextType    = GameState.PageType.Select_Meal;
                    nextSubType = GameState.PageSubType.Dinner;
                }
                else
                {
                    nextType    = GameState.PageType.Summarize_Activity;
                    nextSubType = GameState.PageSubType.Daily;
                }
                return(true);

            case GameState.PageType.Summarize_Activity:
                switch (CurrentState.CurrentPage.SubType)
                {
                case GameState.PageSubType.Breakfast:
                    nextType    = GameState.PageType.Select_Meal;
                    nextSubType = GameState.PageSubType.Lunch;
                    return(true);

                case GameState.PageSubType.Dinner:
                    nextType    = GameState.PageType.Day_Intro;
                    nextSubType = GameState.PageSubType.Daily;
                    return(true);

                case GameState.PageSubType.Lunch:
                    nextType    = GameState.PageType.Select_Activity;
                    nextSubType = GameState.PageSubType.Daily;

                    return(true);

                case GameState.PageSubType.Daily:
                    // Loop if possible
                    if (
                        false == CurrentState.Player.ReadyToEndDay
                        )
                    {
                        nextType    = GameState.PageType.Select_Activity;
                        nextSubType = GameState.PageSubType.Daily;
                        return(true);
                    }
                    nextType    = GameState.PageType.Select_Meal;
                    nextSubType = GameState.PageSubType.Dinner;

                    return(true);
                }
                break;

            case GameState.PageType.Summarize_Day:
                nextType    = GameState.PageType.Day_Intro;
                nextSubType = GameState.PageSubType.Daily;
                return(true);
            }
            return(false);
        }