<commit_before>// Denounement
// j("That mode of communication?"); j("It's imprecise, impersonal, impossible to truly connect.");

// Recap what happened.
// Who's to blame.
// All coming towards --> Break up now, or try to stay together?

// Love you, X. Love you, Y.
// IMMEDIATELY CUT TO NOW - WE BROKE UP.

function Start_Jack_2(){

	/////// SET UP SCENE ////////

	Show("background","bedroom_2");
	Show("us","bedroom_us_2");
	Show("light","bedroom_light_2",{x:0,y:159});

	PlaySound("bg","bedroom_2",{loop:-1,volume:0.5});

	if($.punched){
		Show("punch","bedroom_punch",{x:256,y:404});
	}

	/////////////////////////////

	n("やあジャック。");
	if($.sadsack){
		j("やあニッキー。まだどうしようもなく悲観的な気分かい?");
	}else{
		j("やあニッキー。");
	}
	j("親へのカミングアウトはどうだった? うまくいったろ?");

	Choose({
		"Jack... we messed up big time, Jack.": function(message){
			n(message);
			j("No... no, no.");
			j("You're kidding me, right? What happened?");
			What_Happened();
		},
		"Things could have been worse.": function(message){
			n(message);
			j("Oh. Oh no.");
			j("I didn't expect that they'd... what... what happened?");
			What_Happened();
		},
		"Shut up, Jack.": function(message){
			n(message);
			j("Ha, yes, I knew I was right!");
			n("No. Jack, we can't see each other ever again.");
			j("Wait.");
			j("No, no, no. You're kidding me, right? What happened?");
			What_Happened();
		}
	});

}

function What_Happened(){

	if($.punched){
		Choose({
			"My dad punched me in the face.": What_Happened_Abuse,
			"They're making me change schools.": What_Happened_School,
			"They read all our texts.": What_Happened_Texts
		});
	}else if($.father_oblivious==false){
		Choose({
			"My parents got verbally violent with each other.": What_Happened_Abuse,
			"They're making me change schools.": What_Happened_School,
			"They read all our texts.": What_Happened_Texts
		});
	}else{
		n("Well, my dad's oblivious. For now. But my mom...");
		if($.changing_schools){
			Choose({
				"She's making me change schools.": What_Happened_School,
				"She's setting me up with a girl I've never met.": What_Happened_Girl,
				"She read all our texts.": What_Happened_Texts,
			});
		}else{
			Choose({
				"She got a tutor to kill all my after-school hours.": What_Happened_School,
				"She's setting me up with a girl I've never met.": What_Happened_Girl,
				"She read all our texts.": What_Happened_Texts,
			});
		}
	}

}

function What_Happened_Abuse(message){
	$.told_jack = "abuse";

	n(message);
	j("Oh my god!");
	j("Nicky, you need to call Child Protective Services.");
	n("What?! No. That's way too much.");
	j("Just... okay, but at least promise me you'll visit the school counselor tomorrow?");
	n("Fine.");
	j(". . .");
	What_Happened_2();
}
function What_Happened_School(message){
	$.told_jack = "school";

	n(message);
	j("No!");
	j("Why?! Why are they doing that?");
	n("Because 'Jack and the school is a bad influence on me', or something. They just want to break us up.");
	j("That's horrible...");
	What_Happened_2();
}
function What_Happened_Girl(message){
	$.told_jack = "girl";

	n(message);
	j("Ew, seriously?");
	n("Her name's Claire Something. She'll also be tutoring me.");
	j("Ew squared, they're also hooking you up with your own tutor?");
	n("Yup.");
	What_Happened_2();
}
function What_Happened_Texts(message){
	$.told_jack = "texts";

	n(message);
	j("That is just plain rude!");
	j("Wait, what will you do with these texts right now, then?");
	n("I can hide them better. My parents aren't exactly a tech-savvy bunch.");
	j("...just plain rude.");
	What_Happened_2();
}

function What_Happened_2(){

	n("And that's just one out of three crappy things that happened.");
	j("Nicky...");
	j("I am truly, truly apologetic.");
	j("This is my fault. I urged you to come out to your parents. Stupid me.");

	Choose({
		"Yeah, stupid you.": function(message){
			$.blame = "jack";

			n(message);
			n("If you hadn't been all so 'ohhhh Nicky coming out is good for the soul' and shit, this never would have...");
			j(". . .");
			n("I'm sorry. You're the only person I can lash out on.");
			n("Isn't that just fucked up?");
			What_Now();
		},
		"No, it's THEIR fault.": function(message){
			$.blame = "parents";

			n(message);
			n("They already read our texts. Anything I would have said after that couldn't change what happened.");
			if($.told_jack!="texts"){
				j("What! You didn't tell me they also read your texts!");
			}else{
				j("And they're stuck in their old-fashioned moralities, the poor things.");
				n("I wouldn't go so far as to pity them.");
			}
			What_Now();
		},
		"No, this is all my fault.": function(message){
			$.blame = "nicky";

			n(message);
			n("I should have passcode-locked my phone, or use encrypted text, or hid it better...");
			if($.told_jack!="texts"){
				j("They read your texts, too?...");
			}
			j("Nicky, you had every right to trust them, they're your parents. They abused that trust. It's not your fault.");
			n("Yeah...");
			What_Now();
		}
	});

}

function What_Now(){

	j(". . .");

	n("You know... talking with my parents, it's like...");
	n("That mode of communication?");
	n("It's imprecise, impersonal, impossible to truly connect.");

	j(". . .");
	j("What now?");

	Choose({
		"I'm going to sabotage my parents' plans.": function(message){
			n(message);

			if($.told_jack=="texts"){
				n("I'll set up a new email and virtual phone number to talk with you.");
				n("This way they can't spy on our communications anymore.");
			}else if($.told_jack=="girl"){
				n("I'll tell Claire everything. With any luck, she'll help me fight back.");
			}else{
				n("I'll figure out a way, somehow...");
			}

			What_Now_2();
		},
		"I'll visit the school counselor tomorrow.": function(message){
			n(message);

			if($.told_jack=="abuse"){
				n("Like I promised. Like you made me promise.");
			}else if($.told_jack=="school"){
				n("My current school, that is. I don't know how soon they'll be transferring me.");
			}else{
				n("At least they'll be someone else I can lash out on.");
			}

			What_Now_2();
		},
		"I'm getting out of this house.": function(message){
			n(message);

			n("Not running away, I mean. Although if I did I could crash at your place.");
			n("But anyway. I'm going to try to get an internship or scholarship in the US.");
			n("And get far, far away from these people.");
			What_Now_2();
		}
	});

}

function What_Now_2(){

	j("No, I mean... what now, between us?");
	n("Jack...");
	j("What do we do? What... What happens?");
	n(". . .");

	Choose({
		"We have to break up.": function(message){
			$.breaking_up_soon = true;

			n(message);

			j("No, no no...");
			n("I can't do this to you, Jack. I can't pull you down with me.");
			j("At least, don't type 'we can still be friends'.");
			n("we can still be frie");
			n(". . .");
			j("Because, of course we're friends. Of course we are.");
			n(". . .");
			What_Now_3();
		},
		"We stick together as long as we can.": function(message){
			n(message);

			j(". . .");
			j("As long as we can.");
			n(". . .");
			What_Now_3();
		},
		"I don't know.": function(message){
			$.breaking_up_soon = true;

			n(message);

			j(". . .");
			What_Now_3();
		}
	});

}

function What_Now_3(){

	n("It's late.");
	n("There's a lot I need to sleep on, now.");
	j("Okay.");
	j(". . .");
	j("I love you, Nicky.");
	n("I love you too, Jack.");

	var insult = "";
	if($.hippies) insult+=" new-age hippie";
	if($.im_a_poet) insult+=" amateur poet";
	if(insult!=""){
		n("You"+insult+".");
	}else{
		n("You goof.");
	}

	The_Game_Ends();

}

function The_Game_Ends(){
	Wait(500);
	Start_Outro();
}

<commit_msg>Translation undergoing.<commit_after>// Denounement
// j("That mode of communication?"); j("It's imprecise, impersonal, impossible to truly connect.");

// Recap what happened.
// Who's to blame.
// All coming towards --> Break up now, or try to stay together?

// Love you, X. Love you, Y.
// IMMEDIATELY CUT TO NOW - WE BROKE UP.

function Start_Jack_2(){

	/////// SET UP SCENE ////////

	Show("background","bedroom_2");
	Show("us","bedroom_us_2");
	Show("light","bedroom_light_2",{x:0,y:159});

	PlaySound("bg","bedroom_2",{loop:-1,volume:0.5});

	if($.punched){
		Show("punch","bedroom_punch",{x:256,y:404});
	}

	/////////////////////////////

	n("やあジャック。");
	if($.sadsack){
		j("やあニッキー。まだどうしようもなく悲観的な気分かい?");
	}else{
		j("やあニッキー。");
	}
	j("親へのカミングアウトはどうだった? うまくいったろ?");

	Choose({
		"メチャメチャだよ、ジャック...": function(message){
			n(message);
			j("そんな... 嘘だろ。");
			j("なぁ、冗談だろ? 何があった?");
			What_Happened();
		},
		"「最悪」ってほどではなかったよ。": function(message){
			n(message);
			j("えっ、まさか。");
			j("うまく行くと思ったんだよ... 何が... 何があったの?");
			What_Happened();
		},
		"黙っててくれ、ジャック。": function(message){
			n(message);
			j("な、うまく行くと思ってたよ!");
			n("違うんだ。ジャック、君とはもう逢えなくなる。");
			j("ちょっと待て。");
			j("おいおい、嘘だろ? 何があった?");
			What_Happened();
		}
	});

}

function What_Happened(){

	if($.punched){
		Choose({
			"親父に顔をぶん殴られた。": What_Happened_Abuse,
			"親に転校させられることになった。": What_Happened_School,
			"僕らのメールを全部見られた。": What_Happened_Texts
		});
	}else if($.father_oblivious==false){
		Choose({
			"二人とも僕を口汚く罵った。": What_Happened_Abuse,
			"転校しろって言われた。": What_Happened_School,
			"僕らのメールを全部見られた。": What_Happened_Texts
		});
	}else{
		n("ああ、親父は忘れっぽいし、しばらくは平気だろう。だけど母さんは...");
		if($.changing_schools){
			Choose({
				"She's making me change schools.": What_Happened_School,
				"She's setting me up with a girl I've never met.": What_Happened_Girl,
				"She read all our texts.": What_Happened_Texts,
			});
		}else{
			Choose({
				"She got a tutor to kill all my after-school hours.": What_Happened_School,
				"She's setting me up with a girl I've never met.": What_Happened_Girl,
				"She read all our texts.": What_Happened_Texts,
			});
		}
	}

}

