What Happens When I Program Before Coffee

Started by
8 comments, last by SolDirix 10 years, 8 months ago

Quite often I will start coding something when I am not fully awake, and can end up with some interesting results.

Here is a code test I was working on some time ago - looking at it now, about 60% of the code is redundant.


<html>
<?php
class reasource{
#stone
   public $basic_stone = 0;
   public $building_stone = 0;
   public $sturdy_stone = 0;
   public $reinforced_stone = 0;
   public $fancy_stone = 0;
#wood
   public $rough_lumber = 0;
   public $smooth_lumber = 0;
   public $plank = 0;
   public $wooden_dowl = 0;
   public $wooden_strip = 0;
   public $fine_wooden_strip = 0;
   public $wooden_rod = 0;   
#food
   public $food_ration = 100;
   public $animal_feed = 0;
#magic
   public $red_energy_rune = 0;
   public $blue_energy_rune = 0;
   public $green_energy_rune = 0;
   public $black_energy_rune = 0;
   public $fine_oil = 0;
   public $raw_wool = 0;
   public $novic_battle_wand = 0;
   public $journeyman_battle_wand = 0;
   public $expert_battle_wand = 0;
#military
   public $armor_plate = 0;
   public $enchanted_armor_plate = 0;
   public $sword = 0;
   public $pike = 0;
   public $bow = 0;
   public $bow_string = 0;
   public $horse = 0;
#researcher
   public $paper = 0;
   public $ink = 0;
#engineer
   public $raw_iron = 0;
   public $coal_chunks = 0;
   public $iron_bar = 0;
   public $enchanted_iron_bar = 0;
   public $taned_leather = 0;
#spy
   public $dagger = 0;
   public $leather_armor = 0;
   public $poison = 0;
   public $sapper_tools = 0;
   }
class army{
#mod array(attack,defence)
   public $pit_fighter = 0;
   public $mod_pit_fighter = array(1,1);
   public $swordsman = 0;
   public $mod_swordsman = array(3,1);
   public $armored_swordsman = 0;
   public $mod_armored_swordsman = array(3,3);
   public $knight = 0;
   public $mod_knight = array(5,5);
   public $bowman = 0;
   public $mod_bowman = array(4,1);
   public $pikeman = 0;
   public $mod_pikeman = array(1,4);
   public $catapult = 0;
   public $mod_catapult = array(10,0);
   }
class engineer{
#mod array(modifier)
   public $tinker = 0;
   public $mod_tinker = array(1);
   public $novic_black_smith = 0;
   public $mod_novic_black_smith = array(2);
   public $journeyman_black_smith = 0;
   public $mod_journeyman_black_smith = array(5);
   public $expert_black_smith = 0;
   public $mod_expert_black_smith = array(10);
   public $novic_construction = 0;
   public $mod_novice_construction = array(2);
   public $journeyman_construction = 0;
   public $mod_journeyman_construction = array(5);
   public $expert_construction = 0;
   public $mod_expert_construction = array(10);
   }
class wizard{
#mod array(modifier)
   public $hedge_mage = 0;
   public $mod_hedge_mage = array(1);
   public $novic_red_mage = 0;
   public $mod_novic_mage = array(2);
   public $journeyman_mage = 0;
   public $mod_journeyman_mage = array(5);
   public $expert_mage = 0;
   public $mod_expert_mage = array(10);
   
   }
class spy{
#mod array(modifier)
   public $sneak = 0;
   public $mod_sneak = array(1);
   public $novic_spy = 0;
   public $mod_novic_spy = array(2);
   public $journeyman_spy = 0;
   public $mod_journeyman_spy = array(5);
   public $expert_spy = 0;
   public $mod_expert_spy = array(10);
   }
   
