/*
 * Copyright 2015 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package org.drools.games.wumpus.server.view

import org.drools.games.wumpus.Cell
import org.drools.games.wumpus.Direction
import org.drools.games.wumpus.Hero
import org.drools.games.wumpus.Gold
import org.drools.games.wumpus.Pit
import org.drools.games.wumpus.Wumpus
import org.drools.games.wumpus.Thing
import org.drools.games.wumpus.FeelBreeze
import org.drools.games.wumpus.SeeGlitter
import org.drools.games.wumpus.FeelBump
import org.drools.games.wumpus.SmellStench
import org.drools.games.wumpus.HearScream
import org.drools.games.wumpus.view.GameView
import org.drools.games.wumpus.view.GameUI

import javax.imageio.ImageIO
import java.awt.image.BufferedImage

import java.awt.Color;
import java.awt.Graphics

import javax.swing.JPanel;

function void paintSensorCell(String image, int x, int y,  GameUI gui, Graphics graphics2D) {     
     graphics2D.setColor( Color.WHITE ); // background
     graphics2D.fillRect( x, y,  100, 100);
     graphics2D.drawImage( ImageIO.read( GameView.class.getResource( image ) ), x, y,100,100, gui.getSensorPanel() );
}

function void clearSensorCell(int x, int y,  Graphics graphics2D) {     
     graphics2D.setColor( Color.WHITE ); // background
     graphics2D.fillRect( x, y,  100, 100);
}

dialect "mvel"


rule "Base Sensor" when
    $gui : GameUI( )
then
end    

rule "Feel Breeze" extends "Base Sensor" agenda-group "PaintSensor" when
    FeelBreeze()
then
    paintSensorCell("breeze.png", 0, 0, $gui, $gui.sensorPanel.graphics2D );
end

rule "Breeze Gone" extends "Base Sensor" agenda-group "PaintSensor" when
    not FeelBreeze()
then
    clearSensorCell( 0, 0, $gui.sensorPanel.graphics2D );
end

rule "Smell Stench" extends "Base Sensor" agenda-group "PaintSensor"when
    SmellStench()
then
    paintSensorCell("stench.png", 103, 0, $gui, $gui.sensorPanel.graphics2D );
end

rule "Stench Gone" extends "Base Sensor" agenda-group "PaintSensor"when
    not SmellStench()
then
    clearSensorCell( 103, 0, $gui.sensorPanel.graphics2D );
end

rule "See Glitter" extends "Base Sensor" agenda-group "PaintSensor"when
    SeeGlitter()
then
    paintSensorCell("glitter.png", 206, 0, $gui, $gui.sensorPanel.graphics2D );
end

rule "Glitter Gone" extends "Base Sensor"  agenda-group "PaintSensor" when
    not SeeGlitter()
then
    clearSensorCell( 206, 0, $gui.sensorPanel.graphics2D );
end

rule "Feel Bump" extends "Base Sensor" agenda-group "PaintSensor"when
    FeelBump()
then
    paintSensorCell("bump.png", 309, 0, $gui, $gui.sensorPanel.graphics2D );
end

rule "Bump Gone"  extends "Base Sensor" agenda-group "PaintSensor" when
    not FeelBump()
then
    clearSensorCell( 309, 0, $gui.sensorPanel.graphics2D );
end

rule "Hear Scream"  extends "Base Sensor" agenda-group "PaintSensor" when
    HearScream()
then
    paintSensorCell("scream.png", 412, 0, $gui, $gui.sensorPanel.graphics2D );
end

rule "Scream Gone"  extends "Base Sensor" agenda-group "PaintSensor" when
    not HearScream()
then
    clearSensorCell( 412, 0, $gui.sensorPanel.graphics2D );
end