function What_Happened_Abuse(message){
	$.told_jack = "abuse";

	n(message);
	j("Oh my god!");
	j("Nicky, you need to call Child Protective Services.");
	n("What?! No. That's way too much.");
	j("Just... okay, but at least promise me you'll visit the school counselor tomorrow?");
	n("Fine.");
	j(". . .");
	What_Happened_2();
}
function What_Happened_School(message){
	$.told_jack = "school";

	n(message);
	j("No!");
	j("Why?! Why are they doing that?");
	n("Because 'Jack and the school is a bad influence on me', or something. They just want to break us up.");
	j("That's horrible...");
	What_Happened_2();
}
function What_Happened_Girl(message){
	$.told_jack = "girl";

	n(message);
	j("Ew, seriously?");
	n("Her name's Claire Something. She'll also be tutoring me.");
	j("Ew squared, they're also hooking you up with your own tutor?");
	n("Yup.");
	What_Happened_2();
}
function What_Happened_Texts(message){
	$.told_jack = "texts";

	n(message);
	j("That is just plain rude!");
	j("Wait, what will you do with these texts right now, then?");
	n("I can hide them better. My parents aren't exactly a tech-savvy bunch.");
	j("...just plain rude.");
	What_Happened_2();
}

function What_Happened_2(){

	n("And that's just one out of three crappy things that happened.");
	j("Nicky...");
	j("I am truly, truly apologetic.");
	j("This is my fault. I urged you to come out to your parents. Stupid me.");

	Choose({
		"Yeah, stupid you.": function(message){
			$.blame = "jack";

			n(message);
			n("If you hadn't been all so 'ohhhh Nicky coming out is good for the soul' and shit, this never would have...");
			j(". . .");
			n("I'm sorry. You're the only person I can lash out on.");
			n("Isn't that just fucked up?");
			What_Now();
		},
		"No, it's THEIR fault.": function(message){
			$.blame = "parents";

			n(message);
			n("They already read our texts. Anything I would have said after that couldn't change what happened.");
			if($.told_jack!="texts"){
				j("What! You didn't tell me they also read your texts!");
			}else{
				j("And they're stuck in their old-fashioned moralities, the poor things.");
				n("I wouldn't go so far as to pity them.");
			}
			What_Now();
		},
		"No, this is all my fault.": function(message){
			$.blame = "nicky";

			n(message);
			n("I should have passcode-locked my phone, or use encrypted text, or hid it better...");
			if($.told_jack!="texts"){
				j("They read your texts, too?...");
			}
			j("Nicky, you had every right to trust them, they're your parents. They abused that trust. It's not your fault.");
			n("Yeah...");
			What_Now();
		}
	});

}

function What_Now(){

	j(". . .");

	n("You know... talking with my parents, it's like...");
	n("That mode of communication?");
	n("It's imprecise, impersonal, impossible to truly connect.");

	j(". . .");
	j("What now?");

	Choose({
		"I'm going to sabotage my parents' plans.": function(message){
			n(message);

			if($.told_jack=="texts"){
				n("I'll set up a new email and virtual phone number to talk with you.");
				n("This way they can't spy on our communications anymore.");
			}else if($.told_jack=="girl"){
				n("I'll tell Claire everything. With any luck, she'll help me fight back.");
			}else{
				n("I'll figure out a way, somehow...");
			}

			What_Now_2();
		},
		"I'll visit the school counselor tomorrow.": function(message){
			n(message);

			if($.told_jack=="abuse"){
				n("Like I promised. Like you made me promise.");
			}else if($.told_jack=="school"){
				n("My current school, that is. I don't know how soon they'll be transferring me.");
			}else{
				n("At least they'll be someone else I can lash out on.");
			}

			What_Now_2();
		},
		"I'm getting out of this house.": function(message){
			n(message);

			n("Not running away, I mean. Although if I did I could crash at your place.");
			n("But anyway. I'm going to try to get an internship or scholarship in the US.");
			n("And get far, far away from these people.");
			What_Now_2();
		}
	});

}

function What_Now_2(){

	j("No, I mean... what now, between us?");
	n("Jack...");
	j("What do we do? What... What happens?");
	n(". . .");

	Choose({
		"We have to break up.": function(message){
			$.breaking_up_soon = true;

			n(message);

			j("No, no no...");
			n("I can't do this to you, Jack. I can't pull you down with me.");
			j("At least, don't type 'we can still be friends'.");
			n("we can still be frie");
			n(". . .");
			j("Because, of course we're friends. Of course we are.");
			n(". . .");
			What_Now_3();
		},
		"We stick together as long as we can.": function(message){
			n(message);

			j(". . .");
			j("As long as we can.");
			n(". . .");
			What_Now_3();
		},
		"I don't know.": function(message){
			$.breaking_up_soon = true;

			n(message);

			j(". . .");
			What_Now_3();
		}
	});

}

function What_Now_3(){

	n("It's late.");
	n("There's a lot I need to sleep on, now.");
	j("Okay.");
	j(". . .");
	j("I love you, Nicky.");
	n("I love you too, Jack.");

	var insult = "";
	if($.hippies) insult+=" new-age hippie";
	if($.im_a_poet) insult+=" amateur poet";
	if(insult!=""){
		n("You"+insult+".");
	}else{
		n("You goof.");
	}

	The_Game_Ends();

}

function The_Game_Ends(){
	Wait(500);
	Start_Outro();
}

<|endoftext|>


<commit_before>var GoogleMaps = (function(document) {
  'use strict';

  return function(domId, googleMapConfig) {
    var cfg = googleMapConfig || {};

    var i = 0,
      styledMapType,
      image = 'images/google-marker.png',
      places = [
        ['melbourne', new google.maps.LatLng(-37.83232752310328, 144.93427991867065)],
        ['dalian', new google.maps.LatLng(38.847000, 121.509789)]
      ];

    this.defaultPlace = cfg.defaultPlace || places[0][1];
    this.zoom = cfg.zoom || 16;

    this.addPlace = function(name, lat, lng) {
      places.push([name, new google.maps.LatLng(lat, lng)]);
    };

    this.addMarker = function(position, title) {
      title = title || 'Marker Title';

      return new google.maps.Marker({
        position: position,
        map: this.map,
        icon: image,
        animation: google.maps.Animation.DROP,
        title: title
      });
    };

    this.styles=cfg.styles || [{featureType:'water',elementType:'all',stylers:[{hue:'#e9ebed'},{saturation:-78},{lightness:67},{visibility:'simplified'}]},{featureType:'landscape',elementType:'all',stylers:[{hue:'#ffffff'},{saturation:-100},{lightness:100},{visibility:'on'}]},{featureType:'road',elementType:'geometry',stylers:[{hue:'#E7DAC0'},{saturation:-55},{lightness:53},{visibility:'on'}]},{featureType:'poi',elementType:'all',stylers:[{hue:'#E7DAC0'},{saturation:3},{lightness:22},{visibility:'on'}]},{featureType:'road.local',elementType:'all',stylers:[{hue:'#e9ebed'},{saturation:-90},{lightness:-8},{visibility:'simplified'}]},{featureType:'transit',elementType:'all',stylers:[{hue:'#FFEA81'},{saturation:100},{lightness:1},{visibility:'on'}]},{featureType:'administrative.locality',elementType:'all',stylers:[{hue:'#2c2e33'},{saturation:7},{lightness:19},{visibility:'on'}]},{featureType:'road',elementType:'labels',stylers:[{hue:'#E7DAC0'},{saturation:-55},{lightness:53},{visibility:'simplified'}]},{featureType:'road.arterial',elementType:'labels',stylers:[{hue:'#E7DAC0'},{saturation:-55},{lightness:26},{visibility:'on'}]},{featureType:'landscape.man_made',elementType:'geometry',stylers:[{hue:'#E7DAC0'},{saturation:24},{lightness:-7},{visibility:'on'}]}];

    this.map = new google.maps.Map(document.getElementById(domId), {
      mapTypeControlOptions: {
        mapTypeIds: ['Styled', google.maps.MapTypeId.SATELLITE]
      },
      center: this.defaultPlace,
      zoom: this.zoom,
      mapTypeId: 'Styled'
    });

    styledMapType = new google.maps.StyledMapType(this.styles, {
      name: 'Styled'
    });

    this.map.mapTypes.set('Styled', styledMapType);

    while(i < places.length) {
      this.addMarker(places[i][1]);
      i += 1;
    }
  };

})(document);<commit_msg>refactor<commit_after>var GoogleMaps = (function(document) {
  'use strict';

  return function(domId, googleMapConfig) {
    var cfg = googleMapConfig || {},
      styledMapType;

    this.markerImage = cfg.markerImage || 'images/google-marker.png';
    this.defaultPlace = null;
    this.zoom = cfg.zoom || 16;
    this.styles=cfg.styles || [{featureType:'water',elementType:'all',stylers:[{hue:'#e9ebed'},{saturation:-78},{lightness:67},{visibility:'simplified'}]},{featureType:'landscape',elementType:'all',stylers:[{hue:'#ffffff'},{saturation:-100},{lightness:100},{visibility:'on'}]},{featureType:'road',elementType:'geometry',stylers:[{hue:'#E7DAC0'},{saturation:-55},{lightness:53},{visibility:'on'}]},{featureType:'poi',elementType:'all',stylers:[{hue:'#E7DAC0'},{saturation:3},{lightness:22},{visibility:'on'}]},{featureType:'road.local',elementType:'all',stylers:[{hue:'#e9ebed'},{saturation:-90},{lightness:-8},{visibility:'simplified'}]},{featureType:'transit',elementType:'all',stylers:[{hue:'#FFEA81'},{saturation:100},{lightness:1},{visibility:'on'}]},{featureType:'administrative.locality',elementType:'all',stylers:[{hue:'#2c2e33'},{saturation:7},{lightness:19},{visibility:'on'}]},{featureType:'road',elementType:'labels',stylers:[{hue:'#E7DAC0'},{saturation:-55},{lightness:53},{visibility:'simplified'}]},{featureType:'road.arterial',elementType:'labels',stylers:[{hue:'#E7DAC0'},{saturation:-55},{lightness:26},{visibility:'on'}]},{featureType:'landscape.man_made',elementType:'geometry',stylers:[{hue:'#E7DAC0'},{saturation:24},{lightness:-7},{visibility:'on'}]}];
    this.markers = [];

    this.addMarker = function(pos) {
      var LatLng = new google.maps.LatLng(pos.lat, pos.lng),
        title = pos.markerTitle || 'Marker';

      this.markers.push(new google.maps.Marker({
        position: LatLng,
        icon: this.markerImage,
        animation: google.maps.Animation.DROP,
        title: title
      }));
    };

    this.gotoPlace = function(pos) {
      this.map.panTo(new google.maps.LatLng(pos.lat, pos.lng));
    };

    this.startup = function() {
      var i, j;

      // Init Markers
      i = cfg.places.length;
      if (i) {
        while(i-- > 0) {
          this.addMarker(cfg.places[i]);

          if (cfg.places[i].isDefault) {
            this.defaultPlace = cfg.places[i];
          }
        }
      }

      // Custom Map styles
      styledMapType = new google.maps.StyledMapType(this.styles, {
        name: 'Styled'
      });

      // Create Google Map
      this.map = new google.maps.Map(document.getElementById(domId), {
        mapTypeControlOptions: {
          mapTypeIds: ['Styled', google.maps.MapTypeId.SATELLITE]
        },
        center: new google.maps.LatLng(this.defaultPlace.lat,
                  this.defaultPlace.lng),
        zoom: this.zoom,
        mapTypeId: 'Styled'
      });
      this.map.mapTypes.set('Styled', styledMapType);

      // Set markers to Map'
      j = this.markers.length;
      if (j) {
        while(j-- > 0) {
          this.markers[j].setMap(this.map);
        }
      }
    };
  };

})(document);<|endoftext|>


<commit_before>      var map;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          zoom:13,
          center: new google.maps.LatLng(51.048017, 3.727666),
          mapTypeId: 'terrain'
        });

        // Create a <script> tag and set the USGS URL as the source.
        var script = document.createElement('script');
        // This example uses a local copy of the GeoJSON stored at
        // http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp
        script.src = 'js/ecoplan.geojson';
        document.getElementsByTagName('head')[0].appendChild(script);

        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
              lat: position.coords.latitude,
              lng: position.coords.longitude
            };

            var selfMarker = new google.maps.Marker({
            position: new google.maps.LatLng(pos.lat,pos.lng),
            title:"My location",
            icon:'resources/images/markers/home.png',
            map: map
            });// Create a Google Maps Marker
            selfMarker.setPosition(pos);
            map.setCenter(pos);
          }, function() {
            handleLocationError(true, infoWindow, map.getCenter());
          });
        }
      }

      // Loop through the results array and place a marker for each
      // set of coordinates.
      window.ecoplan_callback = function(results) {
        for (var i = 0; i < results.features.length; i++) {
          var coords = results.features[i].geometry.coordinates;
          var latLng = new google.maps.LatLng(coords[1],coords[0]);
          var marker = new google.maps.Marker({
            position: latLng,
            map: map,
            icon:'resources/images/markers/ecoplan.png'
          });
        }
      }<commit_msg>'update'<commit_after>      var map;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          zoom:13,
          center: new google.maps.LatLng(51.048017, 3.727666)
        });

        // Create a <script> tag and set the USGS URL as the source.
        var script = document.createElement('script');
        // This example uses a local copy of the GeoJSON stored at
        // http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp
        script.src = 'js/ecoplan.geojson';
        document.getElementsByTagName('head')[0].appendChild(script);

        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
              lat: position.coords.latitude,
              lng: position.coords.longitude
            };

            var selfMarker = new google.maps.Marker({
            position: new google.maps.LatLng(pos.lat,pos.lng),
            title:"My location",
            icon:'resources/images/markers/home.png',
            map: map
            });// Create a Google Maps Marker
            selfMarker.setPosition(pos);
            map.setCenter(pos);
          }, function() {
            handleLocationError(true, infoWindow, map.getCenter());
          });
        }
      }

      // Loop through the results array and place a marker for each
      // set of coordinates.
      window.ecoplan_callback = function(results) {
        for (var i = 0; i < results.features.length; i++) {
          var coords = results.features[i].geometry.coordinates;
          var latLng = new google.maps.LatLng(coords[1],coords[0]);
          var marker = new google.maps.Marker({
            position: latLng,
            map: map,
            icon:'resources/images/markers/ecoplan.png'
          });
        }
      }<|endoftext|>


<commit_before>'use strict';

function check_neighbor_match(position){
    var match = false;
    var next_positions = [
      [-x_scaled_half, -y_scaled,],
      [-x_scaled, 0,],
      [-x_scaled_half, y_scaled,],
      [x_scaled_half, -y_scaled,],
      [x_scaled, 0,],
      [x_scaled_half, y_scaled,],
    ];
    next_position_loop:
    for(var next_position in next_positions){
        if(position['y'] % y_scaled_double){
            next_positions[next_position][0] += x_scaled;
        }

        var new_next_position = select_hexagon(
          select_y_mod(
            position['x'] + next_positions[next_position][0],
            position['y'] + next_positions[next_position][1]
          ),
          position['y'] + next_positions[next_position][1]
        );
        for(var hexagon in hexagons){
            if(hexagons[hexagon]['x'] === new_next_position['x']
              && hexagons[hexagon]['y'] === new_next_position['y']
              && hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
                match = true;
                break next_position_loop;
            }
        }
    }

    return match;
}

function conquer_hexagon(hexagon, playerid){
    playerid = playerid || player_ids[turn];

    if(hexagons[hexagon]['color'] !== players[playerid]['color']){
        if(hexagons[hexagon]['color'] === settings_settings['default-color']){
            hexagons[hexagon]['color'] = players[playerid]['color'];
            players[playerid]['hexagons'] += 1;
            unclaimed -= 1;

        }else if(random_boolean()){
            var old_color = hexagons[hexagon]['color'];
            hexagons[hexagon]['color'] = players[playerid]['color'];
            players[playerid]['hexagons'] += 1;
            for(var player in players){
                if(old_color === players[player]['color']){
                    lose_hexagon(player);
                    break;
                }
            }
        }
    }
}

function create_hexagon(position, size){
    // Only create a hexagon if one doesn't already exist at this x,y.
    for(var hexagon in hexagons){
        if(hexagons[hexagon]['x'] === position['x']
          && hexagons[hexagon]['y'] === position['y']){
            return;
        }
    }

    hexagons.push({
      'color': settings_settings['default-color'],
      'size': size,
      'x': position['x'],
      'y': position['y'],
    });
    unclaimed = hexagons.length + 1;
}

function create_player(properties){
    properties = properties || {};
    properties = {
      'ai': properties['ai'] || false,
      'color': properties['color'] || random_hex(),
      'hexagons': 0,
      'name': '',
    };
    properties['name'] = (properties['ai']
      ? 'AI'
      : 'P')
      + properties['color'];

    players[player_count] = properties;
    player_ids.push(player_count);

    var hexagon = random_integer({
      'max': hexagons.length,
    });
    while(hexagons[hexagon]['color'] !== settings_settings['default-color']){
        hexagon = random_integer({
          'max': hexagons.length,
        });
    }
    conquer_hexagon(
      hexagon,
      player_count
    );

    player_count += 1;
}

function draw_hexagon(x, y, size, color){
    if(y % Math.floor(settings_settings['hexagon-size'] * 3.2)){
        x += x_scaled_half;
    }

    var vertices = [];
    for(var i = 0; i < 6; i++){
        var angle = math_degrees_to_radians({
          'degrees': 30 + i * 60,
        });
        vertices.push({
          'type': i === 0
            ? 'moveTo'
            : 'lineTo',
          'x': x + Math.cos(angle) * size + canvas_x,
          'y': y + Math.sin(angle) * size + canvas_y,
        });
    }
    canvas_draw_path({
      'properties': {
        'fillStyle': color,
      },
      'vertices': vertices,
    });
}

function draw_logic(){
    // Save the current buffer state.
    canvas_buffer.save();

    // Translate to camera position.
    canvas_buffer.translate(
      camera['x'],
      camera['y']
    );

    // Draw selection if not AI turn.
    if(!players[player_ids[turn]]['ai']){
        draw_hexagon(
          mouse_x,
          mouse_y,
          settings_settings['hexagon-size'] + 5,
          players[player_ids[turn]]['color']
        );
    }

    // Draw hexagons.
    for(var hexagon in hexagons){
        draw_hexagon(
          hexagons[hexagon]['x'],
          hexagons[hexagon]['y'],
          hexagons[hexagon]['size'],
          hexagons[hexagon]['color']
        );
    }

    // Restore the buffer state.
    canvas_buffer.restore();

    // Draw turn info.
    canvas_buffer.fillStyle = '#fff';
    canvas_buffer.fillText(
      'Turn #' + turns + ' ' + players[player_ids[turn]]['name'],
      0,
      25
    );

    // Draw scoreboard.
    var x = 50;
    for(var player in scoreboard){
        if(!players[scoreboard[player]['id']]){
            continue;
        }

        canvas_buffer.fillStyle = players[scoreboard[player]['id']]['color'];
        canvas_buffer.fillText(
          players[scoreboard[player]['id']]['name']  + ': ' + scoreboard[player]['hexagons'],
          0,
          x
        );
        x += 25;
    }

    // Draw winner.
    if(player_count === 1){
        canvas_buffer.fillText(
          players[player_ids[turn]]['name'] + ' wins!',
          0,
          x
        );
        x += 25;
    }

    if(unclaimed > 0){
        // Draw unclaimed hexagons.
        canvas_buffer.fillStyle = settings_settings['default-color'],
        canvas_buffer.fillText(
          'Unclaimed: ' + unclaimed,
          0,
          x
        );
    }
}

function end_turn(){
    if(turn >= player_ids.length - 1){
        turn = 0;

    }else{
        turn += 1;
    }

    turns += 1;

    if(!players[player_ids[turn]]){
        end_turn();
    }
}

