コード例 #1
0
ファイル: Trivia.cs プロジェクト: patrickdgr81/XNA-game
        private void readfilefortrivia()
        {
            string buffer;
            sr = new StreamReader("notepad.txt");

            buffer = sr.ReadLine();
            while (buffer != null)
            {
                string[] data = buffer.Split(',');

                string q = data[0];
                string c1 = data[1];
                string c2 = data[2];
                string c3 = data[3];
                string c4 = data[4];
                int ans = int.Parse(data[5]);
                String ANS = data[6];

                TriviaReadandWrite t = new TriviaReadandWrite(q, c1, c2, c3, c4, ans, ANS);

                questions.Add(t);
                buffer = sr.ReadLine();
                //buffer = sr.ReadLine();
            }
            sr.Close();
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: patrickdgr81/XNA-game
        protected override void Update(GameTime gameTime)
        {
            //if (p.Gold < 0)
            //{
            //    currentGameState = GameState.Dead;
            //}
            MouseState mouse = Mouse.GetState();
            switch (currentGameState)
            {
                case GameState.MainMenu:
                    if (btnPlay.isClicked == true) currentGameState = GameState.Select;
                    if (btnScores.isClicked == true) currentGameState = GameState.HighScores;
                    if (exit.isClicked == true) this.Exit();
                    btnPlay.Update(mouse);
                    btnScores.Update(mouse);
                    exit.Update(mouse);
                    break;
                case GameState.Playing:
                    UI.UpdateUI();
                    getHint.Update(mouse);
                    buyArrows.Update(mouse);
                    currentQuestion = 0;
                    response = "";
                    reason = "";
                    responded = false;
                    b = true;//for high scores
                    if (getHint.isClicked == true)
                    {
                        numbQuestions = 3;
                        reason = "Hint";
                        currentGameState = GameState.Trivia;
                        getHint.isClicked = false;
                        p.Turns++;
                    }
                    if (buyArrows.isClicked == true)
                    {
                        numbQuestions = 3;
                        reason = "Arrows";
                        currentGameState = GameState.Trivia;
                        buyArrows.isClicked = false;
                        p.Turns++;
                    }
                    if (m.player == m.wumpus)
                    {
                        reason = "Wumpus!";
                        numbQuestions = 5;
                        currentGameState = GameState.Trivia;
                    }
                    if (m.player == m.pit1 || m.player == m.pit2)
                    {
                        reason = "Pit";
                        numbQuestions = 3;
                        currentGameState = GameState.Trivia;
                    }
                    if (m.player == m.sbat1 || m.player == m.sbat1)
                    {
                        triviaHint = "Bat Attack!";
                        index++;
                        if (index > 180)
                        {

                            m.player = m.Rooms[25];
                            m.sbat1 = m.Rooms[22];
                            m.sbat2 = m.Rooms[20];
                            index = 0;
                        }
                    }

                    int newroom = m.player;
                    if (oldroom != newroom)
                    {
                        UpdateHint();
                        trw = t.getQuestion();
                        triviaHint = trw.answerHint;
                        p.Turns++;
                        p.Gold++;
                    }
                    oldroom = newroom;
                    break;
                case GameState.HighScores:
                    exit.Update(mouse);
                    menu.Update(mouse);
                    if (menu.isClicked == true)
                    {
                        currentGameState = GameState.MainMenu;
                        if (win) sc.writeFile(name, maps, p.getScore(), p.Turns, p.Gold, p.Arrows);
                    }
                    if (exit.isClicked == true)
                    {
                        if (win) sc.writeFile(name, maps, p.getScore(), p.Turns,p.Gold,p.Arrows);
                        this.Exit();
                    }
                    if (b)
                    {
                        if (win)
                        {
                            sc.addHighScore(name, maps, p.getScore());
                        }
                        highScoreObject = sc.HighScores();
                        b = false;
                    }
                    break;
                case GameState.Trivia:
                    //start.Update(mouse);
                    currentKeyboardState = Keyboard.GetState();
                    foreach (Keys key in triviaResponse)
                    {
                        if (CheckKey(key))
                        {
                            KeysToCheck(key);
                            break;
                        }
                    }
                    lastKeyboardState = currentKeyboardState;
                    break;
                case GameState.Select:
                    if (start.isClicked == true)
                    {
                        c.ReadMap(maps);
                        openDoors = c.GetRooms();
                        UI.getOpenDoors(openDoors);
                        currentGameState = GameState.Playing;
                    }
                    start.Update(mouse);
                    currentKeyboardState = Keyboard.GetState();
                    foreach (Keys key in keysToCheck)
                    {
                        if (CheckKey(key))
                        {
                            AddKeyToText(key);
                            break;
                        }
                    }
                    lastKeyboardState = currentKeyboardState;
                    break;
                case GameState.Dead:
                    win = false;
                    break;
                case GameState.Win:
                    win = true;
                    break;

            }
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: patrickdgr81/XNA-game
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Pink);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            //spriteBatch.Draw(Content.Load<Texture2D>("ocean"), new Rectangle(0, 0, GraphicsDevice.Viewport.Width
            //, GraphicsDevice.Viewport.Width), Color.White);
            switch (currentGameState)
            {
                case GameState.MainMenu:

                    spriteBatch.DrawString(font1, "Hunt the Wumpus!", new Vector2(300, 10), Color.Red);
                    btnPlay.Draw(spriteBatch);
                    btnScores.Draw(spriteBatch);
                    exit.Draw(spriteBatch);
                    break;
                case GameState.Playing:
                    UI.Draw();
                    spriteBatch.DrawString(font1, m.player.ToString(), new Vector2(330,
                        GraphicsDevice.Viewport.Height - 60), Color.Red);
                    spriteBatch.DrawString(font1, hint, new Vector2(GraphicsDevice.Viewport.Width - 222, GraphicsDevice.Viewport.Height - 73),
                        Color.Black);
                    spriteBatch.DrawString(font1, p.Gold.ToString(), new Vector2(200, GraphicsDevice.Viewport.Height - 73), Color.Black);
                    spriteBatch.DrawString(font1, p.Arrows.ToString(), new Vector2(200, GraphicsDevice.Viewport.Height - 40), Color.Black);
                    spriteBatch.DrawString(font1, p.getScore().ToString(), new Vector2(480, 420), Color.Black);
                    spriteBatch.DrawString(font1, "Turn: " + p.Turns, new Vector2(0, 0), Color.Black);
                    spriteBatch.DrawString(font1, triviaHint, new Vector2(0, 30), Color.Black);
                    spriteBatch.DrawString(font1, secret, new Vector2(250, 250), Color.Black);
                    buyArrows.Draw(spriteBatch);
                    getHint.Draw(spriteBatch);
                    break;
                case GameState.HighScores:
                    for(int x = 0; x < 10; x++)
                    {
                        HighScore highScore = highScoreObject[x];
                        spriteBatch.DrawString(font1, highScore.ToString(), new Vector2(250,30*x + 30), Color.Black);
                    }
                    exit.Draw(spriteBatch);
                    menu.Draw(spriteBatch);
                    break;
                case GameState.Trivia:
                    while (trivia)
                    {
                        trw = t.getQuestion();
                        trivia = false;
                    }
                    spriteBatch.DrawString(font1, reason, new Vector2(0, 0), Color.Black);
                    spriteBatch.DrawString(font1, triviaReason, new Vector2(0, 0), Color.Blue);
                    spriteBatch.DrawString(font1, trw.Question, new Vector2(120, 0), Color.Gray);
                    spriteBatch.DrawString(font1, trw.Choice1, new Vector2(250, 50), Color.Gray);
                    spriteBatch.DrawString(font1, trw.Choice2, new Vector2(250, 100), Color.Gray);
                    spriteBatch.DrawString(font1, trw.Choice3, new Vector2(250, 150), Color.Gray);
                    spriteBatch.DrawString(font1, trw.Choice4, new Vector2(250, 200), Color.Gray);
                    spriteBatch.DrawString(font1, response, new Vector2(250, 250), Color.Green);
                    break;
                case GameState.Select:
                    spriteBatch.DrawString(font1, "Enter Name: " + name, new Vector2(300, 10), Color.Red);
                    spriteBatch.DrawString(font1, "Map: " + maps, new Vector2(300, 50), Color.Red);
                    start.Draw(spriteBatch);
                    break;
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }