コード例 #1
0
    // public SteamVR_Input_Sources leftHand;
    // public SteamVR_Input_Sources rightHand;

    // public SteamVR_Action_Boolean leftAction;
    // public SteamVR_Action_Boolean downAction;
    // public SteamVR_Action_Boolean backwardAction;
    // public SteamVR_Action_Boolean rightAction;
    // public SteamVR_Action_Boolean forwardAction;
    // public SteamVR_Action_Boolean holdAction;
    // public SteamVR_Action_Boolean rotateX;
    // public SteamVR_Action_Boolean rotateY;
    // public SteamVR_Action_Boolean rotateZ;
    // public SteamVR_Action_Boolean rotateXNeg;
    // public SteamVR_Action_Boolean rotateYNeg;
    // public SteamVR_Action_Boolean rotateZNeg;
    // public SteamVR_Action_Vector2 trackpadLeftPosition;
    // public SteamVR_Action_Vector2 trackpadRightPosition;


    // public SteamVR_Action_Boolean leftActionJoy;
    // //public SteamVR_Action_Boolean downActionJoy;
    // public SteamVR_Action_Boolean backwardActionJoy;
    // public SteamVR_Action_Boolean rightActionJoy;
    // public SteamVR_Action_Boolean forwardActionJoy;

    // public SteamVR_Action_Boolean rotateXJoy;
    // public SteamVR_Action_Boolean rotateZJoy;
    // public SteamVR_Action_Boolean rotateZNegJoy;
    // public SteamVR_Action_Boolean rotateXNegJoy;
    // public SteamVR_Action_Vector2 leftJoyPosition;
    // public SteamVR_Action_Vector2 rightJoyPosition;


    // Use this for initialization
    void Start()
    {
        wallOff       = 4;
        hasHeldBool   = false;
        yOffset       = 5;
        randomScript  = this.gameObject.GetComponent <RandomPiece>();
        holdScript    = this.gameObject.GetComponent <HoldPiece>();
        currentSpeed  = 2.5f;
        currentScore  = 0;
        currentPieces = 0;
        allPieces     = new HashSet <PieceObject>();
        sizeDim       = 7;
        actualField   = new PieceObject[sizeDim, sizeDim + yOffset, sizeDim];
        boolField     = new bool[sizeDim, sizeDim + yOffset, sizeDim];
        shouldSpawn   = true;
        spawnTop      = new Vector3((int)Mathf.Floor(sizeDim / 2), sizeDim - 2 + yOffset, (int)Mathf.Floor(sizeDim / 2));
        setBoolFieldToAllFalse();

        InvokeRepeating("decreaseCurrentSpeed", 0f, currentDecrementRate);
        Invoke("timedDownMovement", currentSpeed);
    }
