示例#1
0
    void ActivateVisualMove(Amazons.Player player, Amazons.Move move)
    {
        MovingActor = ((Amazon)player.Pawns[move.ID]).Pawn;
        Transform t = MovingActor.GetComponent <Transform>();

        MoveActor   = true;
        MoveTimer   = 0;
        StartingPos = t.position;
        EndPos      = GetVectorFromPoint(move.MoveTo);
    }
示例#2
0
    bool ActivateAI(Amazons.Player player)
    {
        //Amazons.Move move = player.AI.YourTurn();
        //GameInstance.Board
        var OldPlayer = CurrentPlayer;

        CurrentPlayer = player;


        CallWithTimeout(ActivateCurrentPlayer, 10000);
        //ActivateCurrentPlayer();

        Amazons.Move move = CurrentMove;

        SetBoardPoint(player.Pawns[move.ID].Position, 0);   // Set old pos to empty

        if (!CheckLine(player.Pawns[move.ID].Position, move.MoveTo) ||
            !CheckLine(move.MoveTo, move.ShootTo) || move.MoveTo == move.ShootTo)
        {
            GameRunning = false;
            print("FAIL MOVE");
            EndScreen.SetActive(true);
            GameObject.Find("WinnerText").GetComponent <Text>().text = OldPlayer.AI.StudentName + " wins and " + player.AI.StudentName + " loses";
            return(false); // ACTIVE PLAYER LOSES
        }

        //player.Pawns[move.ID].Position = move.MoveTo;		// Set pawn pos to correct pos
        //SetBoardPoint(move.MoveTo, move.ID + player.ID);  // Set new pos to id
        //SetBoardPoint(move.ShootTo, -1);					// Set shoot pos to -1

        SetTile(player.Pawns[move.ID].Position, 0);         // Set previous location to 0
        player.Pawns[move.ID].Position = move.MoveTo;       // Set pawn pos to correct pos
        SetTile(move.MoveTo, player.ID + 1);                // Set new pos to id
        SetTile(move.ShootTo, -1);                          // Set shoot pos to -1

        // SET RED X
        Instantiate(RedXInst, GetVectorFromPoint(move.ShootTo) + new Vector3(0, -0.74f, 0), Quaternion.LookRotation(new Vector3(0, 1, 0)));
        Instantiate(SpearInst, GetVectorFromPoint(move.ShootTo) + new Vector3(0.09f, -0.38f, 0), Quaternion.identity);

        print("COMPLETE MOVE");
        ActivateVisualMove(player, move);
        return(true);
    }
示例#3
0
    bool ActivateAI(Amazons.Player player)
    {
        //Amazons.Move move = player.AI.YourTurn();
        //GameInstance.Board
        var OldPlayer = CurrentPlayer;
        CurrentPlayer = player;

        CallWithTimeout(ActivateCurrentPlayer, 10000);
        //ActivateCurrentPlayer();

        Amazons.Move move = CurrentMove;

        SetBoardPoint(player.Pawns[move.ID].Position, 0);   // Set old pos to empty

        if (!CheckLine(player.Pawns[move.ID].Position, move.MoveTo) ||
           !CheckLine(move.MoveTo, move.ShootTo) || move.MoveTo == move.ShootTo) {
            GameRunning = false;
            print("FAIL MOVE");
            EndScreen.SetActive (true);
            GameObject.Find ("WinnerText").GetComponent<Text>().text = OldPlayer.AI.StudentName + " wins and " + player.AI.StudentName + " loses";
            return false; // ACTIVE PLAYER LOSES
        }

        //player.Pawns[move.ID].Position = move.MoveTo;		// Set pawn pos to correct pos
        //SetBoardPoint(move.MoveTo, move.ID + player.ID); 	// Set new pos to id
        //SetBoardPoint(move.ShootTo, -1);					// Set shoot pos to -1

        SetTile(player.Pawns[move.ID].Position, 0);			// Set previous location to 0
        player.Pawns[move.ID].Position = move.MoveTo;		// Set pawn pos to correct pos
        SetTile(move.MoveTo, player.ID + 1); 	            // Set new pos to id
        SetTile(move.ShootTo, -1);					        // Set shoot pos to -1

        // SET RED X
        Instantiate(RedXInst, GetVectorFromPoint(move.ShootTo) + new Vector3(0, -0.74f, 0), Quaternion.LookRotation(new Vector3(0, 1, 0)));
        Instantiate(SpearInst, GetVectorFromPoint(move.ShootTo) + new Vector3(0.09f, -0.38f, 0), Quaternion.identity);

        print("COMPLETE MOVE");
        ActivateVisualMove(player, move);
        return true;
    }
