public ActionResult <NewGameResponse> NewGame([FromBody] NewPostBody value)
        {
            //validate input
            if (!NewGameValidation.IsBodyPostValid(value))
            {
                return(BadRequest());
            }

            //create token
            NewGameResponse response = new NewGameResponse();

            response.Token = Guid.NewGuid().ToString();

            //generate structure to save (map with mines)
            MineMatrix mineMatrix = new MineMatrix(value.Height, value.Width, value.Bombs, response.Token);


            //save structure in repository
            //it could be an interface for db, file or memcached
            MineRepository repository = new MineRepository();

            repository.Save(mineMatrix);


            return(response);
        }
Esempio n. 2
0
 private static void ExpectABoardResponse(NewGameResponse response)
 {
     response.Should().BeEquivalentTo(new NewGameResponse
     {
         Board = new Board()
     });
 }
Esempio n. 3
0
        private PlaceTokenResponse GivenACompleteGame()
        {
            NewGameResponse response = _newGame.Execute(new NewGameRequest());

            _board = response.Board;

            WhenIPlaceAToken("X", 1, 1);
            WhenIPlaceAToken("X", 1, 2);
            return(WhenIPlaceAToken("X", 1, 3));
        }
Esempio n. 4
0
        public void startGame(string name)
        {
            NewGameRequest request = new NewGameRequest()
            {
                user = name
            };
            NewGameResponse response = AxiomzenMastermind.newGame(request);

            GameData gameData = new GameData()
            {
                game_key = response.game_key
            };

            _games[Context.ConnectionId] = gameData;

            Clients.Client(Context.ConnectionId).postHistory("New game started", "Start guessing a 8 digit code, with values from 1 to 8.");
        }
Esempio n. 5
0
    private IEnumerator EstablishConnection()
    {
        //print("http://" + url + "/newGame");
        UnityWebRequest myWr = UnityWebRequest.Get("http://" + url + "/newGame");

        print("http://" + url + "/newGame");
        yield return(myWr.SendWebRequest());

        m_connected = myWr.responseCode == 200;
        if (myWr.responseCode == 200)         //Incorrect code length signifies a connection to the test server, not the correct build
        {
            string response = System.Text.Encoding.UTF8.GetString(myWr.downloadHandler.data);
            print(response);

            NewGameResponse res = JsonUtility.FromJson <NewGameResponse>(response);
            m_code = res.code;

            //Debug.Log(m_code);
            if (MenuScript.Instance != null)
            {
                MenuScript.Instance.UpdatePhoneCode();
            }
            print("ws://" + url + "/" + m_code);
            m_client.Connect("ws://" + res.connectionString + "/" + m_code);

            if (onCodeChange != null)
            {
                onCodeChange.Invoke(m_code);
            }
        }
        else
        {
            Debug.Log("CONNECTION TO '" + url + "' HAS FAILED!\nReverting to non-phone gamemode if possible");
            if (onCodeChange != null)
            {
                onCodeChange.Invoke(null);
            }
            Enabled = false;
        }
    }
        public static NewGameResponse newGame(NewGameRequest newGameRequest)
        {
            try
            {
                string         url     = serviceUrl + "new_game?user="******"POST";
                request.ContentType = "text/json";

                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    DataContractJsonSerializer jsonResponseSerializer = new DataContractJsonSerializer(typeof(NewGameRequest));
                    jsonResponseSerializer.WriteObject(streamWriter.BaseStream, newGameRequest);
                    streamWriter.Flush();
                    streamWriter.Close();
                }

                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception(String.Format("Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription));
                    }

                    DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(NewGameResponse));
                    object          objResponse  = jsonSerializer.ReadObject(response.GetResponseStream());
                    NewGameResponse jsonResponse = objResponse as NewGameResponse;
                    return(jsonResponse);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
Esempio n. 7
0
        private void GivenANewGame()
        {
            NewGameResponse response = _newGame.Execute(new NewGameRequest());

            _board = response.Board;
        }
Esempio n. 8
0
        public void CanCreateANewGame()
        {
            NewGameResponse response = Execute(new NewGameRequest());

            ExpectABoardResponse(response);
        }