private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            int numSurvivors = 0;

            for (int i = 0; i < GameIO.numPlayers; i++)
            {
                Game2 temp = (Game2)Game2Form.allPlayersAsGame2[i];
                if (temp.isEliminated <= 1)
                {
                    numSurvivors++;
                }
            }

            if (numSurvivors <= 2)
            {
                MusicalChairsFinalWinnersPage page = new MusicalChairsFinalWinnersPage();
                Game2Form win = (Game2Form)Window.GetWindow(this);
                win.Content = page;
            }
            else
            {
                MusicalChairsElectionPage page = new MusicalChairsElectionPage();
                Game2Form win = (Game2Form)Window.GetWindow(this);
                win.Content = page;
            }
        }
Exemple #2
0
        public static Boolean save(ArrayList list, int gameID)
        {
            switch (gameID)
            {
            case 0:
                for (int i = 0; i < numPlayers; i++)
                {
                    Player       temp     = (Player)list[i];
                    string       pathName = "master/" + temp.id.ToString() + ".txt";
                    StreamWriter srcFile  = new StreamWriter(pathName);
                    srcFile.WriteLine(temp.firstName);
                    srcFile.WriteLine(temp.lastName);
                    string tempBalance = (temp.balance).ToString("F");
                    srcFile.WriteLine(tempBalance);
                    srcFile.Close();
                }
                break;

            case 1:
                string       pathName1      = "game1/gamestate.txt";
                StreamWriter file1          = new StreamWriter(pathName1);
                int          totalVicPoints = 0;
                file1.WriteLine("yes");
                for (int i = 0; i < GameIO.numPlayers; i++)
                {
                    Game1 temp = (Game1)list[i];
                    totalVicPoints += temp.victoryPoints;
                    string vicPointsString = temp.victoryPoints.ToString();
                    file1.WriteLine(vicPointsString);
                }
                string totalVicPointsString = totalVicPoints.ToString();
                file1.WriteLine(totalVicPointsString);
                file1.Close();
                break;

            case 2:
                string       pathName2 = "game2/gamestate.txt";
                StreamWriter file2     = new StreamWriter(pathName2);
                file2.WriteLine("yes");
                for (int i = 0; i < GameIO.numPlayers; i++)
                {
                    Game2 temp = (Game2)list[i];
                    file2.WriteLine(temp.currentCPassID);
                    file2.WriteLine(temp.prevCPassID);
                    file2.WriteLine(temp.isEliminated.ToString());
                }
                file2.Close();
                break;

            case 3:
                break;

            default:
                return(false);
            }
            return(true);
        }
Exemple #3
0
 public Game2Form()
 {
     InitializeComponent();
     minoritygametitle.Content = "-Musical Chairs Round " + GameIO.game2Round.ToString() + "-";
     for (int i = 0; i < GameIO.numPlayers; i++)
     {
         Game2 temp = (Game2)allPlayersAsGame2[i];
         temp.didSit = false;
     }
 }
Exemple #4
0
        public static ArrayList playerToGame2()
        {
            ArrayList allPlayerAsGame2 = new ArrayList(GameIO.numPlayers);

            for (int i = 0; i < GameIO.numPlayers; i++)
            {
                Game2 member = new Game2((i + 1), -1, 0, 0, false);
                allPlayerAsGame2.Add(member);
            }
            return(allPlayerAsGame2);
        }
Exemple #5
0
        public MusicalChairsFinalWinnersPage()
        {
            InitializeComponent();

            for (int i = 0; i < GameIO.numPlayers; i++)
            {
                Game2  temp  = (Game2)allPlayersAsGame2[i];
                Player temp2 = (Player)allPlayers[i];
                if (temp.isEliminated <= 1)
                {
                    finalWinnerLabel.Content += temp2.firstName + " " + temp2.lastName + "\n";
                }
            }
        }