function handle_ai_turn(){
    if(!players[player_ids[turn]]['ai']
      || scoreboard.length === 1){
        return;
    }

    var options = [];
    for(var hexagon in hexagons){
        if(hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
            continue;
        }

        if(check_neighbor_match({
          'x': hexagons[hexagon]['x'],
          'y': hexagons[hexagon]['y'],
        })){
            if(hexagons[hexagon]['color'] === settings_settings['default-color']){
                conquer_hexagon(hexagon);
                break;

            }else{
                options.push(hexagon);
            }
        }
    }
    if(options.length > 0){
        sort_random({
          'array': options,
        });
        scoreboard_loop:
        for(var i = scoreboard.length; i--;){
            if(!players[scoreboard[i]['id']]){
                continue;
            }

            for(var option in options){
                if(hexagons[options[option]]['color'] === players[scoreboard[i]['id']]['color']){
                    conquer_hexagon(options[option]);
                    break scoreboard_loop;
                }
            }
        }
    }

    end_turn();
}

function logic(){
    if(canvas_menu){
        return;
    }

    // Move camera down.
    if(key_down){
        camera['y'] -= settings_settings['scroll-speed'];
    }

    // Move camera left.
    if(key_left){
        camera['x'] += settings_settings['scroll-speed'];
    }

    // Move camera right.
    if(key_right){
        camera['x'] -= settings_settings['scroll-speed'];
    }

    // Move camera up.
    if(key_up){
        camera['y'] += settings_settings['scroll-speed'];
    }

    handle_ai_turn();
    update_scoreboard();
}

function lose_hexagon(player){
    players[player]['hexagons'] -= 1;
    if(players[player]['hexagons'] <= 0){
        delete players[player];
        player_count -= 1;
    }
}

function select_hexagon(x, y){
    return {
      'x': Math.ceil((x - x_scaled_half) / x_scaled) * x_scaled,
      'y': Math.ceil((y - y_scaled_half) / y_scaled) * y_scaled,
    };
}

function select_y_mod(x, y, move){
    move = move || -(x_scaled_half);

    var y_mod = Math.abs(y % y_scaled_double);
    if(y_mod > y_scaled_half
      && y_mod < y_scaled * 1.5){
        x += move;
    }

    return x;
}

function setmode_logic(newgame){
    camera = {
      'x': 0,
      'y': 0,
    };
    hexagons = [];
    player_count = 0;
    player_ids = [];
    players = {};
    scoreboard = [];
    turn = 0;
    turns = 0;
    unclaimed = 0;

    // Main menu mode.
    if(canvas_mode === 0){
        document.body.innerHTML = '

New Game

'
          + '

<input id=camera-keys maxlength=4>Camera ↑←↓→
'
          + '<input id=delete-player>Delete Player
'
          + '<input id=end-turn-key>End Turn
'
          + '<input disabled value=ESC>Menu

'
          + '
<input id=ai>AI
'
          + '<input id=default-color type=color>Default Color
'
          + '<input id=height>Height
'
          + '<input id=hexagons>Hexagons
'
          + '<input id=hexagon-size>Hexagon Size
'
          + '<input id=players>Players
'
          + '<input id=scroll-speed>Scroll Speed
'
          + '<input id=width>Width
'
          + 'Reset Settings

';
        settings_update();

    // New game mode.
    }else if(newgame){
        settings_save();

        key_down = false;
        key_left = false;
        key_right = false;
        key_up = false;

        x_scaled = settings_settings['hexagon-size'] * 1.84;
        x_scaled_half = x_scaled / 2;
        y_scaled = settings_settings['hexagon-size'] * 1.6;
        y_scaled_double = y_scaled * 2;
        y_scaled_half = y_scaled / 2;
    }
}

function update_scoreboard(){
    scoreboard = [];
    for(var player in players){
        scoreboard.push({
          'hexagons': players[player]['hexagons'],
          'id': player,
        });
    }
    sort_property({
      'array': scoreboard,
      'reverse': true,
      'property': 'hexagons',
    });
}

var camera = {};
var hexagons = [];
var key_down = false;
var key_left = false;
var key_right = false;
var key_up = false;
var mouse_x = 0;
var mouse_y = 0;
var player_count = 0;
var player_ids = [];
var players = {};
var scoreboard = [];
var turn = 0;
var turns = 0;
var unclaimed = 0;
var x_scaled = 0;
var x_scaled_half = 0;
var y_scaled = 0;
var y_scaled_double = 0;
var y_scaled_half = 0;

window.onload = function(){
    settings_init({
      'prefix': 'Hexagons-2D.htm-',
      'settings': {
        'ai': 4,
        'camera-keys': 'WASD',
        'default-color': '#ffffff',
        'delete-player': 'P',
        'end-turn-key': 'H',
        'height': 500,
        'hexagon-size': 25,
        'hexagons': 150,
        'players': 1,
        'scroll-speed': 5,
        'width': 500,
      },
    });
    canvas_init();

    window.onkeydown = function(e){
        if(canvas_mode <= 0){
            return;
        }

        var key = e.keyCode || e.which;

        // ESC: return to main menu.
        if(key === 27){
            canvas_menu_toggle();
            return;
        }

        key = String.fromCharCode(key);

        if(key === settings_settings['camera-keys'][1]){
            key_left = true;

        }else if(key === settings_settings['camera-keys'][3]){
            key_right = true;

        }else if(key === settings_settings['camera-keys'][2]){
            key_down = true;

        }else if(key === settings_settings['camera-keys'][0]){
            key_up = true;

        }else if(key === 'Q'){
            canvas_menu_quit();

        }else if(!players[player_ids[turn]]['ai']){
            if(key === settings_settings['end-turn-key']){
                end_turn();

            }else if(key === 'P'){
                if(player_count > 1){
                    for(var hexagon in hexagons){
                        if(!players[player_ids[turn]]){
                            break;
                        }
                        if(hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
                            hexagons[hexagon]['color'] = settings_settings['default-color'];
                            lose_hexagon(player_ids[turn]);
                        }
                    }
                    end_turn();
                }
            }
        }
    };

    window.onkeyup = function(e){
        var key = String.fromCharCode(e.keyCode || e.which);

        if(key === settings_settings['camera-keys'][1]){
            key_left = false;

        }else if(key === settings_settings['camera-keys'][3]){
            key_right = false;

        }else if(key === settings_settings['camera-keys'][2]){
            key_down = false;

        }else if(key === settings_settings['camera-keys'][0]){
            key_up = false;
        }
    };

    window.onmousedown = function(e){
        if(canvas_mode <= 0
          || players[player_ids[turn]]['ai']){
            return;
        }

        var position = select_hexagon(
          mouse_x,
          mouse_y
        );

        // Check if a hexagon exists at this location
        //   with a different color.
        var target = false;
        for(var hexagon in hexagons){
            if(hexagons[hexagon]['x'] === position['x']
              && hexagons[hexagon]['y'] === position['y']
              && hexagons[hexagon]['color'] !== players[player_ids[turn]]['color']){
                target = hexagon;
                break;
            }
        }
        if(target === false){
            return;
        }

        // Check if current player has a hexagon next to target hexagon.
        if(!check_neighbor_match({
          'x': hexagons[target]['x'],
          'y': hexagons[target]['y'],
        })){
            return;
        }

        // Attempt to conquer the hexagon.
        conquer_hexagon(hexagon);

        end_turn();
    };

    window.onmousemove = function(e){
        var x = e.pageX - canvas_x - camera['x'];
        var y = e.pageY - canvas_y - camera['y'];
        var position = select_hexagon(
          select_y_mod(
            x,
            y
          ),
          y
        );
        mouse_x = position['x'];
        mouse_y = position['y'];
    };
};
<commit_msg>adjusted UI<commit_after>'use strict';

function check_neighbor_match(position){
    var match = false;
    var next_positions = [
      [-x_scaled_half, -y_scaled,],
      [-x_scaled, 0,],
      [-x_scaled_half, y_scaled,],
      [x_scaled_half, -y_scaled,],
      [x_scaled, 0,],
      [x_scaled_half, y_scaled,],
    ];
    next_position_loop:
    for(var next_position in next_positions){
        if(position['y'] % y_scaled_double){
            next_positions[next_position][0] += x_scaled;
        }

        var new_next_position = select_hexagon(
          select_y_mod(
            position['x'] + next_positions[next_position][0],
            position['y'] + next_positions[next_position][1]
          ),
          position['y'] + next_positions[next_position][1]
        );
        for(var hexagon in hexagons){
            if(hexagons[hexagon]['x'] === new_next_position['x']
              && hexagons[hexagon]['y'] === new_next_position['y']
              && hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
                match = true;
                break next_position_loop;
            }
        }
    }

    return match;
}

function conquer_hexagon(hexagon, playerid){
    playerid = playerid || player_ids[turn];

    if(hexagons[hexagon]['color'] !== players[playerid]['color']){
        if(hexagons[hexagon]['color'] === settings_settings['default-color']){
            hexagons[hexagon]['color'] = players[playerid]['color'];
            players[playerid]['hexagons'] += 1;
            unclaimed -= 1;

        }else if(random_boolean()){
            var old_color = hexagons[hexagon]['color'];
            hexagons[hexagon]['color'] = players[playerid]['color'];
            players[playerid]['hexagons'] += 1;
            for(var player in players){
                if(old_color === players[player]['color']){
                    lose_hexagon(player);
                    break;
                }
            }
        }
    }
}

function create_hexagon(position, size){
    // Only create a hexagon if one doesn't already exist at this x,y.
    for(var hexagon in hexagons){
        if(hexagons[hexagon]['x'] === position['x']
          && hexagons[hexagon]['y'] === position['y']){
            return;
        }
    }

    hexagons.push({
      'color': settings_settings['default-color'],
      'size': size,
      'x': position['x'],
      'y': position['y'],
    });
    unclaimed = hexagons.length + 1;
}

function create_player(properties){
    properties = properties || {};
    properties = {
      'ai': properties['ai'] || false,
      'color': properties['color'] || random_hex(),
      'hexagons': 0,
      'name': '',
    };
    properties['name'] = (properties['ai']
      ? 'AI'
      : 'P')
      + properties['color'];

    players[player_count] = properties;
    player_ids.push(player_count);

    var hexagon = random_integer({
      'max': hexagons.length,
    });
    while(hexagons[hexagon]['color'] !== settings_settings['default-color']){
        hexagon = random_integer({
          'max': hexagons.length,
        });
    }
    conquer_hexagon(
      hexagon,
      player_count
    );

    player_count += 1;
}

