//for test public bool isPointInside(Vector2 xy) { bool proj = false; int closestEdge = getClosestEdge(xy); Vector2 ab = MathGame.lineToVector(getEdge(closestEdge)); //вектор грани Vector2 ap = MathGame.lineToVector(getEdge(closestEdge)[0], xy); //вектор от начала грани до точки /*Проверка пренадлежности делается с помощью вычисления векторного произведения *между вектором образованым ближайшей гранью (ab) и вектором между курсором и началом ближайшей грани (ap) * если произведение меньше 0, то точка принадлежит полигону. *Для полигонов с острыми углами еще нужна проверка на длину. ap не должно быть > ab. * * * Checking by using cross product between vector creating by nearest edge (ab) and * vector specified by start point of ab and xy coordinates. Negative value of cross means pont * is inside poly. Length check is for non-square polys. */ float cross = MathGame.crs2d(ap, ab); if (cross < 0 && ab.magnitude >= ap.magnitude) { //cross - векторное умножение - проверка тупой угол или острый proj = true; } else { proj = false; } return(proj); }
private void StateChangeCheck() { if (QuestionsCorrect >= ModerateModeLimit) { MathGame.ChangeState(new HardGameState(this)); } }
private float[] getEdgeSquare() { int width = 10; float[] vertices = new float[8]; //Получаем координаты грани Vector2 st = new Vector2(shapeCreator.getNodes()[nodesToLink[0]].getX(), shapeCreator.getNodes()[nodesToLink[0]].getY()); Vector2 fn = new Vector2(shapeCreator.getNodes()[nodesToLink[1]].getX(), shapeCreator.getNodes()[nodesToLink[1]].getY()); //Результирующий вектор Vector2 edgeVector = MathGame.lineToVector(st, fn); //базовый вектор //Теперь нам нужно найти нормаль к вектору. Координаты вектора-нормали ищется по формулам: //x = (-y*y')/x', y = (-x*x')/y'. Тут x' и y' - координаты базового вектора //x или y выбираем любой, например y = 1. float normY; if (edgeVector.x >= 0)//Проверяем, что векто рв правой части графика - тогда Y положительный и наоборот { normY = 1; } else { normY = -1; } float normX = -(normY * edgeVector.y) / edgeVector.x; //X компонента вектора нормали Vector2 resNormal1 = new Vector2(normX, normY); //Y компоненту мы уже определили resNormal1.Normalize(); //нормализуем вектор нормали resNormal1.x = resNormal1.x * width; // умножаем на ширину нашего прямоугольника resNormal1.y = resNormal1.y * width; Vector2 resNormal2 = new Vector2(resNormal1.x, resNormal1.y); //Назначаем оппозитный вектор к нормали, чтобы была вторая сторона прямоугольника resNormal2.x = -resNormal2.x; //отражаем оппозитный вектор resNormal2.y = -resNormal2.y; vertices[0] = resNormal1.x + st.x; vertices[1] = resNormal1.y + st.y; vertices[2] = resNormal2.x + st.x; vertices[3] = resNormal2.y + st.y; vertices[4] = resNormal2.x + fn.x; vertices[5] = resNormal2.y + fn.y; vertices[6] = resNormal1.x + fn.x; vertices[7] = resNormal1.y + fn.y; return(vertices); }
public void FindOpponent() { //// First fetch the player from our players collection having current connection id var player = mathPlayers.FirstOrDefault(x => x.ConnectionId == Context.ConnectionId); if (player == null) { //// Since player would be registered before making this call, //// we should not reach here. If we are here, something somewhere in the flow above is broken. return; } //// Set that player is seraching for opponent. player.IsSearchingOpponent = true; //// We will follow a queue, so find a player who registered earlier as opponent. //// This would only be the case if more than 2 players are looking for opponent. var opponent = mathPlayers.Where(x => x.ConnectionId != Context.ConnectionId && x.IsSearchingOpponent && !x.IsPlaying).OrderBy(x => x.RegisterTime).FirstOrDefault(); if (opponent == null) { //// Could not find any opponent, invoke opponentNotFound method in the client. Clients.Client(Context.ConnectionId).InvokeAsync(Constants.OpponentNotFound, mathPlayers); return; } //// Set both players as playing. player.IsPlaying = true; player.IsSearchingOpponent = false; //// Make him unsearchable for opponent search opponent.IsPlaying = true; opponent.IsSearchingOpponent = false; //// Set each other as opponents. //player.Opponent = opponent; //opponent.Opponent = player; //// Notify both players that they can play the game by invoking opponentFound method for both the players. //// Also pass the opponent name and opoonet image, so that they can visualize it. //// Here we are directly using connection id, but group is a good candidate and use here. //Clients.Client(Context.ConnectionId).InvokeAsync(Constants.OpponentFound, opponent.Name, opponent.Image); //Clients.Client(opponent.ConnectionId).InvokeAsync(Constants.OpponentFound, player.Name, player.Image); var newGame = new MathGame(player, opponent); mathGames.Add(newGame); Clients.All.InvokeAsync("hello"); Clients.All.InvokeAsync("startMathGame", newGame); //Clients.User(newGame.Player2.ConnectionId).InvokeAsync("startMathGame", newGame); //// Create a new game with these 2 player and add it to games collection. //StartGame(newGame); }
public void setPointPosition() { int edge = this.parentEdge; float length = this.edgePosition; Vector2[] edVec = new Vector2[2]; Vector2 tmp; edVec = shapeCreator.getPolygons()[this.parentPoly].getEdge(edge); tmp = new Vector2(edVec[1].x - edVec[0].x, edVec[1].y - edVec[0].y); tmp = MathGame.scl(tmp, length); tmp.x = tmp.x + edVec[0].x; tmp.y = tmp.y + edVec[0].y; setPosition(tmp); }
static void Main(string[] args) { SettingsGameJSON SF = new SettingsGameJSON(); ConsoleKeyInfo choose; for (;;) { Console.Clear(); Console.WriteLine("---GRA W LICZENIE---\n\n" + "MENU GŁÓWNE:\n" + "---------------------\n" + "1. Dodawanie\n" + "2. Odejmowanie\n" + "3. Mnożenie\n" + "4. Dzielenie\n" + "---------------------\n" + "5. Opcje\n" + "---------------------\n" + "9. Wyjście\n"); choose = Console.ReadKey(); switch (choose.Key.ToString()) { case "D1": case "D2": case "D3": case "D4": MathGame.Play(SF.Range, SF.Quantity, choose); break; case "D5": OptionsMenu.SetGame(SF); break; case "D9": Environment.Exit(0); break; } } }
//Awake is called when the script instance is being loaded. void Awake() { //Load spritesheet // numberSprites = Resources.LoadAll<Sprite>("Images/MathGame/0thru13"); /*for (int i = 0; i < numberSprites.Length; i++) * { * Debug.Log("Loaded " + numberSprites[i].name + " from spritesheet."); * } */ if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } numberSprites = new Sprite[maxNumber + 1]; LoadAllSprites(); //Begin(); }
public ModerateGameState(int questionsAttempted, int questionsCorrect, MathGame mathGame) { QuestionsAttempted = questionsAttempted; QuestionsCorrect = questionsCorrect; MathGame = mathGame; }
internal void StartGame(MathGame game) { //mathGames.Add(game); Clients.User(game.Player1.ConnectionId).InvokeAsync("startMathGame", game); Clients.User(game.Player2.ConnectionId).InvokeAsync("startMathGame", game); }
private void Awake() { instance = this; }