using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Audio; namespace Colto1 { class WordManager { Level1 parent; public Word[] words; public WordBoard wBoard; string[,] wordData = { {"bathtub", "vann"}, {"birthday", "sünnipäev"}, {"bookshop", "raamatupood"}, {"classroom", "klassiruum"}, {"game", "mäng"}, {"home", "kodu"}, {"kitchen", "köök"}, {"living room", "elutuba"}, {"love", "armastus"}, {"night", "öö"}, {"old", "vana"}, {"right", "parem"}, {"sea", "meri"}, {"shop", "pood"}, {"sun", "päike"}, {"water", "vesi"}, {"year", "aasta"} }; string[] levels = { "abstract", "animal", "colour", "food", "number", "object", "people" }; public int levelnr=0; public int wordsperlevel=6; // List w2 = new List(); public WordManager(Level1 parent) { this.parent = parent; words = new Word[] { new Word(parent, "Hello1"), new Word(parent, "Hello2"), new Word(parent, "Hello3") }; wBoard = new WordBoard(parent); //w2 = new List((IEnumerable)wordData); } public void LoadContent(ContentManager manager) { wBoard.LoadContent(manager); } public void Update() { for (int i = 0; i < words.Length; i++) { words[i].Update(); } } public void Draw(SpriteBatch batch) { for (int i = 0; i < words.Length; i++) { words[i].Draw(batch); } wBoard.Draw(batch); } public void StartFalling() { for (int i = 0; i < words.Length; i++) { words[i].position.X = parent.xs[i]; words[i].position.Y = 0; } } public void RandomWords() { List numbers = new List(); Random r=new Random(); for (int i = 0; i < 3; i++) { int nr = r.Next(wordData.GetLength(0)); while (numbers.Contains(nr)) { nr = r.Next(wordData.GetLength(0)); } numbers.Add(nr); words[i].value = wordData[nr, 1]; words[i].answer = wordData[nr, 0]; words[i].chooseRandomImage(); } wBoard.content = words[r.Next(3)].answer; } public void readWordData(string category) { IEnumerable cache=File.ReadAllLines("words.csv"). Select(line => line.Split(new char[] { ';' })). Where(m => m[0]==category). Select(m => new string[]{m[1], m[2]}); wordData = new string[cache.Count(), 2]; for (int i = 0; i < cache.Count(); i++) { wordData[i, 0] = cache.ElementAt(i)[0]; wordData[i, 1] = cache.ElementAt(i)[1]; } } public void loadNextLevel() { levelnr++; if (levelnr >= levels.GetLength(0)) { levelnr = 0; } readWordData(levels[levelnr]); wBoard.levelname = levels[levelnr]; } } }