function draw_hexagon(x, y, size, color){
    if(y % Math.floor(settings_settings['hexagon-size'] * 3.2)){
        x += x_scaled_half;
    }

    var vertices = [];
    for(var i = 0; i < 6; i++){
        var angle = math_degrees_to_radians({
          'degrees': 30 + i * 60,
        });
        vertices.push({
          'type': i === 0
            ? 'moveTo'
            : 'lineTo',
          'x': x + Math.cos(angle) * size + canvas_x,
          'y': y + Math.sin(angle) * size + canvas_y,
        });
    }
    canvas_draw_path({
      'properties': {
        'fillStyle': color,
      },
      'vertices': vertices,
    });
}

function draw_logic(){
    // Save the current buffer state.
    canvas_buffer.save();

    // Translate to camera position.
    canvas_buffer.translate(
      camera['x'],
      camera['y']
    );

    // Draw selection if not AI turn.
    if(!players[player_ids[turn]]['ai']){
        draw_hexagon(
          mouse_x,
          mouse_y,
          settings_settings['hexagon-size'] + 5,
          players[player_ids[turn]]['color']
        );
    }

    // Draw hexagons.
    for(var hexagon in hexagons){
        draw_hexagon(
          hexagons[hexagon]['x'],
          hexagons[hexagon]['y'],
          hexagons[hexagon]['size'],
          hexagons[hexagon]['color']
        );
    }

    // Restore the buffer state.
    canvas_buffer.restore();

    // Draw turn info.
    canvas_buffer.fillStyle = '#fff';
    canvas_buffer.fillText(
      'Turn #' + turns + ' ' + players[player_ids[turn]]['name'],
      0,
      25
    );

    var x = 50;
    if(unclaimed > 0){
        // Draw unclaimed hexagons.
        canvas_buffer.fillStyle = settings_settings['default-color'],
        canvas_buffer.fillText(
          'Unclaimed: ' + unclaimed,
          0,
          x
        );
        x += 25;
    }

    // Draw scoreboard.
    for(var player in scoreboard){
        if(!players[scoreboard[player]['id']]){
            continue;
        }

        canvas_buffer.fillStyle = players[scoreboard[player]['id']]['color'];
        canvas_buffer.fillText(
          players[scoreboard[player]['id']]['name']  + ': ' + scoreboard[player]['hexagons'],
          0,
          x
        );
        x += 25;
    }

    // Draw winner.
    if(player_count === 1){
        canvas_buffer.fillText(
          players[player_ids[turn]]['name'] + ' wins!',
          0,
          x
        );
    }
}

function end_turn(){
    if(turn >= player_ids.length - 1){
        turn = 0;

    }else{
        turn += 1;
    }

    turns += 1;

    if(!players[player_ids[turn]]){
        end_turn();
    }
}

function handle_ai_turn(){
    if(!players[player_ids[turn]]['ai']
      || scoreboard.length === 1){
        return;
    }

    var options = [];
    for(var hexagon in hexagons){
        if(hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
            continue;
        }

        if(check_neighbor_match({
          'x': hexagons[hexagon]['x'],
          'y': hexagons[hexagon]['y'],
        })){
            if(hexagons[hexagon]['color'] === settings_settings['default-color']){
                conquer_hexagon(hexagon);
                break;

            }else{
                options.push(hexagon);
            }
        }
    }
    if(options.length > 0){
        sort_random({
          'array': options,
        });
        scoreboard_loop:
        for(var i = scoreboard.length; i--;){
            if(!players[scoreboard[i]['id']]){
                continue;
            }

            for(var option in options){
                if(hexagons[options[option]]['color'] === players[scoreboard[i]['id']]['color']){
                    conquer_hexagon(options[option]);
                    break scoreboard_loop;
                }
            }
        }
    }

    end_turn();
}

function logic(){
    if(canvas_menu){
        return;
    }

    // Move camera down.
    if(key_down){
        camera['y'] -= settings_settings['scroll-speed'];
    }

    // Move camera left.
    if(key_left){
        camera['x'] += settings_settings['scroll-speed'];
    }

    // Move camera right.
    if(key_right){
        camera['x'] -= settings_settings['scroll-speed'];
    }

    // Move camera up.
    if(key_up){
        camera['y'] += settings_settings['scroll-speed'];
    }

    handle_ai_turn();
    update_scoreboard();
}

function lose_hexagon(player){
    players[player]['hexagons'] -= 1;
    if(players[player]['hexagons'] <= 0){
        delete players[player];
        player_count -= 1;
    }
}

function select_hexagon(x, y){
    return {
      'x': Math.ceil((x - x_scaled_half) / x_scaled) * x_scaled,
      'y': Math.ceil((y - y_scaled_half) / y_scaled) * y_scaled,
    };
}

function select_y_mod(x, y, move){
    move = move || -(x_scaled_half);

    var y_mod = Math.abs(y % y_scaled_double);
    if(y_mod > y_scaled_half
      && y_mod < y_scaled * 1.5){
        x += move;
    }

    return x;
}

function setmode_logic(newgame){
    camera = {
      'x': 0,
      'y': 0,
    };
    hexagons = [];
    player_count = 0;
    player_ids = [];
    players = {};
    scoreboard = [];
    turn = 0;
    turns = 0;
    unclaimed = 0;

    // Main menu mode.
    if(canvas_mode === 0){
        document.body.innerHTML = '

New Game

'
          + '

<input id=camera-keys maxlength=4>Camera ↑←↓→
'
          + '<input id=delete-player>Delete Player
'
          + '<input id=end-turn-key>End Turn
'
          + '<input disabled value=ESC>Menu

'
          + '
<input id=ai>AI
'
          + '<input id=default-color type=color>Default Color
'
          + '<input id=height>Height
'
          + '<input id=hexagons>Hexagons
'
          + '<input id=hexagon-size>Hexagon Size
'
          + '<input id=players>Players
'
          + '<input id=scroll-speed>Scroll Speed
'
          + '<input id=width>Width
'
          + 'Reset Settings

';
        settings_update();

    // New game mode.
    }else if(newgame){
        settings_save();

        key_down = false;
        key_left = false;
        key_right = false;
        key_up = false;

        x_scaled = settings_settings['hexagon-size'] * 1.84;
        x_scaled_half = x_scaled / 2;
        y_scaled = settings_settings['hexagon-size'] * 1.6;
        y_scaled_double = y_scaled * 2;
        y_scaled_half = y_scaled / 2;
    }
}

function update_scoreboard(){
    scoreboard = [];
    for(var player in players){
        scoreboard.push({
          'hexagons': players[player]['hexagons'],
          'id': player,
        });
    }
    sort_property({
      'array': scoreboard,
      'reverse': true,
      'property': 'hexagons',
    });
}

var camera = {};
var hexagons = [];
var key_down = false;
var key_left = false;
var key_right = false;
var key_up = false;
var mouse_x = 0;
var mouse_y = 0;
var player_count = 0;
var player_ids = [];
var players = {};
var scoreboard = [];
var turn = 0;
var turns = 0;
var unclaimed = 0;
var x_scaled = 0;
var x_scaled_half = 0;
var y_scaled = 0;
var y_scaled_double = 0;
var y_scaled_half = 0;

window.onload = function(){
    settings_init({
      'prefix': 'Hexagons-2D.htm-',
      'settings': {
        'ai': 4,
        'camera-keys': 'WASD',
        'default-color': '#ffffff',
        'delete-player': 'P',
        'end-turn-key': 'H',
        'height': 500,
        'hexagon-size': 25,
        'hexagons': 150,
        'players': 1,
        'scroll-speed': 5,
        'width': 500,
      },
    });
    canvas_init();

    window.onkeydown = function(e){
        if(canvas_mode <= 0){
            return;
        }

        var key = e.keyCode || e.which;

        // ESC: return to main menu.
        if(key === 27){
            canvas_menu_toggle();
            return;
        }

        key = String.fromCharCode(key);

        if(key === settings_settings['camera-keys'][1]){
            key_left = true;

        }else if(key === settings_settings['camera-keys'][3]){
            key_right = true;

        }else if(key === settings_settings['camera-keys'][2]){
            key_down = true;

        }else if(key === settings_settings['camera-keys'][0]){
            key_up = true;

        }else if(key === 'Q'){
            canvas_menu_quit();

        }else if(!players[player_ids[turn]]['ai']){
            if(key === settings_settings['end-turn-key']){
                end_turn();

            }else if(key === 'P'){
                if(player_count > 1){
                    for(var hexagon in hexagons){
                        if(!players[player_ids[turn]]){
                            break;
                        }
                        if(hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
                            hexagons[hexagon]['color'] = settings_settings['default-color'];
                            lose_hexagon(player_ids[turn]);
                        }
                    }
                    end_turn();
                }
            }
        }
    };

    window.onkeyup = function(e){
        var key = String.fromCharCode(e.keyCode || e.which);

        if(key === settings_settings['camera-keys'][1]){
            key_left = false;

        }else if(key === settings_settings['camera-keys'][3]){
            key_right = false;

        }else if(key === settings_settings['camera-keys'][2]){
            key_down = false;

        }else if(key === settings_settings['camera-keys'][0]){
            key_up = false;
        }
    };

    window.onmousedown = function(e){
        if(canvas_mode <= 0
          || players[player_ids[turn]]['ai']){
            return;
        }

        var position = select_hexagon(
          mouse_x,
          mouse_y
        );

        // Check if a hexagon exists at this location
        //   with a different color.
        var target = false;
        for(var hexagon in hexagons){
            if(hexagons[hexagon]['x'] === position['x']
              && hexagons[hexagon]['y'] === position['y']
              && hexagons[hexagon]['color'] !== players[player_ids[turn]]['color']){
                target = hexagon;
                break;
            }
        }
        if(target === false){
            return;
        }

        // Check if current player has a hexagon next to target hexagon.
        if(!check_neighbor_match({
          'x': hexagons[target]['x'],
          'y': hexagons[target]['y'],
        })){
            return;
        }

        // Attempt to conquer the hexagon.
        conquer_hexagon(hexagon);

        end_turn();
    };

    window.onmousemove = function(e){
        var x = e.pageX - canvas_x - camera['x'];
        var y = e.pageY - canvas_y - camera['y'];
        var position = select_hexagon(
          select_y_mod(
            x,
            y
          ),
          y
        );
        mouse_x = position['x'];
        mouse_y = position['y'];
    };
};
<|endoftext|>


