Example #1
0
        public override void MakeMove(GameApi api)
        {
            IEnumerable <CountryApi> countries = api.Countries;
            CountryApi myCountry = api.Country;

            foreach (CountryApi c in countries)
            {
                myCountry.TryDeclareWar(this, c);
            }

            IEnumerable <ArmyApi> armies = api.Country.Armies;

            foreach (ArmyApi a in armies)
            {
                if (a.MovingDirection == Direction.None)
                {
                    if (a.IsArmyMovePossible(this, Direction.East))
                    {
                        a.TrySendArmy(this, Direction.East);
                    }
                    else if (a.IsArmyMovePossible(this, Direction.North))
                    {
                        a.TrySendArmy(this, Direction.North);
                    }
                    else if (a.IsArmyMovePossible(this, Direction.West))
                    {
                        a.TrySendArmy(this, Direction.West);
                    }
                    else if (a.IsArmyMovePossible(this, Direction.South))
                    {
                        a.TrySendArmy(this, Direction.South);
                    }
                }
            }
        }
Example #2
0
        public static void PlayGame(GameApi gameApi, string userResponse)
        {
            Console.WriteLine(gameApi.ProcessCommand(userResponse));
            string newResponse = Console.ReadLine();

            PlayGame(gameApi, newResponse);
        }
Example #3
0
        static void Main()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Welcome To");
            Console.WriteLine("____   ____.__ __   .__                 __________.__                    .___ ________                          __   ");
            Console.WriteLine("\\   \\ /   /|__|  | _|__| ____    ____   \\______   \\  |   ____   ____   __| _/ \\_____  \\  __ __   ____   _______/  |_ ");
            Console.WriteLine(" \\   Y   / |  |  |/ /  |/    \\  / ___\\   |    |  _/  |  /  _ \\ /  _ \\ / __ |   /  / \\  \\|  |  \\_/ __ \\ /  ___/\\   __\\");
            Console.WriteLine("  \\     /  |  |    <|  |   |  \\/ /_/  >  |    |   \\  |_(  <_> |  <_> ) /_/ |  /   \\_/.  \\  |  /\\  ___/ \\___ \\  |  |  ");
            Console.WriteLine("   \\___/   |__|__|_ \\__|___|  /\\___  /   |______  /____/\\____/ \\____/\\____ |  \\_____\\ \\_/____/  \\___  >____  > |__|  ");
            Console.WriteLine("                   \\/       \\//_____/           \\/                        \\/         \\__>           \\/     \\/        ");
            Console.ResetColor();
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("                           ___");
            Console.WriteLine("                          ( ((");
            Console.WriteLine("                           ) ))");
            Console.WriteLine("  .::.                    / /(");
            Console.WriteLine(" \'M .-;-.-.-.-.-.-.-.-.-/| ((::::::::::::::::::::::::::::::::::::::::::::::.._");
            Console.WriteLine("(J ( ( ( ( ( ( ( ( ( ( ( |  ))   -====================================-      _.>");
            Console.WriteLine(" `P `-;-`-`-`-`-`-`-`-`-\\| ((::::::::::::::::::::::::::::::::::::::::::::::\'\'");
            Console.WriteLine("  `::\'                    \\ \\(");
            Console.WriteLine("                           ) ))");
            Console.WriteLine("                          (_((");

            Console.WriteLine(GameApi.StartGame());

            while (GameRunning)
            {
                var commandProcessed = GameApi.ProcessCommand(Console.ReadLine());
                Console.WriteLine(commandProcessed.Item1);
                GameRunning = commandProcessed.Item2;
            }
            Console.ReadLine();
        }
Example #4
0
 public Assessments(string jsonPath, GameApi gameApi)
 {
     JsonPath = jsonPath;
     GameApi  = gameApi;
     Classes  = new(this);
     Members  = new(this);
 }
Example #5
0
 void Awake()
 {
     Debug.Log(gameCodeName);
     if (Volume == false) VolumeOff();
     if (Volume == true) VolumeOn();
     gameapi = gameObject.GetComponent<GameApi>();
 }
