This is an excellent question and there is nothing to be embarrassed of. The traditional approach states that the entire Torah was given to "Moses" at Sinai (Rashi beginning of chapter 25 Vayikra). But as you already pointed out, how come other commandments weren't written down only later?
The Ramban grapples with the question in his introduction to sefer Devarim. He suggests that even though Moses learnt everything at Sinai, the nation of Israel didn't receive everything at once, but was taught in the order of the Parshiyos.
Furthermore, according to Ramban some Mitzvos weren't even taught to the yotzei mitzraim (the generation that witnessed the exodus) only to their children as these Mitzvos only applied to the generation that was about to enter the land of Israel, and was irrelevant to the previous generation.
Regarding your other question when the entire Torah was written down (at Sinai or after the "forty years"). The traditional approach states it happened right before Moses's death, where at least most parts of the Torah were written down. The Ramban in his introduction to his commentary writes that according to the position of "megila megila nitnah" (Gittin 60a), when Moses came down from Mt. Sinai he wrote from the beginning of the Torah til after the Mishkan (which means the end of Shmos). The rest he finished before he died. According to the other position that "Torah chasumah nitnah" (which means the Torah was written at once), everything from beginning to end was written before he died (see Ramban Dvarim 31:9. he takes the position of "Torah chasumah nitnah" and that the entire Torah was written after forty years). But note that according to both positions (according to the Ramban's understanding) none of the narratives were written before they had occurred. This strongly suggests that the biblical narratives were written only after they had occurred. See also Rashi Shmos 24:7 regarding the sefer habris and what it contained. Rashi seems to agree with this approach.
There is no reason to say that Moses wrote down the bibilical stories prophetically before it happened. This idea is clearly stated in the Gemara (bava basra 15a), "is it possible that Moses is dead and he writes 'And Moses died there' (Dvarim 34:5), but Moses wrote until here, from here on Joshua wrote." If we assume that Moses wrote the entire Torah at Sinai and predicted stories that have not happened yet, what is the big deal with Moses writing "and Moses died there"? This is a clear indication that Moses did not write down the biblical stories before it happened but only afterwards.