<commit_before>'use strict';

function check_neighbor_match(position){
    var match = false;
    var next_positions = [
      [-23, -40,],
      [-46, 0,],
      [-23, 40,],
      [23, -40,],
      [46, 0,],
      [23, 40,],
    ];
    next_position_loop:
    for(var next_position in next_positions){
        if(position['y'] % 80){
            next_positions[next_position][0] += 46;
        }

        var new_next_position = select_hexagon(
          select_y_mod(
            position['x'] + next_positions[next_position][0],
            position['y'] + next_positions[next_position][1]
          ),
          position['y'] + next_positions[next_position][1]
        );
        for(var hexagon in hexagons){
            if(hexagons[hexagon]['x'] === new_next_position['x']
              && hexagons[hexagon]['y'] === new_next_position['y']
              && hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
                match = true;
                break next_position_loop;
            }
        }
    }

    return match;
}

function conquer_hexagon(hexagon){
    if(hexagons[hexagon]['color'] !== players[player_ids[turn]]['color']){
        if(hexagons[hexagon]['color'] === settings_settings['default-color']
          || random_boolean()){
            var old_color = hexagons[hexagon]['color'];
            hexagons[hexagon]['color'] = players[player_ids[turn]]['color'];
            players[player_ids[turn]]['hexagons'] += 1;
            for(var player in players){
                if(old_color === players[player]['color']){
                    lose_hexagon(player);
                    break;
                }
            }
        }
    }
}

function create_hexagon(position, size){
    // Only create a hexagon if one doesn't already exist at this x,y.
    for(var hexagon in hexagons){
        if(hexagons[hexagon]['x'] === position['x']
          && hexagons[hexagon]['y'] === position['y']){
            return;
        }
    }

    hexagons.push({
      'color': settings_settings['default-color'],
      'size': size,
      'x': position['x'],
      'y': position['y'],
    });
}

function create_player(properties){
    properties = properties || {};
    properties = {
      'ai': properties['ai'] || false,
      'color': properties['color'] || random_hex(),
      'hexagons': 1,
      'name': '',
    };

    var hexagon = random_integer({
      'max': hexagons.length,
    });
    while(hexagons[hexagon]['color'] !== settings_settings['default-color']){
        hexagon = random_integer({
          'max': hexagons.length,
        });
    }
    hexagons[hexagon]['color'] = properties['color'];

    player_ids.push(player_count);
    properties['name'] = (properties['ai']
      ? 'AI'
      : 'P')
      + player_count;
    players[player_count] = properties;
    player_count += 1;
}

function draw_hexagon(x, y, size, color){
    if(y % 80){
        x += 23;
    }

    var vertices = [];
    for(var i = 0; i < 6; i++){
        var angle = math_degrees_to_radians({
          'degrees': 30 + i * 60,
        });
        vertices.push({
          'type': i === 0
            ? 'moveTo'
            : 'lineTo',
          'x': x + Math.cos(angle) * size + canvas_x,
          'y': y + Math.sin(angle) * size + canvas_y,
        });
    }
    canvas_draw_path(
      vertices,
      {
        'fillStyle': color,
      }
    );
}

function draw_logic(){
    // Save the current buffer state.
    canvas_buffer.save();

    // Translate to camera position.
    canvas_buffer.translate(
      camera['x'],
      camera['y']
    );

    // Draw selection if not AI turn.
    if(!players[player_ids[turn]]['ai']){
        draw_hexagon(
          mouse_x,
          mouse_y,
          30,
          players[player_ids[turn]]['color']
        );
    }

    // Draw hexagons.
    for(var hexagon in hexagons){
        draw_hexagon(
          hexagons[hexagon]['x'],
          hexagons[hexagon]['y'],
          hexagons[hexagon]['size'],
          hexagons[hexagon]['color']
        );
    }

    // Restore the buffer state.
    canvas_buffer.restore();

    // Draw turn info.
    canvas_buffer.fillStyle = '#fff';
    canvas_buffer.fillText(
      'Turn #' + turns + ' ' + players[player_ids[turn]]['name'],
      0,
      25
    );

    if(player_count === 1){
        canvas_buffer.fillText(
          players[player_ids[turn]]['name'] + ' wins!',
          0,
          75
        );
    }

    var x = 50;
    for(var player in scoreboard){
        if(!players[scoreboard[player]['id']]){
            continue;
        }

        canvas_buffer.fillStyle = players[scoreboard[player]['id']]['color'];
        canvas_buffer.fillText(
          players[scoreboard[player]['id']]['name']  + ': ' + scoreboard[player]['hexagons'],
          0,
          x
        );
        x += 25;
    }
}

function end_turn(){
    if(turn >= player_ids.length - 1){
        turn = 0;

    }else{
        turn += 1;
    }

    turns += 1;

    if(!players[player_ids[turn]]){
        end_turn();
    }
}

function handle_ai_turn(){
    if(!players[player_ids[turn]]['ai']
      || scoreboard.length === 1){
        return;
    }

    var options = [];
    for(var hexagon in hexagons){
        if(hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
            continue;
        }

        if(check_neighbor_match({
          'x': hexagons[hexagon]['x'],
          'y': hexagons[hexagon]['y'],
        })){
            if(hexagons[hexagon]['color'] === settings_settings['default-color']){
                conquer_hexagon(hexagon);
                break;

            }else{
                options.push(hexagon);
            }
        }
    }
    if(options.length > 0){
        sort_random({
          'array': options,
        });
        scoreboard_loop:
        for(var i = scoreboard.length; i--;){
            if(!players[scoreboard[i]['id']]){
                continue;
            }

            for(var option in options){
                if(hexagons[options[option]]['color'] === players[scoreboard[i]['id']]['color']){
                    conquer_hexagon(options[option]);
                    break scoreboard_loop;
                }
            }
        }
    }

    end_turn();
}

function logic(){
    if(canvas_menu){
        return;
    }

    // Move camera down.
    if(key_down){
        camera['y'] -= settings_settings['scroll-speed'];
    }

    // Move camera left.
    if(key_left){
        camera['x'] += settings_settings['scroll-speed'];
    }

    // Move camera right.
    if(key_right){
        camera['x'] -= settings_settings['scroll-speed'];
    }

    // Move camera up.
    if(key_up){
        camera['y'] += settings_settings['scroll-speed'];
    }

    handle_ai_turn();
    update_scoreboard();
}

function lose_hexagon(player){
    players[player]['hexagons'] -= 1;
    if(players[player]['hexagons'] <= 0){
        delete players[player];
        player_count -= 1;
    }
}

function select_hexagon(x, y){
    return {
      'x': Math.ceil((x - 23) / 46) * 46,
      'y': Math.ceil((y - 20) / 40) * 40,
    };
}

function select_y_mod(x, y, move){
    move = move || -23;

    var y_mod = Math.abs(y % 80);
    if(y_mod > 20
      && y_mod < 60){
        x += move;
    }

    return x;
}

function setmode_logic(newgame){
    camera = {
      'x': 0,
      'y': 0,
    };
    hexagons = [];
    player_count = 0;
    player_ids = [];
    players = {};
    scoreboard = [];
    turn = 0;
    turns = 0;

    // Main menu mode.
    if(canvas_mode === 0){
        document.body.innerHTML = '

New Game

'
          + '

<input id=camera-keys maxlength=4>Camera ↑←↓→
'
          + '<input id=delete-player>Delete Player
'
          + '<input id=end-turn-key>End Turn
'
          + '<input disabled value=ESC>Menu

'
          + '
<input id=ai>AI
'
          + '<input id=default-color type=color>Default Color
'
          + '<input id=height>Height
'
          + '<input id=hexagons>Hexagons
'
          + '<input id=players>Players
'
          + '<input id=scroll-speed>Scroll Speed
'
          + '<input id=width>Width
'
          + 'Reset Settings

';
        settings_update();

    // New game mode.
    }else if(newgame){
        settings_save();

        key_down = false;
        key_left = false;
        key_right = false;
        key_up = false;
    }
}

function update_scoreboard(){
    scoreboard = [];
    for(var player in players){
        scoreboard.push({
          'hexagons': players[player]['hexagons'],
          'id': player,
        });
    }
    sort_property({
      'array': scoreboard,
      'reverse': true,
      'property': 'hexagons',
    });
}

var camera = {};
var hexagons = [];
var key_down = false;
var key_left = false;
var key_right = false;
var key_up = false;
var mouse_x = 0;
var mouse_y = 0;
var player_count = 0;
var player_ids = [];
var players = {};
var scoreboard = [];
var turn = 0;
var turns = 0;

window.onload = function(){
    settings_init({
      'prefix': 'Hexagons-2D.htm-',
      'settings': {
        'ai': 4,
        'camera-keys': 'WASD',
        'default-color': '#ffffff',
        'delete-player': 'P',
        'end-turn-key': 'H',
        'height': 500,
        'hexagons': 100,
        'players': 1,
        'scroll-speed': 5,
        'width': 500,
      },
    });
    canvas_init();

    window.onkeydown = function(e){
        if(canvas_mode <= 0){
            return;
        }

        var key = e.keyCode || e.which;

        // ESC: return to main menu.
        if(key === 27){
            canvas_menu_toggle();
            return;
        }

        key = String.fromCharCode(key);

        if(key === settings_settings['camera-keys'][1]){
            key_left = true;

        }else if(key === settings_settings['camera-keys'][3]){
            key_right = true;

        }else if(key === settings_settings['camera-keys'][2]){
            key_down = true;

        }else if(key === settings_settings['camera-keys'][0]){
            key_up = true;

        }else if(key === 'Q'){
            canvas_menu_quit();

        }else if(!players[player_ids[turn]]['ai']){
            if(key === settings_settings['end-turn-key']){
                end_turn();

            }else if(key === 'P'){
                if(player_count > 1){
                    for(var hexagon in hexagons){
                        if(!players[player_ids[turn]]){
                            break;
                        }
                        if(hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
                            hexagons[hexagon]['color'] = settings_settings['default-color'];
                            lose_hexagon(player_ids[turn]);
                        }
                    }
                    end_turn();
                }
            }
        }
    };

    window.onkeyup = function(e){
        var key = String.fromCharCode(e.keyCode || e.which);

        if(key === settings_settings['camera-keys'][1]){
            key_left = false;

        }else if(key === settings_settings['camera-keys'][3]){
            key_right = false;

        }else if(key === settings_settings['camera-keys'][2]){
            key_down = false;

        }else if(key === settings_settings['camera-keys'][0]){
            key_up = false;
        }
    };

    window.onmousedown = function(e){
        if(canvas_mode <= 0
          || players[player_ids[turn]]['ai']){
            return;
        }

        var position = select_hexagon(
          mouse_x,
          mouse_y
        );

        // Check if a hexagon exists at this location
        //   with a different color.
        var target = false;
        for(var hexagon in hexagons){
            if(hexagons[hexagon]['x'] === position['x']
              && hexagons[hexagon]['y'] === position['y']
              && hexagons[hexagon]['color'] !== players[player_ids[turn]]['color']){
                target = hexagon;
                break;
            }
        }
        if(target === false){
            return;
        }

        // Check if current player has a hexagon next to target hexagon.
        if(!check_neighbor_match({
          'x': hexagons[target]['x'],
          'y': hexagons[target]['y'],
        })){
            return;
        }

        // Attempt to conquer the hexagon.
        conquer_hexagon(hexagon);

        end_turn();
    };

    window.onmousemove = function(e){
        var x = e.pageX - canvas_x - camera['x'];
        var y = e.pageY - canvas_y - camera['y'];
        var position = select_hexagon(
          select_y_mod(
            x,
            y
          ),
          y
        );
        mouse_x = position['x'];
        mouse_y = position['y'];
    };
};
<commit_msg>switched canvas.js to args<commit_after>'use strict';