示例#4
0
    public void StartGame()
    {
        GameObject.Destroy(GameObject.Find("Canvas"));
        NumberOfPlayers = ActiveAI.Count;

        //open map
        StreamReader sr = new StreamReader("./AI/map.txt");

        Width = Int32.Parse(sr.ReadLine());
        Height = Int32.Parse(sr.ReadLine());

        //CALCULATE OFFSET
        Vector3 offset = new Vector3((((Width - 1) * 1.1f) + 0.2f)/ 2.0f, 0, (((Height - 1) * 1.1f) + 0.2f) / 2.0f);
        //DRAW BOARD
        List<List<int>> newBoard = new List<List<int>>(Width);
        List<List<GameObject>> newTiles = new List<List<GameObject>>(Width);
        for (int x = 0; x < Width; ++x) {
            newTiles.Add(new List<GameObject>(Height));
            newBoard.Add(new List<int>(Height));
            for(int y = 0; y < Height; ++y) {
                newBoard[x].Add(0);
                newTiles[x].Add((GameObject)Instantiate(TileInst, new Vector3((x + ((x + 1) * 0.1f)),0 , (y + 1 + ((y + 1) * 0.1f))) - offset, Quaternion.LookRotation(new Vector3(0, 1, 0))));
            }
        }
        GameInstance.SetBoard(newTiles, newBoard, Width, Height);
        //ADD PLAYERS
        Amazons.Player[] players = new Amazons.Player[NumberOfPlayers];
        for (int i = 0; i < NumberOfPlayers; ++i) {
            players[i] = new Amazons.Player(i, GameInstance);
            players[i].Pawns = new List<Amazons.Pawn>();
            players[i].AI = ActiveAI[i];
            players[i].AI.Owner = players[i];
        }
           	GameInstance.SetPlayers(players);
        //BOARD GEN
        for (int i = Height - 1; i > -1; --i) {
                var j = 0;
                var tok = sr.ReadLine().Split(' ');
                foreach(var str in tok) {
                    switch(Int32.Parse(str))
                    {
                    case 9:
                        var p = new Point(j, i);
                        SetTile(p, -1);					        // Set shoot pos to -1
                        Instantiate(RedXInst, GetVectorFromPoint(p) + new Vector3(0, -0.74f, 0), Quaternion.LookRotation(new Vector3(0, 1, 0)));
                        Instantiate(SpearInst, GetVectorFromPoint(p) + new Vector3(0.09f, -0.38f, 0), Quaternion.identity);
                        break;
                    case 0:
                        break;
                    default:
                        var pos = new Point(j, i);
                        GameObject newAmazon = (GameObject)Instantiate(AmazonInst, GetVectorFromPoint(pos), Quaternion.identity);
                        SetTile(pos, Int32.Parse(str));
                    players[Int32.Parse(str) - 1].Pawns.Add (new Amazon(newAmazon, players[Int32.Parse(str) - 1].Pawns.Count, pos));
                        break;
                    }
                    j++;
            }
        }

        /*
        //ADD AMAZONS
        System.Random rand = new System.Random();
        foreach(var player in players) {
            for(int i = 0; i < NumberOfAmazons; ++i) {
                //CALCULATE POSITION
                Point pos = new Point(rand.Next(0, Width), rand.Next(0, Height));
                GameObject newAmazon = (GameObject)Instantiate(AmazonInst, GetVectorFromPoint(pos), Quaternion.identity);
                SetTile(pos, player.ID + 1);
                player.Pawns.Add (new Amazon(newAmazon, i, pos));
            }
        }*/
        foreach (var player in players) {
            print (player.Pawns.Count);
        }
        sr.Close();  // close the in stream
        GameRunning = true;
        ActivateAI(GameInstance.Players[0]);
        CurrentPlayer = GameInstance.Players[1];
    }