class buildings{
#mod array(attack,defence,land usage,modifier)
     public $village_house = 5;
	 public $mod_village_house = array(0,0,5,15);
	 public $dorm = 0;
	 public $mod_dorm = array(0,0,10,50);
	 public $apartment = 0;
	 public $mod_apartment = array(0,0,20,200);
	 public $barrack = 0;
	 public $mod_barrack = array(0,0,10,10);
	 public $army_base = 0;
	 public $mod_army_base = array(0,0,25,100);
     public $tower = 0;
	 public $mod_tower = array(0,0,10,10);
	 public $mage_tower = 0;
	 public $mod_mage_tower = array(0,0,25,100);
	 public $den = 0;
	 public $mod_den = array(0,0,10,10);
	 public $large_den = 0;
	 public $mod_large_den = array(0,0,25,100);
	 public $foundry = 0;
	 public $mod_foundry = array(0,0,10,10);
	 public $large_foundry = 0;
	 public $mod_large_foundry = array(0,0,25,30);
	 public $factory = 0;
	 public $mod_factory = array(0,0,10,10);
	 public $large_factory = 0;
	 public $mod_large_factory = array(0,0,25,30);
	 public $wall = 0;
	 public $mod_wall = array(0,1,5,0);
	 public $tall_wall = 0;
	 public $mod_tall_wall = array(0,5,10,0);
	 public $great_wall = 0;
	 public $mod_great_wall = array(0,12,25,0);
	 public $training_camp = 0;
	 public $mod_training_camp = array(0,0,10,10);
	 public $boot_camp = 0;
	 public $mod_boot_camp = array(0,0,25,30);
	 # functions
	 function get_building_ad(){
	    $x = 
		    ($this->$village_house * $this->$mod_village_house[0]) +
			($this->$dorm * $this->$mod_dorm[0]) +
		    ($this->$apartment * $this->$mod_apartment[0]) +
			($this->$barrack * $this->$mod_barrack[0]) +
			($this->$army_base * $this->$mod_army_base[0]) +
			($this->$tower * $this->$mod_tower[0]) +
			($this->$mage_tower * $this->$mod_mage_tower[0]) +
			($this->$den * $this->$mod_den[0]) +
			($this->$large_den * $this->$mod_large_den[0]) +
			($this->$foundry * $this->$mod_foundry[0]) +
			($this->$large_foundry * $this->$mod_large_foundry[0]) +
			($this->$factory * $this->$mod_factory[0]) +
			($this->$large_factory * $this->$mod_large_factory[0]) +
			($this->$wall * $this->$mod_wall[0]) +
			($this->$tall_wall * $this->$mod_tall_wall[0]) +
			($this->$great_wall * $this->$mod_great_wall[0]) +
			($this->$training_camp * $this->$mod_training_camp[0]) +
			($this->$boot_camp * $this->$mod_boot_camp[0]) ;
        $y =
		    ($this->$village_house * $this->$mod_village_house[1]) +
			($this->$dorm * $this->$mod_dorm[1]) +
		    ($this->$apartment * $this->$mod_apartment[1]) +
			($this->$barrack * $this->$mod_barrack[1]) +
			($this->$army_base * $this->$mod_army_base[1]) +
			($this->$tower * $this->$mod_tower[1]) +
			($this->$mage_tower * $this->$mod_mage_tower[1]) +
			($this->$den * $this->$mod_den[1]) +
			($this->$large_den * $this->$mod_large_den[1]) +
			($this->$foundry * $this->$mod_foundry[1]) +
			($this->$large_foundry * $this->$mod_large_foundry[1]) +
			($this->$factory * $this->$mod_factory[1]) +
			($this->$large_factory * $this->$mod_large_factory[1]) +
			($this->$wall * $this->$mod_wall[1]) +
			($this->$tall_wall * $this->$mod_tall_wall[1]) +
			($this->$great_wall * $this->$mod_great_wall[1]) +
			($this->$training_camp * $this->$mod_training_camp[1]) +
			($this->$boot_camp * $this->$mod_boot_camp[1]) ;
	    return arrray($x,$y);
		}
		function add_building($build,$amount){
		    if ($build == "village_house"){$this->$village_house += $amount;}
			if ($build == "dorm"){$this->$dorm += $amount;}
		    if ($build == "apartment"){$this->$apartment += $amount;}
			if ($build == "barrack"){$this->$barrack += $amount;}
			if ($build == "army_base"){$this->$army_base += $amount;}
			if ($build == "tower"){$this->$tower += $amount;}
			if ($build == "mage_tower"){$this->$mage_tower += $amount;}
			if ($build == "den"){$this->$den += $amount;}
			if ($build == "large_den"){$this->$large_den += $amount;}
			if ($build == "foundry"){$this->$foundry += $amount;}
			if ($build == "large_foundry"){$this->$large_foundry += $amount;}
			if ($build == "factory"){$this->$factory += $amount;}
			if ($build == "large_factory"){$this->$large_factory += $amount;}
			if ($build == "wall"){$this->$wall += $amount;}
			if ($build == "tall_wall"){$this->$tall_wall += $amount;}
			if ($build == "great_wall"){$this->$great_wall += $amount;}
			if ($build == "training_camp"){$this->$training_camp += $amount;}
			if ($build == "boot_camp"){$this->$boot_camp += $amount;}
		}
		function sub_building($build,$amount){
		    if ($build == "village_house"){$this->$village_house = abs($this->$village_house - $amount);}
			if ($build == "dorm"){$this->$dorm = abs($this->$dorm - $amount);}
		    if ($build == "apartment"){$this->$apartment = abs($this->$apartment - $amount);}
			if ($build == "barrack"){$this->$barrack = abs($this->$barrak - $amount);}
			if ($build == "army_base"){$this->$army_base = abs($this->$army_base - $amount);}
			if ($build == "tower"){$this->$tower = abs($this->$tower - $amount);}
			if ($build == "mage_tower"){$this->$mage_tower = abs($this->$mage_tower - $amount);}
			if ($build == "den"){$this->$den = abs($this->$den - $amount);}
			if ($build == "large_den"){$this->$large_den = abs($this->$large_den - $amount);}
			if ($build == "foundry"){$this->$foundry = abs($this->$foundry - $amount);}
			if ($build == "large_foundry"){$this->$large_foundry = abs($this->$large_foundry - $amount);}
			if ($build == "factory"){$this->$factory = abs($this->$factory - $amount);}
			if ($build == "large_factory"){$this->$large_factory = abs($this->$large_factory - $amount);}
			if ($build == "wall"){$this->$wall = abs($this->$$wall - $amount);}
			if ($build == "tall_wall"){$this->$tall_wall = abs($this->$tall_wall - $amount);}
			if ($build == "great_wall"){$this->$great_wall = abs($this->$great_wall - $amount);}
			if ($build == "training_camp"){$this->$training_camp = abs($this->$training_camp - $amount);}
			if ($build == "boot_camp"){$this->$boot_camp = abs($this->$boot_camp - $amount);}
		}
		function get_people_storage(){
		$x =
		    ($this->$village_house * $this->$mod_village_house[3]) +
	        ($this->$dorm * $this->$mod_dorm[3]) +
	        ($this->$apartment * $this->$mod_apartment[3]);
		return $x;
		}
		function get_army_storage(){
		$x =
		   ($this->$barrack * $this->$mod_barrack[3]) +
		   ($this->$army_base * $this->$mod_army_base[3]);
		return $x;
		}
		function get_mage_storage(){
		$x =
		   ($this->$tower * $this->$mod_tower[3]) +
		   ($this->$mage_tower * $this->$mod_mage_tower[3]);
		return $x;
		}
		function get_spy_storage(){
		$x =
		   ($this->$den * $this->$mod_den[3]) +
		   ($this->$large_den = $this->$mod_large_den[3]);
		return $x;
		}
	    }