Example #6
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            [Queue("fleeteventranks"), StorageAccount("sttfleetg5618_STORAGE")] ICollector <string> msg,
            ExecutionContext context,
            ILogger log)
        {
            log.LogInformation("Fleet event ranks started");
            var configuration = new Configuration(context.FunctionAppDirectory);
            var gameApi       = new GameApi(configuration.STTApiConfiguration);
            await gameApi.Login();

            var data = await gameApi.GetFleetMemberInfo();

            var userdailies = UserDailies.Load(data);
            var squadranks  = SquadEventRank.Load(data);

            log.LogInformation("Fleet event ranks users: " + userdailies.Count);

            var queueItem = new EventRankQueueItem()
            {
                UserDailies = userdailies, SquadEventRanks = squadranks
            };

            msg.Add(JsonConvert.SerializeObject(queueItem));

            return(new OkResult());
        }
Example #7
0
        static void Main(string[] args)
        {
            var repo   = new InMemoryRepository <Game>();
            var logger = new NLogLogger("ConsoleGameRunner");

            // TODO: move to IOC Container if this gets more complicated
            var gameApi = new GameApi(new SimpleGameFactory(), repo, new PublicGameAuthorizer(repo), logger);

            Console.WriteLine("Welcome to Battleship");
            logger.Info("Welcome to Battleship");

            var player1Name = args.Length == 2 ? args[0] : "Player 1";
            var player2Name = args.Length == 2 ? args[1] : "Player 2";

            var gameId = gameApi.Create(player1Name, player2Name, GameCreatorUserId);

            CaptureShipLocation(gameApi, gameId, player1Name);
            CaptureShipLocation(gameApi, gameId, player2Name);

            var game = gameApi.Read(gameId, GameCreatorUserId);

            while (game.Status != GameStatus.Completed)
            {
                Console.WriteLine();
                Console.WriteLine(GameDisplayer.Display(game));
                Console.WriteLine();
                CaptureAttack(gameApi, gameId);
            }

            Console.WriteLine();
            Console.WriteLine(GameDisplayer.Display(game));

            Console.ReadLine();
        }
Example #8
0
        private static void CaptureAttack(GameApi gameApi, Guid gameId)
        {
            var game = gameApi.Read(gameId, GameCreatorUserId);

            var playerNumber = game.CurrentTurnPlayer;
            var playerName   = playerNumber == 1 ? game.Player1 : game.Player2;
            var attackProceededWithoutException = false;

            while (!attackProceededWithoutException)
            {
                Console.WriteLine($"{playerName}: Enter a location to attack (e.g. 'D4')");
                var attackLocation = Console.ReadLine();

                try
                {
                    gameApi.Attack(gameId, playerName, new Location(attackLocation));

                    attackProceededWithoutException = true;
                }
                catch (FormatException)
                {
                    Console.WriteLine($"'{attackLocation}' is not in the expected format");
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"A serious error occurred: {ex.Message}");
                }
            }
        }
Example #9
0
        private static void CaptureShipLocation(GameApi gameApi, Guid gameId, string playerName)
        {
            var game = gameApi.Read(gameId, GameCreatorUserId);

            var playerIndex = playerName == game.Player1 ? 0 : 1;

            while (game.Ships[playerIndex].Status != ShipStatus.Active)
            {
                Console.WriteLine($"{playerName}: Enter your ship location (e.g. 'A3 A5')");
                var shipLocation       = Console.ReadLine();
                var shipLocationTokens = shipLocation.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                try
                {
                    gameApi.PlaceShip(gameId, playerName, new Location(shipLocationTokens[0]), new Location(shipLocationTokens[1]));

                    game = gameApi.Read(gameId, GameCreatorUserId);
                }
                catch (FormatException)
                {
                    Console.WriteLine($"'{shipLocation}' is not in the expected format");
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"A serious error occurred: {ex.Message}");
                }
            }
        }