コード例 #2
0
        static void Main(string[] args)
        {
            // // initialize game state
            GameState game = new GameState(6, 8);

            game.players = new Dictionary <int, Player>();
            Dictionary <string, Lobby> lobbies = new Dictionary <string, Lobby>();

            // // printing
            Prints infoPrinter = new Prints();

            // // CHANGE - RECIEVED FROM THE FRONTEND - REPLACEMENT
            int numBots = 1;

            switch (numBots)
            {
            case 1:
                game.bot = new SingleBot();
                break;

            case 2:
                game.bot = new DoubleBot();
                break;

            case 3:
                game.bot = new TripleBot();
                break;

            default:
                game.bot = null;
                break;
            }


            List <Block> bot1Blocks  = new List <Block>();
            List <Block> bot2Blocks  = new List <Block>();
            List <Block> bot3Blocks  = new List <Block>();
            RandomPiece  randomPiece = new RandomPiece();

            // game.board.board =  new int[,]{
            //     {0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 1},
            //     {0, 0, 0, 1, 1, 1},
            //     {1, 0, 1, 1, 1, 1}
            // };

            // game.board.board = new int[,]{
            //     {0, 0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 1, 1},
            //     {0, 0, 0, 1, 0, 1, 1},
            //     {1, 0, 1, 1, 1, 1, 1},
            // };
            game.board.board = new int[, ] {
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 1, 1, 0 },
                { 0, 0, 0, 1, 0, 1, 1, 0 },
                { 0, 0, 0, 1, 1, 1, 1, 1 },
            };
            int[][] block11 = new int[][] {
                new int[] { 0, 0, 0, 0 },
                new int[] { 0, 1, 1, 0 },
                new int[] { 0, 1, 0, 0 },
                new int[] { 0, 0, 0, 0 },
            };
            int[][] block21 = new int[][] {
                new int[] { 0, 0, 0, 0 },
                new int[] { 0, 1, 0, 0 },
                new int[] { 1, 1, 0, 0 },
                new int[] { 0, 1, 0, 0 },
            };
            int[][] block31 = new int[][] {
                new int[] { 0, 0, 0, 0 },
                new int[] { 0, 1, 0, 0 },
                new int[] { 0, 1, 0, 0 },
                new int[] { 0, 1, 0, 0 },
            };
            // int[][] block11 = randomPiece.GenerateRandomPiece();
            // int[][] block21 = randomPiece.GenerateRandomPiece();
            // int[][] block31 = randomPiece.GenerateRandomPiece();
            // bot1Blocks.Add(new Block(block11, 1));
            // bot2Blocks.Add(new Block(block21, 1));
            // bot3Blocks.Add(new Block(block31, 1));
            // List<List<Block>> blocks = new List<List<Block>>();
            // blocks.Add(bot1Blocks);
            // blocks.Add(bot2Blocks);
            // blocks.Add(bot3Blocks);

            // game.bot.GetMove(game.board, blocks);
            // try {
            //     game.bot.GetMove(game.board, blocks);
            // } catch (Exception e) {
            //     Console.WriteLine("Recieved error: "  + e.Message);
            // }

            // connection and adding to the db scores
            // List<string> players = new List<string>();
            // players.Add("modified");
            // players.Add("hi");
            // players.Add(null);
            // players.Add(null);
            // ScoresInfo scoresInfo = new ScoresInfo("Team HIHIOWE", players, 1, 6000);
            // SQLConnection.AddTeamScore(scoresInfo);
            // Tuple<List<ScoresInfo>, ScoresInfo> retrievedInfo = SQLConnection.GetTopTeamsAndCurrentTeam("Team HIHIOWE");
            // Console.WriteLine("Top teams");
            // infoPrinter.PrintScoreList(retrievedInfo.Item1);
            // Console.WriteLine("Current team");
            // infoPrinter.PrintScoreInfo(retrievedInfo.Item2);


            // List<ScoresInfo> retrieved = SQLConnection.GetTopTeams();
            // infoPrinter.PrintScoreList(retrieved);


            // string teamName = "Team10";
            // int score = 100;
            // string scoreInfo = "Best achieving score: " + score;

            // PointF firstLocation = new PointF(120f, 200f);
            // PointF secondLocation = new PointF(120f, 240f);

            // Bitmap bitmap = new System.Drawing.Bitmap("canvas.png");
            // string imageFilePath = "canvas.bmp";

            // using(Graphics graphics = Graphics.FromImage(bitmap))
            // {
            //     using (Font arialFont =  new Font("Arial", 20))
            //     {
            //         graphics.DrawString(teamName, arialFont, Brushes.Red, firstLocation);
            //         int i = teamName.Length;
            //         while(i < scoreInfo.Length - 2) {
            //             graphics.DrawString(".", arialFont, Brushes.Red, new PointF((120 + teamName.Length * 8) + (10 * i), 200f));
            //             i++;
            //         }
            //         graphics.DrawString(scoreInfo, arialFont, Brushes.Blue, secondLocation);
            //     }
            // }

            // string outputFileName =imageFilePath;
            // using (MemoryStream memory = new MemoryStream())
            // {
            //     using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
            //     {
            //         bitmap.Save(memory, ImageFormat.Jpeg);
            //         byte[] bytes = memory.ToArray();
            //         fs.Write(bytes, 0, bytes.Length);
            //     }
            // }


            // string teamName = "AHHHH";
            // int score = 50;
            // string scoreInfo = "Best achieving score: " + score;

            // PointF firstLocation = new PointF(320f, 400f);
            // PointF secondLocation = new PointF(320f, 490f);

            // Bitmap b = null;
            // Bitmap bitmap;
            // if(b == null) {
            //     bitmap = new System.Drawing.Bitmap("canvas.png");
            // } else {
            //     bitmap = b;
            // }


            // using(Graphics graphics = Graphics.FromImage(bitmap))
            // {
            //     using (Font arialFont =  new Font("Arial", 50))
            //     {
            //         graphics.DrawString(teamName, arialFont, Brushes.Red, firstLocation);
            //         int i = teamName.Length;
            //         graphics.DrawString(scoreInfo, arialFont, Brushes.Blue, secondLocation);
            //     }
            // }

            // string imageFilePath = "canvas.bmp";
            // string outputFileName = imageFilePath;
            // using (MemoryStream memory = new MemoryStream())
            // {
            //     using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
            //     {
            //         bitmap.Save(memory, ImageFormat.Jpeg);
            //         byte[] bytes = memory.ToArray();
            //         fs.Write(bytes, 0, bytes.Length);
            //     }
            // }


            // Bitmap bImage = bitmap;
            // System.IO.MemoryStream ms = new MemoryStream();
            // bImage.Save(ms, ImageFormat.Jpeg);
            // byte[] byteImage = ms.ToArray();
            // var encodedImage= Convert.ToBase64String(byteImage);
            // Console.WriteLine("ENCODED IMAGE " +  encodedImage);


            // create localhost web socket server on port 5202
            var wssv = new WebSocketServer("ws://0.0.0.0:5202");

            wssv.Start();
            wssv.AddWebSocketService <LobbyManager>("/lobby", () => new LobbyManager(lobbies));
            wssv.AddWebSocketService <Play>("/play", () => new Play(lobbies));
            wssv.AddWebSocketService <ScoresManager>("/scores", () => new ScoresManager());
            wssv.AddWebSocketService <ShareManager>("/share", () => new ShareManager());
            wssv.AddWebSocketService <LegendManager>("/legend", () => new LegendManager());
            wssv.AddWebSocketService <ScoresDirectManager>("/scoresDirect", () => new ScoresDirectManager());
            GameManager gameManager = new GameManager(lobbies);

            Console.WriteLine("Starting to check for sockets");
            // start game broadcasting service
            gameManager.startGame();
            Console.ReadKey(true);
            wssv.Stop();
        }