class events{
   public $attract_villager = 86400;
   public $last_attract_villager = 0;
   public $import = 86400;
   public $last_import = 0;
   # functions
   function set_event_villager(){
   $this->$last_attract_villager = mktime() + $this->$attract_villager ;
   }
   function check_event_villager(){
   if (mktime() > $this->$last_attract_villager){
      return FALSE;
     }
   else{
      return TRUE;
     }
   }
   function set_event_import(){
   $this->$last_import = mktime() + $this->$attract_villager ;
   }
   function check_event_import(){
   if (mktime() > $this->$last_import){
      return FALSE;
     }
   else{
      return TRUE;
     }
   }
   }
   ?>
</html>

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

Advertisement

Is it sad that after a few years away from web development, I'm starting to consider writing software in PHP as the real WTF?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Is it sad that after a few years away from web development, I'm starting to consider writing software in PHP as the real WTF?

As opposed to .... ASP.NET? They've had a few cluster***ks themselves.

Beginner in Game Development?  Read here. And read here.

 


As opposed to .... ASP.NET? They've had a few cluster***ks themselves.

No, I'm kind of lumping all web technologies in the same boat here.

The joys of writing desktop software, in a high-level language, with a real debugger and profiler hooked into your IDE, is hard to overstate...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


As opposed to .... ASP.NET? They've had a few cluster***ks themselves.

No, I'm kind of lumping all web technologies in the same boat here.

The joys of writing desktop software, in a high-level language, with a real debugger and profiler hooked into your IDE, is hard to overstate...

Ah, yes. Then I agree. That is a WTF.

Beginner in Game Development?  Read here. And read here.

 

The joys of writing desktop software, in a high-level language, with a real debugger and profiler hooked into your IDE, is hard to overstate...

Or a not-so-high level language such as C++ IMO is much better - just as easy to use once you learn it but much more control.


As opposed to .... ASP.NET? They've had a few cluster***ks themselves.

No, I'm kind of lumping all web technologies in the same boat here.

The joys of writing desktop software, in a high-level language, with a real debugger and profiler hooked into your IDE, is hard to overstate...

Meh, Python with Django is pretty darn enjoyable, only thing i've found that comes close to being as enjoyable on the desktop side is QT.

PHP however is quite awful, it was only a good choice when the only real competior was ASP with VBScript. (The only reason to use it today is because its popular)

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

99% of all the host sites I have used ( that actually allow API ), have PHP and nothing else.

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

99% of all the host sites I have used ( that actually allow API ), have PHP and nothing else.

Pretty much all of them have perl, and CGI scripts (not that those are generally any better choices).

If you upgrade to a VPS, you can generally install pretty much whatever you want in the way of scripting languages. Windows servers for ASP.net tend to cost extra, but who'd want that anyway? ;)

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I don't drink coffee.

View my game dev blog here!

This topic is closed to new replies.

Advertisement