Ejemplo n.º 1
0
 private void RefreshCalculation()
 //刷新游戏算式
 {
     TimeLeft = 3;
     //重置时间为3
     lbTimeLeft.Text = "残り時間:" + TimeLeft.ToString();
     //显示重置的时间3
     LeftNum   = RandomNum.Next(1, 20); //(生成1-20之间的随机数,不包括20)
     RightNum  = RandomNum.Next(1, 20); //(生成1-20之间的随机数,不包括20)
     Algorithm = RandomNum.Next(0, 1);  //(生成0-1之间的随机数,不包括20)
     if (Algorithm >= 0.5)
     {
         //如果Algorithm >= 0.5,则进行加法运算
         lbLeftNum.Text  = LeftNum.ToString();
         lbRightNum.Text = RightNum.ToString();
         //将LeftNum与RightNum显示在label里
         lbAlgorithm.Text = "+";
         //lbAlgorithm显示加法
         RealResult   = LeftNum + RightNum;//RealResult是正确计算的结果
         RandomResult = int.Parse(RandomNum.Next(RealResult - 1, RealResult + 1).ToString());
         //随机生成错误结果,与正确结果差1以内
         lbResult.Text = RandomResult.ToString();
         //随机生成的结果显示在lbResult内
     }
     else
     {
         //如果Algorithm < 0.5,则进行减法运算
         RealResult = LeftNum - RightNum;
         //RealResult是正确计算的结果
         lbLeftNum.Text  = LeftNum.ToString();
         lbRightNum.Text = RightNum.ToString();
         //将LeftNum与RightNum显示在label里
         lbAlgorithm.Text = "-";
         //lbAlgorithm显示减法
         RealResult   = LeftNum - RightNum;//这是正确计算的结果
         RandomResult = int.Parse(RandomNum.Next(RealResult - 1, RealResult + 1).ToString());
         //随机生成错误结果,与正确结果差1以内
         lbResult.Text = RandomResult.ToString();
         //随机生成的结果显示在lbResult内
     }
 }
Ejemplo n.º 2
0
        public async Task RandomMeme()
        {
            RandomResult result = (RandomResult)rand.Next(0, 2);

            switch (result)
            {
            case RandomResult.YoutubeLink:
            {
                string meme = InfoImportClass.GetRandomYoutubeLink();

                if (meme != "")
                {
                    await ReplyAsync(meme);
                }
                else
                {
                    await ReplyAsync("Failed to get a meme, message Abe");
                    await Log("Failed to post youtube link to the channel " + Context.Channel.ToString() + " in the guild " + Context.Guild.ToString(), LogSeverity.Error);

                    break;
                }
                break;
            }

            case RandomResult.Image:
            {
                string meme = InfoImportClass.GetRandomImageFromFile();
                if (meme != "")
                {
                    await Context.Channel.SendFileAsync(meme, "");
                }
                else
                {
                    await ReplyAsync("Tried to upload image but failed to get one.");
                    await Log("Failed to upload a image to the channel " + Context.Channel.ToString() + " in the guild " + Context.Guild.ToString(), LogSeverity.Error);

                    break;
                }
                break;
            }

            case RandomResult.Video:
            {
                string meme = InfoImportClass.GetRandomVideoFromFile();
                if (meme != "")
                {
                    await Context.Channel.SendFileAsync(meme, "");
                }
                else
                {
                    await ReplyAsync("Tried to upload a video but failed to get one.");
                    await Log("Failed to upload a video to the channel " + Context.Channel.ToString() + " in the guild " + Context.Guild.ToString(), LogSeverity.Error);

                    break;
                }
                break;
            }

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        public static RandomGame RandomFight(int minerals = 2000, bool save = false)
        {
            Player _player = new Player();

            _player.Name   = "Player#1";
            _player.Pos    = 1;
            _player.ID     = paxgame.GetPlayerID();
            _player.Race   = UnitRace.Terran;
            _player.inGame = true;
            _player.Units  = new List <Unit>(UnitPool.Units.Where(x => x.Race == _player.Race));

            Player _opp = new Player();

            _opp.Name   = "Player#2";
            _opp.Pos    = 4;
            _opp.ID     = paxgame.GetPlayerID();
            _opp.Race   = UnitRace.Terran;
            _opp.inGame = true;
            _opp.Units  = new List <Unit>(UnitPool.Units.Where(x => x.Race == _opp.Race));

            GameHistory game = new GameHistory();

            _player.Game    = game;
            _player.Game.ID = paxgame.GetGameID();
            _player.Game.Players.Add(_player);
            _player.Game.Players.Add(_opp);

            _opp.Game = _player.Game;

            _player.Units = new List <Unit>(UnitPool.Units.Where(x => x.Race == _player.Race && x.Cost > 0));
            _opp.Units    = new List <Unit>(UnitPool.Units.Where(x => x.Race == _opp.Race && x.Cost > 0));

            _player.MineralsCurrent = minerals;
            _opp.MineralsCurrent    = minerals;

            OppService.BPRandom(_player).GetAwaiter().GetResult();
            OppService.BPRandom(_opp).GetAwaiter().GetResult();

            BBuild bplayer = new BBuild(_player);
            BBuild bopp    = new BBuild(_opp);

            bplayer.SetBuild(_player);
            bopp.SetBuild(_opp);

            GameService.GenFight(_player.Game).GetAwaiter().GetResult();
            StatsService.GenRoundStats(game, false).GetAwaiter().GetResult();
            Stats result    = new Stats();
            Stats oppresult = new Stats();

            result.DamageDone            = game.Stats.Last().Damage[1];
            result.MineralValueKilled    = game.Stats.Last().Killed[1];
            oppresult.DamageDone         = game.Stats.Last().Damage[0];
            oppresult.MineralValueKilled = game.Stats.Last().Killed[0];

            RandomResult result1 = new RandomResult();

            result1.DamageDone         = oppresult.DamageDone;
            result1.MineralValueKilled = oppresult.MineralValueKilled;
            RandomResult result2 = new RandomResult();

            result2.DamageDone         = result.DamageDone;
            result2.MineralValueKilled = result.MineralValueKilled;

            RandomGame rgame = new RandomGame();

            rgame.player1 = bplayer;
            rgame.player2 = bopp;
            rgame.result1 = result1;
            rgame.result2 = result2;
            rgame.Result  = game.Stats.Last().winner;

            if (save == true)
            {
                SaveGame(rgame, _player, _opp);
            }

            return(rgame);
        }