Example #10
0
        private static void TestConsumer(GameApi api, PlayersApi players, Configuration config)
        {
            GameRules rules = new GameRules(true, 2, "Test", 1, password: null);

            PrintHeader("Create Game");
            int game = api.CreateGame(rules);

            Print("Game ID: " + game);
            Print("Stats : " + api.GetGameState(game));
            PrintHeader("Join Game");
            players.Join(game);
            ConsumerApi  consumerApi = new ConsumerApi(config);
            JoinResponse response    = consumerApi.RegisterConsumer(game, new ConsumerRegistration("Test", "Ein consumer"));

            Print($"id : {response.Id}");
            Print($"pat : {response.Pat}");
            players.Configuration.ApiKey["pat"] = response.Pat;
            api.Configuration.ApiKey["pat"]     = response.Pat;
            config.ApiKey["pat"] = response.Pat;
            JoinResponse somePlayer = players.Join(game);

            Print(players.GetPlayer(game, somePlayer.Id).ToJson());
            PrintHeader("Start Game");
            api.CommitAction(game, ActionType.STARTGAME);
            PrintHeader("Fetch Events");
            EventHandlingApi eventApi = new EventHandlingApi(config);

            for (int i = 0; i < 8; i++)
            {
                Print(eventApi.FetchNextEvent(game).Type.ToString());
            }
        }
