In spanish we put a gender to the sustantives (masculine and feminine), With this we can know how to add some other terms like emotions, verbs, etc.
The words that ends with -L, -O, -N, -E, -R, -S are in general masculine, the others are feminine
Your example: La OBRA de teatro que vimos anoche fue muy divertida.
The sustantive is OBRA, it ends with A, so "Obra" is feminine, that's why we say divertidA and not divertido.
If we say, the theater is very fun, "THEATER" is masculine, so we say it this way:
El Teatro es muy divertido.