background preloader

Learning Projects

Facebook Twitter

Autofight - a PHP job interview task - Part 3 Page 2. Part 3, Page 2: EXTERMINATE This is Part 3 of the PHP Job Interview Task tutorial series.

Autofight - a PHP job interview task - Part 3 Page 2

See part 1 and part 2. For page one, see here. Units The Infantry The Infantry Unit is the basic and most common combat unit. Aside from the messages array (as described in part 2), we need to add a static getRarity method as well, so that a subclass can return its rarity (making it static on an abstract class would return the rarity of the abstract, which is not what we want).

Now we just need to define the act method as dictated by the Interface. This seems kind of bland and lame, though. Let's digest this line by line. Seeing as the method now has multiple possible actions, including shooting at a fellow soldier, we can expect to have to log an array of results. 0 will trigger a suicide upon which we reduce the health of $this to 0, meaning this soldier is instantly killed. Autofight - a PHP job interview task - Part 3. This is Part 3 of the PHP Job Interview Task tutorial series.

Autofight - a PHP job interview task - Part 3

See part 1 and part 2. In this final part of the Autofight basic series, we'll build the War class from which the battle will be managed, we'll make two different Unit classes and we'll construct a crude logger. It'll be another long post (two pages, actually), so grab a cup of your favorite beverage and join me in building your own mayhem. Logger I should start by saying I'm not happy with this implementation of the Logger. BattleResult Let's create a new PHP class in Classes/autofight called BattleResult.php This file is a simple class with no functionality - it's used as an object to carry the result of a Unit's "act". The Logger Interface We then create a file called BattleLogger.php in the Interfaces folder, and give it the following content: We first define several message types as constants we can later use to differentiate and style the messages on output.

The web logger. Autofight - a PHP job interview task - Part 2. This is Part 2 of the PHP Job Interview Task tutorial series.

Autofight - a PHP job interview task - Part 2

Part 1 is here. Just to whet your apetite furhter, here's a teaser of how the finished version actually performs in CLI mode. Now that we've got the skeleton classes in place and are vaguely familiar with the structure of our project, we can start fleshing it out. This tutorial is a little bit longer and more concrete in content, so grab a cup of your favorite beverage and roll up your sleeves. The Interface Let's start out with a basic Unit interface, and work our way up from that. Autofight - a PHP job interview task - Part 1. Part 1: Planning A while ago, I was measuring how much I'm worth in the world of web development in Croatia, and applied for a job.

Autofight - a PHP job interview task - Part 1

The way job interviews usually go is you need to do a task like making a substandard web app with a log-in interface, or add some asinine functionality to their already buggy and rusty Drupal/Wordpress website. This company, however, was different - their task consisted of barely two sentences: "Make two armies fight each other in PHP, and introduce an element of randomness". That was basically it. This was refreshing for two reasons: It was unusual and didn't sound boring.It allowed a display of creativity and embraced the developer's freedom - they wanted to see how a developer thinks, not how he can regurgitate other people's samples and rules. Initialization I rolled up my sleeves, made some coffee and got to thinking. Rules of development Rough structure The project was supposed to have two armies fight each other. Practical OOP: Building a Quiz App - Bootstrapping.

At a certain point of my development as a PHP programmer, I was building MVC applications by-the-book, without understanding the ins-and-outs.

Practical OOP: Building a Quiz App - Bootstrapping

I did what I was told: fat model, thin controller. Don’t put logic in your views. What I didn’t understand was how to create a cohesive application structure that allowed me to express my business ideas as maintainable code, nor did I understand how to really separate my concerns into tight layers without leaking low-level logic into higher layers. I’d heard about SOLID principles, but applying them to a web app was a mystery. In this series, we’ll build a quiz application using these concepts. Why MVC Isn’t Enough: MVC, which stands for Model-View-Controller, is a powerful design pattern for web applications. In building our quiz app, we’ll be using the Domain Model pattern described in Martin Fowler’s Patterns of Enterprise Application Architecture. The Service Layer Pattern: The Service Layer pattern addresses this problem. Getting Started: Social Network Style Posting with PHP, MongoDB and jQuery - part 1.

Post mechanisms similar to Facebook are nowadays very common within any application.

Social Network Style Posting with PHP, MongoDB and jQuery - part 1

The concept of Post-Like-Comment is familiar to everyone who ever used a social network. In this article, we will learn how to create a similar working model wherein the user will be able to post his status, like posts and comment on them. What’s more interesting is that after learning things from this article, going forward you will be able to implement a lot of other features on your own. I’ll be using PHP as the coding language, MongoDB as the database and jQuery for JavaScript operations. It is assumed the reader is familiar with the basics of PHP and MongoDB to understand the article thoroughly. There are two articles in this series. Before getting started, let us look at the final work we will develop (Fig 1 ). Download Code: Download the code provided with the article from its Github repo. Index.php : This is the main file which displays all the posts and from where the user will interact.