package org.drools.games.pong

import org.drools.games.pong.Ball
import org.drools.games.pong.Bat
import org.drools.games.pong.Player
import org.drools.games.pong.PlayerId
import org.drools.games.pong.PongGame
import org.drools.games.pong.PointWin
import org.drools.games.pong.Collision
import org.drools.games.pong.CollisionType

import java.lang.Math

import java.awt.Color
import java.awt.Graphics
import java.awt.event.KeyEvent

import java.awt.Color
import java.awt.Graphics
import java.awt.Graphics2D
import java.awt.event.KeyEvent
import java.awt.font.FontRenderContext
import java.awt.font.TextLayout
import java.awt.Font
import org.kie.internal.runtime.StatefulKnowledgeSession


global PongConfiguration pconf

dialect "mvel"


rule "PlayerOne Win" agenda-group "Game" when
    ui : PongUI( )
    ball : Ball( x >= pconf.tableWidth + width )
    player : Player( id == PlayerId.PlayerOne )

then
    ui.clearBall(ball); // deltas won't match new position, so clear now

    modify ( ball ) { x = (pconf.tableWidth/2)-(pconf.ballWidth/2), y = (pconf.tableHeight/2)-(pconf.ballWidth/2),
                      dx = 1, dy = 0, speed = pconf.ballStartingSpeed }
    modify( player ) { score = player.score + 1 };
end


rule "PlayerTwo Win" agenda-group "Game" when
    ui : PongUI( )
    ball : Ball( x <= 0 )
    player : Player( id == PlayerId.PlayerTwo )
then
    ui.clearBall(ball); // deltas won't match new position, so clear now
                     
    modify ( ball ) { x = (pconf.tableWidth/2)-(pconf.ballWidth/2), y = (pconf.tableHeight/2)-(pconf.ballWidth/2),
                     dx = -1, dy = 0, speed = pconf.ballStartingSpeed }

    modify( player ) { score = player.score + 1 };
end