示例#5
0
    public void StartGame()
    {
        GameObject.Destroy(GameObject.Find("Canvas"));
        NumberOfPlayers = ActiveAI.Count;

        //open map
        StreamReader sr = new StreamReader("./AI/map.txt");

        Width  = Int32.Parse(sr.ReadLine());
        Height = Int32.Parse(sr.ReadLine());


        //CALCULATE OFFSET
        Vector3 offset = new Vector3((((Width - 1) * 1.1f) + 0.2f) / 2.0f, 0, (((Height - 1) * 1.1f) + 0.2f) / 2.0f);
        //DRAW BOARD
        List <List <int> >        newBoard = new List <List <int> >(Width);
        List <List <GameObject> > newTiles = new List <List <GameObject> >(Width);

        for (int x = 0; x < Width; ++x)
        {
            newTiles.Add(new List <GameObject>(Height));
            newBoard.Add(new List <int>(Height));
            for (int y = 0; y < Height; ++y)
            {
                newBoard[x].Add(0);
                newTiles[x].Add((GameObject)Instantiate(TileInst, new Vector3((x + ((x + 1) * 0.1f)), 0, (y + 1 + ((y + 1) * 0.1f))) - offset, Quaternion.LookRotation(new Vector3(0, 1, 0))));
            }
        }
        GameInstance.SetBoard(newTiles, newBoard, Width, Height);
        //ADD PLAYERS
        Amazons.Player[] players = new Amazons.Player[NumberOfPlayers];
        for (int i = 0; i < NumberOfPlayers; ++i)
        {
            players[i]          = new Amazons.Player(i, GameInstance);
            players[i].Pawns    = new List <Amazons.Pawn>();
            players[i].AI       = ActiveAI[i];
            players[i].AI.Owner = players[i];
        }
        GameInstance.SetPlayers(players);
        //BOARD GEN
        for (int i = Height - 1; i > -1; --i)
        {
            var j   = 0;
            var tok = sr.ReadLine().Split(' ');
            foreach (var str in tok)
            {
                switch (Int32.Parse(str))
                {
                case 9:
                    var p = new Point(j, i);
                    SetTile(p, -1);                                                                     // Set shoot pos to -1
                    Instantiate(RedXInst, GetVectorFromPoint(p) + new Vector3(0, -0.74f, 0), Quaternion.LookRotation(new Vector3(0, 1, 0)));
                    Instantiate(SpearInst, GetVectorFromPoint(p) + new Vector3(0.09f, -0.38f, 0), Quaternion.identity);
                    break;

                case 0:
                    break;

                default:
                    var        pos       = new Point(j, i);
                    GameObject newAmazon = (GameObject)Instantiate(AmazonInst, GetVectorFromPoint(pos), Quaternion.identity);
                    SetTile(pos, Int32.Parse(str));
                    players[Int32.Parse(str) - 1].Pawns.Add(new Amazon(newAmazon, players[Int32.Parse(str) - 1].Pawns.Count, pos));
                    break;
                }
                j++;
            }
        }

        /*
         * //ADD AMAZONS
         * System.Random rand = new System.Random();
         * foreach(var player in players) {
         *      for(int i = 0; i < NumberOfAmazons; ++i) {
         *              //CALCULATE POSITION
         *              Point pos = new Point(rand.Next(0, Width), rand.Next(0, Height));
         *              GameObject newAmazon = (GameObject)Instantiate(AmazonInst, GetVectorFromPoint(pos), Quaternion.identity);
         * SetTile(pos, player.ID + 1);
         *              player.Pawns.Add (new Amazon(newAmazon, i, pos));
         *      }
         * }*/
        foreach (var player in players)
        {
            print(player.Pawns.Count);
        }
        sr.Close();          // close the in stream
        GameRunning = true;
        ActivateAI(GameInstance.Players[0]);
        CurrentPlayer = GameInstance.Players[1];
    }