/*
 Copyright (c) 2015 Justin White <jw@justinwhite.net>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:

 1. Redistributions of source code must retain the above copyright notice,
 this list of conditions and the following disclaimer.

 2. Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution.

 3. Neither the name of the copyright holder nor the names of its
 contributors may be used to endorse or promote products derived from this
 software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.

 */

package net.justinwhite.scoreit_p10;

import java.util.ArrayList;
import java.util.UUID;

class Game {
    private final UUID id;
    private final Integer numPlayers;
    private String g_name = "";
    private ArrayList<Player> players = new ArrayList<Player>(0);

    public Game(Integer numPlayers) {
        this.id = UUID.randomUUID();
        this.numPlayers = numPlayers;
        players.ensureCapacity(numPlayers);
        Player newPlayer;
        for (Integer i = 0; i < numPlayers; i++) {
            newPlayer = new Player();
            players.add(i, newPlayer);
            newPlayer.setName(String.format("Player %d", i + 1));
        }
    }

    public String toString() {

        return String.format("Game: %s\nUUID: %s\nPlayer count: %d\nPlayers: %s\n",
                             g_name,
                             id.toString(),
                             numPlayers,
                             players.toString()
        );
    }

    public void setName() {
        g_name = "";
        for (Player p : players) {
            g_name += p.getInitials();
        }
    }


    class Player {
        private String p_name;
        private Integer score = 0;
        private Integer phase = 1;

        public Player() {
            setName("Player X");
        }

        public Player(String _name) {
            setName(_name);
        }

        public String toString() {
            return String.format(
                    "Name: '%s', Score: %d, Phase: %d",
                    getName(),
                    getScore(),
                    getPhase()
            );
        }

        public void setName(String _name) {
            p_name = _name;
            Game.this.setName();
        }

        public String getName() {
            return p_name;
        }

        public String getInitial() {
            return p_name.substring(0, 1);
        }

        public String getInitials() {
            String names[] = p_name.split(" ");
            if (names.length > 1) {
                return String.join("", names[0].substring(0, 1), names[1].substring(0, 1));
            } else {
                return getInitial();
            }
        }

        public Integer getScore() {
            return score;
        }

        public void addScore(Integer _score) {
            score += _score;
        }

        public Integer getPhase() {
            return phase;
        }

        public void completePhase(Integer _phase) {
            phase += _phase;
        }
    }

}

@@ -1715,18 +1715,16 @@
  String 
-g_
 name = %22
@@ -2328,26 +2328,24 @@
             
-g_
 name,%0A      
@@ -2501,27 +2501,29 @@
 public void 
-set
+build
 Name() %7B%0A   
@@ -2523,26 +2523,24 @@
 ) %7B%0A        
-g_
 name = %22%22;%0A 
@@ -2589,10 +2589,8 @@
     
-g_
 name
@@ -2627,16 +2627,73 @@
 %0A    %7D%0A%0A
+    public String getName() %7B%0A        return name;%0A    %7D%0A
 %0A    cla
@@ -2727,18 +2727,16 @@
  String 
-p_
 name;%0A  
@@ -3252,18 +3252,16 @@
         
-p_
 name = _
@@ -3288,19 +3288,21 @@
 me.this.
-set
+build
 Name();%0A
@@ -3361,26 +3361,24 @@
      return 
-p_
 name;%0A      
@@ -3438,18 +3438,16 @@
  return 
-p_
 name.sub
@@ -3542,10 +3542,8 @@
 %5D = 
-p_
 name

Refactor *_name vars and let shadowing handle the conflicts.