Example #11
0
        public void SetUp()
        {
            dbContext = DbContextUtility.CreateMockDb();
            var logger     = Substitute.For <ILogger <GameApi> >();
            var cdnService = Substitute.For <ICdnService>();

            testObj = new GameApi(logger, dbContext, cdnService);
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="toolControl"/> class.
        /// </summary>
        public toolControl()
        {
            var url = "http://localhost/BlackJackApi/";

            this.InitializeComponent();
            //initialize connection
            _lobbyClient = new LobbyApi(url);
            _gameClient  = new GameApi(url);
        }
Example #13
0
        public override void Load()
        {
            Bind <IProgram>().To <Program>();
            Bind <IScreen>().To <Screen>().InSingletonScope();
            Bind <IStateMachine>().To <StateMachine>().InSingletonScope();
            Bind <ILobby>().To <Lobby>();
            Bind <IGame>().To <Game>();
            var gameApi = new GameApi("http://www.glueware.nl/Klootzakken/kzapi");

            Bind <GameApi>().ToConstant(gameApi);
        }
Example #14
0
    void Awake()
    {
        if (_api == null)
        {
            _api = FindObjectOfType <GameApi>();
        }

        if (_api == null)
        {
            Debug.LogError("'Api' field must be set!");
        }
    }
Example #15
0
        static void Main(string[] args)
        {
            Configuration c = new Configuration {
                BasePath = "http://localhost:5050/v1"
            };
            GameApi    api     = new GameApi(c);
            PlayersApi players = new PlayersApi(c);

            PrintHeader("{Test Game Lifecycle}");
            TestStartGame(api, players, c);
            return;

            PrintHeader("\n{Test Consumers}");
            TestConsumer(api, players, c);
        }
Example #16
0
        static void Main(string[] args)
        {
            GameApi gameApi = new GameApi();

            while (gameApi.GetGameId().Equals(""))
            {
                Console.WriteLine("Would you like to Load a Game or Start a new Game?(Load / New Slot Number(1, 2, 3, 4))");
                Console.WriteLine(gameApi.Command(Console.ReadLine()));
                while (gameApi.GetGameId() != "")
                {
                    Console.WriteLine("What would you like to do?");
                    Console.WriteLine(gameApi.Command(Console.ReadLine()));
                }
            }
        }
Example #17
0
        static void Main(string[] args)
        {
            GameApi gameApi = new GameApi();


            Console.WriteLine("Welcome to the Castle Grimtol Text Adventure Game!");
            Console.WriteLine("Would you like to play a game? (Yes No or Tutorial)");
            var userResponse = Console.ReadLine();

            Console.WriteLine(gameApi.StartGame(userResponse));
            var newResponse = Console.ReadLine();

            PlayGame(gameApi, newResponse);
            Console.WriteLine(gameApi.GetGameHistory());
            Console.ReadLine();
        }
Example #18
0
            protected void InitWithGame(Game game)
            {
                _game    = game;
                _id      = new Guid();
                _factory = Substitute.For <IGameFactory>();
                _factory.Create(Arg.Any <string>(), Arg.Any <string>()).Returns(_game);

                _repo = Substitute.For <IRepository <Game> >();
                _repo.Add(Arg.Any <Game>()).Returns(_id);
                _repo.Get(Arg.Any <Guid>()).Returns(_game);

                _authorizer = Substitute.For <IAuthorizer>();
                _logger     = Substitute.For <ILogger>();

                _sut = new GameApi(_factory, _repo, _authorizer, _logger);
            }
Example #19
0
        static void nMain(string[] args)
        {
            var url = "http://localhost/BlackJackApi/";

            lobbyClient = new LobbyApi(url);

            var games = lobbyClient.ApiLobbyListGet();

            var gameId = lobbyClient.ApiLobbyNewgameNameMinbetMaxbetPost("HelloTomx", 10, 100).Replace("\"", "");

            gameClient = new GameApi(url);
            Player1    = gameClient.GameIdJoinPut(gameId, "John Snow", Position1);
            Player2    = gameClient.GameIdJoinPut(gameId, "Stephen Fry", Position2);
            PlayRound(gameId);
            return;
        }
Example #20
0
        static void cameraFix()
        {
            GameApi game = new GameApi();
            BotApi  bot  = new BotApi();

            string img = Directory.GetCurrentDirectory() + @"\Images\Game\unfixedcamera.png";

            if (File.Exists(img))
            {
                game.camera.toggleIfUnlocked();
            }
            else
            {
                bot.log("cameraFix error: Image not found.");
            }
        }
Example #21
0
 public static object fetchGameDetail(string gameId)
 {
     return(new ThunkAction <AppState>((dispatcher, getState) => {
         return GameApi.FetchGameDetail(gameId: gameId)
         .Then(gameDetailResponse => {
             dispatcher.dispatch(new RankListAction {
                 rankList = new List <RankData> {
                     gameDetailResponse
                 }
             });
             dispatcher.dispatch(new FetchGameDetailSuccessAction());
         })
         .Catch(error => {
             dispatcher.dispatch(new FetchGameDetailFailureAction());
             Debuger.LogError(message: error);
         });
     }));
 }
Example #22
0
        private static double?PlayRound(string gameId, GameApi gameClient, int position, PlayerAccount player, int bet)
        {
            return(0);
            //gameClient.GameIdPlayerPlayerIdBetAmountPost(gameId, player.Id, bet);

            //gameClient.GameIdPlayerPlayerIdStandPost(gameId, player.Id);
            //result = gameClient.GameIdDetailsGet(gameId);

            //outcome = result.RoundInProgressSettlements.FirstOrDefault(s => s.PlayerPosition == position);
            //if (outcome == null)
            //{
            //    Console.WriteLine("oops");
            //}
            //else
            //{
            //    Console.WriteLine("outcome : " + outcome.WagerOutcome);
            //}
            //return result.Players.First(p => p.Id == player.Id).Account.Balance;
        }
Example #23
0
        private static void TestStartGame(GameApi api, PlayersApi players, Configuration config)
        {
            GameRules rules = new GameRules(true, 2, "Test", 1, password: null);

            PrintHeader("Create Game");
            int game = api.CreateGame(rules);

            Print("Game ID: " + game);
            Print("Stats : " + api.GetGameState(game));
            PrintHeader("Join Game");
            JoinResponse response = players.Join(game);

            Print($"id : {response.Id}");
            Print($"pat : {response.Pat}");
            players.Configuration.ApiKey["pat"] = response.Pat;
            api.Configuration.ApiKey["pat"]     = response.Pat;
            config.ApiKey["pat"] = response.Pat;
            players.Join(game);

            Print(players.GetPlayer(game, response.Id).ToJson());
            PrintHeader("Start Game");
            api.CommitAction(game, ActionType.STARTGAME);
            PrintHeader("Fetch Events");
            EventHandlingApi eventApi = new EventHandlingApi(config);
            bool             run      = true;
            int c = 1;

            try {
                while (run)
                {
                    EventType type = eventApi.TraceEvent(game, wait: true, batch: false)[0];
                    run = type != EventType.Gameendevent;
                    GenericEvent ev = eventApi.FetchNextEvent(game);
                    Print(c++ + ". Event: " + type);
                    Print(ev.ToJson() + "\n");
                }
            }
            catch (Exception) {
                Console.Out.WriteLine("TraceEvent(" + game + ")");
                throw;
            }
        }
Example #24
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
            var        api = new GameApi();
            IGameState gameState;

            Console.WriteLine("Welcome Brave soul what is your name? ");
            var playerName = Console.ReadLine();

            gameState = api.TryLoadGame(playerName);
            string welcomeMessage = gameState.IsRestoredGame ? $"Welcome back {playerName}" : $"Welcome new adventurer I will record your history as the tale of {playerName}";

            Console.WriteLine(welcomeMessage);

            while (gameState.Active)
            {
                PrintGameState(gameState);
                gameState = api.ProcessInput(Console.ReadLine(), gameState);
            }
        }