Exemple #6
0
        public static ArrayList load(int gameID)
        {
            string path;

            switch (gameID)
            {
            case 0:
                ArrayList allPlayers = new ArrayList();
                for (int id = 0; id < numPlayers; id++)
                {
                    path = "master/" + (id + 1).ToString() + ".txt";
                    StreamReader file0         = new StreamReader(path);
                    string       firstName     = file0.ReadLine();
                    string       lastName      = file0.ReadLine();
                    string       balanceString = file0.ReadLine();
                    double       balance       = double.Parse(balanceString);
                    balance = Math.Round(balance, 2);
                    Player ret = new Player(firstName, lastName, (id + 1), balance);
                    file0.Close();
                    allPlayers.Add(ret);
                }

                Player bank = new Player("Bank", "System", 0, 1000000000000);
                allPlayers.Add(bank);
                return(allPlayers);

            case 1:
                ArrayList allPlayersAsGame1 = new ArrayList();
                path = "game1/gamestate.txt";
                StreamReader file1 = new StreamReader(path);
                if (file1.ReadLine() == "no")
                {
                    for (int i = 0; i < GameIO.numPlayers; i++)
                    {
                        Game1 ret = new Game1((i + 1), 0, 0, false, 0);
                        allPlayersAsGame1.Add(ret);
                    }
                }
                else
                {
                    for (int i = 0; i < numPlayers; i++)
                    {
                        string vicPointsString = file1.ReadLine();
                        int    vicPoints;
                        int.TryParse(vicPointsString, out vicPoints);
                        Game1 ret = new Game1((i + 1), 0, vicPoints, false, 0);
                        allPlayersAsGame1.Add(ret);
                    }
                }
                file1.Close();
                return(allPlayersAsGame1);

            case 2:
                ArrayList allPlayersAsGame2 = new ArrayList();
                path = "game2/gamestate.txt";
                StreamReader file2 = new StreamReader(path);
                if (file2.ReadLine() == "no")
                {
                    allPlayersAsGame2 = Game2.playerToGame2();
                }
                else
                {
                    for (int i = 0; i < numPlayers; i++)
                    {
                        int    currCPID; int prevCPID; int isEliminated;
                        string currentCPassID = file2.ReadLine();
                        string prevCPassID    = file2.ReadLine();
                        string isElim         = file2.ReadLine();
                        int.TryParse(currentCPassID, out currCPID);
                        int.TryParse(prevCPassID, out prevCPID);
                        int.TryParse(isElim, out isEliminated);
                        Game2 ret = new Game2((i + 1), currCPID, prevCPID, isEliminated, false);
                        allPlayersAsGame2.Add(ret);
                    }
                }
                file2.Close();
                return(allPlayersAsGame2);

            case 3:
                break;

            default:
                return(null);
            }
            return(null);
        }
        public MusicalChairsResultsPage()
        {
            InitializeComponent();
            minoritygametitle.Content = "-Musical Chairs Round " + (GameIO.game2Round - 1).ToString() + " Results-";
            eliminatedPlayers.Content = "";
            Boolean[] affectedThisRound = new Boolean[GameIO.numPlayers];
            for (int i = 0; i < GameIO.numPlayers; i++)
            {
                affectedThisRound[i] = false;
            }
            int numLostALife    = 0;
            int numLostTwoLives = 0;

            for (int i = 0; i < GameIO.numPlayers; i++)
            {
                Game2  temp  = (Game2)Game2Form.allPlayersAsGame2[i];
                Player temp2 = (Player)allPlayers[i];
                if (temp.didSit == false)
                {
                    temp.currentCPassID  = 0;
                    temp.prevCPassID     = 0;
                    affectedThisRound[i] = true;
                    temp.isEliminated++;
                }
            }

            for (int j = 0; j < GameIO.numPlayers; j++)
            {
                Game2  temp  = (Game2)Game2Form.allPlayersAsGame2[j];
                Player temp2 = (Player)allPlayers[j];
                if (temp.isEliminated == 1 && affectedThisRound[j])
                {
                    numLostALife++;
                    eliminatedPlayers.Content += "-" + temp2.firstName + " " + temp2.lastName + "\n";
                }
            }

            if (numLostALife == 1)
            {
                eliminatedPlayers.Content += "has lost a life.\n";
            }
            else if (numLostALife > 1)
            {
                eliminatedPlayers.Content += "have each lost a life.\n";
            }

            for (int k = 0; k < GameIO.numPlayers; k++)
            {
                Game2  temp  = (Game2)Game2Form.allPlayersAsGame2[k];
                Player temp2 = (Player)allPlayers[k];
                if (temp.isEliminated == 2 && affectedThisRound[k])
                {
                    numLostTwoLives++;
                    eliminatedPlayers.Content += "-" + temp2.firstName + " " + temp2.lastName + "\n";
                }
            }

            if (numLostTwoLives == 1)
            {
                eliminatedPlayers.Content += "has been eliminated.";
            }
            else if (numLostTwoLives > 1)
            {
                eliminatedPlayers.Content += "have been eliminated.";
            }

            if (numLostALife == 0 && numLostTwoLives == 0)
            {
                eliminatedPlayers.Content += "No players have lost any lives.";
            }


            GameIO.save(Game2Form.allPlayersAsGame2, 2);
        }
