コード例 #1
0
ファイル: Server.cs プロジェクト: skawafuchi/Swarch
        private void checkPlayers(Phagocyte client)
        {
            foreach (int i in clients.Keys) {
                if (clients[i].inGame && i != client.myPNum) {
                    //check to see if collision
                    if (((client.xpos - clients[i].xpos) * (client.xpos - clients[i].xpos)) + ((client.ypos - clients[i].ypos) * (client.ypos - clients[i].ypos)) <= (Math.Pow((Math.Pow(1.2, client.radius) / 2) + (Math.Pow(1.2, clients[i].radius) / 2), 2)))
                    {
                        //if the two players are the same size, reset them both
                        if (client.radius == clients[i].radius) {

                            client.resetPlayer();
                            clients[i].resetPlayer();
                            //Update scores in database.
                            //Must do this for all clients involved
                            oursqlite.updateScore(client.clientName, client.score);
                            oursqlite.updateScore(clients[i].clientName, clients[i].score);
                        }

                        else if (client.radius > clients[i].radius)
                        {
                            client.score += 10;
                            client.radius++;

                            byte[] toSend = new byte[50];
                            toSend[0] = 6;
                            toSend[1] = (byte)client.myPNum;
                            toSend[2] = (byte)client.score;
                            toSend[3] = (byte)client.radius;

                            broadcast(toSend);

                            clients[i].resetPlayer();
                            oursqlite.updateScore(client.clientName, client.score);
                            oursqlite.updateScore(clients[i].clientName, clients[i].score);
                        }
                        else {
                            byte[] toSend = new byte[50];
                            clients[i].score += 10;
                            clients[i].radius++;

                            toSend[0] = 6;
                            toSend[1] = (byte)clients[i].myPNum;
                            toSend[2] = (byte)clients[i].score;
                            toSend[3] = (byte)clients[i].radius;

                            broadcast(toSend);

                            client.resetPlayer();
                            oursqlite.updateScore(client.clientName, client.score);
                            oursqlite.updateScore(clients[i].clientName, clients[i].score);
                        }
                        oursqlite.printTable();
                    }
                }
            }
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: skawafuchi/Swarch
        //Method to check if a player hits a pellet
        //Increments player score, their radius, and broadcasts the info to all players
        private void checkPellet(Phagocyte client)
        {
            for (int i = 0; i < 5; i++) {
                if (((client.xpos - pellets[i].x)*(client.xpos - pellets[i].x)) + ((client.ypos - pellets[i].y)*(client.ypos - pellets[i].y)) <= (Math.Pow((Math.Pow(1.2,client.radius)/2)+0.5,2))){
                    client.score++;
                    client.radius++;
                    //Update client's score in database
                    oursqlite.updateScore(client.clientName, client.score);
                    oursqlite.printTable();

                    pellets[i] = new Point(randGen.Next(-2, 18), randGen.Next(-10, 10));
                    byte[] toSend = new byte[50];
                    toSend[0] = 3;
                    toSend[1] = (byte)client.myPNum;
                    toSend[2] = (byte)client.score;
                    toSend[3] = (byte)client.radius;

                    int counter = 0;
                    for (int k = 4; k <= 12; k += 2)
                    {
                        toSend[k] = (byte)(Server.pellets[k - (4 + counter)].x + 2);
                        toSend[k + 1] = (byte)(Server.pellets[k - (4 + counter)].y + 10);
                        counter++;
                    }
                    broadcast(toSend);
                }
            }
        }