As for playing other chords, like B major while in the key of C Major, you can almost always find a way to use any chord you want. These chords are no longer diatonic but still follow traditional tonal harmony.
* A lot of information is coming, and can be difficult to keep track of without someone being there in person to guide you through it. A good way to keep track of it is by getting some manuscript paper and writing the notes of each chord down, then labling them with the Roman Numeral analysis (like I, iii, V, and V/V).*
One way to get non-diatonic chords is through the use of secondary dominant chords. The Dominant is simply a name for the major chord build of the 5th of a tonic (In the key of C major: C is the Tonic, G is the Dominant). Now, a secondary dominant means the dominant of something that isn't the tonic. For example, a common progression is I-II-V-I (note that the ii [D, F, A] is replaced by II [D, F#, A]). The chord II is actually the dominant of V (D being the 5th note in G major). So instead of II we could also write this as V/V (five of five, or dominant of the dominant). With me?
Now, another common cadential progression is iii-II-V-I (or in our case, E minor, D major, G Major, C major). We can modify this progression with a B Major functioning as the dominant of iii (B is the fifth note in E minor). Therefore, B Major is the dominant of E minor, which is written as V/iii.
So our progression is VII-iii-II-V-I. Or, V/iii-iii-V/V-I. B major- E minor- D major- G major, C major.
Alright...I know that's a lot of information is you're not familiar with it, but tonal harmony is really fun when you get a hang of it. As a re-cap, one way of creating tonal progressions that have non-diatonic (with pitches that are not in the scale of the tonic, in our example C major) chords, is by using secondary dominant chords (which are major chords of the 5th scale degree of any chord that are not the tonic).
If you're confused, don't worry, I was too when I was learning this. Check out some on-line resources for Tonal Harmony. There are a ton of interactive lessons out there!
also look at the 8notes theory page