function check_neighbor_match(position){
    var match = false;
    var next_positions = [
      [-23, -40,],
      [-46, 0,],
      [-23, 40,],
      [23, -40,],
      [46, 0,],
      [23, 40,],
    ];
    next_position_loop:
    for(var next_position in next_positions){
        if(position['y'] % 80){
            next_positions[next_position][0] += 46;
        }

        var new_next_position = select_hexagon(
          select_y_mod(
            position['x'] + next_positions[next_position][0],
            position['y'] + next_positions[next_position][1]
          ),
          position['y'] + next_positions[next_position][1]
        );
        for(var hexagon in hexagons){
            if(hexagons[hexagon]['x'] === new_next_position['x']
              && hexagons[hexagon]['y'] === new_next_position['y']
              && hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
                match = true;
                break next_position_loop;
            }
        }
    }

    return match;
}

function conquer_hexagon(hexagon){
    if(hexagons[hexagon]['color'] !== players[player_ids[turn]]['color']){
        if(hexagons[hexagon]['color'] === settings_settings['default-color']
          || random_boolean()){
            var old_color = hexagons[hexagon]['color'];
            hexagons[hexagon]['color'] = players[player_ids[turn]]['color'];
            players[player_ids[turn]]['hexagons'] += 1;
            for(var player in players){
                if(old_color === players[player]['color']){
                    lose_hexagon(player);
                    break;
                }
            }
        }
    }
}

function create_hexagon(position, size){
    // Only create a hexagon if one doesn't already exist at this x,y.
    for(var hexagon in hexagons){
        if(hexagons[hexagon]['x'] === position['x']
          && hexagons[hexagon]['y'] === position['y']){
            return;
        }
    }

    hexagons.push({
      'color': settings_settings['default-color'],
      'size': size,
      'x': position['x'],
      'y': position['y'],
    });
}

function create_player(properties){
    properties = properties || {};
    properties = {
      'ai': properties['ai'] || false,
      'color': properties['color'] || random_hex(),
      'hexagons': 1,
      'name': '',
    };

    var hexagon = random_integer({
      'max': hexagons.length,
    });
    while(hexagons[hexagon]['color'] !== settings_settings['default-color']){
        hexagon = random_integer({
          'max': hexagons.length,
        });
    }
    hexagons[hexagon]['color'] = properties['color'];

    player_ids.push(player_count);
    properties['name'] = (properties['ai']
      ? 'AI'
      : 'P')
      + player_count;
    players[player_count] = properties;
    player_count += 1;
}

function draw_hexagon(x, y, size, color){
    if(y % 80){
        x += 23;
    }

    var vertices = [];
    for(var i = 0; i < 6; i++){
        var angle = math_degrees_to_radians({
          'degrees': 30 + i * 60,
        });
        vertices.push({
          'type': i === 0
            ? 'moveTo'
            : 'lineTo',
          'x': x + Math.cos(angle) * size + canvas_x,
          'y': y + Math.sin(angle) * size + canvas_y,
        });
    }
    canvas_draw_path({
      'properties': {
        'fillStyle': color,
      },
      'vertices': vertices,
    });
}

function draw_logic(){
    // Save the current buffer state.
    canvas_buffer.save();

    // Translate to camera position.
    canvas_buffer.translate(
      camera['x'],
      camera['y']
    );

    // Draw selection if not AI turn.
    if(!players[player_ids[turn]]['ai']){
        draw_hexagon(
          mouse_x,
          mouse_y,
          30,
          players[player_ids[turn]]['color']
        );
    }

    // Draw hexagons.
    for(var hexagon in hexagons){
        draw_hexagon(
          hexagons[hexagon]['x'],
          hexagons[hexagon]['y'],
          hexagons[hexagon]['size'],
          hexagons[hexagon]['color']
        );
    }

    // Restore the buffer state.
    canvas_buffer.restore();

    // Draw turn info.
    canvas_buffer.fillStyle = '#fff';
    canvas_buffer.fillText(
      'Turn #' + turns + ' ' + players[player_ids[turn]]['name'],
      0,
      25
    );

    if(player_count === 1){
        canvas_buffer.fillText(
          players[player_ids[turn]]['name'] + ' wins!',
          0,
          75
        );
    }

    var x = 50;
    for(var player in scoreboard){
        if(!players[scoreboard[player]['id']]){
            continue;
        }

        canvas_buffer.fillStyle = players[scoreboard[player]['id']]['color'];
        canvas_buffer.fillText(
          players[scoreboard[player]['id']]['name']  + ': ' + scoreboard[player]['hexagons'],
          0,
          x
        );
        x += 25;
    }
}

function end_turn(){
    if(turn >= player_ids.length - 1){
        turn = 0;

    }else{
        turn += 1;
    }

    turns += 1;

    if(!players[player_ids[turn]]){
        end_turn();
    }
}

function handle_ai_turn(){
    if(!players[player_ids[turn]]['ai']
      || scoreboard.length === 1){
        return;
    }

    var options = [];
    for(var hexagon in hexagons){
        if(hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
            continue;
        }

        if(check_neighbor_match({
          'x': hexagons[hexagon]['x'],
          'y': hexagons[hexagon]['y'],
        })){
            if(hexagons[hexagon]['color'] === settings_settings['default-color']){
                conquer_hexagon(hexagon);
                break;

            }else{
                options.push(hexagon);
            }
        }
    }
    if(options.length > 0){
        sort_random({
          'array': options,
        });
        scoreboard_loop:
        for(var i = scoreboard.length; i--;){
            if(!players[scoreboard[i]['id']]){
                continue;
            }

            for(var option in options){
                if(hexagons[options[option]]['color'] === players[scoreboard[i]['id']]['color']){
                    conquer_hexagon(options[option]);
                    break scoreboard_loop;
                }
            }
        }
    }

    end_turn();
}

function logic(){
    if(canvas_menu){
        return;
    }

    // Move camera down.
    if(key_down){
        camera['y'] -= settings_settings['scroll-speed'];
    }

    // Move camera left.
    if(key_left){
        camera['x'] += settings_settings['scroll-speed'];
    }

    // Move camera right.
    if(key_right){
        camera['x'] -= settings_settings['scroll-speed'];
    }

    // Move camera up.
    if(key_up){
        camera['y'] += settings_settings['scroll-speed'];
    }

    handle_ai_turn();
    update_scoreboard();
}

function lose_hexagon(player){
    players[player]['hexagons'] -= 1;
    if(players[player]['hexagons'] <= 0){
        delete players[player];
        player_count -= 1;
    }
}

function select_hexagon(x, y){
    return {
      'x': Math.ceil((x - 23) / 46) * 46,
      'y': Math.ceil((y - 20) / 40) * 40,
    };
}

function select_y_mod(x, y, move){
    move = move || -23;

    var y_mod = Math.abs(y % 80);
    if(y_mod > 20
      && y_mod < 60){
        x += move;
    }

    return x;
}

function setmode_logic(newgame){
    camera = {
      'x': 0,
      'y': 0,
    };
    hexagons = [];
    player_count = 0;
    player_ids = [];
    players = {};
    scoreboard = [];
    turn = 0;
    turns = 0;

    // Main menu mode.
    if(canvas_mode === 0){
        document.body.innerHTML = '

New Game

'
          + '

<input id=camera-keys maxlength=4>Camera ↑←↓→
'
          + '<input id=delete-player>Delete Player
'
          + '<input id=end-turn-key>End Turn
'
          + '<input disabled value=ESC>Menu

'
          + '
<input id=ai>AI
'
          + '<input id=default-color type=color>Default Color
'
          + '<input id=height>Height
'
          + '<input id=hexagons>Hexagons
'
          + '<input id=players>Players
'
          + '<input id=scroll-speed>Scroll Speed
'
          + '<input id=width>Width
'
          + 'Reset Settings

';
        settings_update();

    // New game mode.
    }else if(newgame){
        settings_save();

        key_down = false;
        key_left = false;
        key_right = false;
        key_up = false;
    }
}

function update_scoreboard(){
    scoreboard = [];
    for(var player in players){
        scoreboard.push({
          'hexagons': players[player]['hexagons'],
          'id': player,
        });
    }
    sort_property({
      'array': scoreboard,
      'reverse': true,
      'property': 'hexagons',
    });
}

var camera = {};
var hexagons = [];
var key_down = false;
var key_left = false;
var key_right = false;
var key_up = false;
var mouse_x = 0;
var mouse_y = 0;
var player_count = 0;
var player_ids = [];
var players = {};
var scoreboard = [];
var turn = 0;
var turns = 0;

