Comments + Tests

This commit is contained in:
Antoine H 2020-12-05 15:22:00 +01:00
parent 538f05aa15
commit 4355551189
5 changed files with 30 additions and 19 deletions

View file

@ -2,14 +2,16 @@
using System.Collections.Generic;
using UnityEngine;
//Define the behavior of a client
[RequireComponent(typeof(Collider2D))]
public class Client_controller : MonoBehaviour
{
public float consumeTime = 3.0f; //Time to consume currentMug
public float waitingTime = 10.0f; //Patience after ordering
GameObject currentMug = null;
GameObject currentMug = null; //Mug currently held by the client
//Return wether the object is taken from tavernkeeper
//Handle objects interactions w/ Workshop
//Return wether the object is taken from tavernkeeper
public bool use(GameObject object_used)
{
if(currentMug is null) //No mug in hand

View file

@ -3,14 +3,13 @@ using System.Collections.Generic;
using UnityEngine;
using System;
//Represents consumable : sprite and informations
public class Consumable //: MonoBehaviour
{
private HashSet<string> allowed_types = new HashSet<string>(new [] {"beer", "pression", "vodka"});
private string _type;
private string _type; //Type from allowed_types
private int _value;
private Sprite _sprite;
private Sprite _sprite; //Display details
//Read-only accessors
public string Type
@ -29,9 +28,11 @@ public class Consumable //: MonoBehaviour
// set{}
}
//Constructor
//TODO : Handle sprite = null
public Consumable(string type, int value, Sprite sprite)
{
//Test if type is an allowed type
if(!allowed_types.Contains(type))
{
throw new Exception("Invalid consumable type :"+type);

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
//Define the behavior of a mug (movable container of Consumable)
[RequireComponent(typeof(Collider2D))]
public class Mug : MonoBehaviour, IGrabable
{
@ -23,7 +24,7 @@ public class Mug : MonoBehaviour, IGrabable
gameObject.transform.position = position;
}
public void fill(Consumable new_content)
public void fill(Consumable new_content) //Fill Mug w/ new Consumable
{
if(content is null)
{
@ -34,7 +35,7 @@ public class Mug : MonoBehaviour, IGrabable
Debug.Log(gameObject.name+" cannot be filled (already full) with "+new_content.Type);
}
}
public void consume()
public void consume() //Empty Mug of its Consumable
{
content=null;
}

View file

@ -79,10 +79,15 @@ public class Tavernkeeper_controller : MonoBehaviour
rigidbody2d.MovePosition(position); //Movement processed by the phyisc engine for Collision, etc.
}
//Handle action with hands
//TODO : Factoriser actions des IGrabable et actions des Clients/Workshop
//Handle action with hands ("left" or "right")
void handAction(string hand)
{
//Test
if(!hand_container.ContainsKey(hand))
{
throw new Exception("Invalid key for hands :"+hand);
}
// Test collision of ray from tavernkeeper center (A verifier) at action_dist unit distance on Interactions layer
RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, action_dist, LayerMask.GetMask("Interactions"));
if (hit.collider != null)
@ -91,6 +96,8 @@ public class Tavernkeeper_controller : MonoBehaviour
// Debug.Log("Raycast has hit the object " + hit_object.name+ hit_object.tag);
if (hit_object != null)
{
//Handle objects interactions by tags
//TODO : Factoriser actions des IGrabable et actions des Clients/Workshop
if(hit_object.tag == "Mug")
{
if(hand_container[hand] is null) //Empty hand : try grab mug
@ -115,7 +122,6 @@ public class Tavernkeeper_controller : MonoBehaviour
if(client.use(hand_container[hand])) //Interactions w/ object in hands
{
//Object taken by client
// Destroy(hand_container[hand]);
hand_container[hand]=null;
}
}
@ -129,20 +135,19 @@ public class Tavernkeeper_controller : MonoBehaviour
if(workshop.use(hand_container[hand])) //Interactions w/ object in hands
{
//Object taken by workshop
// Destroy(hand_container[hand]);
hand_container[hand]=null;
}
}
}
else
{
Debug.Log(hit_object.tag+" tag not handled by "+gameObject.name);
}
}
}
//Full hand : drop
else if (hand_container[hand] != null)
else if (hand_container[hand] != null) //Hand full and no hits
{
// Debug.Log("Hand full with "+ hand_container[hand]);
// hand_container[hand].transform.SetParent(null);
if (hand_container[hand].tag == "Mug")
if (hand_container[hand].tag == "Mug") //Drop mug on player position
{
Mug obj = hand_container[hand].GetComponent<Mug>();
if(obj !=null)

View file

@ -2,15 +2,17 @@
using System.Collections.Generic;
using UnityEngine;
//Define the behavior of a workshop (producer of Consumable)
[RequireComponent(typeof(Collider2D))]
public class Workshop : MonoBehaviour
{
public string product_name;
public int product_value;
public Sprite product_sprite;
public float prepTime = 2.0f;
protected int _stock = 5;
public float prepTime = 2.0f; //Time for preparation of product
protected int _stock = 5; //Stock of prodcut
//Handle objects interactions w/ Workshop
//Return wether the object is taken from tavernkeeper
public bool use(GameObject object_used)
{