Example #25
0
 public static object fetchGames(int page)
 {
     return(new ThunkAction <AppState>((dispatcher, getState) => {
         return GameApi.FetchGames(page: page)
         .Then(gamesResponse => {
             dispatcher.dispatch(new RankListAction {
                 rankList = gamesResponse.rankList
             });
             var gameIds = new List <string>();
             gamesResponse.rankList.ForEach(rankData => { gameIds.Add(item: rankData.id); });
             dispatcher.dispatch(new FetchGameSuccessAction {
                 gameIds = gameIds,
                 hasMore = gamesResponse.hasMore,
                 pageNumber = gamesResponse.currentPage
             });
         })
         .Catch(error => {
             dispatcher.dispatch(new FetchGameFailureAction());
             Debuger.LogError(message: error);
         });
     }));
 }
Example #26
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ExecutionContext context,
            ILogger log)
        {
            log.LogInformation("Fleet dailies started");
            var configuration = new Configuration(context.FunctionAppDirectory);
            var gameApi       = new GameApi(configuration.STTApiConfiguration);
            await gameApi.Login();

            var data = await gameApi.GetFleetMemberInfo();

            var fleet = UserDailies.Load(data);

            log.LogInformation("Fleet dailies users: " + fleet.Count);
            StringBuilder message = new StringBuilder();

            message.AppendLine($"Dailies (UTC) {DateTime.UtcNow.ToString("dd.MM.yyyy HH:mm")}");
            var grouped = fleet.GroupBy(d => d.Squadron);

            foreach (var group in grouped)
            {
                var squadName = Regex.Replace(group?.Key ?? string.Empty, @"\<\#[^<>]*\>", string.Empty);
                message.AppendLine($"__{squadName}__");
                foreach (var member in group)
                {
                    message.AppendLine($"{member.Name}: **{member.Dailies}**");
                }
                message.AppendLine(string.Empty);
            }

            HttpClient client = new HttpClient();
            var        d1     = JsonConvert.SerializeObject(new { content = message.ToString() });
            var        result = await client.PostAsync(configuration.DiscordConfiguration.DiscordDailiesWebhookUrl, new StringContent(d1, Encoding.UTF8, "application/json"));

            result.EnsureSuccessStatusCode();

            return(new OkResult());
        }
        public static void Main(string[] args)
        {
            GameApi game = new GameApi();

            Console.WriteLine("");
            Console.WriteLine("Welcome to Calorie Castle!");
            Console.WriteLine("");

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(game.processCommand("H"));
            game.startGame();


            string PlayerChoice;

            bool playing = true;

            while (playing)
            {
                Console.WriteLine("");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("What would you like to do next? (Note: You can not use food items you have not taken.)");
                Console.ResetColor();
                PlayerChoice = Console.ReadLine();
                if (PlayerChoice == "H")
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(game.processCommand(PlayerChoice));
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine(game.processCommand(PlayerChoice));
                }
            }
        }
Example #28
0
 public Game MapApiGame(GameApi gameApi)
 {
     return(m_mapper.Map <GameApi, Game>(gameApi));
 }
Example #29
0
 public abstract void MakeMove(GameApi api);
Example #30
0
 void Awake()
 {
     gameapi = gameObject.GetComponent<GameApi>();
 }
 public void ExitGame()
 {
     GameApi.Navigate_Levelboard();
 }
 public void ResumeGame()
 {
     GameApi.Gameplay_Resume();
 }