Changeset 60


Ignore:
Timestamp:
02/23/2012 02:18:54 PM (3 years ago)
Author:
acarter
Message:

Added checking in the Match minigame.

Location:
Code/oMaE
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • Code/oMaE/oMaE/GameDriver.cs

    r59 r60  
    208208            this.otherSide = otherSide;
    209209            World3D.Visible = false;
     210            try
     211            {
     212                MiniGame temp = (MiniGame)game;
     213                if (temp.Completed)
     214                    CompleteMinigame(game);
     215            }
     216            catch (Exception)
     217            {
     218            }
    210219            return game;
    211220        }
  • Code/oMaE/oMaE/MiniGames/FractionalTraffic.cs

    r57 r60  
    113113            screen.DrawText(String.Format("{0}/{1} of the lights that are on are not red,", n2, d2), new Vector2(30, 120), TextHorizontal.LEFT, TextVertical.TOP, Color.White);
    114114            screen.DrawText(String.Format("and so that {0}/{1} of those are green!", n1, d1), new Vector2(30, 140), TextHorizontal.LEFT, TextVertical.TOP, Color.White);
    115             screen.DrawText(Sliders[0].Selected.ToString(), new Vector2(90, 50 + 300), TextHorizontal.RIGHT, TextVertical.CENTERED, new Color(217, 244, 65));
    116             screen.DrawText(Sliders[1].Selected.ToString(), new Vector2(90, 100 + 300), TextHorizontal.RIGHT, TextVertical.CENTERED, Color.Yellow);
    117             screen.DrawText(Sliders[2].Selected.ToString(), new Vector2(90, 150 + 300), TextHorizontal.RIGHT, TextVertical.CENTERED, Color.Red);
     115            screen.DrawText(Sliders[0].Selected.ToString(), new Vector2(90, 50 + 300), TextHorizontal.RIGHT, TextVertical.CENTERED, Color.Black);// new Color(217, 244, 65));
     116            screen.DrawText(Sliders[1].Selected.ToString(), new Vector2(90, 100 + 300), TextHorizontal.RIGHT, TextVertical.CENTERED, Color.Black);
     117            screen.DrawText(Sliders[2].Selected.ToString(), new Vector2(90, 150 + 300), TextHorizontal.RIGHT, TextVertical.CENTERED, Color.Black);
     118            screen.FillRectangle(new Rectangle(210, 340, 20, 20), Color.Green);
     119            screen.FillRectangle(new Rectangle(210, 390, 20, 20), Color.Green);
     120            screen.FillRectangle(new Rectangle(210, 440, 20, 20), Color.Green);
     121            screen.FillRectangle(new Rectangle(240, 390, 20, 20), Color.Yellow);
     122            screen.FillRectangle(new Rectangle(240, 440, 20, 20), Color.Yellow);
     123            screen.FillRectangle(new Rectangle(270, 440, 20, 20), Color.Red);
    118124            base.Draw(screen);
    119125        }
  • Code/oMaE/oMaE/MiniGames/Match.cs

    r58 r60  
    2020    public class Match : MiniGame
    2121    {
    22         private enum line_t { NONE, NEW, WRONG, CORRECT };
     22        private struct RadioPair { public RadioButton First, Second; public RadioPair(RadioButton first, RadioButton second) { First = first; Second = second; } }
     23        // FIXME Base off of radio buttons and not locations.
     24        private Dictionary<RadioButton, MatchImage> inputs = new Dictionary<RadioButton, MatchImage>(), outputs = new Dictionary<RadioButton, MatchImage>();
     25        private int totalLines = 6;
     26        private int validLines = 0;
     27        private int seed;
     28        private enum LINE_TYPE { NONE, NEW, WRONG, CORRECT };
    2329        RadioGroup radioGroup, matchGroup;
    2430        int[] offset = new int[]{22, 17, 0, 25, 38};
    2531        String[] energies = new String[] { "Kinetic Energy", "Electric Energy", "Chemical Energy", "Sound Energy", "Light Energy", "Thermal Energy", "Wind Energy" };
    26         Dictionary<Vector4, bool> lines = new Dictionary<Vector4, bool>();
     32        Dictionary<RadioPair, LINE_TYPE> pairs = new Dictionary<RadioPair, LINE_TYPE>();
     33
     34        public Match(int seed = 0)
     35        {
     36            this.seed = seed;
     37        }
    2738        /// <summary>
    2839        /// Initializes the match minigame.
     
    3748            matchGroup = new RadioGroup();
    3849            children.Add(matchGroup);
    39             children.Add(new MatchImage(matchGroup, new Image2D("Sprites/drum", new Rectangle(270, 70, 100, 100))));
    40             children.Add(new MatchImage(matchGroup, new Image2D("Sprites/microphone", new Rectangle(295, 190, 50, 100))));
    41             children.Add(new MatchImage(matchGroup, new Image2D("Sprites/speaker", new Rectangle(270, 310, 100, 100))));
     50            // FIXME
     51            LinkedList<String[]> possibilities = new LinkedList<String[]>();
     52            possibilities.AddLast(new String[] { "Sprites/drum", "Kinetic Energy", "Sound Energy"});
     53            possibilities.AddLast(new String[] { "Sprites/microphone", "Sound Energy", "Electric Energy" });
     54            possibilities.AddLast(new String[] { "Sprites/speaker", "Electric Energy", "Sound Energy" });
     55            possibilities.AddLast(new String[] { "Sprites/lightbulb", "Electric Energy", "Light Energy" });
     56            possibilities.AddLast(new String[] { "Sprites/windmill", "Wind Energy", "Electric Energy" });
     57            for (int i = 0; i < 3; ++i)
     58            {
     59                int index = seed % possibilities.Count;
     60                String[] temp = possibilities.ElementAt(index);
     61                possibilities.Remove(temp);
     62                int less_width = temp[0] == "Sprites/microphone" || temp[0] == "Sprites/windmill" ? 50 :
     63                                 temp[0] == "Sprites/lightbulb" ? 32 : 0;
     64                MatchImage image = new MatchImage(matchGroup, new Image2D(temp[0], new Rectangle(270 + less_width / 2, 70 + i * 120, 100 - less_width, 100)), temp[1], temp[2]);
     65                children.Add(image);
     66                inputs.Add(image.Left, image);
     67                outputs.Add(image.Right, image);
     68            }
    4269            base.Initialize();
    4370        }
     71        /// <summary>
     72        /// Updates the radio button pairs
     73        /// </summary>
    4474        public override void Update()
    4575        {
    4676            if (radioGroup.ActiveButton != null && matchGroup.ActiveButton != null)
    4777            {
    48                 Vector4 line = new Vector4(radioGroup.ActiveButton.Center.X,
    49                                            radioGroup.ActiveButton.Center.Y,
    50                                            matchGroup.ActiveButton.Center.X,
    51                                            matchGroup.ActiveButton.Center.Y);
    52                 if (!lines.ContainsKey(line))
    53                     lines.Add(line, true);
    54                 else
    55                     lines[line] = !lines[line];
     78                if((radioGroup.ActiveButton.Center.X < 250) ^ (outputs.ContainsKey(matchGroup.ActiveButton)))
     79                {
     80                    RadioPair pair = new RadioPair(radioGroup.ActiveButton, matchGroup.ActiveButton);
     81                    if (!pairs.ContainsKey(pair))
     82                        pairs.Add(pair, LINE_TYPE.NONE);
     83
     84                    if(pairs[pair] == LINE_TYPE.NONE && validLines < totalLines)
     85                    {
     86                        pairs[pair] = LINE_TYPE.NEW;
     87                        validLines++;
     88                    }
     89                    else if (pairs[pair] == LINE_TYPE.NEW)
     90                    {
     91                        pairs[pair] = LINE_TYPE.NONE;
     92                        validLines--;
     93                    }
     94                }
    5695                radioGroup.ClearActive();
    5796                matchGroup.ClearActive();
    5897            }
    5998            base.Update();
     99        }
     100        /// <summary>
     101        /// Checks for correctness
     102        /// </summary>
     103        public override bool Correct
     104        {
     105            get
     106            {
     107                if(validLines != totalLines)
     108                    return false;
     109                Dictionary<RadioPair, LINE_TYPE> copy = new Dictionary<RadioPair, LINE_TYPE>(pairs);
     110                foreach (KeyValuePair<RadioPair, LINE_TYPE> pair in pairs)
     111                {
     112                    if (pair.Value == LINE_TYPE.NEW)
     113                    {
     114                        if (inputs.ContainsKey(pair.Key.Second) && inputs[pair.Key.Second].From.Contains(pair.Key.First.Text)
     115                            || outputs.ContainsKey(pair.Key.Second) && outputs[pair.Key.Second].To.Contains(pair.Key.First.Text))
     116                        {
     117                            copy[pair.Key] = LINE_TYPE.CORRECT;
     118                        }
     119                        else
     120                        {
     121                            copy[pair.Key] = LINE_TYPE.WRONG;
     122                            validLines--;
     123                        }
     124                    }
     125                }
     126                pairs = copy;
     127                return validLines == totalLines;
     128            }
    60129        }
    61130        /// <summary>
     
    70139            if (matchGroup.ActiveButton != null)
    71140                screen.DrawLine(matchGroup.ActiveButton.Center, gameState.MousePos, Color.Black);
    72             foreach (KeyValuePair<Vector4, bool> pair in lines)
    73                 if (pair.Value)
    74                     screen.DrawLine(new Vector2(pair.Key.X, pair.Key.Y), new Vector2(pair.Key.Z, pair.Key.W), Color.White);
     141            foreach (KeyValuePair<RadioPair, LINE_TYPE> pair in pairs)
     142            {
     143                Color lineColor;
     144                switch(pair.Value)
     145                {
     146                    case LINE_TYPE.NEW:
     147                        lineColor = Color.White;
     148                        break;
     149                    case LINE_TYPE.CORRECT:
     150                        lineColor = Color.DarkGreen;
     151                        break;
     152                    case LINE_TYPE.WRONG:
     153                        lineColor = Color.Red;
     154                        break;
     155                    default:
     156                        continue;
     157                }
     158                screen.DrawLine(pair.Key.First.Center, pair.Key.Second.Center, lineColor);
     159            }
    75160            screen.DrawText("Match the images to the forms of energy that they convert", new Vector2(320, 10), TextHorizontal.CENTERED, TextVertical.TOP, Color.White);
    76161            screen.DrawText("Starts as", new Vector2(220, 60), TextHorizontal.CENTERED, TextVertical.TOP, Color.White);
    77162            screen.DrawText("and becomes", new Vector2(420, 60), TextHorizontal.CENTERED, TextVertical.TOP, Color.White);
     163            screen.DrawText(String.Format("Currently matched {0}/{1} items", validLines, totalLines), new Vector2(800, 300), TextHorizontal.CENTERED, TextVertical.TOP, Color.White);
    78164            base.Draw(screen, gameState);
    79165        }
  • Code/oMaE/oMaE/MinigameFactory.cs

    r59 r60  
    4040        public override void Initialize()
    4141        {
     42            minigames.Add(new Match(3));
     43            minigames.Add(new FractionalTraffic(1, 6, 3, 8));
    4244            minigames.Add(new Match());
    43             minigames.Add(new FractionalTraffic(1, 6, 3, 8));
    4445            minigames.Add(new FractionalTraffic(3, 4, 3, 5));
     46            minigames.Add(new Match(25));
    4547            minigames.Add(new FractionalTraffic(2, 3, 3, 8));
    4648            minigames.Add(new FractionalTraffic(5, 6, 3, 4));
     49            minigames.Add(new Match(1038));
    4750            minigames.Add(new FractionalTraffic(2, 5, 1, 4));
    4851            minigames.Add(new FractionalTraffic(1, 7, 1, 3));
     52            minigames.Add(new Match(19));
    4953            minigames.Add(new FractionalTraffic(5, 7, 3, 4));
    5054            minigames.Add(new FractionalTraffic(5, 7, 1, 3));
  • Code/oMaE/oMaE/Overworld/Objects/Door.cs

    r59 r60  
    115115        public override void Update(GameState gameState)
    116116        {
    117             if (elephantNear && gameState.Down(Keys.Space))
     117            if (elephantNear && gameState.Pressed(Keys.Space))
     118            {
     119                gameState.handle(Keys.Space);
    118120                driver.Play2DGame(DoorLock, otherSide);
     121            }
    119122            if (DoorLock.Completed)
    120123                door.Color = completed;
  • Code/oMaE/oMaE/Widgets/MatchImage.cs

    r42 r60  
    2828        public RadioButton Right;
    2929        /// <summary>
     30        /// From these energies
     31        /// </summary>
     32        public string[] From;
     33        /// <summary>
     34        /// To these energies.
     35        /// </summary>
     36        public string[] To;
     37        /// <summary>
    3038        /// Creates a new match image.
    3139        /// </summary>
    3240        /// <param name="group">The radio group of the buttons.</param>
    3341        /// <param name="image">The image to be displayed.</param>
    34         public MatchImage(RadioGroup group, Image2D image)
     42        public MatchImage(RadioGroup group, Image2D image, String From, String To)
    3543        {
    3644            this.image = image;
    3745            Left = group.addRadioButton(new Vector2(image.Location.Left - 30, image.Location.Center.Y));
    3846            Right = group.addRadioButton(new Vector2(image.Location.Right + 30, image.Location.Center.Y));
     47            this.From = new string[] { From };
     48            this.To = new string[] { To };
    3949        }
    4050        /// <summary>
  • Code/oMaE/oMaE/Widgets/RadioButton.cs

    r58 r60  
    2626        /// </summary>
    2727        private String text;
    28 
     28        public String Text { get { return text; } }
    2929        /// <summary>
    3030        /// The center of the radio button.
  • Code/oMaE/oMaEContent/oMaEContent.contentproj

    r53 r60  
    201201    </Compile>
    202202  </ItemGroup>
     203  <ItemGroup>
     204    <Compile Include="Sprites\lightbulb.png">
     205      <Name>lightbulb</Name>
     206      <Importer>TextureImporter</Importer>
     207      <Processor>TextureProcessor</Processor>
     208    </Compile>
     209    <Compile Include="Sprites\windmill.png">
     210      <Name>windmill</Name>
     211      <Importer>TextureImporter</Importer>
     212      <Processor>TextureProcessor</Processor>
     213    </Compile>
     214  </ItemGroup>
    203215  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
    204216  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset for help on using the changeset viewer.