Exemple #8
0
 private void seatButton_Click(object sender, RoutedEventArgs e)
 {
     if (isValidID(playerID.Text))
     {
         if (isValidCPassID(cpassID.Text))
         {
             if (cpassCode.Text != null)
             {
                 //password is correct
                 if (cpassCode.Text == cpasses[int.Parse(cpassID.Text) - 1].answer)
                 {
                     int   cpid     = int.Parse(cpassID.Text);
                     int   playerid = int.Parse(playerID.Text);
                     Game2 temp     = (Game2)allPlayersAsGame2[int.Parse(playerID.Text) - 1];
                     if (temp.isEliminated >= 2)
                     {
                         errorLabel.Content   = "";
                         successLabel.Content = "Player has already been eliminated.";
                         return;
                     }
                     //person didn't sit in this last time
                     if (cpid != temp.prevCPassID)
                     {
                         //cpass is available
                         if (cpasses[int.Parse(cpassID.Text) - 1].isAvail == true && cpasses[int.Parse(cpassID.Text) - 1].isElim == false)
                         {
                             if (temp.didSit == true)
                             {
                                 errorLabel.Content   = "Player ID:" + playerid.ToString() + " has already sat this round. ";
                                 successLabel.Content = "";
                                 return;
                             }
                             cpasses[int.Parse(cpassID.Text) - 1].isAvail = false;
                             temp.currentCPassID  = cpid;
                             temp.prevCPassID     = cpid;
                             temp.didSit          = true;
                             errorLabel.Content   = "";
                             successLabel.Content = "Player ID: " + playerid.ToString() + " sat in CPass ID: " + cpid.ToString();
                         }
                         else if (cpasses[int.Parse(cpassID.Text) - 1].isElim == true)
                         {
                             errorLabel.Content   = "CPass " + cpid.ToString() + " has been eliminated.";
                             successLabel.Content = "";
                         }
                         else
                         {
                             errorLabel.Content   = "CPass " + cpid.ToString() + " is not available this round.";
                             successLabel.Content = "";
                         }
                     }
                     else
                     {
                         errorLabel.Content   = "Player sat in this chair last round.";
                         successLabel.Content = "";
                     }
                 }
                 else
                 {
                     errorLabel.Content   = "CPass code is incorrect.";
                     successLabel.Content = "";
                 }
             }
             else
             {
                 errorLabel.Content   = "Please enter a CPass code.";
                 successLabel.Content = "";
             }
         }
         else
         {
             errorLabel.Content   = "Please enter valid CPass ID.";
             successLabel.Content = "";
         }
     }
     else
     {
         errorLabel.Content   = "Please enter valid player ID.";
         successLabel.Content = "";
     }
 }