コード例 #3
0
    public GameManager(Dictionary <string, Lobby> lobbies)
    {
        this.lobbies = lobbies;
        thread       = new Thread(stateUpdate);
        // List<Block> bot1Blocks = new List<Block>();
        // List<Block> bot2Blocks = new List<Block>();
        // List<Block> bot3Blocks = new List<Block>();

        // int[][] block11 = new int[][] {
        //     new int[] {0, 0, 1, 0},
        //     new int[] {0, 0, 1, 0},
        //     new int[] {0, 0, 1, 0},
        //     new int[] {0, 0, 1, 0},
        // };
        // int[][] block21 = new int[][] {
        //     new int[] {0, 1, 0, 0},
        //     new int[] {0, 0, 0, 0},
        //     new int[] {0, 0, 0, 0},
        //     new int[] {0, 0, 0, 0},
        // };
        // int[][] block31 = new int[][] {
        //     new int[] {0, 1, 0, 0},
        //     new int[] {0, 0, 0, 0},
        //     new int[] {0, 0, 0, 0},
        //     new int[] {0, 0, 0, 0},
        // };
        // bot1Blocks.Add(new Block(block11, 1));
        // bot2Blocks.Add(new Block(block21, 1));
        // bot3Blocks.Add(new Block(block31, 1));
        // allBlocks = new List<List<Block>>();
        // allBlocks.Add(bot1Blocks);
        // allBlocks.Add(bot2Blocks);
        // allBlocks.Add(bot3Blocks);


        List <Block> bot1Blocks = new List <Block>();
        List <Block> bot2Blocks = new List <Block>();
        List <Block> bot3Blocks = new List <Block>();

        randomPiece = new RandomPiece();

        for (int i = 0; i < 100; i++)
        {
            int[][] block11 = randomPiece.GenerateRandomPiece();
            int[][] block21 = randomPiece.GenerateRandomPiece();
            int[][] block31 = randomPiece.GenerateRandomPiece();
            bot1Blocks.Add(new Block(block11, 1));
            bot2Blocks.Add(new Block(block21, 1));
            bot3Blocks.Add(new Block(block31, 1));
        }

        allBlocks = new List <List <Block> >();
        allBlocks.Add(bot1Blocks);
        allBlocks.Add(bot2Blocks);
        allBlocks.Add(bot3Blocks);

        data = new int[][] {
            new int[] { 0, 0, 1, 0 },
            new int[] { 0, 0, 1, 0 },
            new int[] { 0, 0, 1, 0 },
            new int[] { 0, 0, 0, 0 },
        };
    }