window.onload = function(){
    settings_init({
      'prefix': 'Hexagons-2D.htm-',
      'settings': {
        'ai': 4,
        'camera-keys': 'WASD',
        'default-color': '#ffffff',
        'delete-player': 'P',
        'end-turn-key': 'H',
        'height': 500,
        'hexagons': 100,
        'players': 1,
        'scroll-speed': 5,
        'width': 500,
      },
    });
    canvas_init();

    window.onkeydown = function(e){
        if(canvas_mode <= 0){
            return;
        }

        var key = e.keyCode || e.which;

        // ESC: return to main menu.
        if(key === 27){
            canvas_menu_toggle();
            return;
        }

        key = String.fromCharCode(key);

        if(key === settings_settings['camera-keys'][1]){
            key_left = true;

        }else if(key === settings_settings['camera-keys'][3]){
            key_right = true;

        }else if(key === settings_settings['camera-keys'][2]){
            key_down = true;

        }else if(key === settings_settings['camera-keys'][0]){
            key_up = true;

        }else if(key === 'Q'){
            canvas_menu_quit();

        }else if(!players[player_ids[turn]]['ai']){
            if(key === settings_settings['end-turn-key']){
                end_turn();

            }else if(key === 'P'){
                if(player_count > 1){
                    for(var hexagon in hexagons){
                        if(!players[player_ids[turn]]){
                            break;
                        }
                        if(hexagons[hexagon]['color'] === players[player_ids[turn]]['color']){
                            hexagons[hexagon]['color'] = settings_settings['default-color'];
                            lose_hexagon(player_ids[turn]);
                        }
                    }
                    end_turn();
                }
            }
        }
    };

    window.onkeyup = function(e){
        var key = String.fromCharCode(e.keyCode || e.which);

        if(key === settings_settings['camera-keys'][1]){
            key_left = false;

        }else if(key === settings_settings['camera-keys'][3]){
            key_right = false;

        }else if(key === settings_settings['camera-keys'][2]){
            key_down = false;

        }else if(key === settings_settings['camera-keys'][0]){
            key_up = false;
        }
    };

    window.onmousedown = function(e){
        if(canvas_mode <= 0
          || players[player_ids[turn]]['ai']){
            return;
        }

        var position = select_hexagon(
          mouse_x,
          mouse_y
        );

        // Check if a hexagon exists at this location
        //   with a different color.
        var target = false;
        for(var hexagon in hexagons){
            if(hexagons[hexagon]['x'] === position['x']
              && hexagons[hexagon]['y'] === position['y']
              && hexagons[hexagon]['color'] !== players[player_ids[turn]]['color']){
                target = hexagon;
                break;
            }
        }
        if(target === false){
            return;
        }

        // Check if current player has a hexagon next to target hexagon.
        if(!check_neighbor_match({
          'x': hexagons[target]['x'],
          'y': hexagons[target]['y'],
        })){
            return;
        }

        // Attempt to conquer the hexagon.
        conquer_hexagon(hexagon);

        end_turn();
    };

    window.onmousemove = function(e){
        var x = e.pageX - canvas_x - camera['x'];
        var y = e.pageY - canvas_y - camera['y'];
        var position = select_hexagon(
          select_y_mod(
            x,
            y
          ),
          y
        );
        mouse_x = position['x'];
        mouse_y = position['y'];
    };
};
<|endoftext|>


<commit_before>(function($) {

	function Flip(config){
		var defaults = {
			tiles: {
				count: 30,
				margin: 2,
				spacing: 2
			}
		}

		// mash config with defaults
		this.config = $.extend(true, {}, defaults, config);

		this.init();
		this.calc();
		this.createTiles();
		this.fillTiles();

		this.config.$container.data("config", this.config).addClass("flip");

		// return to jQuery chain
		return this;
	}

	// figure out the stuff
	Flip.prototype.init = function(){
		this.config.width = this.config.$container.width();
		this.config.height = this.config.$container.height();

		this.config.tiles.width = Math.floor(this.config.width / this.config.tiles.count);
		this.config.tiles.halfHeight = Math.floor((this.config.height / 2) - 1);

		this.config.$container.append($("<span>").addClass("dyn"));
	}

	Flip.prototype.calc = function(){
		var emptyLength;

		this.config.number = this.config.number.toString()
		this.config.textLength = this.config.text.length;
		this.config.numberLength = this.config.number.length;

		// count empty tiles, round down to nearest even number
		emptyLength = Math.floor((this.config.tiles.count - this.config.textLength - this.config.numberLength - this.config.tiles.spacing) / 2);

		// determine where to place text, numbers
		this.config.textStart = emptyLength;
		this.config.numberStart = emptyLength + this.config.textLength + this.config.tiles.spacing;
	}

	Flip.prototype.createTiles = function(){
		this.config.$dyn = this.config.$container.find(".dyn");

		for(var tile = 0; tile < this.config.tiles.count; tile++){

			var $tile = $("<span>").addClass("tile").css({
				'width': this.config.tiles.width,
				'height': this.config.height,
				'padding-left': this.config.tiles.margin
			});
			var $top = $("<span>").addClass("top").css({
				'width': '100%',
				'height': this.config.tiles.halfHeight
			}).append($("<span>").css({
				'font-size': this.config.tiles.halfHeight * 1.6,
				'line-height': this.config.tiles.halfHeight * 2 + "px"
			}));

			var $bot = $("<span>").addClass("bot").css({
				'width': '100%',
				'height': this.config.tiles.halfHeight,
				'margin-top': this.config.tiles.spacing
			}).append($("<span>").css({
				'margin-top': this.config.tiles.halfHeight * -1,
				'font-size': this.config.tiles.halfHeight * 1.6,
				'line-height': this.config.tiles.halfHeight * 2 + "px"
			}));

			$tile.append($top).append($bot);

			this.config.$dyn.append($tile);

		}
		this.config.$container.append(this.config.$dyn.html());
	}

	Flip.prototype.fillTiles = function(){
		var $tiles = this.config.$dyn.find(".tile");

		for(var t = this.config.textStart; t < (this.config.textStart + this.config.textLength); t++){
			var $tile = $($tiles[t]);
			var $top = $tile.find(".top span");
			var $bot = $tile.find(".bot span");
			var text = this.config.text.charAt(t - this.config.textStart);

			$top.html(text);
			$bot.html(text);
			$tile.addClass("filled");
		}

		for(var n = this.config.numberStart; n < (this.config.numberStart + this.config.numberLength); n++){
			var $tile = $($tiles[n]);
			var $top = $tile.find(".top span");
			var $bot = $tile.find(".bot span");
			var text = this.config.number.charAt(n - this.config.numberStart);

			$top.html(text);
			$bot.html(text);
			$tile.addClass("filled");
		}
	}

	// for the jquery duh
	$.fn.flip = function(config){

		// add container to config
		config.$container = $(this);

		// instance
		var flip = new Flip(config);

		return this;

	}

})(jQuery);<commit_msg>define flip gap<commit_after>(function($) {

	function Flip(config){
		var defaults = {
			tiles: {
				count: 24,
				margin: 2,
				gap: 1,
				spacing: 2
			}
		}

		// mash config with defaults
		this.config = $.extend(true, {}, defaults, config);

		this.init();
		this.calc();
		this.createTiles();
		this.fillTiles();

		this.config.$container.data("config", this.config).addClass("flip");

		// return to jQuery chain
		return this;
	}

	// figure out the stuff
	Flip.prototype.init = function(){
		this.config.width = this.config.$container.width();
		this.config.height = this.config.$container.height();

		this.config.tiles.width = Math.floor(this.config.width / this.config.tiles.count);
		this.config.tiles.halfHeight = Math.floor((this.config.height / 2) - 1);

		this.config.$container.append($("<span>").addClass("dyn"));
	}

	Flip.prototype.calc = function(){
		var emptyLength;

		this.config.number = this.config.number.toString()
		this.config.textLength = this.config.text.length;
		this.config.numberLength = this.config.number.length;

		// count empty tiles, round down to nearest even number
		emptyLength = Math.floor((this.config.tiles.count - this.config.textLength - this.config.numberLength - this.config.tiles.spacing) / 2);

		// determine where to place text, numbers
		this.config.textStart = emptyLength;
		this.config.numberStart = emptyLength + this.config.textLength + this.config.tiles.spacing;
	}

	Flip.prototype.createTiles = function(){
		this.config.$dyn = this.config.$container.find(".dyn");

		for(var tile = 0; tile < this.config.tiles.count; tile++){

			var $tile = $("<span>").addClass("tile").css({
				'width': this.config.tiles.width,
				'height': this.config.height,
				'padding-left': this.config.tiles.margin
			});
			var $top = $("<span>").addClass("top").css({
				'width': '100%',
				'height': this.config.tiles.halfHeight
			}).append($("<span>").css({
				'font-size': this.config.tiles.halfHeight * 1.6,
				'line-height': this.config.tiles.halfHeight * 2 + "px"
			}));

			var $bot = $("<span>").addClass("bot").css({
				'width': '100%',
				'height': this.config.tiles.halfHeight,
				'margin-top': this.config.tiles.gap
			}).append($("<span>").css({
				'margin-top': this.config.tiles.halfHeight * -1,
				'font-size': this.config.tiles.halfHeight * 1.6,
				'line-height': this.config.tiles.halfHeight * 2 + "px"
			}));

			$tile.append($top).append($bot);

			this.config.$dyn.append($tile);

		}
		this.config.$container.append(this.config.$dyn.html());
	}

	Flip.prototype.fillTiles = function(){
		var $tiles = this.config.$dyn.find(".tile");

		for(var t = this.config.textStart; t < (this.config.textStart + this.config.textLength); t++){
			var $tile = $($tiles[t]);
			var $top = $tile.find(".top span");
			var $bot = $tile.find(".bot span");
			var text = this.config.text.charAt(t - this.config.textStart);

			$top.html(text);
			$bot.html(text);
			$tile.addClass("filled");
		}

		for(var n = this.config.numberStart; n < (this.config.numberStart + this.config.numberLength); n++){
			var $tile = $($tiles[n]);
			var $top = $tile.find(".top span");
			var $bot = $tile.find(".bot span");
			var text = this.config.number.charAt(n - this.config.numberStart);

			$top.html(text);
			$bot.html(text);
			$tile.addClass("filled");
		}
	}

	// for the jquery duh
	$.fn.flip = function(config){

		// add container to config
		config.$container = $(this);

		// instance
		var flip = new Flip(config);

		return this;

	}

})(jQuery);<|endoftext|>